Jump to content
  • Advertisement
Sign in to follow this  

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

This topic is 2799 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;
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);

"[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;


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] 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
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.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!