Jump to content
  • Advertisement
Sign in to follow this  

[xna] deferred spot light depth precision problem

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

i'm trying to solve this for over a week, i tried everything i can think of, and it's still not working - i mean spot lights in my deferred renderer, these are some screens and short movie:



the green one is a point light, the yellow one is a spot light, they share most of the hlsl and c# code, position reconstruction is the same, samplers etc are also the same, i tried almost every sampler state and texture format, i use [color=#2b91af]SurfaceFormat.Color for gbuffer's render targets: diffuse , normal depth, i use [color=#2b91af]SurfaceFormat.Rgba64 for light buffer, in the light stage i use [color=#2b91af]SamplerState.LinearClamp for diffuse and normal rt and PointClamp for depth (i use sphere and cone as light primitives), i don't use linear depth, just normal way:

[color=blue]float3 UnitToColor([color=blue]in [color=blue]float unit)
[color=blue]const [color=blue]float3 factor = [color=blue]float3([color=navy]1, [color=navy]255, [color=navy]65025);
[color=blue]const [color=blue]float mask = [color=navy]1.0 / [color=navy]256.0;
[color=blue]float3 color = unit * factor.rgb;
color.gb = [color=maroon]frac(color.gb);
color.rg -= color.gb * mask;
[color=blue]return [color=maroon]saturate(color);
gbuffer.fx :
output.Depth = [color=blue]float4(UnitToColor(input.Depth.x / input.Depth.y), [color=navy]1.0f);

light shader:

[color=blue]float ColorToUnit([color=blue]in [color=blue]float3 color)
[color=blue]const [color=blue]float3 factorinv = [color=navy]1.0 / [color=blue]float3([color=navy]1, [color=navy]255, [color=navy]65025);
[color=blue]return [color=maroon]dot(color, factorinv);

input.ScreenPosition.xy /= input.ScreenPosition.w;
[color=blue]float2 UV = [color=navy]0.5f * ([color=blue]float2(input.ScreenPosition.x, -input.ScreenPosition.y) + [color=navy]1) - [color=blue]float2([color=navy]1.0f / GBufferTextureSize.xy);
[color=blue]float4 Position = [color=navy]1.0f;
Position.xy = input.ScreenPosition.xy;
Position.z = ColorToUnit(Depth);
Position = [color=maroon]mul(Position, InverseViewProjection);
Position /= Position.w;

it's the same in point light and in spot light, how is this possible that point light works ok, and i have these depth precision issues with spot light? near/far plane ratio affect these artifacts very much, but even 10-100 is not ok (now it's 1 - 10000)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!