Added adjustable attenuation to dynamic lights.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@726 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2007-06-21 21:06:21 +00:00
parent 01fea0198a
commit 010e9b2fc1
10 changed files with 46 additions and 31 deletions

View File

@ -1,13 +1,24 @@
Changes in version 1.3.1 (20 Jun 2007)
Changes in version 1.4 (... 2007)
- Fixed a typo to do with 2nd light vectors in opengl parallax and normal map renderers.
- 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.
Changes in version 1.3.1 (20 Jun 2007)
- Fixed a bug with negative exponents in fast_atof, posted by RVL
- renamed IAnimatedMeshSceneNode::getAbsoluteTransformation to getMD3TagTransformation
to avoid conflicts with ISceneNode::getAbsoluteTransformation
- renamed IAnimatedMeshSceneNode::getAbsoluteTransformation to
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
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)
- CSphereSceneNode is now texture wrapped with sphere mapping by exactly one
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
artifacts at the borders).
- The Sky box scene node now clamps its textures now by default (meaning no
more ugly artifacts at the borders).
- Frustum culling fixed by using the fixed classifyPointRelation function.
@ -84,7 +95,8 @@ Changes in version 1.3.1 (20 Jun 2007)
- 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)

View File

@ -36,8 +36,9 @@ by the irrlicht engine.
*/
struct SLight
{
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),
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),
Attenuation(1.0f, 0.0f, 0.0f), Radius(100.0f),
CastShadows(true), Type(ELT_POINT)
{};
@ -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.
core::vector3df Position;
//! Attenuation factors
core::vector3df Attenuation;
//! Radius of light. Everything within this radius be be lighted.
f32 Radius;

View File

@ -338,9 +338,7 @@ namespace video
{
// These pointers are checked during assignment
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
{
TextureMatrix[i] = 0;
}
*this = other;
}
@ -348,8 +346,7 @@ namespace video
~SMaterial()
{
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
if (TextureMatrix[i])
delete TextureMatrix[i];
delete TextureMatrix[i];
}
//! Assignment operator

View File

@ -1550,7 +1550,7 @@ namespace core
{
M[0] = (T)sx;
M[5] = (T)sy;
definitelyIdentityMatrix=false;
definitelyIdentityMatrix = definitelyIdentityMatrix && (sx==1.0f) && (sy==1.0f) ;
}
template <class T>

View File

@ -1714,9 +1714,9 @@ void CD3D8Driver::addDynamicLight(const SLight& dl)
light.Ambient = *(D3DCOLORVALUE*)((void*)(&dl.AmbientColor));
light.Range = MaxLightDistance;
light.Attenuation0 = 0.0f;
light.Attenuation1 = 1.0f / dl.Radius;
light.Attenuation2 = 0.0f;
light.Attenuation0 = dl.Attenuation.X;
light.Attenuation1 = dl.Attenuation.Y;
light.Attenuation2 = dl.Attenuation.Z;
++LastSetLight;
pID3DDevice->SetLight(LastSetLight, &light);

View File

@ -1707,9 +1707,9 @@ void CD3D9Driver::addDynamicLight(const SLight& dl)
light.Specular = *(D3DCOLORVALUE*)((void*)(&dl.SpecularColor));
light.Ambient = *(D3DCOLORVALUE*)((void*)(&dl.AmbientColor));
light.Attenuation0 = 0.0f;
light.Attenuation1 = 1.f / dl.Radius;
light.Attenuation2 = 0.0f;
light.Attenuation0 = dl.Attenuation.X;
light.Attenuation1 = dl.Attenuation.Y;
light.Attenuation2 = dl.Attenuation.Z;
++LastSetLight;
pID3DDevice->SetLight(LastSetLight, &light);

View File

@ -147,6 +147,7 @@ void CLightSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeRe
out->addColorf ("AmbientColor", LightData.AmbientColor);
out->addColorf ("DiffuseColor", LightData.DiffuseColor);
out->addColorf ("SpecularColor", LightData.SpecularColor);
out->addVector3d("Attenuation", LightData.Attenuation);
out->addFloat ("Radius", LightData.Radius);
out->addBool ("CastShadows", LightData.CastShadows);
out->addEnum ("LightType", LightData.Type, video::LightTypeNames);
@ -158,6 +159,7 @@ void CLightSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeR
LightData.AmbientColor = in->getAttributeAsColorf("AmbientColor");
LightData.DiffuseColor = in->getAttributeAsColorf("DiffuseColor");
LightData.SpecularColor = in->getAttributeAsColorf("SpecularColor");
LightData.Attenuation = in->getAttributeAsVector3d("Attenuation");
LightData.Radius = in->getAttributeAsFloat("Radius");
LightData.CastShadows = in->getAttributeAsBool("CastShadows");
LightData.Type = (video::E_LIGHT_TYPE)in->getAttributeAsEnumeration("LightType", video::LightTypeNames);

View File

@ -1659,12 +1659,12 @@ void COpenGLDriver::addDynamicLight(const SLight& light)
data[3] = light.AmbientColor.a;
glLightfv(lidx, GL_AMBIENT, data);
// 1.0f / (constant + linar * d + quadratic*(d*d);
// 1.0f / (constant + linear * d + quadratic*(d*d);
// set attenuation
glLightf(lidx, GL_CONSTANT_ATTENUATION, 0.0f);
glLightf(lidx, GL_LINEAR_ATTENUATION, 1.0f / light.Radius);
glLightf(lidx, GL_QUADRATIC_ATTENUATION, 0.0f);
glLightf(lidx, GL_CONSTANT_ATTENUATION, light.Attenuation.X);
glLightf(lidx, GL_LINEAR_ATTENUATION, light.Attenuation.Y);
glLightf(lidx, GL_QUADRATIC_ATTENUATION, light.Attenuation.Z);
glEnable(lidx);
}

View File

@ -1373,9 +1373,9 @@ void CSoftwareDriver2::addDynamicLight(const SLight& dl)
// light in eye space
Transformation[ETS_VIEW].m.transformVect ( &l.posEyeSpace.x, l.org.Position );
l.constantAttenuation = 0.f;
l.linearAttenuation = core::reciprocal ( l.org.Radius );
l.quadraticAttenuation = 0.f;
l.constantAttenuation = l.org.Attenuation.X;
l.linearAttenuation = l.org.Attenuation.Y;
l.quadraticAttenuation = l.org.Attenuation.Z;
l.AmbientColor.setColorf ( l.org.AmbientColor );
l.DiffuseColor.setColorf ( l.org.DiffuseColor );
@ -1489,7 +1489,7 @@ void CSoftwareDriver2::lightVertex ( s4DVertex *dest, const S3DVertex *source )
vp.z = light.posEyeSpace.z - vertexEyeSpace.z;
// irrlicht attenuation model
#if 1
#if 0
const f32 d = vp.get_inverse_length_xyz();
vp.x *= d;
@ -1499,7 +1499,7 @@ void CSoftwareDriver2::lightVertex ( s4DVertex *dest, const S3DVertex *source )
#else
const f32 d = vp.get_length_xyz();
attenuation = 1.f / (light.constantAttenuation +
attenuation = core::reciprocal (light.constantAttenuation +
light.linearAttenuation * d +
light.quadraticAttenuation * d * d
);

View File

@ -67,7 +67,7 @@ all linux: staticlib
# Builds Irrlicht as shared lib (libIrrlicht.so.versionNumber) and copies it into /lib/Linux
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)
# Builds Irrlicht as static lib (libIrrlicht.a)