Commit 010e9b2f authored by hybrid's avatar hybrid

Added adjustable attenuation to dynamic lights.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@726 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 01fea019
Changes in version 1.3.1 (20 Jun 2007) Changes in version 1.4 (... 2007)
- Added adjustable Attenuation for dynamic lights. This allows to change the
intensity of a light based on its distance. The default attenuation changed
from (0,1/radius,0) to (1,0,0) which means no effect by distance. Good
values for distance effects simply add small values to the second and third
element.
- Fixed a typo to do with 2nd light vectors in opengl parallax and normal map renderers. - Fixed a typo to do with 2nd light vectors in opengl parallax and normal map
renderers.
Changes in version 1.3.1 (20 Jun 2007)
- Fixed a bug with negative exponents in fast_atof, posted by RVL - Fixed a bug with negative exponents in fast_atof, posted by RVL
- renamed IAnimatedMeshSceneNode::getAbsoluteTransformation to getMD3TagTransformation - renamed IAnimatedMeshSceneNode::getAbsoluteTransformation to
to avoid conflicts with ISceneNode::getAbsoluteTransformation getMD3TagTransformation to avoid conflicts with
ISceneNode::getAbsoluteTransformation
- Added rect::constrainTo for locking a rectangle inside another without resizing it - Added rect::constrainTo for locking a rectangle inside another without
resizing it
- Moved the OpenGL API functions from COpenGL driver into new extension - Moved the OpenGL API functions from COpenGL driver into new extension
handler. Thereby, some renaming took place - the ARB and EXT suffix was handler. Thereby, some renaming took place - the ARB and EXT suffix was
...@@ -26,8 +37,8 @@ Changes in version 1.3.1 (20 Jun 2007) ...@@ -26,8 +37,8 @@ Changes in version 1.3.1 (20 Jun 2007)
- CSphereSceneNode is now texture wrapped with sphere mapping by exactly one - CSphereSceneNode is now texture wrapped with sphere mapping by exactly one
texture. Only a small error on the top remained. texture. Only a small error on the top remained.
- The Sky box scene node now clamps its textures now by default (meaning no more ugly - The Sky box scene node now clamps its textures now by default (meaning no
artifacts at the borders). more ugly artifacts at the borders).
- Frustum culling fixed by using the fixed classifyPointRelation function. - Frustum culling fixed by using the fixed classifyPointRelation function.
...@@ -84,7 +95,8 @@ Changes in version 1.3.1 (20 Jun 2007) ...@@ -84,7 +95,8 @@ Changes in version 1.3.1 (20 Jun 2007)
- Fixed getHeight from terrain scene node. - Fixed getHeight from terrain scene node.
- The FPS counter now works as in previous releases, the accumulating counter can be enabled by a parameter. - The FPS counter now works as in previous releases, the accumulating counter
can be enabled by a parameter.
- getType() is now const correct (API Changes) - getType() is now const correct (API Changes)
......
...@@ -36,8 +36,9 @@ by the irrlicht engine. ...@@ -36,8 +36,9 @@ by the irrlicht engine.
*/ */
struct SLight struct SLight
{ {
SLight() : AmbientColor(0.0f,0.0f,0.0f), DiffuseColor(1.0f, 1.0f, 1.0f), SLight() : AmbientColor(0.0f,0.0f,0.0f), DiffuseColor(1.0f, 1.0f, 1.0f),
SpecularColor(1.0f,1.0f,1.0f), Position(0.0f, 0.0f, 0.0f), Radius(100.0f), SpecularColor(1.0f,1.0f,1.0f), Position(0.0f, 0.0f, 0.0f),
Attenuation(1.0f, 0.0f, 0.0f), Radius(100.0f),
CastShadows(true), Type(ELT_POINT) CastShadows(true), Type(ELT_POINT)
{}; {};
...@@ -55,6 +56,9 @@ struct SLight ...@@ -55,6 +56,9 @@ struct SLight
//! Position of the light. If Type is ELT_DIRECTIONAL, this is the direction vector the light is coming from. //! Position of the light. If Type is ELT_DIRECTIONAL, this is the direction vector the light is coming from.
core::vector3df Position; core::vector3df Position;
//! Attenuation factors
core::vector3df Attenuation;
//! Radius of light. Everything within this radius be be lighted. //! Radius of light. Everything within this radius be be lighted.
f32 Radius; f32 Radius;
......
...@@ -338,9 +338,7 @@ namespace video ...@@ -338,9 +338,7 @@ namespace video
{ {
// These pointers are checked during assignment // These pointers are checked during assignment
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i) for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
{
TextureMatrix[i] = 0; TextureMatrix[i] = 0;
}
*this = other; *this = other;
} }
...@@ -348,8 +346,7 @@ namespace video ...@@ -348,8 +346,7 @@ namespace video
~SMaterial() ~SMaterial()
{ {
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i) for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
if (TextureMatrix[i]) delete TextureMatrix[i];
delete TextureMatrix[i];
} }
//! Assignment operator //! Assignment operator
......
...@@ -1550,7 +1550,7 @@ namespace core ...@@ -1550,7 +1550,7 @@ namespace core
{ {
M[0] = (T)sx; M[0] = (T)sx;
M[5] = (T)sy; M[5] = (T)sy;
definitelyIdentityMatrix=false; definitelyIdentityMatrix = definitelyIdentityMatrix && (sx==1.0f) && (sy==1.0f) ;
} }
template <class T> template <class T>
......
...@@ -1714,9 +1714,9 @@ void CD3D8Driver::addDynamicLight(const SLight& dl) ...@@ -1714,9 +1714,9 @@ void CD3D8Driver::addDynamicLight(const SLight& dl)
light.Ambient = *(D3DCOLORVALUE*)((void*)(&dl.AmbientColor)); light.Ambient = *(D3DCOLORVALUE*)((void*)(&dl.AmbientColor));
light.Range = MaxLightDistance; light.Range = MaxLightDistance;
light.Attenuation0 = 0.0f; light.Attenuation0 = dl.Attenuation.X;
light.Attenuation1 = 1.0f / dl.Radius; light.Attenuation1 = dl.Attenuation.Y;
light.Attenuation2 = 0.0f; light.Attenuation2 = dl.Attenuation.Z;
++LastSetLight; ++LastSetLight;
pID3DDevice->SetLight(LastSetLight, &light); pID3DDevice->SetLight(LastSetLight, &light);
......
...@@ -1707,9 +1707,9 @@ void CD3D9Driver::addDynamicLight(const SLight& dl) ...@@ -1707,9 +1707,9 @@ void CD3D9Driver::addDynamicLight(const SLight& dl)
light.Specular = *(D3DCOLORVALUE*)((void*)(&dl.SpecularColor)); light.Specular = *(D3DCOLORVALUE*)((void*)(&dl.SpecularColor));
light.Ambient = *(D3DCOLORVALUE*)((void*)(&dl.AmbientColor)); light.Ambient = *(D3DCOLORVALUE*)((void*)(&dl.AmbientColor));
light.Attenuation0 = 0.0f; light.Attenuation0 = dl.Attenuation.X;
light.Attenuation1 = 1.f / dl.Radius; light.Attenuation1 = dl.Attenuation.Y;
light.Attenuation2 = 0.0f; light.Attenuation2 = dl.Attenuation.Z;
++LastSetLight; ++LastSetLight;
pID3DDevice->SetLight(LastSetLight, &light); pID3DDevice->SetLight(LastSetLight, &light);
......
...@@ -147,6 +147,7 @@ void CLightSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeRe ...@@ -147,6 +147,7 @@ void CLightSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeRe
out->addColorf ("AmbientColor", LightData.AmbientColor); out->addColorf ("AmbientColor", LightData.AmbientColor);
out->addColorf ("DiffuseColor", LightData.DiffuseColor); out->addColorf ("DiffuseColor", LightData.DiffuseColor);
out->addColorf ("SpecularColor", LightData.SpecularColor); out->addColorf ("SpecularColor", LightData.SpecularColor);
out->addVector3d("Attenuation", LightData.Attenuation);
out->addFloat ("Radius", LightData.Radius); out->addFloat ("Radius", LightData.Radius);
out->addBool ("CastShadows", LightData.CastShadows); out->addBool ("CastShadows", LightData.CastShadows);
out->addEnum ("LightType", LightData.Type, video::LightTypeNames); out->addEnum ("LightType", LightData.Type, video::LightTypeNames);
...@@ -158,6 +159,7 @@ void CLightSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeR ...@@ -158,6 +159,7 @@ void CLightSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeR
LightData.AmbientColor = in->getAttributeAsColorf("AmbientColor"); LightData.AmbientColor = in->getAttributeAsColorf("AmbientColor");
LightData.DiffuseColor = in->getAttributeAsColorf("DiffuseColor"); LightData.DiffuseColor = in->getAttributeAsColorf("DiffuseColor");
LightData.SpecularColor = in->getAttributeAsColorf("SpecularColor"); LightData.SpecularColor = in->getAttributeAsColorf("SpecularColor");
LightData.Attenuation = in->getAttributeAsVector3d("Attenuation");
LightData.Radius = in->getAttributeAsFloat("Radius"); LightData.Radius = in->getAttributeAsFloat("Radius");
LightData.CastShadows = in->getAttributeAsBool("CastShadows"); LightData.CastShadows = in->getAttributeAsBool("CastShadows");
LightData.Type = (video::E_LIGHT_TYPE)in->getAttributeAsEnumeration("LightType", video::LightTypeNames); LightData.Type = (video::E_LIGHT_TYPE)in->getAttributeAsEnumeration("LightType", video::LightTypeNames);
......
...@@ -1659,12 +1659,12 @@ void COpenGLDriver::addDynamicLight(const SLight& light) ...@@ -1659,12 +1659,12 @@ void COpenGLDriver::addDynamicLight(const SLight& light)
data[3] = light.AmbientColor.a; data[3] = light.AmbientColor.a;
glLightfv(lidx, GL_AMBIENT, data); glLightfv(lidx, GL_AMBIENT, data);
// 1.0f / (constant + linar * d + quadratic*(d*d); // 1.0f / (constant + linear * d + quadratic*(d*d);
// set attenuation // set attenuation
glLightf(lidx, GL_CONSTANT_ATTENUATION, 0.0f); glLightf(lidx, GL_CONSTANT_ATTENUATION, light.Attenuation.X);
glLightf(lidx, GL_LINEAR_ATTENUATION, 1.0f / light.Radius); glLightf(lidx, GL_LINEAR_ATTENUATION, light.Attenuation.Y);
glLightf(lidx, GL_QUADRATIC_ATTENUATION, 0.0f); glLightf(lidx, GL_QUADRATIC_ATTENUATION, light.Attenuation.Z);
glEnable(lidx); glEnable(lidx);
} }
......
...@@ -1373,9 +1373,9 @@ void CSoftwareDriver2::addDynamicLight(const SLight& dl) ...@@ -1373,9 +1373,9 @@ void CSoftwareDriver2::addDynamicLight(const SLight& dl)
// light in eye space // light in eye space
Transformation[ETS_VIEW].m.transformVect ( &l.posEyeSpace.x, l.org.Position ); Transformation[ETS_VIEW].m.transformVect ( &l.posEyeSpace.x, l.org.Position );
l.constantAttenuation = 0.f; l.constantAttenuation = l.org.Attenuation.X;
l.linearAttenuation = core::reciprocal ( l.org.Radius ); l.linearAttenuation = l.org.Attenuation.Y;
l.quadraticAttenuation = 0.f; l.quadraticAttenuation = l.org.Attenuation.Z;
l.AmbientColor.setColorf ( l.org.AmbientColor ); l.AmbientColor.setColorf ( l.org.AmbientColor );
l.DiffuseColor.setColorf ( l.org.DiffuseColor ); l.DiffuseColor.setColorf ( l.org.DiffuseColor );
...@@ -1489,7 +1489,7 @@ void CSoftwareDriver2::lightVertex ( s4DVertex *dest, const S3DVertex *source ) ...@@ -1489,7 +1489,7 @@ void CSoftwareDriver2::lightVertex ( s4DVertex *dest, const S3DVertex *source )
vp.z = light.posEyeSpace.z - vertexEyeSpace.z; vp.z = light.posEyeSpace.z - vertexEyeSpace.z;
// irrlicht attenuation model // irrlicht attenuation model
#if 1 #if 0
const f32 d = vp.get_inverse_length_xyz(); const f32 d = vp.get_inverse_length_xyz();
vp.x *= d; vp.x *= d;
...@@ -1499,7 +1499,7 @@ void CSoftwareDriver2::lightVertex ( s4DVertex *dest, const S3DVertex *source ) ...@@ -1499,7 +1499,7 @@ void CSoftwareDriver2::lightVertex ( s4DVertex *dest, const S3DVertex *source )
#else #else
const f32 d = vp.get_length_xyz(); const f32 d = vp.get_length_xyz();
attenuation = 1.f / (light.constantAttenuation + attenuation = core::reciprocal (light.constantAttenuation +
light.linearAttenuation * d + light.linearAttenuation * d +
light.quadraticAttenuation * d * d light.quadraticAttenuation * d * d
); );
......
...@@ -67,7 +67,7 @@ all linux: staticlib ...@@ -67,7 +67,7 @@ all linux: staticlib
# Builds Irrlicht as shared lib (libIrrlicht.so.versionNumber) and copies it into /lib/Linux # Builds Irrlicht as shared lib (libIrrlicht.so.versionNumber) and copies it into /lib/Linux
sharedlib: $(LINKOBJ) sharedlib: $(LINKOBJ)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -shared -Wl,-soname,$(SHARED_LIB) -fPIC -o $(SHARED_LIB).$(VERSION) $^ $(LDFLAGS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -shared -Wl,-soname,$(SHARED_LIB).1 -fPIC -o $(SHARED_LIB).$(VERSION) $^ $(LDFLAGS)
cp $(SHARED_LIB).$(VERSION) $(LIB_PATH) cp $(SHARED_LIB).$(VERSION) $(LIB_PATH)
# Builds Irrlicht as static lib (libIrrlicht.a) # Builds Irrlicht as static lib (libIrrlicht.a)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment