Skip to main content
History: -Point Light Attenuation
View published page
Source of version: 6
(current)
{INCLUDE(page="ogrelex ext tpl")/} --- A point light's attenuation defines how bright it is with respect to its distance from objects. You can set a light's attenuation by using Ogre's __Light::setAttenuation__ function. The function takes four Real parameters: ''Range'', ''Constant'', ''Linear'', and ''Quadratic''. The ''Range'' parameter has nothing to do with the brightness. If an objects distance is greater than the ''range'', the light has no effect on the object. If the object is in range, the light's effect is calculated with the following formulas: * Luminosity = 1 / Attenuation * Attenuation = ''Constant'' + ''Linear'' * Distance + ''Quadratic'' * Distance~np~^~/np~2 Picking the values by trial and error is time consuming and unintuitive. I have calculated some values for the parameters that work well for specified ranges. Using these numbers, the light has 100% intensity at 0 distance, and trails off to near black at a distance equal to the Range. Keep in mind that most of the light falls in the first 20% of the range. ^ __''Range Constant Linear Quadratic''__ 3250, 1.0, 0.0014, 0.000007 600, 1.0, 0.007, 0.0002 325, 1.0, 0.014, 0.0007 200, 1.0, 0.022, 0.0019 160, 1.0, 0.027, 0.0028 100, 1.0, 0.045, 0.0075 65, 1.0, 0.07, 0.017 50, 1.0, 0.09, 0.032 32, 1.0, 0.14, 0.07 20, 1.0, 0.22, 0.20 13, 1.0, 0.35, 0.44 7, 1.0, 0.7, 1.8 ^ {img src="img/wiki_up/Attenuation_Graph.jpg" alt="Attenuation_Graph.jpg"} For example, if you wish to have a light that gradually dims until it has no effect at distance 100: {CODE(wrap="1", colors="c++")} Light *light; //create pointer to light object light = mSceneMgr->createLight("Light #1"); //set the pointer to a newly created light light->setType(Light::LT_POINT); // make this light a point light light->setDiffuseColour(1.0, .5, 0.0); //color the light orange light->setSpecularColour(1.0, 1.0, 0.0); //yellow highlights light->setAttenuation(100, 1.0, 0.045, 0.0075);{CODE} Once you have chosen a ''Range'' and corresponding values, you can tweak the ''Constant'' and ''Linear'' values. Decreasing the ''Constant'' parameter toward 0.0 brightens the light, while increasing it dims the light. Increasing the ''Linear'' parameter causes the light to fade more quickly with distance. I don't suggest changing the ''Quadratic'' value or decreasing the ''Linear'' values, as doing so will require you to recalculate the ''Range''. Negative numbers are not allowed. Finally, Decreasing the ''Range'' value may give your application a performance boost, but decreasing it too much will cause the object to noticeably change brightness when it moves out of range of the point light. !!See also * ((-Light|Light)) * ((Light Attenuation Shortcut)) - code snippet --- {INCLUDE(page="ogrelex ext tpl")/} --- Alias: (alias(Point_Light_Attenuation))
Search by Tags
Search Wiki by Freetags
Latest Changes
Projects using OGRE
Building Your Projects With CMake
Compiled API Reference
Overlay Editor
Introduction - JaJDoo Shader Guide - Basics
RT Shader System
RapidXML Dotscene Loader
One Function Ogre
One Function Ogre
...more
Search
Find
Online Users
269 online users
OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username
Password
CapsLock is on.
Remember me (for 1 year)
Log in