根据强度计算光体积半径 [英] calculate light volume radius from intensity

查看:123
本文介绍了根据强度计算光体积半径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在计算延迟渲染器的光量半径时遇到问题.在低光照强度下,体积大小看起来正确,但是当光照强度(因此半径)增加时,光照体积似乎越来越小.

我正在像这样计算光的半径(在世界空间中):

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

然后我用这个值来缩放一个盒子.

然后在我的着色器中,像这样计算衰减:

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

因此,显然我正在弄乱数学.衰减应该是线性的,对吧?但是,现在如何正确计算光量的世界比例值?

P.S.由于我计划使用HDR渲染,因此浅色可以超过(1,1,1).

解决方案

不使用该方程式,光就永远亮着.

在wolframalpha.com上的

plot 1.0 / (1+5*(x*x)):

[ EDIT ]由于您的浅色值可以超过1,因此以下1/255将需要除以最大的RGB分量.

您将需要一个阈值.假设您的显示器在黑屏之前不能显示比1/255更暗的颜色,

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

f是您的falloff.对于f = 5,有效半径为〜7.

根据您的应用程序,您可能会增加1/255一点,并且您可能不会发现任何严重错误.或者,捏造不是无限的人工衰减函数:)

此问题也在此处讨论: https://gamedev.stackexchange. com/questions/51291/递延渲染和点光源半径,其中该功能已调整为在阈值处达到零.

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.

解决方案

Not using that equation, light goes on forever.

plot 1.0 / (1+5*(x*x)) at wolframalpha.com:

[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

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

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.

这篇关于根据强度计算光体积半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆