Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Deferred shading problem

Started by b3rs3rk 0 replies 900+ views
Original Post
b3rs3rk
b3rs3rk
Hi guys! I have a small problem with my deferred shading implementation... in a nutshell, I'm rendering some point lights, but they continue to move with the camera :S In my G-Buffer, the depth is computed this way: output.Depth = ( viewPosition.z - nearZ ) / ( farZ - nearZ ); then in the light vertex shader I compute the view direction from the frustum corners (rendering a full screen quad):

float3 corner = float3(-cornerFrustrum.x * input.Position.x, cornerFrustrum.y * input.Position.y, cornerFrustrum.z);
output.viewDirection = mul(float4(corner,1), InvertedViewMatrix);

cornerFrustrum is a vector3 created this way:

 float farY = (float)Math.Tan(Math.PI / 3.0 / 2.0) * CameraManager.ActiveCamera.Far;
float farX = farY * CameraManager.ActiveCamera.AspectRatio;
Vector3 frustrumCorner = new Vector3(farX, farY, CameraManager.ActiveCamera.Far);

finally, I compute the position in the pixel shader this way:

float depthVal = tex2D(depthSampler, input.TexCoord).r;
float3 position = cameraPosition + input.viewDirection * depthVal;   

but as I said, the lights continue moving with the camera :( If I remove the multiplication in the VS with InvertedViewMatrix, the lights are correct but they disappear if I move a bit far from their position... Any suggestions?
b3rs3rk
b3rs3rk
Another question (even if nobody still answered to the first...): for point lights should I render a fullscreen quad or a sphere mesh for each light source?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.