Jump to content



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

  • You cannot reply to this topic
1 reply to this topic

#1 db123   Members   -  Reputation: 103

Like
0Likes
Like

Posted 21 February 2012 - 09:20 AM

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

ShadowMap.hsf(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
}
"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 );
    }
}


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.


I don't understand how to fix it.

Thank youPosted Image Posted Image Posted Image Posted Image Posted Image

Ad:

#2 Tsus   Members   -  Reputation: 296

Like
0Likes
Like

Posted 23 February 2012 - 05:06 AM

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!
Acagamics e.V. – IGDA Student Game Development Club (University of Magdeburg, Germany)






We are working on generating results for this topic
PARTNERS