colors
parent
accf424699
commit
112fafe9f3
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
moonlibs/windows/Refresh.dll (Stored with Git LFS)
BIN
moonlibs/windows/Refresh.dll (Stored with Git LFS)
Binary file not shown.
|
@ -3,9 +3,11 @@
|
|||
layout(set = 1, binding = 0) uniform sampler2D uniformTexture;
|
||||
|
||||
layout(location = 0) in vec2 fragCoord;
|
||||
layout(location = 1) in vec4 color;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragColor = texture(uniformTexture, fragCoord);
|
||||
fragColor = texture(uniformTexture, fragCoord) * color;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in vec2 inTexCoord;
|
||||
layout(location = 2) in vec4 inColor;
|
||||
|
||||
layout(location = 0) out vec2 fragCoord;
|
||||
layout(location = 1) out vec4 color;
|
||||
|
||||
layout(set = 2, binding = 0) uniform UBO
|
||||
{
|
||||
|
@ -14,4 +16,5 @@ void main()
|
|||
{
|
||||
gl_Position = ubo.viewProjection * vec4(inPosition, 1.0);
|
||||
fragCoord = inTexCoord;
|
||||
color = inColor;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ struct Vertex
|
|||
{
|
||||
vec3 position;
|
||||
vec2 texcoord;
|
||||
vec4 color;
|
||||
};
|
||||
|
||||
// Binding 0: vertices
|
||||
|
|
|
@ -82,27 +82,43 @@ namespace MoonWorksComputeSpriteBatch
|
|||
CurrentSampler = sampler;
|
||||
}
|
||||
|
||||
public void Add(Sprite sprite, Matrix4x4 transform)
|
||||
public void Add(Sprite sprite, Matrix4x4 transform, Color color)
|
||||
{
|
||||
Vertices[VertexCount].position.X = 0;
|
||||
Vertices[VertexCount].position.Y = 0;
|
||||
Vertices[VertexCount].texcoord.X = sprite.Texcoord.X;
|
||||
Vertices[VertexCount].texcoord.Y = sprite.Texcoord.Y;
|
||||
Vertices[VertexCount].color.X = color.R / 255f;
|
||||
Vertices[VertexCount].color.Y = color.G / 255f;
|
||||
Vertices[VertexCount].color.Z = color.B / 255f;
|
||||
Vertices[VertexCount].color.W = color.A / 255f;
|
||||
|
||||
Vertices[VertexCount + 1].position.X = sprite.Width;
|
||||
Vertices[VertexCount + 1].position.Y = 0;
|
||||
Vertices[VertexCount + 1].texcoord.X = sprite.Texcoord.X + sprite.Texcoord.W;
|
||||
Vertices[VertexCount + 1].texcoord.Y = sprite.Texcoord.Y;
|
||||
Vertices[VertexCount + 1].color.X = color.R / 255f;
|
||||
Vertices[VertexCount + 1].color.Y = color.G / 255f;
|
||||
Vertices[VertexCount + 1].color.Z = color.B / 255f;
|
||||
Vertices[VertexCount + 1].color.W = color.A / 255f;
|
||||
|
||||
Vertices[VertexCount + 2].position.X = 0;
|
||||
Vertices[VertexCount + 2].position.Y = sprite.Height;
|
||||
Vertices[VertexCount + 2].texcoord.X = sprite.Texcoord.X;
|
||||
Vertices[VertexCount + 2].texcoord.Y = sprite.Texcoord.Y + sprite.Texcoord.H;
|
||||
Vertices[VertexCount + 2].color.X = color.R / 255f;
|
||||
Vertices[VertexCount + 2].color.Y = color.G / 255f;
|
||||
Vertices[VertexCount + 2].color.Z = color.B / 255f;
|
||||
Vertices[VertexCount + 2].color.W = color.A / 255f;
|
||||
|
||||
Vertices[VertexCount + 3].position.X = sprite.Width;
|
||||
Vertices[VertexCount + 3].position.Y = sprite.Height;
|
||||
Vertices[VertexCount + 3].texcoord.X = sprite.Texcoord.X + sprite.Texcoord.W;
|
||||
Vertices[VertexCount + 3].texcoord.Y = sprite.Texcoord.Y + sprite.Texcoord.H;
|
||||
Vertices[VertexCount + 3].color.X = color.R / 255f;
|
||||
Vertices[VertexCount + 3].color.Y = color.G / 255f;
|
||||
Vertices[VertexCount + 3].color.Z = color.B / 255f;
|
||||
Vertices[VertexCount + 3].color.W = color.A / 255f;
|
||||
|
||||
VertexCount += 4;
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using MoonWorks;
|
||||
|
@ -124,7 +125,7 @@ namespace MoonWorksComputeSpriteBatch
|
|||
}
|
||||
};
|
||||
|
||||
var vertexAttributes = new VertexAttribute[2]
|
||||
var vertexAttributes = new VertexAttribute[3]
|
||||
{
|
||||
new VertexAttribute
|
||||
{
|
||||
|
@ -139,6 +140,13 @@ namespace MoonWorksComputeSpriteBatch
|
|||
Location = 1,
|
||||
Format = VertexElementFormat.Vector2,
|
||||
Offset = (uint) Marshal.OffsetOf<VertexPositionTexcoord>("texcoord")
|
||||
},
|
||||
new VertexAttribute
|
||||
{
|
||||
Binding = 0,
|
||||
Location = 2,
|
||||
Format = VertexElementFormat.Vector4,
|
||||
Offset = (uint) Marshal.OffsetOf<VertexPositionTexcoord>("color")
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -225,7 +233,8 @@ namespace MoonWorksComputeSpriteBatch
|
|||
for (var i = 0; i < SPRITECOUNT; i += 1)
|
||||
{
|
||||
var transform = Matrix4x4.CreateTranslation(positions[i]);
|
||||
spriteBatch.Add(new Sprite(new Rect { X = 0, Y = 0, W = 0, H = 0 }, 128, 128), transform);
|
||||
var color = new Color((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), 255f);
|
||||
spriteBatch.Add(new Sprite(new Rect { X = 0, Y = 0, W = 0, H = 0 }, 128, 128), transform, color);
|
||||
}
|
||||
|
||||
spriteBatch.Flush(commandBuffer, mainRenderPass, mainFramebuffer, mainRenderArea, spritePipeline, new CameraUniforms { viewProjectionMatrix = viewProjection });
|
||||
|
|
|
@ -4,12 +4,14 @@ using System.Runtime.InteropServices;
|
|||
namespace MoonWorksComputeSpriteBatch
|
||||
{
|
||||
// SPIR-V requires vectors to not cross 16-byte boundaries
|
||||
[StructLayout(LayoutKind.Explicit, Size=32)]
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct VertexPositionTexcoord
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public Vector3 position;
|
||||
[FieldOffset(16)]
|
||||
public Vector2 texcoord;
|
||||
[FieldOffset(32)]
|
||||
public Vector4 color;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue