Commit 59ac6432 authored by hybrid's avatar hybrid

Added Spot lights for hardware drivers. Added per pixel fog support for OpenGL.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@838 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 8f34efc3
Changes in version 1.4 (... 2007)
- Added river support for user defined clip planes, based on mandrav's patch.
- Added Spot light type for dynamic lights. Note that both position and direction for all dynamic lights are now determined by the LightSceneNode, the SLight attributes are only used for internal purposes.
API change! One can easily work around this change by setting the LightSceneNode's Position and Rotation instead of the SLight's. This change won't provoke a compile error, though, and can hence go unrecognized besides the visual problems.
The lights use a default direction (0,0,-1) which is rotated by the usual scene node transformations and can hence be modified by scene node animators.
A change in the Radius usage can lead to strange artifacts. Just increase the Radius in this case. further handling of Radius is to be discussed.
- Added per pixel fog support for OpenGL.
- Added driver support for user defined clip planes, based on mandrav's patch.
The OpenGL version is more picky about ModelView matrices, so it's best to set the projection plane at the time it is used.
- .obj files now load relative indices correctly. Collada files load textures.
- A new MeshBuffer implementation is publicly available. It supports a shared vertex list for all MeshBuffers, used for MS3D meshes.
- MeshBuffers can recalculate their BoundingBoxes on their own now, no need for MeshManipulators. New append methods help to merge MeshBuffers. take care that the types match!
- The new texture generation mode is working. With ETCF_NO_ALPHA_CHANNEL textures are generated without ALPHA bits reserved.
- D3D9 hardware mipmap updates are re-enabled, problems should be reported.
- In some cases fullscreeen modes under win32 should have a better frame rate now.
- Fixed the hillplane mesh to work with non-quadratic dimensions as well. Changed the interface also, so use a u32 dimension to specify the tilecount now.
......
......@@ -133,7 +133,7 @@ int main()
We add a hello world label to the window, using the GUI environment.
*/
guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
rect<int>(10,10,260,22), true);
rect<s32>(10,10,260,22), true);
/*
To display something interesting, we load a Quake 2 model
......
......@@ -213,7 +213,7 @@
corner.</p>
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
<tr>
<td> <pre>guienv-&gt;addStaticText(L&quot;Hello World! This is the Irrlicht Software engine!&quot;,<br> rect&lt;int&gt;(10,10,200,22), true);</pre> </td>
<td> <pre>guienv-&gt;addStaticText(L&quot;Hello World! This is the Irrlicht Software engine!&quot;,<br> rect&lt;s32&gt;(10,10,200,22), true);</pre> </td>
</tr>
</table>
......
......@@ -121,7 +121,7 @@ int main()
// create light
node = smgr->addLightSceneNode(0, core::vector3df(0,0,0),
video::SColorf(1.0f, 0.6f, 0.7f, 1.0f), 600.0f);
video::SColorf(1.0f, 0.6f, 0.7f, 1.0f), 1200.0f);
scene::ISceneNodeAnimator* anim = 0;
anim = smgr->createFlyCircleAnimator (core::vector3df(0,150,0),250.0f);
node->addAnimator(anim);
......@@ -248,13 +248,13 @@ int main()
if (lastFPS != fps)
{
core::stringw str = L"Irrlicht Engine - SpecialFX example [";
str += driver->getName();
str += "] FPS:";
str += fps;
core::stringw str = L"Irrlicht Engine - SpecialFX example [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
......
This diff is collapsed.
......@@ -35,12 +35,12 @@ public:
irr::scene::ILightSceneNode* l = (irr::scene::ILightSceneNode*) node;
core::vector3df now = l->getPosition();
if ( ToFollow )
{
core::vector3df now = l->getPosition();
now += ToFollow->getBoundingBox().getCenter();
now += Offset;
l->setPosition(now);
}
irr::video::SColorHSL color;
......@@ -52,7 +52,6 @@ public:
video::SLight light = l->getLightData();
light.DiffuseColor = rgb;
light.Position = now;
l->setLightData(light);
}
......
......@@ -39,7 +39,7 @@ int main()
case 'b': driverType = video::EDT_DIRECT3D8;break;
case 'c': driverType = video::EDT_OPENGL; break;
case 'd': driverType = video::EDT_SOFTWARE; break;
case 'e': driverType = video::EDT_SOFTWARE2;break;
case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
case 'f': driverType = video::EDT_NULL; break;
default: return 0;
}
......
......@@ -34,8 +34,11 @@ public:
//! Gets the light data associated with this ILightSceneNode
//! \return Returns the light data.
virtual video::SLight& getLightData() = 0;
virtual const video::SLight& getLightData() const = 0;
//! Gets the light data associated with this ILightSceneNode
//! \return Returns the light data.
virtual video::SLight& getLightData() = 0;
};
} // end namespace scene
......
......@@ -17,7 +17,8 @@ enum E_LIGHT_TYPE
{
//! point light, it has a position in space and radiates light in all directions
ELT_POINT,
//! spot light, it has a position in space, a direction, and a limited cone of influence
ELT_SPOT,
//! directional light, coming from a direction from an infinite distance
ELT_DIRECTIONAL
};
......@@ -26,20 +27,21 @@ enum E_LIGHT_TYPE
const c8* const LightTypeNames[] =
{
"Point",
"Spot",
"Directional",
0
};
//! structure for holding data describing a dynamic point light.
/** ambient light and point lights are the only light supported
by the irrlicht engine.
/** Irrlicht supports point lights, spot lights, and directional lights.
*/
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),
Attenuation(1.0f, 0.0f, 0.0f), Radius(100.0f),
CastShadows(true), Type(ELT_POINT)
SLight() : AmbientColor(0.0f,0.0f,0.0f), DiffuseColor(1.0f,1.0f,1.0f),
SpecularColor(1.0f,1.0f,1.0f), Attenuation(1.0f,0.0f,0.0f),
Radius(100.0f), OuterCone(45.0f), InnerCone(0.0f),
Falloff(2.0f), CastShadows(true), Type(ELT_POINT),
Position(0.0f,0.0f,0.0f), Direction(0.0f,0.0f,1.0f)
{};
//! Ambient color emitted by the light
......@@ -53,20 +55,32 @@ struct SLight
/** For details how to use specular highlights, see SMaterial::Shininess */
SColorf SpecularColor;
//! 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;
//! The angle of the spot's outer cone. Ignored for other lights.
f32 OuterCone;
//! The angle of the spot's inner cone. Ignored for other lights.
f32 InnerCone;
//! The light strength's decrease between Outer and Inner cone.
f32 Falloff;
//! Does the light cast shadows?
bool CastShadows;
//! Type of the light. Default: ELT_POINT
E_LIGHT_TYPE Type;
//! Read-ONLY! Position of the light. If Type is ELT_DIRECTIONAL, this is ignored.
core::vector3df Position;
//! Read-ONLY! Direction of the light. If Type is ELT_POINT, this is ignored.
core::vector3df Direction;
};
} // end namespace video
......
......@@ -1693,27 +1693,36 @@ void CD3D8Driver::addDynamicLight(const SLight& dl)
D3DLIGHT8 light;
if ( dl.Type == ELT_POINT )
switch (dl.Type)
{
case ELT_POINT:
light.Type = D3DLIGHT_POINT;
light.Position = *(D3DVECTOR*)((void*)(&dl.Position));
}
else
if ( dl.Type == ELT_DIRECTIONAL )
{
break;
case ELT_SPOT:
light.Type = D3DLIGHT_SPOT;
break;
case ELT_DIRECTIONAL:
light.Type = D3DLIGHT_DIRECTIONAL;
light.Direction = *(D3DVECTOR*)((void*)(&dl.Position));
break;
}
light.Position = *(D3DVECTOR*)((void*)(&dl.Position));
light.Direction = *(D3DVECTOR*)((void*)(&dl.Direction));
light.Range = core::min_(dl.Radius, MaxLightDistance);
light.Falloff = dl.Falloff;
light.Diffuse = *(D3DCOLORVALUE*)((void*)(&dl.DiffuseColor));
light.Specular = *(D3DCOLORVALUE*)((void*)(&dl.SpecularColor));
light.Ambient = *(D3DCOLORVALUE*)((void*)(&dl.AmbientColor));
light.Range = MaxLightDistance;
light.Attenuation0 = dl.Attenuation.X;
light.Attenuation1 = dl.Attenuation.Y;
light.Attenuation2 = dl.Attenuation.Z;
light.Theta = dl.InnerCone * 2.0f * core::DEGTORAD;
light.Phi = dl.OuterCone * 2.0f * core::DEGTORAD;
++LastSetLight;
pID3DDevice->SetLight(LastSetLight, &light);
pID3DDevice->LightEnable(LastSetLight, true);
......
......@@ -1687,19 +1687,24 @@ void CD3D9Driver::addDynamicLight(const SLight& dl)
D3DLIGHT9 light;
if ( dl.Type == ELT_POINT )
switch (dl.Type)
{
case ELT_POINT:
light.Type = D3DLIGHT_POINT;
light.Position = *(D3DVECTOR*)((void*)(&dl.Position));
}
else
if ( dl.Type == ELT_DIRECTIONAL )
{
break;
case ELT_SPOT:
light.Type = D3DLIGHT_SPOT;
break;
case ELT_DIRECTIONAL:
light.Type = D3DLIGHT_DIRECTIONAL;
light.Direction = *(D3DVECTOR*)((void*)(&dl.Position));
break;
}
light.Range = MaxLightDistance;
light.Position = *(D3DVECTOR*)((void*)(&dl.Position));
light.Direction = *(D3DVECTOR*)((void*)(&dl.Direction));
light.Range = core::min_(dl.Radius, MaxLightDistance);
light.Falloff = dl.Falloff;
light.Diffuse = *(D3DCOLORVALUE*)((void*)(&dl.DiffuseColor));
light.Specular = *(D3DCOLORVALUE*)((void*)(&dl.SpecularColor));
......@@ -1709,6 +1714,9 @@ void CD3D9Driver::addDynamicLight(const SLight& dl)
light.Attenuation1 = dl.Attenuation.Y;
light.Attenuation2 = dl.Attenuation.Z;
light.Theta = dl.InnerCone * 2.0f * core::DEGTORAD;
light.Phi = dl.OuterCone * 2.0f * core::DEGTORAD;
++LastSetLight;
pID3DDevice->SetLight(LastSetLight, &light);
pID3DDevice->LightEnable(LastSetLight, true);
......
......@@ -28,10 +28,8 @@ CLightSceneNode::CLightSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
// set some useful specular color
LightData.SpecularColor = color.getInterpolated(video::SColor(255,255,255,255),0.7f);
}
CLightSceneNode::~CLightSceneNode()
{
doLightRecalc();
}
......@@ -65,18 +63,17 @@ void CLightSceneNode::render()
switch ( LightData.Type )
{
case video::ELT_POINT:
case video::ELT_SPOT:
driver->draw3DBox(BBox, LightData.DiffuseColor.toSColor());
break;
case video::ELT_DIRECTIONAL:
driver->draw3DLine(core::vector3df( 0.f, 0.f, 0.f ),
core::vector3df( 0.f, 0.f, 0.f ) + (LightData.Position * 10.f ),
LightData.DiffuseColor.toSColor()
);
driver->draw3DLine(core::vector3df(0.f, 0.f, 0.f),
LightData.Direction * LightData.Radius,
LightData.DiffuseColor.toSColor());
break;
}
}
driver->addDynamicLight(LightData);
}
......@@ -85,8 +82,13 @@ void CLightSceneNode::render()
void CLightSceneNode::setLightData(const video::SLight& light)
{
LightData = light;
ISceneNode::setPosition(light.Position);
ISceneNode::updateAbsolutePosition();
}
//! \return Returns the light data.
const video::SLight& CLightSceneNode::getLightData() const
{
return LightData;
}
......@@ -106,39 +108,28 @@ const core::aabbox3d<f32>& CLightSceneNode::getBoundingBox() const
void CLightSceneNode::doLightRecalc()
{
switch ( LightData.Type )
if ((LightData.Type == video::ELT_SPOT) || (LightData.Type == video::ELT_DIRECTIONAL))
{
case video::ELT_POINT:
{
f32 r = LightData.Radius * LightData.Radius * 0.5f;
BBox.MaxEdge.set( r, r, r );
BBox.MinEdge.set( -r, -r, -r );
setAutomaticCulling( scene::EAC_BOX );
LightData.Position = getAbsolutePosition();
} break;
case video::ELT_DIRECTIONAL:
BBox.reset( 0, 0, 0 );
setAutomaticCulling( scene::EAC_OFF );
// misuse Position as direction..
LightData.Position = getAbsolutePosition();
LightData.Position.invert();
if ( LightData.Position.getLengthSQ() == 0.0 )
{
LightData.Position.set( 0.f, -1.f, 0.f );
os::Printer::log( "Invalid Directional Light Direction" );
}
else
{
LightData.Position.normalize();
}
break;
LightData.Direction = core::vector3df(.0f,.0f,1.0f);
getAbsoluteTransformation().rotateVect(LightData.Direction);
LightData.Direction.normalize();
}
if ((LightData.Type == video::ELT_SPOT) || (LightData.Type == video::ELT_POINT))
{
const f32 r = LightData.Radius * LightData.Radius * 0.5f;
BBox.MaxEdge.set( r, r, r );
BBox.MinEdge.set( -r, -r, -r );
setAutomaticCulling( scene::EAC_BOX );
LightData.Position = getAbsolutePosition();
}
if (LightData.Type == video::ELT_DIRECTIONAL)
{
BBox.reset( 0, 0, 0 );
setAutomaticCulling( scene::EAC_OFF );
}
}
//! Writes attributes of the scene node.
void CLightSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options)
{
......@@ -149,6 +140,9 @@ void CLightSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeRe
out->addColorf ("SpecularColor", LightData.SpecularColor);
out->addVector3d("Attenuation", LightData.Attenuation);
out->addFloat ("Radius", LightData.Radius);
out->addFloat ("OuterCone", LightData.OuterCone);
out->addFloat ("InnerCone", LightData.InnerCone);
out->addFloat ("Falloff", LightData.Falloff);
out->addBool ("CastShadows", LightData.CastShadows);
out->addEnum ("LightType", LightData.Type, video::LightTypeNames);
}
......@@ -160,7 +154,13 @@ void CLightSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeR
LightData.DiffuseColor = in->getAttributeAsColorf("DiffuseColor");
LightData.SpecularColor = in->getAttributeAsColorf("SpecularColor");
if (in->existsAttribute("Attenuation")) // might not exist in older files
LightData.Attenuation = in->getAttributeAsVector3d("Attenuation");
LightData.Attenuation = in->getAttributeAsVector3d("Attenuation");
if (in->existsAttribute("OuterCone")) // might not exist in older files
LightData.OuterCone = in->getAttributeAsFloat("OuterCone");
if (in->existsAttribute("InnerCone")) // might not exist in older files
LightData.InnerCone = in->getAttributeAsFloat("InnerCone");
if (in->existsAttribute("Falloff")) // might not exist in older files
LightData.Falloff = in->getAttributeAsFloat("Falloff");
LightData.Radius = in->getAttributeAsFloat("Radius");
LightData.CastShadows = in->getAttributeAsBool("CastShadows");
LightData.Type = (video::E_LIGHT_TYPE)in->getAttributeAsEnumeration("LightType", video::LightTypeNames);
......
......@@ -22,7 +22,7 @@ public:
CLightSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position, video::SColorf color, f32 range);
virtual ~CLightSceneNode();
virtual ~CLightSceneNode() { }
//! pre render event
virtual void OnRegisterSceneNode();
......@@ -31,7 +31,10 @@ public:
virtual void render();
//! set node light data from light info
virtual void setLightData( const video::SLight& light);
virtual void setLightData(const video::SLight& light);
//! \return Returns the light data.
virtual const video::SLight& getLightData() const;
//! \return Returns the light data.
virtual video::SLight& getLightData();
......
......@@ -1690,30 +1690,47 @@ void COpenGLDriver::addDynamicLight(const SLight& light)
s32 lidx = GL_LIGHT0 + LastSetLight;
GLfloat data[4];
if( light.Type == video::ELT_DIRECTIONAL )
switch (light.Type)
{
// set direction
data[0] = -light.Position.X;
data[1] = -light.Position.Y;
data[2] = -light.Position.Z;
case video::ELT_SPOT:
data[0] = light.Direction.X;
data[1] = light.Direction.Y;
data[2] = light.Direction.Z;
data[3] = 0.0f;
glLightfv(lidx, GL_POSITION, data);
data[3] = 1.0f;
glLightfv(lidx, GL_SPOT_DIRECTION, data);
glLightf(lidx, GL_SPOT_CUTOFF, 180.0f);
glLightf(lidx, GL_SPOT_EXPONENT, 0.0f);
}
else
{
// set position
data[0] = light.Position.X;
data[1] = light.Position.Y;
data[2] = light.Position.Z;
data[3] = 1.0f;
data[3] = 1.0f; // 1.0f for positional light
glLightfv(lidx, GL_POSITION, data);
glLightf(lidx, GL_SPOT_EXPONENT, light.Falloff);
glLightf(lidx, GL_SPOT_CUTOFF, light.OuterCone);
break;
case video::ELT_POINT:
// set position
data[0] = light.Position.X;
data[1] = light.Position.Y;
data[2] = light.Position.Z;
data[3] = 1.0f; // 1.0f for positional light
glLightfv(lidx, GL_POSITION, data);
glLightf(lidx, GL_SPOT_EXPONENT, 0.0f);
glLightf(lidx, GL_SPOT_CUTOFF, 180.0f);
break;
case video::ELT_DIRECTIONAL:
// set direction
data[0] = -light.Direction.X;
data[1] = -light.Direction.Y;
data[2] = -light.Direction.Z;
data[3] = 0.0f; // 0.0f for directional light
glLightfv(lidx, GL_POSITION, data);
glLightf(lidx, GL_SPOT_EXPONENT, 0.0f);
glLightf(lidx, GL_SPOT_CUTOFF, 180.0f);
break;
}
// set diffuse color
......@@ -2006,6 +2023,11 @@ void COpenGLDriver::setFog(SColor c, bool linearFog, f32 start,
else
glFogf(GL_FOG_DENSITY, density);
if (pixelFog)
glHint(GL_FOG_HINT, GL_NICEST);
else
glHint(GL_FOG_HINT, GL_FASTEST);
SColorf color(c);
GLfloat data[4] = {color.r, color.g, color.b, color.a};
glFogfv(GL_FOG_COLOR, data);
......
......@@ -361,12 +361,13 @@ void CShadowVolumeSceneNode::setMeshToRenderFrom(IMesh* mesh)
// create as much shadow volumes as there are lights but
// do not ignore the max light settings.
u32 lights = SceneManager->getVideoDriver()->getDynamicLightCount();
const u32 lights = SceneManager->getVideoDriver()->getDynamicLightCount();
core::matrix4 mat = Parent->getAbsoluteTransformation();
core::vector3df parentpos = Parent->getAbsolutePosition();
const core::vector3df parentpos = Parent->getAbsolutePosition();
core::vector3df lpos;
mat.makeInverse();
// TODO: Only correct for point lights.
for (i=0; i<lights; ++i)
{
const video::SLight& dl = SceneManager->getVideoDriver()->getDynamicLight(i);
......
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