Jump to content

  • Log In with Google      Sign In   
  • Create Account


light pre-pass


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 Hassanbasil   Members   -  Reputation: 189

Like
0Likes
Like

Posted 25 December 2011 - 01:05 PM

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? :D), 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)

Thank you for your time.

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS