Skip to content

Commit

Permalink
Minor optimization of board_to_pixel shader
Browse files Browse the repository at this point in the history
  • Loading branch information
Ealrann committed May 2, 2019
1 parent 941ab54 commit 7f2096b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ public ConfigurationBufferLoader(Buffer buffer)
super(buffer);
buffer.setSize(BYTE_SIZE);

var application = (VSandApplication) EcoreUtil.getRootContainer(buffer);
final var application = (VSandApplication) EcoreUtil.getRootContainer(buffer);

ByteBuffer bBuffer = MemoryUtil.memAlloc(BYTE_SIZE);
for (Material material : application.getMaterials().getMaterials())
final ByteBuffer bBuffer = MemoryUtil.memAlloc(BYTE_SIZE);
for (final Material material : application.getMaterials().getMaterials())
{
bBuffer.putInt(material.isIsStatic() ? 1 : 0);
bBuffer.putInt(material.getDensity());
bBuffer.putInt(material.getRunoff());

int rgb = material.getR() << 16 | material.getG() << 8 | material.getB();
final int rgb = material.getR() | material.getG() << 8 | material.getB() << 16;

bBuffer.putInt(rgb);
}
Expand Down
19 changes: 10 additions & 9 deletions org.sheepy.vsand/src/main/resources/board_to_pixel.comp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ layout(rgba8, binding = 2) uniform image2D outImage;

const uint G_MASK = 255 << 8;
const uint B_MASK = 255;
const vec4 DEBUG_COLOR = vec4(1.0, 0.5, 0.5, 0.0);

void main()
{
Expand All @@ -56,17 +57,17 @@ void main()
{
if(pushConstants.showSleepChunks == 1)
{
imageStore(outImage, ivec2(gl_GlobalInvocationID.xy), vec4(1.0, 0.5, 0.5, 0.0));
uint index = board.data[gl_GlobalInvocationID.x][gl_GlobalInvocationID.y];
Entry material = configuration.materials[index];
vec4 color = unpackUnorm4x8(material.rgb) / 4;
color.r = 0.0;
imageStore(outImage, ivec2(gl_GlobalInvocationID.xy), DEBUG_COLOR + color);
}
return;
}

Entry material =
configuration.materials[board.data[gl_GlobalInvocationID.x][gl_GlobalInvocationID.y]];

float r = (material.rgb >> 16) / 255.;
float g = ((material.rgb & G_MASK) >> 8) / 255.;
float b = (material.rgb & B_MASK) / 255.;

imageStore(outImage, ivec2(gl_GlobalInvocationID.xy), vec4(r, g, b, 0.0));
uint index = board.data[gl_GlobalInvocationID.x][gl_GlobalInvocationID.y];
Entry material = configuration.materials[index];
vec4 color = unpackUnorm4x8(material.rgb);
imageStore(outImage, ivec2(gl_GlobalInvocationID.xy), color);
}
4 changes: 2 additions & 2 deletions org.sheepy.vsand/src/main/resources/board_to_pixel.comp.spv
Git LFS file not shown

0 comments on commit 7f2096b

Please sign in to comment.