Lighting help?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
SGH
Posts: 13
Joined: Wed Aug 24, 2011 2:53 pm

Lighting help?

Post by SGH »

In my project i need to scale an planar object (2 polys, right) by 15 units. Done this, i enable lighting on the plane and on two objects (one static, one animated), and add a light.
Result: the objects have their lighting, but the plane is totally black. When the plane isn't scaled, lighting works well.
I tried to both enable and disable normals-normalization for the plane, but no result.
I'd like to understand if it's an Engine bug or if i have to write some line more.
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Re: Lighting help?

Post by shadowslair »

Irrlicht`s default lighting is per vertex. Easiest way in your case would be to simply use a plane with more tris, to get more vertices to be lit in order to get a nice result. The more, the smoother the lighting will be. The other option is by using shaders and per pixel lighting.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Re: Lighting help?

Post by Lonesome Ducky »

With the other option being the fastest, easiest to implement, and can easily be made into more advanced lighting shaders.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Lighting help?

Post by hybrid »

If the normals are correctly normalized, the original scene should also work without problems. Even with just two triangles.
SGH
Posts: 13
Joined: Wed Aug 24, 2011 2:53 pm

Re: Lighting help?

Post by SGH »

Ok, thank you for your answers, i'll give you a feedback tomorrow.
@shadowslair : I have to keep my code as fast as possible for my future uses, so i think i'll try @Lonesome Ducky 's tip before.
@hybrid : IDK, i'm sure i used irrlicht's integrated Normals Normalization function ( it was setMaterialFlag - EMF_NORMALIZED_NORMALS , wasn't it? )
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Lighting help?

Post by mongoose7 »

hybrid wrote:If the normals are correctly normalized, the original scene should also work without problems. Even with just two triangles.
I think the problem shadowslair was referring to was that the vertices are beyond the light and so are dark, even if the middle of the triangles should be fully lit.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Lighting help?

Post by hybrid »

Yes, this can indeed happen. When I thought about this scenario yesterday, I wrongly assumed that just a scale would keep at least one corner of the plane at the original place. This is not the case, though, so it could also happen that the light is just not affecting the vertices anymore.
To explain this in a little more detail:

Code: Select all

 
  *              *
|---|    |----------------|        
 
Assume these sketches as the scene before and after the scale, the start being the light. The light strength is always measured at the vertices (plane border in the picture) and interpolated acrss the plane. In the scaled version, the light might be too soft at the vertices. So the interpolation gives only a very shallow light effect. If you make the plane a little more detailed (in the picture, one traingulation would be enough, but this depends on teh position of the light), it would work again. For pixel shaders, the lighting equation can be calculated for each pixel, so the correct value can be used.
SGH
Posts: 13
Joined: Wed Aug 24, 2011 2:53 pm

Re: Lighting help?

Post by SGH »

I think you properly understood my problem, and i like you did, i'm going to try these solutions right now, wait 10 minutes and i'll tell you.
SGH
Posts: 13
Joined: Wed Aug 24, 2011 2:53 pm

Re: Lighting help?

Post by SGH »

Ok, i solved my problem, in fact in the end without the Gourard shading the result is almost the same, so i cut the plane in different sectors.
And i've enabled NormalizedNormals, and everything goes well now. (Gourard shading is enabled) Thank you anyway!
Post Reply