OpenGL Volumetric Lighting

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.

OpenGL Volumetric Lighting

Postby varmint » Wed Jan 02, 2008 9:45 pm

Over the holidays and in between family stuff :D I thought it'd be kewl to have some volumetric lighting in Irrlicht for flashlights, car lights, street lights, etc. I looked around and didn't see anything so whipped up this little thing.

It's far from 100% and could still use some work, but it's far enough along for our purposes, so I figured to post it for others.

Feel free to use it / modify it and improve it. :P It's been tested in Mac and Windows and against the latest SVN head.

I started with CCubeSceneNode frame and went from there.

1) in ISceneManager.h add the following just before addCubeSceneNode

Code: Select all
      //! adds Volume Lighting Scene Node.
      //! the returned pointer must not be dropped.
      virtual ISceneNode* addVolumeLightSceneNode(ISceneNode* parent=0, s32 id=-1,
         const s32 subdivU = 32, const s32 subdivV = 32,
         const video::SColor foot = video::SColor(51, 0, 230, 180),
         const video::SColor tail = video::SColor(0, 0, 0, 0),
         const core::vector3df& position = core::vector3df(0,0,0),
         const core::vector3df& rotation = core::vector3df(0,0,0),
         const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f)) = 0;


2) in CSceneManager.h add the following just before addCubeSceneNode

Code: Select all
      //! adds Volume Lighting Scene Node.
      //! the returned pointer must not be dropped.
      virtual ISceneNode* addVolumeLightSceneNode(ISceneNode* parent=0, s32 id=-1,
         const s32 subdivU = 32, const s32 subdivV = 32,
         const video::SColor foot = video::SColor(51, 0, 230, 180),
         const video::SColor tail = video::SColor(0, 0, 0, 0),
         const core::vector3df& position = core::vector3df(0,0,0),   const core::vector3df& rotation = core::vector3df(0,0,0),   const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));


3) In CSceneManager.cpp add the following just before #include "CCubeSceneNode.h"

Code: Select all
#include "CVolumeLightSceneNode.h"


4) In CSceneManager.cpp add the following just before addCubeSceneNode block

Code: Select all
//! adds Volume Lighting Scene Node.
//! the returned pointer must not be dropped.
ISceneNode* CSceneManager::addVolumeLightSceneNode(ISceneNode* parent, s32 id,
   const s32 subdivU, const s32 subdivV,
   const video::SColor foot,
   const video::SColor tail,
   const core::vector3df& position, const core::vector3df& rotation, const core::vector3df& scale)
{
   if (!parent)
      parent = this;

   ISceneNode* node = new CVolumeLightSceneNode(parent, this, id, subdivU, subdivV, foot, tail, position, rotation, scale);
   node->drop();

   return node;
}


5) Now copy and add CVolumeLightSceneNode.cpp and CVolumeLightSceneNode.h to your project and build irrlicht.


To use I used the meshViewer to test it. Add the following code, I added it just before the main loop to draw everything.

Code: Select all
   //test for volume lighting
   scene::ISceneNode * n = smgr->addVolumeLightSceneNode(NULL, -1,
                        32, //Sub Divid U
                        32, //Sub Divid V
                        video::SColor(30, 255, 255, 255),   //foot colour
                        video::SColor(0, 255, 0, 0)         //tail colour
                        );
   
   if (n) {
      n->setScale(core::vector3df(66.0f, 75.0f, 66.0f));
      video::SMaterial& mat = n->getMaterial(0);
      mat.setTexture(0, smgr->getVideoDriver()->getTexture("lightFalloff.png"));
   }


Image

Code Links
http://shadow.krabbit.com/varmint/volLight/CVolumeLightSceneNode.cpp
http://shadow.krabbit.com/varmint/volLight/CVolumeLightSceneNode.h
test image
http://shadow.krabbit.com/varmint/volLight/lightFalloff.png

enjoy :D
User avatar
varmint
 
Posts: 46
Joined: Fri Oct 06, 2006 4:33 pm

Postby FuzzYspo0N » Sat Jan 05, 2008 12:00 am

wow varmint thats really cool!

Im gonna look at including it in my game that im making now, just for fun...

I like the way u use it too, its neat.
User avatar
FuzzYspo0N
 
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa

Postby FlyingIsFun1217 » Sat Jan 05, 2008 12:18 am

I can't wait to see more of these kind of things added into the main SVN branch, so that multiple people start looking through it and make it even better :D

FlyingIsFun1217
FlyingIsFun1217
 
Posts: 219
Joined: Fri Apr 13, 2007 8:29 pm
Location: Illinois

Postby MasterGod » Sat Jan 05, 2008 2:43 am

It Looks Amazing!! - If something like this isn't going into the library core I'm gonna kill someone :twisted:
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
User avatar
MasterGod
 
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel

Postby bitplane » Sat Jan 05, 2008 5:39 pm

Wow how did I miss that? Looks really cool.
To be included in the engine it would need the new material stuff to be in an IMaterialRenderer, and the drawing the buffer part use drawMeshBuffer. And of course directx materials too.
May use it myself as it is though :)
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
User avatar
bitplane
Admin
 
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England

Postby Dorth » Sat Jan 05, 2008 6:38 pm

Hmmm, may I suggest a patch/addition forum to be added? Maybe people could only reply and dev post/move topics there?

That way, good things like this and a couple of others wouldn't get lost in the pile. Either they'd adapt tobe included, were included or take too much time / no longer be needed and moved back to another topic / closed. That way, active stuff is all and any topic open in that section.
Dorth
 
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Postby varmint » Sun Jan 06, 2008 9:17 am

thx for comments :P I'm always shy about me code :P

Just posted an update. Works better now in scenes and stuff. :D
User avatar
varmint
 
Posts: 46
Joined: Fri Oct 06, 2006 4:33 pm

Postby varmint » Sun Jan 06, 2008 9:18 am

bitplane wrote:Wow how did I miss that? Looks really cool.
To be included in the engine it would need the new material stuff to be in an IMaterialRenderer, and the drawing the buffer part use drawMeshBuffer. And of course directx materials too.
May use it myself as it is though :)


I'd love to add it in with DirectX support. Problem I was having and reason for calling opengl commands directly is I didn't see a way to set the footer and tail colours of the verts, with Alpha. Is there away to do this? :D

I dew have a
Code: Select all
   driver->setMaterial(Buffer->Material);
   driver->drawVertexPrimitiveList(
         Buffer->getVertices(), Buffer->getVertexCount(),
         Buffer->getIndices(), Buffer->getIndexCount() / 4 ,
         Buffer->getVertexType(), EPT_QUADS);

in there.. intended for this purpose ;)
Also I'm working on motion trails based on the same type of logic, using QUADS.. I could add that in too :) It uses Empty Scene Nodes as markets were to render them. :D
User avatar
varmint
 
Posts: 46
Joined: Fri Oct 06, 2006 4:33 pm

Postby varmint » Sun Jan 06, 2008 9:34 am

actually I was working with EMT_ONETEXTURE_BLEND and pack_texureBlendFunc i can probably dew it with :D
User avatar
varmint
 
Posts: 46
Joined: Fri Oct 06, 2006 4:33 pm

Postby hybrid » Sun Jan 06, 2008 9:34 am

You should change to tri lists/strips for cross driver compatibility, because quads are not supported in d3d.
hybrid
Admin
 
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany

Postby MasterGod » Sun Jan 06, 2008 1:07 pm

1. Awesome :shock:
2. Please post more screen shots :!:
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
User avatar
MasterGod
 
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel

Postby varmint » Sun Jan 06, 2008 1:32 pm

Converted to tris and added to SVN trunk. :D

Direct 3D 9 Screenie

Image


OpenGL on OSX screenie

Image
User avatar
varmint
 
Posts: 46
Joined: Fri Oct 06, 2006 4:33 pm

Postby MasterGod » Sun Jan 06, 2008 2:11 pm

No way it looks so good!!!
Amazing work there varmint!! I Love it.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
User avatar
MasterGod
 
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel

Postby etcaptor » Sun Jan 06, 2008 6:12 pm

Awesome! This is will be a great addition to engine.
ImageImage
Site development -Rock and metal online
--- etcaptor.com ------freenetlife.com
etcaptor
 
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla

thanksssss...

Postby doqkhanh » Sun Mar 02, 2008 7:51 am

Thank you very much. This is great feature!
But my demo program has been crashed after replaced irrlicht.dll with new dll build from modified code by your topic.
doqkhanh
 
Posts: 158
Joined: Sat Mar 01, 2008 3:14 am
Location: Tokyo, Japan

Next

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest

cron