mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-12-01 03:47:07 -05:00
Merge pull request #659 from lunkhound/d3d-proj-fix
removed z coord adjustment in shadow2D() shader builtin for HLSL
This commit is contained in:
commit
c47216a32c
10 changed files with 19 additions and 8 deletions
|
@ -7,8 +7,12 @@ $input v_position
|
|||
|
||||
#include "../common/common.sh"
|
||||
|
||||
uniform vec4 u_depthScaleOffset; // for GL, map depth values into [0, 1] range
|
||||
#define u_depthScale u_depthScaleOffset.x
|
||||
#define u_depthOffset u_depthScaleOffset.y
|
||||
|
||||
void main()
|
||||
{
|
||||
float depth = v_position.z/v_position.w * 0.5 + 0.5;
|
||||
float depth = v_position.z/v_position.w * u_depthScale + u_depthOffset;
|
||||
gl_FragColor = packFloatToRgba(depth);
|
||||
}
|
||||
|
|
|
@ -91,6 +91,13 @@ int _main_(int _argc, char** _argv)
|
|||
bgfx::UniformHandle u_shadowMap = bgfx::createUniform("u_shadowMap", bgfx::UniformType::Int1);
|
||||
bgfx::UniformHandle u_lightPos = bgfx::createUniform("u_lightPos", bgfx::UniformType::Vec4);
|
||||
bgfx::UniformHandle u_lightMtx = bgfx::createUniform("u_lightMtx", bgfx::UniformType::Mat4);
|
||||
// When using GL clip space depth range [-1, 1] and packing depth into color buffer, we need to
|
||||
// adjust the depth range to be [0, 1] for writing to the color buffer
|
||||
bgfx::UniformHandle u_depthScaleOffset = bgfx::createUniform("u_depthScaleOffset", bgfx::UniformType::Vec4);
|
||||
const float depthScale = flipV ? 0.5f : 1.0f;
|
||||
const float depthOffset = flipV ? 0.5f : 0.0f;
|
||||
float depthScaleOffset[4] = {depthScale, depthOffset, 0.0f, 0.0f};
|
||||
bgfx::setUniform(u_depthScaleOffset, depthScaleOffset);
|
||||
|
||||
// Vertex declarations.
|
||||
bgfx::VertexDecl PosNormalDecl;
|
||||
|
@ -303,8 +310,8 @@ int _main_(int _argc, char** _argv)
|
|||
{
|
||||
0.5f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, sy, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.5f, 0.0f,
|
||||
0.5f, 0.5f, 0.5f, 1.0f,
|
||||
0.0f, 0.0f, depthScale, 0.0f,
|
||||
0.5f, 0.5f, depthOffset, 1.0f,
|
||||
};
|
||||
|
||||
float mtxTmp[16];
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -75,13 +75,13 @@ struct BgfxSampler2DShadow
|
|||
|
||||
float bgfxShadow2D(BgfxSampler2DShadow _sampler, vec3 _coord)
|
||||
{
|
||||
return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xy, _coord.z * 2.0 - 1.0);
|
||||
return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xy, _coord.z);
|
||||
}
|
||||
|
||||
float bgfxShadow2DProj(BgfxSampler2DShadow _sampler, vec4 _coord)
|
||||
{
|
||||
vec3 coord = _coord.xyz * rcp(_coord.w);
|
||||
return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, coord.xy, coord.z * 2.0 - 1.0);
|
||||
return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, coord.xy, coord.z);
|
||||
}
|
||||
|
||||
struct BgfxSampler3D
|
||||
|
@ -196,9 +196,9 @@ float bgfxShadow2D(sampler2DShadow _sampler, vec3 _coord)
|
|||
{
|
||||
#if 0
|
||||
float occluder = tex2D(_sampler, _coord.xy).x;
|
||||
return step(_coord.z * 2.0 - 1.0, occluder);
|
||||
return step(_coord.z, occluder);
|
||||
#else
|
||||
return tex2Dproj(_sampler, vec4(_coord.xy, _coord.z * 2.0 - 1.0, 1.0) ).x;
|
||||
return tex2Dproj(_sampler, vec4(_coord.xy, _coord.z, 1.0) ).x;
|
||||
#endif // 0
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,7 @@ float bgfxShadow2DProj(sampler2DShadow _sampler, vec4 _coord)
|
|||
#if 0
|
||||
vec3 coord = _coord.xyz * rcp(_coord.w);
|
||||
float occluder = tex2D(_sampler, coord.xy).x;
|
||||
return step(coord.z * 2.0 - 1.0, occluder);
|
||||
return step(coord.z, occluder);
|
||||
#else
|
||||
return tex2Dproj(_sampler, _coord).x;
|
||||
#endif // 0
|
||||
|
|
Loading…
Reference in a new issue