main
cosmonaut 2022-01-17 21:03:02 -08:00
parent accf424699
commit 112fafe9f3
10 changed files with 40 additions and 7 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
moonlibs/windows/Refresh.dll (Stored with Git LFS)

Binary file not shown.

View File

@ -3,9 +3,11 @@
layout(set = 1, binding = 0) uniform sampler2D uniformTexture; layout(set = 1, binding = 0) uniform sampler2D uniformTexture;
layout(location = 0) in vec2 fragCoord; layout(location = 0) in vec2 fragCoord;
layout(location = 1) in vec4 color;
layout(location = 0) out vec4 fragColor; layout(location = 0) out vec4 fragColor;
void main() void main()
{ {
fragColor = texture(uniformTexture, fragCoord); fragColor = texture(uniformTexture, fragCoord) * color;
} }

View File

@ -2,8 +2,10 @@
layout(location = 0) in vec3 inPosition; layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec2 inTexCoord; layout(location = 1) in vec2 inTexCoord;
layout(location = 2) in vec4 inColor;
layout(location = 0) out vec2 fragCoord; layout(location = 0) out vec2 fragCoord;
layout(location = 1) out vec4 color;
layout(set = 2, binding = 0) uniform UBO layout(set = 2, binding = 0) uniform UBO
{ {
@ -14,4 +16,5 @@ void main()
{ {
gl_Position = ubo.viewProjection * vec4(inPosition, 1.0); gl_Position = ubo.viewProjection * vec4(inPosition, 1.0);
fragCoord = inTexCoord; fragCoord = inTexCoord;
color = inColor;
} }

View File

@ -4,6 +4,7 @@ struct Vertex
{ {
vec3 position; vec3 position;
vec2 texcoord; vec2 texcoord;
vec4 color;
}; };
// Binding 0: vertices // Binding 0: vertices

View File

@ -82,27 +82,43 @@ namespace MoonWorksComputeSpriteBatch
CurrentSampler = sampler; 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.X = 0;
Vertices[VertexCount].position.Y = 0; Vertices[VertexCount].position.Y = 0;
Vertices[VertexCount].texcoord.X = sprite.Texcoord.X; Vertices[VertexCount].texcoord.X = sprite.Texcoord.X;
Vertices[VertexCount].texcoord.Y = sprite.Texcoord.Y; 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.X = sprite.Width;
Vertices[VertexCount + 1].position.Y = 0; Vertices[VertexCount + 1].position.Y = 0;
Vertices[VertexCount + 1].texcoord.X = sprite.Texcoord.X + sprite.Texcoord.W; Vertices[VertexCount + 1].texcoord.X = sprite.Texcoord.X + sprite.Texcoord.W;
Vertices[VertexCount + 1].texcoord.Y = sprite.Texcoord.Y; 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.X = 0;
Vertices[VertexCount + 2].position.Y = sprite.Height; Vertices[VertexCount + 2].position.Y = sprite.Height;
Vertices[VertexCount + 2].texcoord.X = sprite.Texcoord.X; Vertices[VertexCount + 2].texcoord.X = sprite.Texcoord.X;
Vertices[VertexCount + 2].texcoord.Y = sprite.Texcoord.Y + sprite.Texcoord.H; 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.X = sprite.Width;
Vertices[VertexCount + 3].position.Y = sprite.Height; Vertices[VertexCount + 3].position.Y = sprite.Height;
Vertices[VertexCount + 3].texcoord.X = sprite.Texcoord.X + sprite.Texcoord.W; 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].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; VertexCount += 4;

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using MoonWorks; using MoonWorks;
@ -124,7 +125,7 @@ namespace MoonWorksComputeSpriteBatch
} }
}; };
var vertexAttributes = new VertexAttribute[2] var vertexAttributes = new VertexAttribute[3]
{ {
new VertexAttribute new VertexAttribute
{ {
@ -139,6 +140,13 @@ namespace MoonWorksComputeSpriteBatch
Location = 1, Location = 1,
Format = VertexElementFormat.Vector2, Format = VertexElementFormat.Vector2,
Offset = (uint) Marshal.OffsetOf<VertexPositionTexcoord>("texcoord") 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) for (var i = 0; i < SPRITECOUNT; i += 1)
{ {
var transform = Matrix4x4.CreateTranslation(positions[i]); 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 }); spriteBatch.Flush(commandBuffer, mainRenderPass, mainFramebuffer, mainRenderArea, spritePipeline, new CameraUniforms { viewProjectionMatrix = viewProjection });

View File

@ -4,12 +4,14 @@ using System.Runtime.InteropServices;
namespace MoonWorksComputeSpriteBatch namespace MoonWorksComputeSpriteBatch
{ {
// SPIR-V requires vectors to not cross 16-byte boundaries // SPIR-V requires vectors to not cross 16-byte boundaries
[StructLayout(LayoutKind.Explicit, Size=32)] [StructLayout(LayoutKind.Explicit)]
public struct VertexPositionTexcoord public struct VertexPositionTexcoord
{ {
[FieldOffset(0)] [FieldOffset(0)]
public Vector3 position; public Vector3 position;
[FieldOffset(16)] [FieldOffset(16)]
public Vector2 texcoord; public Vector2 texcoord;
[FieldOffset(32)]
public Vector4 color;
} }
} }