diff --git a/examples/12-lod/fs_tree.sc b/examples/12-lod/fs_tree.sc index 4ff3b4805..0a80e71c4 100644 --- a/examples/12-lod/fs_tree.sc +++ b/examples/12-lod/fs_tree.sc @@ -7,8 +7,8 @@ $input v_pos, v_view, v_normal, v_texcoord0 #include "../common/common.sh" -SAMPLER2D(u_texColor, 0); -SAMPLER2D(u_texStipple, 1); +SAMPLER2D(s_texColor, 0); +SAMPLER2D(s_texStipple, 1); uniform vec4 u_stipple; vec2 blinn(vec3 _lightDir, vec3 _normal, vec3 _viewDir) @@ -23,8 +23,8 @@ void main() { vec2 viewport = (u_viewRect.zw - u_viewRect.xy) * vec2(1.0/8.0, 1.0/4.0); vec2 stippleUV = viewport*(v_pos.xy*0.5 + 0.5); - vec4 color = texture2D(u_texColor, v_texcoord0); - if ( (u_stipple.x - texture2D(u_texStipple,stippleUV).x)*u_stipple.y > u_stipple.z + vec4 color = texture2D(s_texColor, v_texcoord0); + if ( (u_stipple.x - texture2D(s_texStipple,stippleUV).x)*u_stipple.y > u_stipple.z || color.w < 0.5) { discard; diff --git a/examples/12-lod/lod.cpp b/examples/12-lod/lod.cpp index 931f64305..9c69c69e9 100644 --- a/examples/12-lod/lod.cpp +++ b/examples/12-lod/lod.cpp @@ -15,7 +15,7 @@ struct KnightPos int32_t m_y; }; -KnightPos knightTour[8*4] = +static const KnightPos knightTour[8*4] = { {0,0}, {1,2}, {3,3}, {4,1}, {5,3}, {7,2}, {6,0}, {5,2}, {7,3}, {6,1}, {4,0}, {3,2}, {2,0}, {0,1}, {1,3}, {2,1}, @@ -23,275 +23,298 @@ KnightPos knightTour[8*4] = {7,1}, {6,3}, {5,1}, {7,0}, {6,2}, {4,3}, {3,1}, {2,3}, }; -int _main_(int _argc, char** _argv) +class Lod : public entry::AppI { - Args args(_argc, _argv); - - uint32_t width = 1280; - uint32_t height = 720; - uint32_t debug = BGFX_DEBUG_TEXT; - uint32_t reset = BGFX_RESET_VSYNC; - - bgfx::init(args.m_type, args.m_pciId); - bgfx::reset(width, height, reset); - - // Enable debug text. - bgfx::setDebug(debug); - - // Set view 0 clear state. - bgfx::setViewClear(0 - , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH - , 0x303030ff - , 1.0f - , 0 - ); - - bgfx::UniformHandle s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Int1); - bgfx::UniformHandle s_texStipple = bgfx::createUniform("s_texStipple", bgfx::UniformType::Int1); - bgfx::UniformHandle u_stipple = bgfx::createUniform("u_stipple", bgfx::UniformType::Vec4); - - bgfx::ProgramHandle program = loadProgram("vs_tree", "fs_tree"); - - bgfx::TextureHandle textureLeafs = loadTexture("leafs1.dds"); - bgfx::TextureHandle textureBark = loadTexture("bark1.dds"); - - bgfx::TextureHandle textureStipple; - - const bgfx::Memory* stippleTex = bgfx::alloc(8*4); - memset(stippleTex->data, 0, stippleTex->size); - - for (uint32_t ii = 0; ii < 32; ++ii) + void init(int _argc, char** _argv) BX_OVERRIDE { - stippleTex->data[knightTour[ii].m_y * 8 + knightTour[ii].m_x] = ii*4; - } + Args args(_argc, _argv); - textureStipple = bgfx::createTexture2D(8, 4, 1 + m_width = 1280; + m_height = 720; + m_debug = BGFX_DEBUG_TEXT; + m_reset = BGFX_RESET_VSYNC; + + bgfx::init(args.m_type, args.m_pciId); + bgfx::reset(m_width, m_height, m_reset); + + // Enable debug text. + bgfx::setDebug(m_debug); + + // Set view 0 clear state. + bgfx::setViewClear(0 + , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH + , 0x303030ff + , 1.0f + , 0 + ); + + s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Int1); + s_texStipple = bgfx::createUniform("s_texStipple", bgfx::UniformType::Int1); + u_stipple = bgfx::createUniform("u_stipple", bgfx::UniformType::Vec4); + + m_program = loadProgram("vs_tree", "fs_tree"); + + m_textureLeafs = loadTexture("leafs1.dds"); + m_textureBark = loadTexture("bark1.dds"); + + const bgfx::Memory* stippleTex = bgfx::alloc(8*4); + memset(stippleTex->data, 0, stippleTex->size); + + for (uint32_t ii = 0; ii < 32; ++ii) + { + stippleTex->data[knightTour[ii].m_y * 8 + knightTour[ii].m_x] = ii*4; + } + + m_textureStipple = bgfx::createTexture2D(8, 4, 1 , bgfx::TextureFormat::R8 , BGFX_TEXTURE_MAG_POINT|BGFX_TEXTURE_MIN_POINT , stippleTex ); - Mesh* meshTop[3] = + m_meshTop[0] = meshLoad("meshes/tree1b_lod0_1.bin"); + m_meshTop[1] = meshLoad("meshes/tree1b_lod1_1.bin"); + m_meshTop[2] = meshLoad("meshes/tree1b_lod2_1.bin"); + + m_meshTrunk[0] = meshLoad("meshes/tree1b_lod0_2.bin"); + m_meshTrunk[1] = meshLoad("meshes/tree1b_lod1_2.bin"); + m_meshTrunk[2] = meshLoad("meshes/tree1b_lod2_2.bin"); + + // Imgui. + imguiCreate(); + + m_scrollArea = 0; + m_transitions = true; + + m_transitionFrame = 0; + m_currLod = 0; + m_targetLod = 0; + } + + virtual int shutdown() BX_OVERRIDE { - meshLoad("meshes/tree1b_lod0_1.bin"), - meshLoad("meshes/tree1b_lod1_1.bin"), - meshLoad("meshes/tree1b_lod2_1.bin"), - }; + imguiDestroy(); - Mesh* meshTrunk[3] = + for (uint32_t ii = 0; ii < BX_COUNTOF(m_meshTop); ++ii) + { + meshUnload(m_meshTop[ii]); + meshUnload(m_meshTrunk[ii]); + } + + // Cleanup. + bgfx::destroyProgram(m_program); + + bgfx::destroyUniform(s_texColor); + bgfx::destroyUniform(s_texStipple); + bgfx::destroyUniform(u_stipple); + + bgfx::destroyTexture(m_textureStipple); + bgfx::destroyTexture(m_textureLeafs); + bgfx::destroyTexture(m_textureBark); + + // Shutdown bgfx. + bgfx::shutdown(); + + return 0; + } + + bool update() BX_OVERRIDE { - meshLoad("meshes/tree1b_lod0_2.bin"), - meshLoad("meshes/tree1b_lod1_2.bin"), - meshLoad("meshes/tree1b_lod2_2.bin"), - }; - - // Imgui. - imguiCreate(); - - const uint64_t stateCommon = 0 - | BGFX_STATE_RGB_WRITE - | BGFX_STATE_ALPHA_WRITE - | BGFX_STATE_DEPTH_TEST_LESS - | BGFX_STATE_CULL_CCW - | BGFX_STATE_MSAA - ; - - const uint64_t stateTransparent = stateCommon - | BGFX_STATE_BLEND_ALPHA - ; - - const uint64_t stateOpaque = stateCommon - | BGFX_STATE_DEPTH_WRITE - ; - - int32_t scrollArea = 0; - - bool transitions = true; - int transitionFrame = 0; - int currLOD = 0; - int targetLOD = 0; - - float at[3] = { 0.0f, 1.0f, 0.0f }; - float eye[3] = { 0.0f, 1.0f, -2.0f }; - - entry::MouseState mouseState; - while (!entry::processEvents(width, height, debug, reset, &mouseState) ) - { - imguiBeginFrame(mouseState.m_mx - , mouseState.m_my - , (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) - | (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) - | (mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0) - , mouseState.m_mz - , width - , height - ); - - imguiBeginScrollArea("Toggle transitions", width - width / 5 - 10, 10, width / 5, height / 6, &scrollArea); - imguiSeparatorLine(); - - if (imguiButton(transitions ? "ON" : "OFF") ) + if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) ) { - transitions = !transitions; - } + imguiBeginFrame(m_mouseState.m_mx + , m_mouseState.m_my + , (m_mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) + | (m_mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) + | (m_mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0) + , m_mouseState.m_mz + , m_width + , m_height + ); - static float distance = 2.0f; - imguiSlider("Distance", distance, 2.0f, 6.0f, .01f); + imguiBeginScrollArea("Toggle m_transitions", m_width - m_width / 5 - 10, 10, m_width / 5, m_height / 6, &m_scrollArea); + imguiSeparatorLine(); - imguiEndScrollArea(); - imguiEndFrame(); - - // Set view 0 default viewport. - bgfx::setViewRect(0, 0, 0, width, height); - - // This dummy draw call is here to make sure that view 0 is cleared - // if no other draw calls are submitted to view 0. - bgfx::touch(0); - - int64_t now = bx::getHPCounter(); - static int64_t last = now; - const int64_t frameTime = now - last; - last = now; - const double freq = double(bx::getHPFrequency() ); - const double toMs = 1000.0/freq; - - // Use debug font to print information about this example. - bgfx::dbgTextClear(); - bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/12-lod"); - bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Mesh LOD transitions."); - bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs); - bgfx::dbgTextPrintf(0, 4, transitions ? 0x2f : 0x1f, transitions ? "Transitions on" : "Transitions off"); - - eye[2] = -distance; - - // Set view and projection matrix for view 0. - const bgfx::HMD* hmd = bgfx::getHMD(); - if (NULL != hmd && 0 != (hmd->flags & BGFX_HMD_RENDERING) ) - { - float view[16]; - bx::mtxQuatTranslationHMD(view, hmd->eye[0].rotation, eye); - - float proj[16]; - bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 100.0f); - - bgfx::setViewTransform(0, view, proj); - - // Set view 0 default viewport. - // - // Use HMD's width/height since HMD's internal frame buffer size - // might be much larger than window size. - bgfx::setViewRect(0, 0, 0, hmd->width, hmd->height); - } - else - { - float view[16]; - bx::mtxLookAt(view, eye, at); - - float proj[16]; - bx::mtxProj(proj, 60.0f, float(width)/float(height), 0.1f, 100.0f); - bgfx::setViewTransform(0, view, proj); - - // Set view 0 default viewport. - bgfx::setViewRect(0, 0, 0, width, height); - } - - float mtx[16]; - bx::mtxScale(mtx, 0.1f, 0.1f, 0.1f); - - float stipple[3]; - float stippleInv[3]; - - const int currentLODframe = transitions ? 32-transitionFrame : 32; - const int mainLOD = transitions ? currLOD : targetLOD; - - stipple[0] = 0.0f; - stipple[1] = -1.0f; - stipple[2] = (float(currentLODframe)*4.0f/255.0f) - (1.0f/255.0f); - - stippleInv[0] = (float(31)*4.0f/255.0f); - stippleInv[1] = 1.0f; - stippleInv[2] = (float(transitionFrame)*4.0f/255.0f) - (1.0f/255.0f); - - bgfx::setTexture(0, s_texColor, textureBark); - bgfx::setTexture(1, s_texStipple, textureStipple); - bgfx::setUniform(u_stipple, stipple); - meshSubmit(meshTrunk[mainLOD], 0, program, mtx, stateOpaque); - - bgfx::setTexture(0, s_texColor, textureLeafs); - bgfx::setTexture(1, s_texStipple, textureStipple); - bgfx::setUniform(u_stipple, stipple); - meshSubmit(meshTop[mainLOD], 0, program, mtx, stateTransparent); - - if (transitions - && (transitionFrame != 0) ) - { - bgfx::setTexture(0, s_texColor, textureBark); - bgfx::setTexture(1, s_texStipple, textureStipple); - bgfx::setUniform(u_stipple, stippleInv); - meshSubmit(meshTrunk[targetLOD], 0, program, mtx, stateOpaque); - - bgfx::setTexture(0, s_texColor, textureLeafs); - bgfx::setTexture(1, s_texStipple, textureStipple); - bgfx::setUniform(u_stipple, stippleInv); - meshSubmit(meshTop[targetLOD], 0, program, mtx, stateTransparent); - } - - int lod = 0; - if (eye[2] < -2.5f) - { - lod = 1; - } - - if (eye[2] < -5.0f) - { - lod = 2; - } - - if (targetLOD!=lod) - { - if (targetLOD==currLOD) + if (imguiButton(m_transitions ? "ON" : "OFF") ) { - targetLOD = lod; + m_transitions = !m_transitions; } + + static float distance = 2.0f; + imguiSlider("Distance", distance, 2.0f, 6.0f, .01f); + + imguiEndScrollArea(); + imguiEndFrame(); + + // Set view 0 default viewport. + bgfx::setViewRect(0, 0, 0, m_width, m_height); + + // This dummy draw call is here to make sure that view 0 is cleared + // if no other draw calls are submitted to view 0. + bgfx::touch(0); + + int64_t now = bx::getHPCounter(); + static int64_t last = now; + const int64_t frameTime = now - last; + last = now; + const double freq = double(bx::getHPFrequency() ); + const double toMs = 1000.0/freq; + + // Use debug font to print information about this example. + bgfx::dbgTextClear(); + bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/12-lod"); + bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Mesh LOD m_transitions."); + bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs); + bgfx::dbgTextPrintf(0, 4, m_transitions ? 0x2f : 0x1f, m_transitions ? "m_transitions on" : "m_transitions off"); + + float at[3] = { 0.0f, 1.0f, 0.0f }; + float eye[3] = { 0.0f, -distance, -2.0f }; + + // Set view and projection matrix for view 0. + const bgfx::HMD* hmd = bgfx::getHMD(); + if (NULL != hmd && 0 != (hmd->flags & BGFX_HMD_RENDERING) ) + { + float view[16]; + bx::mtxQuatTranslationHMD(view, hmd->eye[0].rotation, eye); + + float proj[16]; + bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 100.0f); + + bgfx::setViewTransform(0, view, proj); + + // Set view 0 default viewport. + // + // Use HMD's m_width/m_height since HMD's internal frame buffer size + // might be much larger than window size. + bgfx::setViewRect(0, 0, 0, hmd->width, hmd->height); + } + else + { + float view[16]; + bx::mtxLookAt(view, eye, at); + + float proj[16]; + bx::mtxProj(proj, 60.0f, float(m_width)/float(m_height), 0.1f, 100.0f); + bgfx::setViewTransform(0, view, proj); + + // Set view 0 default viewport. + bgfx::setViewRect(0, 0, 0, m_width, m_height); + } + + float mtx[16]; + bx::mtxScale(mtx, 0.1f, 0.1f, 0.1f); + + float stipple[3]; + float stippleInv[3]; + + const int currentLODframe = m_transitions ? 32-m_transitionFrame : 32; + const int mainLOD = m_transitions ? m_currLod : m_targetLod; + + stipple[0] = 0.0f; + stipple[1] = -1.0f; + stipple[2] = (float(currentLODframe)*4.0f/255.0f) - (1.0f/255.0f); + + stippleInv[0] = (float(31)*4.0f/255.0f); + stippleInv[1] = 1.0f; + stippleInv[2] = (float(m_transitionFrame)*4.0f/255.0f) - (1.0f/255.0f); + + const uint64_t stateTransparent = 0 + | BGFX_STATE_RGB_WRITE + | BGFX_STATE_ALPHA_WRITE + | BGFX_STATE_DEPTH_TEST_LESS + | BGFX_STATE_CULL_CCW + | BGFX_STATE_MSAA + | BGFX_STATE_BLEND_ALPHA + ; + + const uint64_t stateOpaque = BGFX_STATE_DEFAULT; + + bgfx::setTexture(0, s_texColor, m_textureBark); + bgfx::setTexture(1, s_texStipple, m_textureStipple); + bgfx::setUniform(u_stipple, stipple); + meshSubmit(m_meshTrunk[mainLOD], 0, m_program, mtx, stateOpaque); + + bgfx::setTexture(0, s_texColor, m_textureLeafs); + bgfx::setTexture(1, s_texStipple, m_textureStipple); + bgfx::setUniform(u_stipple, stipple); + meshSubmit(m_meshTop[mainLOD], 0, m_program, mtx, stateTransparent); + + if (m_transitions + && (m_transitionFrame != 0) ) + { + bgfx::setTexture(0, s_texColor, m_textureBark); + bgfx::setTexture(1, s_texStipple, m_textureStipple); + bgfx::setUniform(u_stipple, stippleInv); + meshSubmit(m_meshTrunk[m_targetLod], 0, m_program, mtx, stateOpaque); + + bgfx::setTexture(0, s_texColor, m_textureLeafs); + bgfx::setTexture(1, s_texStipple, m_textureStipple); + bgfx::setUniform(u_stipple, stippleInv); + meshSubmit(m_meshTop[m_targetLod], 0, m_program, mtx, stateTransparent); + } + + int lod = 0; + if (eye[2] < -2.5f) + { + lod = 1; + } + + if (eye[2] < -5.0f) + { + lod = 2; + } + + if (m_targetLod != lod) + { + if (m_targetLod == m_currLod) + { + m_targetLod = lod; + } + } + + if (m_currLod != m_targetLod) + { + m_transitionFrame++; + } + + if (m_transitionFrame > 32) + { + m_currLod = m_targetLod; + m_transitionFrame = 0; + } + + // Advance to next frame. Rendering thread will be kicked to + // process submitted rendering primitives. + bgfx::frame(); + + return true; } - if (currLOD != targetLOD) - { - transitionFrame++; - } - - if (transitionFrame>32) - { - currLOD = targetLOD; - transitionFrame = 0; - } - - // Advance to next frame. Rendering thread will be kicked to - // process submitted rendering primitives. - bgfx::frame(); + return false; } - imguiDestroy(); + entry::MouseState m_mouseState; + uint32_t m_width; + uint32_t m_height; + uint32_t m_debug; + uint32_t m_reset; - for (uint32_t ii = 0; ii < 3; ++ii) - { - meshUnload(meshTop[ii]); - meshUnload(meshTrunk[ii]); - } + Mesh* m_meshTop[3]; + Mesh* m_meshTrunk[3]; - // Cleanup. - bgfx::destroyProgram(program); + bgfx::ProgramHandle m_program; + bgfx::UniformHandle s_texColor; + bgfx::UniformHandle s_texStipple; + bgfx::UniformHandle u_stipple; - bgfx::destroyUniform(s_texColor); - bgfx::destroyUniform(s_texStipple); - bgfx::destroyUniform(u_stipple); + bgfx::TextureHandle m_textureStipple; + bgfx::TextureHandle m_textureLeafs; + bgfx::TextureHandle m_textureBark; - bgfx::destroyTexture(textureStipple); - bgfx::destroyTexture(textureLeafs); - bgfx::destroyTexture(textureBark); + int32_t m_scrollArea; + int32_t m_transitionFrame; + int32_t m_currLod; + int32_t m_targetLod; + bool m_transitions; +}; - // Shutdown bgfx. - bgfx::shutdown(); - - return 0; -} +ENTRY_IMPLEMENT_MAIN(Lod); diff --git a/examples/13-stencil/fs_stencil_texture_lightning.sc b/examples/13-stencil/fs_stencil_texture_lightning.sc index 07ce0c842..43e4ff381 100644 --- a/examples/13-stencil/fs_stencil_texture_lightning.sc +++ b/examples/13-stencil/fs_stencil_texture_lightning.sc @@ -16,7 +16,7 @@ uniform vec4 u_color; uniform vec4 u_specular_shininess; uniform vec4 u_lightPosRadius[MAX_NUM_LIGHTS]; uniform vec4 u_lightRgbInnerR[MAX_NUM_LIGHTS]; -SAMPLER2D(u_texColor, 0); +SAMPLER2D(s_texColor, 0); #define u_ambientPass u_params.x #define u_lightingPass u_params.y @@ -80,7 +80,7 @@ void main() } lightColor *= u_lightingPass; - vec3 color = toLinear(texture2D(u_texColor, v_texcoord0)).xyz; + vec3 color = toLinear(texture2D(s_texColor, v_texcoord0)).xyz; vec3 ambient = toGamma(ambientColor * color); vec3 diffuse = toGamma(lightColor * color); diff --git a/examples/15-shadowmaps-simple/fs_sms_shadow.sh b/examples/15-shadowmaps-simple/fs_sms_shadow.sh index f3a88945c..a38a90f2f 100644 --- a/examples/15-shadowmaps-simple/fs_sms_shadow.sh +++ b/examples/15-shadowmaps-simple/fs_sms_shadow.sh @@ -7,10 +7,10 @@ uniform vec4 u_lightPos; #if SHADOW_PACKED_DEPTH -SAMPLER2D(u_shadowMap, 0); +SAMPLER2D(s_shadowMap, 0); # define Sampler sampler2D #else -SAMPLER2DSHADOW(u_shadowMap, 0); +SAMPLER2DSHADOW(s_shadowMap, 0); # define Sampler sampler2DShadow #endif // SHADOW_PACKED_DEPTH @@ -90,7 +90,7 @@ void main() vec2 lc = lit(ld, n, vd, 1.0); vec2 texelSize = vec2_splat(1.0/512.0); - float visibility = PCF(u_shadowMap, v_shadowcoord, shadowMapBias, texelSize); + float visibility = PCF(s_shadowMap, v_shadowcoord, shadowMapBias, texelSize); vec3 ambient = 0.1 * color; vec3 brdf = (lc.x + lc.y) * color * visibility; diff --git a/examples/16-shadowmaps/fs_shadowmaps_color_lightning.sh b/examples/16-shadowmaps/fs_shadowmaps_color_lightning.sh index 9c19212a3..f20905089 100644 --- a/examples/16-shadowmaps/fs_shadowmaps_color_lightning.sh +++ b/examples/16-shadowmaps/fs_shadowmaps_color_lightning.sh @@ -29,10 +29,10 @@ uniform vec4 u_tetraNormalBlue; uniform vec4 u_tetraNormalRed; #endif -SAMPLER2D(u_shadowMap0, 4); -SAMPLER2D(u_shadowMap1, 5); -SAMPLER2D(u_shadowMap2, 6); -SAMPLER2D(u_shadowMap3, 7); +SAMPLER2D(s_shadowMap0, 4); +SAMPLER2D(s_shadowMap1, 5); +SAMPLER2D(s_shadowMap2, 6); +SAMPLER2D(s_shadowMap3, 7); struct Shader { diff --git a/examples/16-shadowmaps/fs_shadowmaps_color_lightning_main.sh b/examples/16-shadowmaps/fs_shadowmaps_color_lightning_main.sh index 3e3373e62..f5393d06d 100644 --- a/examples/16-shadowmaps/fs_shadowmaps_color_lightning_main.sh +++ b/examples/16-shadowmaps/fs_shadowmaps_color_lightning_main.sh @@ -48,7 +48,15 @@ float coverage = texcoordInRange(shadowcoord.xy/shadowcoord.w) * 0.4; colorCoverage = vec3(-coverage, coverage, -coverage); - visibility = computeVisibility(u_shadowMap0, shadowcoord, u_shadowMapBias, u_smSamplingParams, texelSize, u_shadowMapDepthMultiplier, u_shadowMapMinVariance, u_shadowMapHardness); + visibility = computeVisibility(s_shadowMap0 + , shadowcoord + , u_shadowMapBias + , u_smSamplingParams + , texelSize + , u_shadowMapDepthMultiplier + , u_shadowMapMinVariance + , u_shadowMapHardness + ); } else if (selection1) { @@ -56,7 +64,15 @@ float coverage = texcoordInRange(shadowcoord.xy/shadowcoord.w) * 0.4; colorCoverage = vec3(coverage, coverage, -coverage); - visibility = computeVisibility(u_shadowMap1, shadowcoord, u_shadowMapBias, u_smSamplingParams, texelSize/2.0, u_shadowMapDepthMultiplier, u_shadowMapMinVariance, u_shadowMapHardness); + visibility = computeVisibility(s_shadowMap1 + , shadowcoord + , u_shadowMapBias + , u_smSamplingParams + , texelSize/2.0 + , u_shadowMapDepthMultiplier + , u_shadowMapMinVariance + , u_shadowMapHardness + ); } else if (selection2) { @@ -64,7 +80,15 @@ float coverage = texcoordInRange(shadowcoord.xy/shadowcoord.w) * 0.4; colorCoverage = vec3(-coverage, -coverage, coverage); - visibility = computeVisibility(u_shadowMap2, shadowcoord, u_shadowMapBias, u_smSamplingParams, texelSize/3.0, u_shadowMapDepthMultiplier, u_shadowMapMinVariance, u_shadowMapHardness); + visibility = computeVisibility(s_shadowMap2 + , shadowcoord + , u_shadowMapBias + , u_smSamplingParams + , texelSize/3.0 + , u_shadowMapDepthMultiplier + , u_shadowMapMinVariance + , u_shadowMapHardness + ); } else //selection3 { @@ -72,7 +96,15 @@ float coverage = texcoordInRange(shadowcoord.xy/shadowcoord.w) * 0.4; colorCoverage = vec3(coverage, -coverage, -coverage); - visibility = computeVisibility(u_shadowMap3, shadowcoord, u_shadowMapBias, u_smSamplingParams, texelSize/4.0, u_shadowMapDepthMultiplier, u_shadowMapMinVariance, u_shadowMapHardness); + visibility = computeVisibility(s_shadowMap3 + , shadowcoord + , u_shadowMapBias + , u_smSamplingParams + , texelSize/4.0 + , u_shadowMapDepthMultiplier + , u_shadowMapMinVariance + , u_shadowMapHardness + ); } #elif SM_OMNI vec2 texelSize = vec2_splat(u_shadowMapTexelSize/4.0); @@ -115,14 +147,30 @@ colorCoverage = vec3(coverage, -coverage, -coverage); } - visibility = computeVisibility(u_shadowMap0, shadowcoord, u_shadowMapBias, u_smSamplingParams, texelSize, u_shadowMapDepthMultiplier, u_shadowMapMinVariance, u_shadowMapHardness); + visibility = computeVisibility(s_shadowMap0 + , shadowcoord + , u_shadowMapBias + , u_smSamplingParams + , texelSize + , u_shadowMapDepthMultiplier + , u_shadowMapMinVariance + , u_shadowMapHardness + ); #else vec2 texelSize = vec2_splat(u_shadowMapTexelSize); float coverage = texcoordInRange(v_shadowcoord.xy/v_shadowcoord.w) * 0.3; colorCoverage = vec3(coverage, -coverage, -coverage); - visibility = computeVisibility(u_shadowMap0, v_shadowcoord, u_shadowMapBias, u_smSamplingParams, texelSize, u_shadowMapDepthMultiplier, u_shadowMapMinVariance, u_shadowMapHardness); + visibility = computeVisibility(s_shadowMap0 + , v_shadowcoord + , u_shadowMapBias + , u_smSamplingParams + , texelSize + , u_shadowMapDepthMultiplier + , u_shadowMapMinVariance + , u_shadowMapHardness + ); #endif vec3 v = v_view; diff --git a/examples/16-shadowmaps/fs_shadowmaps_color_texture.sc b/examples/16-shadowmaps/fs_shadowmaps_color_texture.sc index eea20d8ff..b81e40d19 100644 --- a/examples/16-shadowmaps/fs_shadowmaps_color_texture.sc +++ b/examples/16-shadowmaps/fs_shadowmaps_color_texture.sc @@ -7,13 +7,13 @@ $input v_texcoord0 #include "../common/common.sh" uniform vec4 u_color; -SAMPLER2D(u_texColor, 0); +SAMPLER2D(s_texColor, 0); void main() { - vec4 tcolor = toLinear(texture2D(u_texColor, v_texcoord0)); + vec4 tcolor = toLinear(texture2D(s_texColor, v_texcoord0)); - if (tcolor.x < 0.1) //OK for now. + if (tcolor.x < 0.1) { discard; } diff --git a/examples/16-shadowmaps/fs_shadowmaps_hblur.sc b/examples/16-shadowmaps/fs_shadowmaps_hblur.sc index 7c4186ed1..7f226049e 100644 --- a/examples/16-shadowmaps/fs_shadowmaps_hblur.sc +++ b/examples/16-shadowmaps/fs_shadowmaps_hblur.sc @@ -6,9 +6,15 @@ $input v_texcoord0, v_texcoord1, v_texcoord2, v_texcoord3, v_texcoord4 */ #include "common.sh" -SAMPLER2D(u_shadowMap0, 4); +SAMPLER2D(s_shadowMap0, 4); void main() { - gl_FragColor = blur9(u_shadowMap0, v_texcoord0, v_texcoord1, v_texcoord2, v_texcoord3, v_texcoord4); + gl_FragColor = blur9(s_shadowMap0 + , v_texcoord0 + , v_texcoord1 + , v_texcoord2 + , v_texcoord3 + , v_texcoord4 + ); } diff --git a/examples/16-shadowmaps/fs_shadowmaps_hblur_vsm.sc b/examples/16-shadowmaps/fs_shadowmaps_hblur_vsm.sc index 50f96c5fc..1173ef7b5 100644 --- a/examples/16-shadowmaps/fs_shadowmaps_hblur_vsm.sc +++ b/examples/16-shadowmaps/fs_shadowmaps_hblur_vsm.sc @@ -6,10 +6,15 @@ $input v_texcoord0, v_texcoord1, v_texcoord2, v_texcoord3, v_texcoord4 */ #include "common.sh" -SAMPLER2D(u_shadowMap0, 4); +SAMPLER2D(s_shadowMap0, 4); void main() { - gl_FragColor = blur9VSM(u_shadowMap0, v_texcoord0, v_texcoord1, v_texcoord2, v_texcoord3, v_texcoord4); + gl_FragColor = blur9VSM(s_shadowMap0 + , v_texcoord0 + , v_texcoord1 + , v_texcoord2 + , v_texcoord3 + , v_texcoord4 + ); } - diff --git a/examples/16-shadowmaps/fs_shadowmaps_texture.sc b/examples/16-shadowmaps/fs_shadowmaps_texture.sc index 42c278142..0f33138b7 100644 --- a/examples/16-shadowmaps/fs_shadowmaps_texture.sc +++ b/examples/16-shadowmaps/fs_shadowmaps_texture.sc @@ -6,9 +6,9 @@ $input v_texcoord0 */ #include "../common/common.sh" -SAMPLER2D(u_texColor, 0); +SAMPLER2D(s_texColor, 0); void main() { - gl_FragColor = texture2D(u_texColor, v_texcoord0); + gl_FragColor = texture2D(s_texColor, v_texcoord0); } diff --git a/examples/16-shadowmaps/fs_shadowmaps_unpackdepth.sc b/examples/16-shadowmaps/fs_shadowmaps_unpackdepth.sc index 592a1d926..c3ed6e0ec 100644 --- a/examples/16-shadowmaps/fs_shadowmaps_unpackdepth.sc +++ b/examples/16-shadowmaps/fs_shadowmaps_unpackdepth.sc @@ -6,14 +6,14 @@ $input v_texcoord0 */ #include "../common/common.sh" -SAMPLER2D(u_shadowMap0, 4); +SAMPLER2D(s_shadowMap0, 4); uniform vec4 u_params2; #define u_depthValuePow u_params2.x void main() { - float depth = unpackRgbaToFloat(texture2D(u_shadowMap0, v_texcoord0) ); + float depth = unpackRgbaToFloat(texture2D(s_shadowMap0, v_texcoord0) ); vec3 rgba = pow(vec3_splat(depth), vec3_splat(u_depthValuePow) ); gl_FragColor = vec4(rgba, 1.0); } diff --git a/examples/16-shadowmaps/fs_shadowmaps_unpackdepth_vsm.sc b/examples/16-shadowmaps/fs_shadowmaps_unpackdepth_vsm.sc index c81ba1856..2e2792ce4 100644 --- a/examples/16-shadowmaps/fs_shadowmaps_unpackdepth_vsm.sc +++ b/examples/16-shadowmaps/fs_shadowmaps_unpackdepth_vsm.sc @@ -6,14 +6,14 @@ $input v_texcoord0 */ #include "../common/common.sh" -SAMPLER2D(u_shadowMap0, 4); +SAMPLER2D(s_shadowMap0, 4); uniform vec4 u_params2; #define u_depthValuePow u_params2.x void main() { - vec4 val = texture2D(u_shadowMap0, v_texcoord0); + vec4 val = texture2D(s_shadowMap0, v_texcoord0); float depth = unpackHalfFloat(val.rg); vec3 rgba = pow(vec3_splat(depth), vec3_splat(u_depthValuePow) ); gl_FragColor = vec4(rgba, 1.0); diff --git a/examples/16-shadowmaps/fs_shadowmaps_vblur.sc b/examples/16-shadowmaps/fs_shadowmaps_vblur.sc index 7c4186ed1..7f226049e 100644 --- a/examples/16-shadowmaps/fs_shadowmaps_vblur.sc +++ b/examples/16-shadowmaps/fs_shadowmaps_vblur.sc @@ -6,9 +6,15 @@ $input v_texcoord0, v_texcoord1, v_texcoord2, v_texcoord3, v_texcoord4 */ #include "common.sh" -SAMPLER2D(u_shadowMap0, 4); +SAMPLER2D(s_shadowMap0, 4); void main() { - gl_FragColor = blur9(u_shadowMap0, v_texcoord0, v_texcoord1, v_texcoord2, v_texcoord3, v_texcoord4); + gl_FragColor = blur9(s_shadowMap0 + , v_texcoord0 + , v_texcoord1 + , v_texcoord2 + , v_texcoord3 + , v_texcoord4 + ); } diff --git a/examples/16-shadowmaps/fs_shadowmaps_vblur_vsm.sc b/examples/16-shadowmaps/fs_shadowmaps_vblur_vsm.sc index 50f96c5fc..1173ef7b5 100644 --- a/examples/16-shadowmaps/fs_shadowmaps_vblur_vsm.sc +++ b/examples/16-shadowmaps/fs_shadowmaps_vblur_vsm.sc @@ -6,10 +6,15 @@ $input v_texcoord0, v_texcoord1, v_texcoord2, v_texcoord3, v_texcoord4 */ #include "common.sh" -SAMPLER2D(u_shadowMap0, 4); +SAMPLER2D(s_shadowMap0, 4); void main() { - gl_FragColor = blur9VSM(u_shadowMap0, v_texcoord0, v_texcoord1, v_texcoord2, v_texcoord3, v_texcoord4); + gl_FragColor = blur9VSM(s_shadowMap0 + , v_texcoord0 + , v_texcoord1 + , v_texcoord2 + , v_texcoord3 + , v_texcoord4 + ); } - diff --git a/examples/16-shadowmaps/shadowmaps.cpp b/examples/16-shadowmaps/shadowmaps.cpp index e447e99a3..050e639ae 100644 --- a/examples/16-shadowmaps/shadowmaps.cpp +++ b/examples/16-shadowmaps/shadowmaps.cpp @@ -223,8 +223,8 @@ static const uint16_t s_planeIndices[] = static bool s_flipV = false; static float s_texelHalf = 0.0f; -static bgfx::UniformHandle u_texColor; -static bgfx::UniformHandle u_shadowMap[ShadowMapRenderTargets::Count]; +static bgfx::UniformHandle s_texColor; +static bgfx::UniformHandle s_shadowMap[ShadowMapRenderTargets::Count]; static bgfx::FrameBufferHandle s_rtShadowMap[ShadowMapRenderTargets::Count]; static bgfx::FrameBufferHandle s_rtBlur; @@ -1012,12 +1012,12 @@ struct Mesh // Set textures. if (bgfx::invalidHandle != _texture.idx) { - bgfx::setTexture(0, u_texColor, _texture); + bgfx::setTexture(0, s_texColor, _texture); } for (uint8_t ii = 0; ii < ShadowMapRenderTargets::Count; ++ii) { - bgfx::setTexture(4 + ii, u_shadowMap[ii], s_rtShadowMap[ii]); + bgfx::setTexture(4 + ii, s_shadowMap[ii], s_rtShadowMap[ii]); } // Apply render state. @@ -1351,11 +1351,11 @@ int _main_(int _argc, char** _argv) // Uniforms. s_uniforms.init(); - u_texColor = bgfx::createUniform("u_texColor", bgfx::UniformType::Int1); - u_shadowMap[0] = bgfx::createUniform("u_shadowMap0", bgfx::UniformType::Int1); - u_shadowMap[1] = bgfx::createUniform("u_shadowMap1", bgfx::UniformType::Int1); - u_shadowMap[2] = bgfx::createUniform("u_shadowMap2", bgfx::UniformType::Int1); - u_shadowMap[3] = bgfx::createUniform("u_shadowMap3", bgfx::UniformType::Int1); + s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Int1); + s_shadowMap[0] = bgfx::createUniform("s_shadowMap0", bgfx::UniformType::Int1); + s_shadowMap[1] = bgfx::createUniform("s_shadowMap1", bgfx::UniformType::Int1); + s_shadowMap[2] = bgfx::createUniform("s_shadowMap2", bgfx::UniformType::Int1); + s_shadowMap[3] = bgfx::createUniform("s_shadowMap3", bgfx::UniformType::Int1); // Programs. s_programs.init(); @@ -2814,12 +2814,12 @@ int _main_(int _argc, char** _argv) if (bVsmOrEsm && currentSmSettings->m_doBlur) { - bgfx::setTexture(4, u_shadowMap[0], s_rtShadowMap[0]); + bgfx::setTexture(4, s_shadowMap[0], s_rtShadowMap[0]); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(currentShadowMapSizef, currentShadowMapSizef, s_flipV); bgfx::submit(RENDERVIEW_VBLUR_0_ID, s_programs.m_vBlur[depthType]); - bgfx::setTexture(4, u_shadowMap[0], s_rtBlur); + bgfx::setTexture(4, s_shadowMap[0], s_rtBlur); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(currentShadowMapSizef, currentShadowMapSizef, s_flipV); bgfx::submit(RENDERVIEW_HBLUR_0_ID, s_programs.m_hBlur[depthType]); @@ -2830,12 +2830,12 @@ int _main_(int _argc, char** _argv) { const uint8_t viewId = RENDERVIEW_VBLUR_0_ID + jj; - bgfx::setTexture(4, u_shadowMap[0], s_rtShadowMap[ii]); + bgfx::setTexture(4, s_shadowMap[0], s_rtShadowMap[ii]); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(currentShadowMapSizef, currentShadowMapSizef, s_flipV); bgfx::submit(viewId, s_programs.m_vBlur[depthType]); - bgfx::setTexture(4, u_shadowMap[0], s_rtBlur); + bgfx::setTexture(4, s_shadowMap[0], s_rtBlur); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(currentShadowMapSizef, currentShadowMapSizef, s_flipV); bgfx::submit(viewId+1, s_programs.m_hBlur[depthType]); @@ -3065,7 +3065,7 @@ int _main_(int _argc, char** _argv) // Draw depth rect. if (settings.m_drawDepthBuffer) { - bgfx::setTexture(4, u_shadowMap[0], s_rtShadowMap[0]); + bgfx::setTexture(4, s_shadowMap[0], s_rtShadowMap[0]); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(currentShadowMapSizef, currentShadowMapSizef, s_flipV); bgfx::submit(RENDERVIEW_DRAWDEPTH_0_ID, s_programs.m_drawDepth[depthType]); @@ -3074,7 +3074,7 @@ int _main_(int _argc, char** _argv) { for (uint8_t ii = 1; ii < settings.m_numSplits; ++ii) { - bgfx::setTexture(4, u_shadowMap[0], s_rtShadowMap[ii]); + bgfx::setTexture(4, s_shadowMap[0], s_rtShadowMap[ii]); bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE); screenSpaceQuad(currentShadowMapSizef, currentShadowMapSizef, s_flipV); bgfx::submit(RENDERVIEW_DRAWDEPTH_0_ID+ii, s_programs.m_drawDepth[depthType]); @@ -3147,11 +3147,11 @@ int _main_(int _argc, char** _argv) s_programs.destroy(); - bgfx::destroyUniform(u_texColor); - bgfx::destroyUniform(u_shadowMap[3]); - bgfx::destroyUniform(u_shadowMap[2]); - bgfx::destroyUniform(u_shadowMap[1]); - bgfx::destroyUniform(u_shadowMap[0]); + bgfx::destroyUniform(s_texColor); + bgfx::destroyUniform(s_shadowMap[3]); + bgfx::destroyUniform(s_shadowMap[2]); + bgfx::destroyUniform(s_shadowMap[1]); + bgfx::destroyUniform(s_shadowMap[0]); s_uniforms.destroy(); diff --git a/examples/19-oit/fs_oit_wb_blit.sc b/examples/19-oit/fs_oit_wb_blit.sc index d6b1157db..6380967d1 100644 --- a/examples/19-oit/fs_oit_wb_blit.sc +++ b/examples/19-oit/fs_oit_wb_blit.sc @@ -7,12 +7,12 @@ $input v_texcoord0 #include "../common/common.sh" -SAMPLER2D(u_texColor0, 0); -SAMPLER2D(u_texColor1, 1); +SAMPLER2D(s_texColor0, 0); +SAMPLER2D(s_texColor1, 1); void main() { - vec4 accum = texture2D(u_texColor0, v_texcoord0); - float opacity = texture2D(u_texColor1, v_texcoord0).x; + vec4 accum = texture2D(s_texColor0, v_texcoord0); + float opacity = texture2D(s_texColor1, v_texcoord0).x; gl_FragColor = vec4(accum.xyz / clamp(accum.w, 1e-4, 5e4), opacity); } diff --git a/examples/19-oit/fs_oit_wb_separate_blit.sc b/examples/19-oit/fs_oit_wb_separate_blit.sc index 9c3a9ed1c..195c5ff7d 100644 --- a/examples/19-oit/fs_oit_wb_separate_blit.sc +++ b/examples/19-oit/fs_oit_wb_separate_blit.sc @@ -7,13 +7,13 @@ $input v_texcoord0 #include "../common/common.sh" -SAMPLER2D(u_texColor0, 0); -SAMPLER2D(u_texColor1, 1); +SAMPLER2D(s_texColor0, 0); +SAMPLER2D(s_texColor1, 1); void main() { - vec4 accum = texture2D(u_texColor0, v_texcoord0); + vec4 accum = texture2D(s_texColor0, v_texcoord0); float opacity = accum.w; - float weight = texture2D(u_texColor1, v_texcoord0).x; + float weight = texture2D(s_texColor1, v_texcoord0).x; gl_FragColor = vec4(accum.xyz / clamp(weight, 1e-4, 5e4), opacity); } diff --git a/examples/runtime/shaders/glsl/fs_tree.bin b/examples/runtime/shaders/glsl/fs_tree.bin index 48d7ea940..8608ba095 100644 Binary files a/examples/runtime/shaders/glsl/fs_tree.bin and b/examples/runtime/shaders/glsl/fs_tree.bin differ