0

i am currently having a problem with calculating the light volume radius for a deferred renderer. On low light intensities the volume size looks correct but when the light intensity (and therefore the radius) increases, the light volume seems to be more and more too small.

I am calculating the light volume radius (in world space) like this:

const float LIGHT_CUTOFF_DEFAULT = 50;
mRadius = sqrt(color.length() * LIGHT_CUTOFF_DEFAULT);

I then use this value to scale a box.

In my shader i then calculate the attenuation like this:

float falloff = 5;
float attenuation = max(0, 1.0 / (1+falloff*(distance*distance)));

So obviously I am messing around with the math. The attenuation should be linear, right? But how do I now correctly calculate the world scale value for the light volume?

P.S. the light color can go beyond (1,1,1) since I am planning to use HDR rendering.

genpfault
  • 51,148
  • 11
  • 85
  • 139
C0dR
  • 320
  • 1
  • 6
  • 23

1 Answers1

4

Not using that equation, light goes on forever.

plot 1.0 / (1+5*(x*x)) at wolframalpha.com: enter image description here

[EDIT] Since your light colour values can go above one, the following 1/255 will need to be divided by the largest RGB component.

You'll need a threshold. Assuming your monitor can't display anything dimmer than 1/255 before black,

solve 1.0 / (1+f*(x*x)) = 1/255, x

enter image description here

Where f is your falloff. For f = 5, the effective radius is ~7.

enter image description here

You could probably increase 1/255 a little depending on your application and you might not notice anything badly wrong. Alternatively, fudge an artificial falloff function which isn't infinite :)

This issue is also discussed here: https://gamedev.stackexchange.com/questions/51291/deferred-rendering-and-point-light-radius, where the function is adjusted to reach zero at the threshold.

Community
  • 1
  • 1
jozxyqk
  • 16,424
  • 12
  • 91
  • 180
  • I calculate radius now like this: `radius = sqrt(colMaxVal*254) / sqrt(LIGHT_CUTTOFF_DEFAULT);` and it looks correct to me. But now i have another question: am i event right that i allow light values above 1.0 for HDR? And with this attenuation function i need pretty high light values to get larger areas lit. I assume to solve this i have to use another one? But this one looks pretty physically correct to me... – C0dR Nov 24 '14 at 14:18
  • 1
    @C0dR found a related post here: http://gamedev.stackexchange.com/questions/21057/does-the-linear-attenuation-component-in-lighting-models-have-a-physical-counter. To make deferred rendering efficient you want to keep the radius small, but with a quadratic attenuation most of the computation is for only small additions. For this reason you might want a more gradual falloff, adding a linear component. – jozxyqk Nov 24 '14 at 15:18