# light pre-pass

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

## Recommended Posts

Hello everyone,

I've been trying to implement light pre-pass recently, following this tutorial, i'm using Direct3D11 (shader model 4)
my problem is getting the pixel position in my pixel shader, here's the code (light map building shader):
 float2 PostProjToScreen ( float4 position ) { float2 screenPos = position.xy / position.w; return 0.5f * ( float2 ( screenPos.x + 1, 1 - screenPos.y ) ); } float2 HalfPixel ( void ) { return float2 ( 0.5f / screenSize.x, 0.5f / screenSize.y ); } VS_OUT VS ( VS_IN input ) { VS_OUT output; output.position = mul ( float4 ( input.position, 1.0f ), gWVP ); output.tex = ((output.position.xy + float2(1.0f,1.0f))/2.0f); output.tex.y = 1.0f - output.tex.y; return output; } float4 PS ( VS_OUT input ) : SV_TARGET { float2 texC = input.tex; //PostProjToScreen ( input.position ) + HalfPixel ( ); doesn't work float z = depthMap.Sample ( gSampler, texC ); float x = texC.x * 2.0f - 1.0f; float y = (1.0f - texC.y) * 2.0f - 1.0f; float4 vProjectedPos = float4 ( x, y, z, 1.0f ); float4 vPositionVS = mul ( vProjectedPos, gProjMatrixInverse ); float3 pixelPosition = vPositionVS.xyz / vPositionVS.w; //littile problems with this variable also float3 pixelNormal = normalMap.Sample ( gSampler, texC ); float3 lDir = -normalize ( gLightDir ); float nl = 1.0f / dot ( pixelNormal, lDir ); float3 camDir = normalize ( gEyePosW - pixelPosition ); // Calculate specular term float3 h = normalize ( lDir + camDir ); float spec = pow ( saturate ( dot ( pixelNormal, h ) ), gSpecPower ); return float4 ( gLightColor * nl, spec ); } 

so here's the whole thing: "PostProjToScreen ( input.position ) + HalfPixel ( )" line didn't work at all, it changed when my rendered shape changed which means it's not the real coords of the pixel (am i right? ), so i took it out and replaced it with the texcoords from the vertex shader, this only works when i render a fullscreen quad (to implement directional light, for example), but i wan't a more "general" solution so that it could work with other primitives/types of light

now the second thing is: the pixel z position is not being calculated correctly: i tested (with working texcoords from vertex shader) x and y and they seem to be fine, but the z seems to be buggy, im not sure how to debug this because im a little confused about it so i would appreciate some help.

note: the depth map is automatically generated by hardware, i didn't output it myself (i tried doing it myself, the depth map looked weird, alot of big flickers everywhere, even the model depth is screwed up)

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633737
• Total Posts
3013612
×