Jump to content


Shadow maps, map [-1, 1] to [0, 1]


3 replies to this topic

#1 kruseborn

    Member

  • Members
  • PipPip
  • 33 posts

Posted 11 January 2009 - 01:42 PM

I am looking at example from nvidias homepage: Variance Shadow Mapping.

They use a texture2d for the shadowmapping and saving the depth value in it. What i understand now is that you want to map the texcoord values [-1, 1] to [0, 1] and you do this by scaling and biasing. Tex.xy * float2(0.5, 0.5)+0.5.

But what they do is that they use a negative 0.5 on the y variable. Why?
tex.xy = Tex.xy * float2(0.5, -0.5)+0.5. They are using Directx 10.

Here is the vertex and pixel shader:

PSIn VSDrawScene( VSIn input )
{
    PSIn output = (PSIn)0.0f;
    
    output.tex = input.tex;
    
    float4 worldPos = mul( float4( input.pos, 1.0f ), mWorld );
    float4 lightViewPos = mul( worldPos, mShadowView );
    float3 lightVec = vLightPos.xyz - worldPos.xyz;

    output.pos = mul( mul( worldPos, mView ), mProj );

    output.lightViewPos = mul( lightViewPos, mShadowProj );
    output.wNorm = normalize( mul( float4( input.norm, 0.0f ), mWorld ) );
    output.wLight = normalize( lightVec );
    

    return output;
}

float4 PS( uniform bool bVSM, PSIn input ) : SV_Target
{
	float4 output = (float4)0.0f;

    input.lightViewPos.xyz /= input.lightViewPos.w;
    float2 tex = input.lightViewPos.xy *float2(0.5, -0.5) + 0.5f;
       
	
	float lit = PCF_FILTER( tex, input.lightViewPos.z );
	

	float3 wLight = normalize( input.wLight );
	float3 wNormal = normalize( input.wNorm );

	float3 diffuse = texDiffuse.Sample( FILT_LINEAR_WRAP, texScaled );
	diffuse *= dot( normalize( wNormal ), wLight );
	return  float4( diffuse, 1.0f ) * lit;
}


#2 JarkkoL

    Senior Member

  • Members
  • PipPipPipPip
  • 467 posts

Posted 11 January 2009 - 02:14 PM

kruseborn said:

But what they do is that they use a negative 0.5 on the y variable. Why?
Because in texture coordinates y points down while in screen space y points up, so you have to flip it for texture sampling.

#3 kruseborn

    Member

  • Members
  • PipPip
  • 33 posts

Posted 11 January 2009 - 02:33 PM

k thank you

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 11 January 2009 - 07:08 PM

Also, just for future reference, please use [code]...[/code] to post code in the forum.
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users