Jump to content
  • Advertisement
Sign in to follow this  
MegaPixel

Deferred shading - Incorrect lighting !

This topic is 2909 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

Hi all,

I implemented a deferred renderer, I'm outputting eye linear depth in this way:

float4 p = float4(Input.pos,1.f);
float3 eyeLinear = mul(p,worldViewMatrix).xyz; //trasform into view space

vs_out.oNormalDepth.w = eyeLinear.z;

than in the pixel shader I output normalized eye linear depth ( dividing it by farClip plane distance). I use a one channel 32bit floating point render target to store eye linear depth:

ps_out.eyeLinearDepthBuffer = Input.oNormalDepth.w / zFarzyw.x;


I don't know if I'm calculating the eye linear depth correctly (I've read several thread on this forum etc. and I think It should be correct).

However during the lighting pass I'm gettin strange artifacts/results. I output just the diffuse component to test it and I can notice that the background ( which should be black ) is picking the diffuse shading as well :| while I would expect that just the objects were shaded. Plus, as I move around with the camera the lighting changes. I checked that all my vector for the lighting calculation were in view space just in case and I'm sure they are.

I'm using only one point light to lit a sphere on a plane and I perform lighting in view space.

I checked my gbuffer output and it seems to be correct to me.

View space position buffer is:

black bottom left
red bottom left
yellow top right
green top left

Normal are in view space too:

blue pointing toward the viewer
green on top
red on the right

I don't know how to post images straight on the window thread otherwise I would put some screens of the gbuffer output and a screen with the wrong lighting. (I know that some screens could help ...)

Thanks in advance for any reply

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by MegaPixel

black bottom left
red bottom left
yellow top right
green top left



Objously is:

red bottom right

thanks :D

Share this post


Link to post
Share on other sites
Quote:
Original post by MegaPixel
I don't know how to post images straight on the window thread otherwise I would put some screens of the gbuffer output and a screen with the wrong lighting. (I know that some screens could help ...)


Run your application, press PrtScr/SysRq (and hold Alt to capture just that window); open some image editing program (even mspaint works), paste whatever is in the clipboard, and save it as a PNG. Go to www.imageshack.us, and upload your PNG. Copy the "Direct URL" link, and post it on here like this: <img src="the_url_from_imageshack"/>

Share this post


Link to post
Share on other sites
Quote:
Original post by nullsquared
Quote:
Original post by MegaPixel
I don't know how to post images straight on the window thread otherwise I would put some screens of the gbuffer output and a screen with the wrong lighting. (I know that some screens could help ...)


Run your application, press PrtScr/SysRq (and hold Alt to capture just that window); open some image editing program (even mspaint works), paste whatever is in the clipboard, and save it as a PNG. Go to www.imageshack.us, and upload your PNG. Copy the "Direct URL" link, and post it on here like this: <img src="the_url_from_imageshack"/>


Hi,

thanks I know how to take screenshots under windows :D, I just didn't know how to post the image on the forum (I do know imageshack but I saw some other user posting the image straight on the thread without any external link). However what I didn't know was how to put a reference to an external link, which what you suggest me.

Thanks a lot I'll upload some screens as soon as I can

Share this post


Link to post
Share on other sites
Ok I uploaded some screens.


Here are the wrong lighting results (plus as I go far away with the camera the background goes pure white and if I go forward It gets black ! ... ):



Then the gbuffers output ( all the data are in view space ):

view space normals:



view space positions:



eye linear depth:



Thanks for any hint ;)

Share this post


Link to post
Share on other sites
Quote:
Original post by nullsquared
Can you post your shader code? I can't quite tell what's wrong just from the screenshots.


Just a quick one: how can I post the shader code using the text box? ... :P

... otherwise I'll just cut and paste it ... ;)

thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by MegaPixel
Quote:
Original post by nullsquared
Can you post your shader code? I can't quite tell what's wrong just from the screenshots.


Just a quick one: how can I post the shader code using the text box? ... :P

... otherwise I'll just cut and paste it ... ;)

thanks


Use [source]stuff[/source]

Share this post


Link to post
Share on other sites
Ok I'll just cut and paste the code, as I don't know how to create a code snippet:

vertex shader gbuffer pass:


//vertex shader gbuffer pass
VS_OUTPUT vs_gbuffer_main(VS_INPUT Input)
{
VS_OUTPUT vs_out = (VS_OUTPUT)0;

vs_out.oNormalDepth.xyz = normalize( mul((float3x3)invTransWorldViewMatrix,Input.iNormal) );//output just x,y and z = sqrt(1-x*x-y*y);

float4 p = float4(Input.pos,1.f);
float3 eyeLinear = mul(p,worldViewMatrix).xyz; //trasform into eye linear space (camera space)

//write out eye linear depth
#ifdef OGL
vs_out.oNormalDepth.w = -eyeLinear.z; //negate depth if we use ogl as the we use a right handed frame of reference
#else
vs_out.oNormalDepth.w = eyeLinear.z; //d3d is left handed
#endif

vs_out.oPos = mul(p,mul(worldViewMatrix,prjMatrix));

return vs_out;
}




the pixel shader during the lighting pass (vertex shader is just the fullscreen aligned quad therefore I omitted that):


float4 ps_lighting_main( in float2 iTc : TEXCOORD
,in float3 iFrustumCorner : TEXCOORD1 ) : COLOR
{
float fPixelDepth = tex2D(depthTextureSamplerD3D, iTc).r;

//fragment position in eye/view space
float4 vPositionVS = float4(iFrustumCorner.xy*fPixelDepth,fPixelDepth, 1.f);

//fragment normal in eye space
float3 normal = float3(tex2D(normalTextureSamplerD3D, iTc).xy,0);
normal.z = sqrt(1.f-normal.x*normal.x-normal.y*normal.y);

normal = normalize( normal );

//lighting calculation is done in view space
float pointLightAtt = (lightType == 1.f) ? get_light_attenuation(lightPos,vPositionVS.xyz) : 1.f;
float spotLightInfluenceFactor = (lightType == 2.f) ? get_spotLight_influence(lightPos,vPositionVS.xyz) : 1.f;

float3 pointToLightDir = normalize( get_light_dir(lightPos,vPositionVS.xyz) );
float3 eyeDir = normalize(-vPositionVS.xyz); //eye dir in view space

float specular = 0;
float diffuse = 0;

//phong lighting model is used ( in the future will be possible to choose different lighting model as well )
phong(normal,pointToLightDir,eyeDir,20.f,specular,diffuse);

return fPixelDepth;//diffuse;//(specular+diffuse*float4(lightColor,1))*pointLightAtt*spotLightInfluenceFactor;
}



Thanks


Share this post


Link to post
Share on other sites
Quote:
Original post by MegaPixel
Ok I'll just cut and paste the code, as I don't know how to create a code snippet:


Forgot to remove this line :P

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!