Jump to content

  • Log In with Google      Sign In   
  • Create Account


We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!

Deferred shading - problems with point lights

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
2 replies to this topic

#1 AdamJ77   Members   -  Reputation: 106


Posted 08 November 2012 - 12:14 PM

Hi everyone. I am working on deferred shading because I want to add this to my own engine. Currently geometry phase and directional lights from lighting phase are working fine on both versions of directx 9 and 11.
I stucked on points lights. Here is a shader's code for point light:

[source lang="cpp"]cbuffer VertexShaderParameters{ matrix ModelViewProjection;};cbuffer PixelShaderParameters{ float3 LightPosition; float4 LightColor; float LightIntensity; float LightRange; matrix ViewProjectionInverse;};Texture2D DepthMap;Texture2D NormalMap;SamplerState PointClampSampler;struct VertexShaderInput{ float3 Position : Position;};struct PixelShaderInput{ float4 Position : SV_Position;};PixelShaderInput VertexShaderMain(VertexShaderInput input){ PixelShaderInput output; output.Position = mul(float4(input.Position, 1.0f), ModelViewProjection); return output;}float4 PixelShaderMain(PixelShaderInput input) : SV_Target{ float3 posXYZ = input.Position.xyz / input.Position.w; float2 uv = float2(posXYZ.x, -posXYZ.y) * 0.5f + 0.5f; float depth = DepthMap.Sample(PointClampSampler, uv); float3 normal = NormalMap.Sample(PointClampSampler, uv) * 2.0f - 1.0f; float4 posXYZW = float4(posXYZ.xy, depth, 1.0f); float4 worldPosition = mul(posXYZW, ViewProjectionInverse); worldPosition /= worldPosition.w; float3 lightVector = LightPosition - worldPosition.xyz; float3 lightDirection = normalize(lightVector); float dotProduct = dot(lightDirection, normalize(normal)); float lightDistance = length(lightVector); float falloff = saturate(1.0f - lightDistance / LightRange); float i = saturate(dotProduct) * LightIntensity * falloff * falloff; return LightColor * i;}[/source]

Implementation that is working in DirectX 9 isn't working on DirectX 11.

Please for help to resolve this problem.

Attached Thumbnails

  • PointLightOnQuad.png


#2 MikeBMcL   Members   -  Reputation: 172


Posted 08 November 2012 - 07:31 PM

Try changing line 50 to:

float dotProduct = abs(dot(lightDirection, normalize(normal)));

#3 MJP   Moderators   -  Reputation: 11786


Posted 08 November 2012 - 07:45 PM

I would suggest outputting your position to make sure that you're reconstructing the correct value. You can also try outputting your normals to verify that they're correct. You can also debug your shader in PIX or the VS 2012 graphics debugger, so that you can step through and see where you're going wrong. And if you haven't enabled debug output when creating your device, then you should do so to ensure that you catch any errors.

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.