diff --git a/examples/37-gpudrivenrendering/cs_gdr_occlude_props.sc b/examples/37-gpudrivenrendering/cs_gdr_occlude_props.sc index 76fa534c8..aced7da3c 100644 --- a/examples/37-gpudrivenrendering/cs_gdr_occlude_props.sc +++ b/examples/37-gpudrivenrendering/cs_gdr_occlude_props.sc @@ -84,11 +84,13 @@ void main() mip = level_lower; //load depths from high z buffer - vec4 depth = { texture2DLod(s_texOcclusionDepth, boxUVs.xy, mip).x, - texture2DLod(s_texOcclusionDepth, boxUVs.zy, mip).x, - texture2DLod(s_texOcclusionDepth, boxUVs.xw, mip).x, - texture2DLod(s_texOcclusionDepth, boxUVs.zw, mip).x, - }; + vec4 depth = + { + texture2DLod(s_texOcclusionDepth, boxUVs.xy, mip).x, + texture2DLod(s_texOcclusionDepth, boxUVs.zy, mip).x, + texture2DLod(s_texOcclusionDepth, boxUVs.xw, mip).x, + texture2DLod(s_texOcclusionDepth, boxUVs.zw, mip).x, + }; //find the max depth float maxDepth = max( max(depth.x, depth.y), max(depth.z, depth.w) ); diff --git a/examples/37-gpudrivenrendering/fs_gdr_instanced_indirect_rendering.sc b/examples/37-gpudrivenrendering/fs_gdr_instanced_indirect_rendering.sc index b638de1b0..14f484991 100644 --- a/examples/37-gpudrivenrendering/fs_gdr_instanced_indirect_rendering.sc +++ b/examples/37-gpudrivenrendering/fs_gdr_instanced_indirect_rendering.sc @@ -7,18 +7,20 @@ $input v_materialID #include "../common/common.sh" -uniform vec4 u_colour[50]; +uniform vec4 u_color[32]; void main() { - vec4 colour = u_colour[uint(v_materialID)]; + vec4 color = u_color[uint(v_materialID)]; - if ( colour.w < 1.0f ) + if (color.w < 1.0f) { //render dithered alpha if ( (int(gl_FragCoord.x) % 2) == (int(gl_FragCoord.y) % 2) ) + { discard; + } } - gl_FragColor = vec4( colour.xyz,1 ); + gl_FragColor = vec4(color.xyz, 1.0); } diff --git a/examples/37-gpudrivenrendering/gpudrivenrendering.cpp b/examples/37-gpudrivenrendering/gpudrivenrendering.cpp index 1a0e2ad5d..b1382d7e7 100644 --- a/examples/37-gpudrivenrendering/gpudrivenrendering.cpp +++ b/examples/37-gpudrivenrendering/gpudrivenrendering.cpp @@ -353,10 +353,10 @@ struct Prop RenderPass::Enum m_renderPass; }; -//A simplistic material, comprised of a colour only +//A simplistic material, comprised of a color only struct Material { - float m_colour[4]; + float m_color[4]; }; inline void setVector4(float* dest, float x, float y, float z, float w) @@ -419,10 +419,11 @@ public: // Enable debug text. bgfx::setDebug(m_debug); - //create uniforms - u_inputRTSize = bgfx::createUniform("u_inputRTSize", bgfx::UniformType::Vec4); - u_cullingConfig = bgfx::createUniform("u_cullingConfig", bgfx::UniformType::Vec4); - u_colour = bgfx::createUniform("u_colour", bgfx::UniformType::Vec4); + // Create uniforms and samplers. + u_inputRTSize = bgfx::createUniform("u_inputRTSize", bgfx::UniformType::Vec4); + u_cullingConfig = bgfx::createUniform("u_cullingConfig", bgfx::UniformType::Vec4); + u_color = bgfx::createUniform("u_color", bgfx::UniformType::Vec4, 32); + s_texOcclusionDepth = bgfx::createUniform("s_texOcclusionDepth", bgfx::UniformType::Int1); //create props { @@ -464,7 +465,7 @@ public: bx::vec4MulMtx(prop.m_instances->m_bboxMax, temp, prop.m_instances->m_world); prop.m_materialID = m_noofMaterials; - setVector4(m_materials[prop.m_materialID].m_colour, 0.0f, 0.6f, 0.0f, 1.0f); + setVector4(m_materials[prop.m_materialID].m_color, 0.0f, 0.6f, 0.0f, 1.0f); m_noofMaterials++; m_totalInstancesCount += prop.m_noofInstances; @@ -504,7 +505,7 @@ public: prop.m_materialID = m_noofMaterials; //add a "material" for this prop - setVector4(m_materials[prop.m_materialID].m_colour, 0.0f, 0.0f, 1.0f, 0.0f); + setVector4(m_materials[prop.m_materialID].m_color, 0.0f, 0.0f, 1.0f, 0.0f); m_noofMaterials++; m_totalInstancesCount += prop.m_noofInstances; @@ -539,7 +540,7 @@ public: } prop.m_materialID = m_noofMaterials; - setVector4(m_materials[prop.m_materialID].m_colour, 1.0f, 1.0f, 0.0f, 1.0f); + setVector4(m_materials[prop.m_materialID].m_color, 1.0f, 1.0f, 0.0f, 1.0f); m_noofMaterials++; m_totalInstancesCount += prop.m_noofInstances; @@ -572,7 +573,7 @@ public: } prop.m_materialID = m_noofMaterials; - setVector4(m_materials[prop.m_materialID].m_colour, 1.0f, 0.0f, 0.0f, 1.0f); + setVector4(m_materials[prop.m_materialID].m_color, 1.0f, 0.0f, 0.0f, 1.0f); m_noofMaterials++; m_totalInstancesCount += prop.m_noofInstances; @@ -773,9 +774,6 @@ public: BGFX_BUFFER_COMPUTE_READ | BGFX_BUFFER_INDEX32 ); - //create samplers - s_texOcclusionDepthIn = bgfx::createUniform("s_texOcclusionDepthIn", bgfx::UniformType::Int1); - m_timeOffset = bx::getHPCounter(); m_useIndirect = true; @@ -822,10 +820,10 @@ public: bgfx::destroy(m_allPropsVertexbufferHandle); bgfx::destroy(m_allPropsIndexbufferHandle); - bgfx::destroy(s_texOcclusionDepthIn); + bgfx::destroy(s_texOcclusionDepth); bgfx::destroy(u_inputRTSize); bgfx::destroy(u_cullingConfig); - bgfx::destroy(u_colour); + bgfx::destroy(u_color); delete[] m_allPropVerticesDataCPU; delete[] m_allPropIndicesDataCPU; @@ -930,7 +928,7 @@ public: void renderOccludePropsPass() { // run the computer shader to determine visibility of each instance - bgfx::setImage(0, bgfx::getTexture(m_hiZBuffer, 0), 0, bgfx::Access::Read); + bgfx::setTexture(0, s_texOcclusionDepth, bgfx::getTexture(m_hiZBuffer, 0) ); bgfx::setBuffer(1, m_instanceBoundingBoxes, bgfx::Access::Read); bgfx::setBuffer(2, m_drawcallInstanceCounts, bgfx::Access::ReadWrite); @@ -1008,8 +1006,8 @@ public: const uint16_t instanceStride = sizeof(InstanceData); - // Set "material" data (currently a colour only) - bgfx::setUniform(u_colour, &m_materials[0].m_colour, m_noofMaterials); + // Set "material" data (currently a color only) + bgfx::setUniform(u_color, &m_materials[0].m_color, m_noofMaterials); if (m_useIndirect) { @@ -1205,10 +1203,10 @@ public: bgfx::VertexBufferHandle m_instanceBuffer; bgfx::DynamicVertexBufferHandle m_culledInstanceBuffer; - bgfx::UniformHandle s_texOcclusionDepthIn; + bgfx::UniformHandle s_texOcclusionDepth; bgfx::UniformHandle u_inputRTSize; bgfx::UniformHandle u_cullingConfig; - bgfx::UniformHandle u_colour; + bgfx::UniformHandle u_color; Prop* m_props; Material* m_materials; diff --git a/examples/runtime/shaders/dx11/fs_gdr_instanced_indirect_rendering.bin b/examples/runtime/shaders/dx11/fs_gdr_instanced_indirect_rendering.bin index 20ad526f7..7d3b633a9 100644 Binary files a/examples/runtime/shaders/dx11/fs_gdr_instanced_indirect_rendering.bin and b/examples/runtime/shaders/dx11/fs_gdr_instanced_indirect_rendering.bin differ diff --git a/examples/runtime/shaders/glsl/cs_gdr_occlude_props.bin b/examples/runtime/shaders/glsl/cs_gdr_occlude_props.bin index fef97341e..e775dd91e 100644 Binary files a/examples/runtime/shaders/glsl/cs_gdr_occlude_props.bin and b/examples/runtime/shaders/glsl/cs_gdr_occlude_props.bin differ diff --git a/examples/runtime/shaders/glsl/fs_gdr_instanced_indirect_rendering.bin b/examples/runtime/shaders/glsl/fs_gdr_instanced_indirect_rendering.bin index 4ee108850..a60877da5 100644 Binary files a/examples/runtime/shaders/glsl/fs_gdr_instanced_indirect_rendering.bin and b/examples/runtime/shaders/glsl/fs_gdr_instanced_indirect_rendering.bin differ diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 1db67993e..e924c0ea9 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -6819,16 +6819,24 @@ namespace bgfx { namespace gl case Binding::Image: { - const TextureGL& texture = m_textures[bind.m_idx]; - GL_CHECK(glBindImageTexture(ii - , texture.m_id - , bind.m_un.m_compute.m_mip - , texture.isCubeMap() ? GL_TRUE : GL_FALSE - , 0 - , s_access[bind.m_un.m_compute.m_access] - , s_imageFormat[bind.m_un.m_compute.m_format]) - ); - barrier |= GL_SHADER_IMAGE_ACCESS_BARRIER_BIT; + if (Access::Read == bind.m_un.m_compute.m_access) + { + TextureGL& texture = m_textures[bind.m_idx]; + texture.commit(ii, texture.m_flags, _render->m_colorPalette); + } + else + { + const TextureGL& texture = m_textures[bind.m_idx]; + GL_CHECK(glBindImageTexture(ii + , texture.m_id + , bind.m_un.m_compute.m_mip + , texture.isCubeMap() ? GL_TRUE : GL_FALSE + , 0 + , s_access[bind.m_un.m_compute.m_access] + , s_imageFormat[bind.m_un.m_compute.m_format]) + ); + barrier |= GL_SHADER_IMAGE_ACCESS_BARRIER_BIT; + } } break;