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.
varmint
Posts: 46
Joined: Fri Oct 06, 2006 4:33 pm

OpenGL Volumetric Lighting

Post by varmint »

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/volLi ... neNode.cpp
http://shadow.krabbit.com/varmint/volLi ... ceneNode.h
test image
http://shadow.krabbit.com/varmint/volLi ... alloff.png

enjoy :D
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

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.
FlyingIsFun1217
Posts: 219
Joined: Fri Apr 13, 2007 8:29 pm
Location: Illinois
Contact:

Post by FlyingIsFun1217 »

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
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

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%
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

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
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

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.
varmint
Posts: 46
Joined: Fri Oct 06, 2006 4:33 pm

Post by varmint »

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

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

Post by varmint »

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
varmint
Posts: 46
Joined: Fri Oct 06, 2006 4:33 pm

Post by varmint »

actually I was working with EMT_ONETEXTURE_BLEND and pack_texureBlendFunc i can probably dew it with :D
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You should change to tri lists/strips for cross driver compatibility, because quads are not supported in d3d.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

1. Awesome :shock:
2. Please post more screen shots :!:
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
varmint
Posts: 46
Joined: Fri Oct 06, 2006 4:33 pm

Post by varmint »

Converted to tris and added to SVN trunk. :D

Direct 3D 9 Screenie

Image


OpenGL on OSX screenie

Image
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

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%
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

Awesome! This is will be a great addition to engine.
ImageImage
Site development -Rock and metal online
--- etcaptor.com ------freenetlife.com
doqkhanh
Posts: 158
Joined: Sat Mar 01, 2008 3:14 am
Location: Tokyo, Japan
Contact:

thanksssss...

Post by doqkhanh »

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.
Post Reply