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-e03cc46cb475master
parent
8f34efc3f4
commit
59ac643248
18
changes.txt
18
changes.txt
|
@ -1,9 +1,25 @@
|
|||
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->addStaticText(L"Hello World! This is the Irrlicht Software engine!",<br> rect<int>(10,10,200,22), true);</pre> </td>
|
||||
<td> <pre>guienv->addStaticText(L"Hello World! This is the Irrlicht Software engine!",<br> rect<s32>(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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
This tutorial shows how to use one of the built in more complex materials in irrlicht:
|
||||
Per pixel lighted surfaces using normal maps and parallax mapping. It will also show
|
||||
how to use fog and moving particle systems. And don't panic: You dont need any
|
||||
Per pixel lighted surfaces using normal maps and parallax mapping. It will also show
|
||||
how to use fog and moving particle systems. And don't panic: You dont need any
|
||||
experience with shaders to use these materials in Irrlicht.
|
||||
|
||||
At first, we need to include all headers and do the stuff we always do, like
|
||||
|
@ -19,7 +19,7 @@ using namespace irr;
|
|||
/*
|
||||
For this example, we need an event receiver, to make it possible for the user
|
||||
to switch between the three available material types. In addition, the event
|
||||
receiver will create some small GUI window which displays what material is
|
||||
receiver will create some small GUI window which displays what material is
|
||||
currently being used. There is nothing special done in this class, so maybe
|
||||
you want to skip reading it.
|
||||
*/
|
||||
|
@ -27,7 +27,7 @@ class MyEventReceiver : public IEventReceiver
|
|||
{
|
||||
public:
|
||||
|
||||
MyEventReceiver(scene::ISceneNode* room,
|
||||
MyEventReceiver(scene::ISceneNode* room,
|
||||
gui::IGUIEnvironment* env, video::IVideoDriver* driver)
|
||||
{
|
||||
// store pointer to room so we can change its drawing mode
|
||||
|
@ -61,7 +61,7 @@ public:
|
|||
ProblemText->setOverrideColor(video::SColor(100,255,255,255));
|
||||
|
||||
// set start material (prefer parallax mapping if available)
|
||||
video::IMaterialRenderer* renderer =
|
||||
video::IMaterialRenderer* renderer =
|
||||
Driver->getMaterialRenderer(video::EMT_PARALLAX_MAP_SOLID);
|
||||
if (renderer && renderer->getRenderCapability() == 0)
|
||||
ListBox->setSelected(2);
|
||||
|
@ -76,7 +76,7 @@ public:
|
|||
if (event.EventType == irr::EET_KEY_INPUT_EVENT &&
|
||||
!event.KeyInput.PressedDown && Room && ListBox)
|
||||
{
|
||||
// change selected item in listbox
|
||||
// change selected item in listbox
|
||||
|
||||
int sel = ListBox->getSelected();
|
||||
if (event.KeyInput.Key == irr::KEY_KEY_R)
|
||||
|
@ -84,13 +84,13 @@ public:
|
|||
else
|
||||
if (event.KeyInput.Key == irr::KEY_KEY_E)
|
||||
--sel;
|
||||
else
|
||||
else
|
||||
return false;
|
||||
|
||||
if (sel > 2) sel = 0;
|
||||
if (sel < 0) sel = 2;
|
||||
ListBox->setSelected(sel);
|
||||
|
||||
|
||||
// set the material which is selected in the listbox
|
||||
setMaterial();
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
// sets the material of the room mesh the the one set in the
|
||||
// sets the material of the room mesh the the one set in the
|
||||
// list box.
|
||||
void setMaterial()
|
||||
{
|
||||
|
@ -120,10 +120,10 @@ private:
|
|||
Room->setMaterialType(type);
|
||||
|
||||
/*
|
||||
We need to add a warning if the materials will not be able to be
|
||||
We need to add a warning if the materials will not be able to be
|
||||
displayed 100% correctly. This is no problem, they will be renderered
|
||||
using fall back materials, but at least the user should know that
|
||||
it would look better on better hardware.
|
||||
using fall back materials, but at least the user should know that
|
||||
it would look better on better hardware.
|
||||
We simply check if the material renderer is able to draw at full
|
||||
quality on the current hardware. The IMaterialRenderer::getRenderCapability()
|
||||
returns 0 if this is the case.
|
||||
|
@ -142,7 +142,7 @@ private:
|
|||
gui::IGUIStaticText* ProblemText;
|
||||
gui::IGUIListBox* ListBox;
|
||||
|
||||
scene::ISceneNode* Room;
|
||||
scene::ISceneNode* Room;
|
||||
video::IVideoDriver* Driver;
|
||||
};
|
||||
|
||||
|
@ -173,7 +173,7 @@ int main()
|
|||
case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
|
||||
case 'f': driverType = video::EDT_NULL; break;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// create device
|
||||
|
||||
|
@ -182,16 +182,16 @@ int main()
|
|||
if (device == 0)
|
||||
return 1; // could not create selected driver.
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Before we start with the interesting stuff, we do some simple things:
|
||||
Before we start with the interesting stuff, we do some simple things:
|
||||
Store pointers to the most important parts of the engine (video driver,
|
||||
scene manager, gui environment) to safe us from typing too much,
|
||||
add an irrlicht engine logo to the window and a user controlled
|
||||
first person shooter style camera. Also, we let the engine now
|
||||
scene manager, gui environment) to safe us from typing too much,
|
||||
add an irrlicht engine logo to the window and a user controlled
|
||||
first person shooter style camera. Also, we let the engine now
|
||||
that it should store all textures in 32 bit. This necessary because
|
||||
for parallax mapping, we need 32 bit textures.
|
||||
*/
|
||||
*/
|
||||
|
||||
video::IVideoDriver* driver = device->getVideoDriver();
|
||||
scene::ISceneManager* smgr = device->getSceneManager();
|
||||
|
@ -202,9 +202,9 @@ int main()
|
|||
// add irrlicht logo
|
||||
env->addImage(driver->getTexture("../../media/irrlichtlogo2.png"),
|
||||
core::position2d<s32>(10,10));
|
||||
|
||||
|
||||
// add camera
|
||||
scene::ICameraSceneNode* camera =
|
||||
scene::ICameraSceneNode* camera =
|
||||
smgr->addCameraSceneNodeFPS(0,100.0f,300.0f);
|
||||
camera->setPosition(core::vector3df(-200,200,-200));
|
||||
|
||||
|
@ -213,7 +213,7 @@ int main()
|
|||
|
||||
|
||||
/*
|
||||
Because we want the whole scene to look a little bit scarier, we add some fog
|
||||
Because we want the whole scene to look a little bit scarier, we add some fog
|
||||
to it. This is done by a call to IVideoDriver::setFog(). There you can set
|
||||
various fog settings. In this example, we use pixel fog, because it will
|
||||
work well with the materials we'll use in this example.
|
||||
|
@ -224,7 +224,7 @@ int main()
|
|||
|
||||
/*
|
||||
To be able to display something interesting, we load a mesh from a .3ds file
|
||||
which is a room I modeled with anim8or. It is the same room as
|
||||
which is a room I modeled with anim8or. It is the same room as
|
||||
from the specialFX example. Maybe you remember from that tutorial,
|
||||
I am no good modeler at all and so I totally messed up the texture
|
||||
mapping in this model, but we can simply repair it with the
|
||||
|
@ -240,9 +240,9 @@ int main()
|
|||
smgr->getMeshManipulator()->makePlanarTextureMapping(
|
||||
roomMesh->getMesh(0), 0.003f);
|
||||
|
||||
/*
|
||||
/*
|
||||
Now for the first exciting thing: If we successfully loaded the mesh
|
||||
we need to apply textures to it. Because we want this room to be
|
||||
we need to apply textures to it. Because we want this room to be
|
||||
displayed with a very cool material, we have to do a little bit more
|
||||
than just set the textures. Instead of only loading a color map as usual,
|
||||
we also load a height map which is simply a grayscale texture. From this
|
||||
|
@ -252,11 +252,11 @@ int main()
|
|||
The normal map texture is being generated by the makeNormalMapTexture method
|
||||
of the VideoDriver. The second parameter specifies the height of the heightmap.
|
||||
If you set it to a bigger value, the map will look more rocky.
|
||||
*/
|
||||
*/
|
||||
|
||||
video::ITexture* colorMap = driver->getTexture("../../media/rockwall.bmp");
|
||||
video::ITexture* normalMap = driver->getTexture("../../media/rockwall_height.bmp");
|
||||
|
||||
|
||||
driver->makeNormalMapTexture(normalMap, 9.0f);
|
||||
|
||||
/*
|
||||
|
@ -264,7 +264,7 @@ int main()
|
|||
use needs some additional informations per vertex like tangents and binormals.
|
||||
Because we are too lazy to calculate that information now, we let Irrlicht do
|
||||
this for us. That's why we call IMeshManipulator::createMeshWithTangents(). It
|
||||
creates a mesh copy with tangents and binormals from any other mesh.
|
||||
creates a mesh copy with tangents and binormals from any other mesh.
|
||||
After we've done that, we simply create a standard mesh scene node with this
|
||||
mesh copy, set color and normal map and adjust some other material settings.
|
||||
Note that we set EMF_FOG_ENABLE to true to enable fog in the room.
|
||||
|
@ -280,7 +280,7 @@ int main()
|
|||
room->getMaterial(0).SpecularColor.set(0,0,0,0);
|
||||
|
||||
room->setMaterialFlag(video::EMF_FOG_ENABLE, true);
|
||||
room->setMaterialType(video::EMT_PARALLAX_MAP_SOLID);
|
||||
room->setMaterialType(video::EMT_PARALLAX_MAP_SOLID);
|
||||
room->getMaterial(0).MaterialTypeParam = 0.035f; // adjust height for parallax effect
|
||||
|
||||
// drop mesh because we created it with a create.. call.
|
||||
|
@ -291,8 +291,8 @@ int main()
|
|||
After we've created a room shaded by per pixel lighting, we add a sphere
|
||||
into it with the same material, but we'll make it transparent. In addition,
|
||||
because the sphere looks somehow like a familiar planet, we make it rotate.
|
||||
The procedure is similar as before. The difference is that we are loading
|
||||
the mesh from an .x file which already contains a color map so we do not
|
||||
The procedure is similar as before. The difference is that we are loading
|
||||
the mesh from an .x file which already contains a color map so we do not
|
||||
need to load it manually. But the sphere is a little bit too small for our
|
||||
needs, so we scale it by the factor 50.
|
||||
*/
|
||||
|
@ -306,12 +306,12 @@ int main()
|
|||
scene::IMeshManipulator *manipulator = smgr->getMeshManipulator();
|
||||
|
||||
// create mesh copy with tangent informations from original earth.x mesh
|
||||
scene::IMesh* tangentSphereMesh =
|
||||
scene::IMesh* tangentSphereMesh =
|
||||
manipulator->createMeshWithTangents(earthMesh->getMesh(0));
|
||||
|
||||
// set the alpha value of all vertices to 200
|
||||
manipulator->setVertexColorAlpha(tangentSphereMesh, 200);
|
||||
|
||||
|
||||
// scale the mesh by factor 50
|
||||
core::matrix4 m;
|
||||
m.setScale ( core::vector3df(50,50,50) );
|
||||
|
@ -328,11 +328,11 @@ int main()
|
|||
|
||||
// adjust material settings
|
||||
sphere->setMaterialFlag(video::EMF_FOG_ENABLE, true);
|
||||
sphere->setMaterialType(video::EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA);
|
||||
sphere->setMaterialType(video::EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA);
|
||||
|
||||
// add rotation animator
|
||||
scene::ISceneNodeAnimator* anim =
|
||||
smgr->createRotationAnimator(core::vector3df(0,0.1f,0));
|
||||
smgr->createRotationAnimator(core::vector3df(0,0.1f,0));
|
||||
sphere->addAnimator(anim);
|
||||
anim->drop();
|
||||
|
||||
|
@ -342,25 +342,25 @@ int main()
|
|||
|
||||
/*
|
||||
Per pixel lighted materials only look cool when there are moving lights. So we
|
||||
add some. And because moving lights alone are so boring, we add billboards
|
||||
to them, and a whole particle system to one of them.
|
||||
add some. And because moving lights alone are so boring, we add billboards
|
||||
to them, and a whole particle system to one of them.
|
||||
We start with the first light which is red and has only the billboard attached.
|
||||
*/
|
||||
|
||||
// add light 1 (nearly red)
|
||||
scene::ILightSceneNode* light1 =
|
||||
smgr->addLightSceneNode(0, core::vector3df(0,0,0),
|
||||
video::SColorf(0.5f, 1.0f, 0.5f, 0.0f), 200.0f);
|
||||
scene::ILightSceneNode* light1 =
|
||||
smgr->addLightSceneNode(0, core::vector3df(0,0,0),
|
||||
video::SColorf(0.5f, 1.0f, 0.5f, 0.0f), 800.0f);
|
||||
|
||||
|
||||
// add fly circle animator to light 1
|
||||
scene::ISceneNodeAnimator* anim =
|
||||
scene::ISceneNodeAnimator* anim =
|
||||
smgr->createFlyCircleAnimator (core::vector3df(50,300,0),190.0f, -0.003f);
|
||||
light1->addAnimator(anim);
|
||||
anim->drop();
|
||||
|
||||
// attach billboard to the light
|
||||
scene::ISceneNode* bill =
|
||||
scene::ISceneNode* bill =
|
||||
smgr->addBillboardSceneNode(light1, core::dimension2d<f32>(60, 60));
|
||||
|
||||
bill->setMaterialFlag(video::EMF_LIGHTING, false);
|
||||
|
@ -370,22 +370,22 @@ int main()
|
|||
/*
|
||||
Now the same again, with the second light. The difference is that we add a particle
|
||||
system to it too. And because the light moves, the particles of the particlesystem
|
||||
will follow. If you want to know more about how particle systems are created in
|
||||
will follow. If you want to know more about how particle systems are created in
|
||||
Irrlicht, take a look at the specialFx example.
|
||||
Maybe you will have noticed that we only add 2 lights, this has a simple reason: The
|
||||
low end version of this material was written in ps1.1 and vs1.1, which doesn't allow
|
||||
more lights. You could add a third light to the scene, but it won't be used to
|
||||
low end version of this material was written in ps1.1 and vs1.1, which doesn't allow
|
||||
more lights. You could add a third light to the scene, but it won't be used to
|
||||
shade the walls. But of course, this will change in future versions of Irrlicht were
|
||||
higher versions of pixel/vertex shaders will be implemented too.
|
||||
*/
|
||||
|
||||
// add light 2 (gray)
|
||||
scene::ISceneNode* light2 =
|
||||
smgr->addLightSceneNode(0, core::vector3df(0,0,0),
|
||||
video::SColorf(1.0f, 0.2f, 0.2f, 0.0f), 200.0f);
|
||||
scene::ISceneNode* light2 =
|
||||
smgr->addLightSceneNode(0, core::vector3df(0,0,0),
|
||||
video::SColorf(1.0f, 0.2f, 0.2f, 0.0f), 800.0f);
|
||||
|
||||
// add fly circle animator to light 2
|
||||
anim = smgr->createFlyCircleAnimator (core::vector3df(0,150,0),200.0f, 0.001f, core::vector3df ( 0.2f, 0.9f, 0.f ));
|
||||
anim = smgr->createFlyCircleAnimator (core::vector3df(0,150,0),200.0f, 0.001f, core::vector3df ( 0.2f, 0.9f, 0.f ));
|
||||
light2->addAnimator(anim);
|
||||
anim->drop();
|
||||
|
||||
|
@ -396,16 +396,16 @@ int main()
|
|||
bill->setMaterialTexture(0, driver->getTexture("../../media/particlewhite.bmp"));
|
||||
|
||||
// add particle system
|
||||
scene::IParticleSystemSceneNode* ps =
|
||||
scene::IParticleSystemSceneNode* ps =
|
||||
smgr->addParticleSystemSceneNode(false, light2);
|
||||
|
||||
ps->setParticleSize(core::dimension2d<f32>(30.0f, 40.0f));
|
||||
|
||||
// create and set emitter
|
||||
scene::IParticleEmitter* em = ps->createBoxEmitter(
|
||||
core::aabbox3d<f32>(-3,0,-3,3,1,3),
|
||||
core::aabbox3d<f32>(-3,0,-3,3,1,3),
|
||||
core::vector3df(0.0f,0.03f,0.0f),
|
||||
80,100,
|
||||
80,100,
|
||||
video::SColor(0,255,255,255), video::SColor(0,255,255,255),
|
||||
400,1100);
|
||||
ps->setEmitter(em);
|
||||
|
@ -424,7 +424,7 @@ int main()
|
|||
|
||||
MyEventReceiver receiver(room, env, driver);
|
||||
device->setEventReceiver(&receiver);
|
||||
|
||||
|
||||
/*
|
||||
Finally, draw everything. That's it.
|
||||
*/
|
||||
|
@ -445,18 +445,18 @@ int main()
|
|||
|
||||
if (lastFPS != fps)
|
||||
{
|
||||
core::stringw str = L"Per pixel lighting example - Irrlicht Engine [";
|
||||
str += driver->getName();
|
||||
str += "] FPS:";
|
||||
str += fps;
|
||||
core::stringw str = L"Per pixel lighting example - Irrlicht Engine [";
|
||||
str += driver->getName();
|
||||
str += "] FPS:";
|
||||
str += fps;
|
||||
|
||||
device->setWindowCaption(str.c_str());
|
||||
lastFPS = fps;
|
||||
device->setWindowCaption(str.c_str());
|
||||
lastFPS = fps;
|
||||
}
|
||||
}
|
||||
|
||||
device->drop();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue