Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 450
- #extension GL_ARB_shading_language_include : require
- #extension GL_ARB_bindless_texture : require
- #include "/buffer_blocks.glsl"
- const uint g_UINT8_MAX = 0x000000FF;
- const uint g_UINT10_MAX = 0x000003FF;
- const float g_invUint8_max = 1.0 / float(g_UINT8_MAX);
- const float g_invUint10_max = 1.0 / float(g_UINT10_MAX);
- layout(location = 0) uniform int u_sourceLevel;
- layout(location = 1) uniform int u_textureIndex;
- layout(binding = 0, r32ui) uniform coherent uimage3D u_dstMip;
- U_VOXELHANDLE_BLOCK(4);
- void main()
- {
- ivec3 dstSize = imageSize(u_dstMip);
- uint x = gl_VertexID;
- uint z = gl_InstanceID;
- for(uint y = 0; y < dstSize.y; ++y)
- {
- ivec3 dstPos = ivec3(x, y, z);
- ivec3 srcPos = dstPos * 2;
- uint srcColor = texelFetch(u_voxelTexture[u_textureIndex], srcPos + ivec3(0, 0, 0), u_sourceLevel).r;
- srcColor += texelFetch(u_voxelTexture[u_textureIndex], srcPos + ivec3(1, 0, 0), u_sourceLevel).r;
- srcColor += texelFetch(u_voxelTexture[u_textureIndex], srcPos + ivec3(0, 1, 0), u_sourceLevel).r;
- srcColor += texelFetch(u_voxelTexture[u_textureIndex], srcPos + ivec3(1, 1, 0), u_sourceLevel).r;
- srcColor += texelFetch(u_voxelTexture[u_textureIndex], srcPos + ivec3(0, 0, 1), u_sourceLevel).r;
- srcColor += texelFetch(u_voxelTexture[u_textureIndex], srcPos + ivec3(1, 0, 1), u_sourceLevel).r;
- srcColor += texelFetch(u_voxelTexture[u_textureIndex], srcPos + ivec3(0, 1, 1), u_sourceLevel).r;
- srcColor += texelFetch(u_voxelTexture[u_textureIndex], srcPos + ivec3(1, 1, 1), u_sourceLevel).r;
- vec3 tmpColor;
- tmpColor.x = float(srcColor & g_UINT10_MAX);
- tmpColor.y = float((srcColor >> 10) & g_UINT10_MAX);
- tmpColor.z = float((srcColor >> 20) & g_UINT10_MAX);
- tmpColor = clamp(tmpColor, vec3(0.0), vec3(g_UINT10_MAX));
- tmpColor = tmpColor * g_invUint8_max / 8.0;
- tmpColor = round(tmpColor * g_UINT8_MAX);
- uint outColor = uint(tmpColor.x) | (uint(tmpColor.y) << 10) | (uint(tmpColor.z) << 20);
- imageStore(u_dstMip, dstPos, uvec4(outColor));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement