# Deferred Shading: point light and bounding volume

## Recommended Posts

Hodgman    51234
That's because there's no connection between the range of your light and the size of your sphere.....

##### Share on other sites
enigmagame    140
[quote name='Hodgman' timestamp='1305017631' post='4808882']
That's because there's no connection between the range of your light and the size of your sphere.....
[/quote]

Do you mean the attenuation? Because if I use the original attenuation formula described on the tutorial:
[code]

//surface-to-light vector
float3 lightVector = lightPosition - position;
//compute attenuation based on distance - linear attenuation
float attenuation = saturate(1.0f - length(lightVector)/lightRadius);
[/code]

I obtain the same, wrong, result.

##### Share on other sites
Hodgman    51234
The range of your light is determined by your attenuation function, yes.

This is pretty straight-forward. Any pixel that has a greater-than-zero attenuation result MUST be covered by your sphere mesh. If you sphere mesh doesn't cover pixels with >0 attenuation, you're going to get a hard edge where pixels stop being lit.

Solve your attenuation function to find out what the maximum range of lit pixels is, and then make your sphere that big.

##### Share on other sites
enigmagame    140
[quote name='Hodgman' timestamp='1305018618' post='4808888']
Solve your attenuation function to find out what the maximum range of lit pixels is, and then make your sphere that big.
[/quote]

Sorry, but I don't understand very well. I'm a bit confused.
I've correctly understood the problem that you've explained, but not the solution.

##### Share on other sites
Hodgman    51234
In the attenuation function you posted, the attenuation becomes zero at a distance of '[font="Courier New"]lightRadius[/font]' units from the centre of the light. Any pixels further than this distance away will not be lit.

Also, any pixels outside of your sphere will not be lit.

Therefore the [i]radius [/i]of your sphere should be at least '[font="Courier New"]lightRadius[/font]' units to avoid getting the hard-line where a pixel that should've been lit, isn't (due to it not being covered by the sphere).

##### Share on other sites
enigmagame    140
Ok guys, I've found the problem, and it was a very, very, very stupid problem: the size of the sphere mesh.
I've created a new mesh, and this is the results:

It seems correct. You confirm?
Thanks.

##### Share on other sites
Pthalicus    738
[quote name='enigmagame' timestamp='1305051190' post='4809061']
I've created a new mesh, and this is the results:

[/quote]

Yeah, looks fine.
It's easy to over look things, it's always best to narrow down where the problem could be, in this case the size of the sphere.
Nice work.