lighting both side of triangle

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Alucard344
Posts: 21
Joined: Wed May 20, 2009 8:17 pm
Location: Qc, Canada

lighting both side of triangle

Post by Alucard344 »

As the title says, i need to light both side of my mesh. this is because i have clipping plane and when a mesh is cut, i don't want to see the interior of the mesh black.

The only way i see to do that would be to duplicate the mesh with the invert normal. but that would lower the performance.

What would be the best way to achieve that ? Does Irrlicht provide any function or material to help on that ?

Thanks
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Post by Klunk »

i don't know about any native irrlicht method of doing it, but in a HLSL shader
you can pass

Code: Select all

float  backfacing 	: VFACE;
to the pixel shader, you can then use it in the pixel shader to modulate the normal for example. IIRC its only available to pixelshader 2 or greater.

for GLSL you would check

Code: Select all

gl_FrontFacing
in the fragment
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Disable backface culling, maybe? Just a guess.
Working on game: Marrbles (Currently stopped).
Alucard344
Posts: 21
Joined: Wed May 20, 2009 8:17 pm
Location: Qc, Canada

Post by Alucard344 »

I already tried to disable backface culling but it doesnt change anything
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Post by Klunk »

The only way i see to do that would be to duplicate the mesh with the invert normal. but that would lower the performance.
is that strictly true ? maybe some initial hit if creating the geometry on the fly and some impact from the scene manager having to handle another object but I can't see the drawing performance being much different for a 2 sided material or a 2 sided mesh. Suppose it costs double the verts, which should be quite cheap depending on the complexity of the mesh.
Alucard344
Posts: 21
Joined: Wed May 20, 2009 8:17 pm
Location: Qc, Canada

Post by Alucard344 »

well i was really curious as if there was a better solution. maybe it wouldn't decrease a lot the performance even if i do have big complex mesh. I just feel that duplicating all mesh is not the optimal way of doing it.

thanks for your answers.
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

The fastest and the simplest way is to use shaders
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

For OpenGL we could add two-sided lighting. But IIRC D3D does not offer this?!
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

If you duplicate the mesh, invert normals, and enable backface culling, it shouldn't be a whole lot more of a performance hit than turning off backface culling on the normal mesh.
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

hybrid wrote:For OpenGL we could add two-sided lighting. But IIRC D3D does not offer this?!
http://irrlicht.sourceforge.net/phpBB2/ ... 206#238206

Yes please :)
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
Alucard344
Posts: 21
Joined: Wed May 20, 2009 8:17 pm
Location: Qc, Canada

Post by Alucard344 »

It would be great if it was someday implemented in irrlicht for openGL.
for now im going to go with duplicating the mesh. i think its the simplest solution.

Thanks.
Post Reply