From 7f2096bcac04ef975982804d90afa3fe5e52bc9f Mon Sep 17 00:00:00 2001 From: ealrann Date: Thu, 2 May 2019 17:21:20 +0200 Subject: [PATCH] Minor optimization of board_to_pixel shader --- .../adapter/ConfigurationBufferLoader.java | 8 ++++---- .../src/main/resources/board_to_pixel.comp | 19 ++++++++++--------- .../main/resources/board_to_pixel.comp.spv | 4 ++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/adapter/ConfigurationBufferLoader.java b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/adapter/ConfigurationBufferLoader.java index b8d75ce5..8c55e129 100644 --- a/org.sheepy.vsand/src/main/java/org/sheepy/vsand/adapter/ConfigurationBufferLoader.java +++ b/org.sheepy.vsand/src/main/java/org/sheepy/vsand/adapter/ConfigurationBufferLoader.java @@ -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); } diff --git a/org.sheepy.vsand/src/main/resources/board_to_pixel.comp b/org.sheepy.vsand/src/main/resources/board_to_pixel.comp index 9160559c..000954ec 100644 --- a/org.sheepy.vsand/src/main/resources/board_to_pixel.comp +++ b/org.sheepy.vsand/src/main/resources/board_to_pixel.comp @@ -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() { @@ -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); } diff --git a/org.sheepy.vsand/src/main/resources/board_to_pixel.comp.spv b/org.sheepy.vsand/src/main/resources/board_to_pixel.comp.spv index a65d8a0e..2e0824fb 100644 --- a/org.sheepy.vsand/src/main/resources/board_to_pixel.comp.spv +++ b/org.sheepy.vsand/src/main/resources/board_to_pixel.comp.spv @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:de6fa4d80ab33081417b241e3f13f9a0c399e6fdf8fb5edd1c61ee002f3329f9 -size 3916 +oid sha256:72de1d0bd497fd7f430721d9ff329a449241d24fe9773f00cc765f42f8da6ae9 +size 4228