Jump to content
  • Advertisement
Sign in to follow this  
db123

DX11 An annoying warning in sm5.0/dx11: warning X4000: Use of potentially uninitialized variable

This topic is 2336 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I write a simple shadow map demo. it works well, but when i compile these codes, it will generate a warning:

ShadowMap.hsf([color=#ff0000]313,6): warning X4000: Use of potentially uninitialized variable

code for shadow map:

static const float SMAP_SIZE = 1024.0f;
static const float SMAP_DX = 1.0f / SMAP_SIZE;
float StandardShadowMap( float4 projTexC )
{
// Complete projection by doing division by w.
projTexC.xyz /= projTexC.w;
// Points outside the light volume are in shadow.
if( projTexC.x < -1.0f || projTexC.x > 1.0f ||
projTexC.y < -1.0f || projTexC.y > 1.0f ||
projTexC.z < 0.0f )
{
return 0.0f;
}
// Transform from NDC space to texture space.
projTexC.x = +0.5f*projTexC.x + 0.5f;
projTexC.y = -0.5f*projTexC.y + 0.5f;
// Depth in NDC space.
float depth = projTexC.z;
// Sample shadow map to get nearest depth to light.
float s0 = g_ShadowMap.Sample(PointSampler, projTexC.xy).r;
#if 1
return depth <= s0+g_ShadBias? 1.0:0.0;
#else
float s1 = g_ShadowMap.Sample(LinearSampler, projTexC.xy + float2(SMAP_DX, 0)).r;
float s2 = g_ShadowMap.Sample(LinearSampler, projTexC.xy + float2(0, SMAP_DX)).r;
float s3 = g_ShadowMap.Sample(LinearSampler, projTexC.xy + float2(SMAP_DX, SMAP_DX)).r;
// Is the pixel depth <= shadow map value?
float result0 = depth <= s0 + g_ShadBias;
float result1 = depth <= s1 + g_ShadBias;
float result2 = depth <= s2 + g_ShadBias;
float result3 = depth <= s3 + g_ShadBias;
// Transform to texel space.
float2 texelPos = SMAP_SIZE*projTexC.xy;
// Determine the interpolation amounts.
float2 t = frac( texelPos );
// Interpolate results.
return lerp( lerp(result0, result1, t.x),
lerp(result2, result3, t.x), t.y);
#endif
}

"[color=#ff0000]if( projTexC.x < -1.0f || projTexC.x > 1.0f || " is No. 313.

this code is how to use it:

float4 StaticMeshSpotLightingSSM( HStaticMeshMaterialVSOutput Input ) : SV_TARGET
{
float4 vLightingColor = SpotLightingShading( Input );
if( dot( vLightingColor.rgb, vLightingColor.rgb ) == 0 )
{
return vLightingColor;
}
// get shadow factor here.
float4 vLightViewPos = mul( Input.oWorldPos, mLightViewProj );

float fShadowFactor = StandardShadowMap(vLightViewPos);

return vLightingColor*fShadowFactor;
}

compile:

technique10 DrawStaticMeshSpotLightingSSM
{
pass p0
{
SetVertexShader ( CompileShader( vs_5_0, StaticMeshVMain() ) );
SetGeometryShader( NULL );
SetPixelShader ( CompileShader( ps_5_0, StaticMeshSpotLightingSSM() ) );
//SetRasterizerState( DisableCulling );
SetRasterizerState( EnableCullingBack );
SetDepthStencilState( DSState, 0 );
SetBlendState( DisableBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
}
}


[color=#ff0000]
[color=#ff0000] the most probable is projTexC, but it just a formal parameter from pixel shader, and the actual parameter is vLightViewPos which is the Position in light view.
this is the vertex shader:


struct HStaticMeshMaterialVSOutput
{
float4 oPos : SV_Position;
float2 oTex : TEXCOORD0;
float4 oWorldPos : TEXCOORD1;
float3 oWorldNormal : TEXCOORD2;
float3 oWorldTangent : TEXCOORD3;
float3 oWorldBitangent : TEXCOORD4;
// float4 oLP : TEXCOORD5;
};
HStaticMeshMaterialVSOutput StaticMeshVMain( HStaticMeshVertexFactory Input )
{
HStaticMeshMaterialVSOutput Output = (HStaticMeshMaterialVSOutput)0;
// Output.oPos = mul( float4(Input.vPos, 1.0), mWorldViewProj );
Output.oTex = Input.vTex;
Output.oWorldPos = mul( float4( Input.vPos, 1.0f ), mWorld );

Output.oWorldNormal = mul( Input.vNormal, (float3x3)mWorldIT );
Output.oWorldTangent = mul( Input.vTangent, (float3x3)mWorldIT );
Output.oWorldBitangent = cross( Output.oWorldNormal, Output.oWorldTangent );
//Output.oLP = mul( float4(Output.oWorldPos.xyz,1.0), mLightViewProj );
Output.oPos = mul( float4(Output.oWorldPos.xyz,1.0), mViewProj );

return Output;
}

if i use oLP in vertex shader output, it warn too.


[color=#FF0000] [color=#FF0000] I don't understand how to fix it.

Thank youunsure.png unsure.png unsure.png unsure.png unsure.png

Share this post


Link to post
Share on other sites
Advertisement
I’m not seeing any potential problem.
Could you attach the full shader file, please?
It might be easier for us to just throw it in the fxc and then experiment around a little.
Cheers!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!