My company has b开发者_StackOverflow中文版een creating an internal level editor in Unity3D for an OpenGL based game. The problem is I'm having trouble mapping Unity's Lighting model to OpenGLs.
Most settings on Unity's lights make sense, although I'm having trouble mapping "range" to OpenGL's constant, linear and quadratic attenuation.
In Unity "range" appears to be the distance where "no light" (a minuscule amount) is received by the surface. I've gotten approximations to work, however I'd love to know the correct mapping.
Range is actually makes no sense, since technically light is governed by a 1/r² falloff. OpenGL fixed function pipeline provides you with two attenuation factors: A linear and a quadratic one. In the linear case the linear factor would be simply 1/range, but the resulting illumination wouldn't look natural. In a quadratic attenuation case you could assume the distance for which the light has attenuated to 1/10 as range (assuming the a falloff to the least significant bit sounds better in theory, but will lead to a too short falloff).
精彩评论