Incorrect Lighting on Simple Entity

Blitz3D Forums/Blitz3D Programming/Incorrect Lighting on Simple Entity

John Blackledge(Posted 2003) [#1]
I have a small problem with a transparent textured entity:
Example 1: Trees I made with leaf surfaces where TextureFilters "leaves",4 does what it should, and all black pixels are transparent. Hurrah!
Example 2: Fences I made with fence textures where TextureFilters "fence",4 does what it should, and all black pixels are transparent. Hurrah!
BUT -
the lighting (ambient or direct) looks all wrong on the fences!
The fences stay very bright (unlike the trees) even when the ambient and direct lights are taken down.
The only clue that I can think of is that the fence is the only entity I have which is just a plane (two triangles) with the texture mapped on.
The effect is that it looks as if the upper-left and lower-right vertices react correcty to light, but the lower-left and upper-right vertices don't react at all!
Anyone got any ideas, or seen this effect before?


Beaker(Posted 2003) [#2]
You need to make sure the normals for the vertices are setup correctly. This might require you to actually make more vertices if you want the fence to be double sided.


John Blackledge(Posted 2003) [#3]
Yeah, the fence is double-sided. Sorry, can you explain what you mean about normals? I've created plenty of models which react perfectly to light (God, do I realy have 82 entities...!) but none which have just one surface of two triangles, so is this the problem?


Beaker(Posted 2003) [#4]
Your lighting on the triangles is calculated according to the direction of the vertex normals. If the normals face the wrong way (as they will do for the reverse side of any double sided mesh) then the lighting will be wrong (often dark).

It's hard to explain it all without pictures, but imagine the Pinhead guy from Hellraiser (movie) the pins represent the normals for his head. :)


Shambler(Posted 2003) [#5]
Try using UpdateNormals() on the mesh.


John Blackledge(Posted 2003) [#6]
Nope. No difference I'm afraid.
Imagine the rectangle made of two triangle like so: [/]
The top-left and bottom-right vertices react correctly to light.
The bottom-left and top-right vertices stay full-bright all the time.
(BTW, how do you include images in this forum?)


Bot Builder(Posted 2003) [#7]
Strange problem.

To include an image, first you have to host it on a website. then simply write a link to the image, like

www.domain.com/image


skidracer(Posted 2003) [#8]
It sounds like your fence is made of 4 triangles, unless the two sides are separate surfaces Blitz will mess up the normals.

I suggest modelling just one side of the fence with two triangles and use EntityFX fence,16 to make it double sided.

If this doesn't make sense can you detail how you are creating the mesh, in a modelling program or using CreateSurface?


iret(Posted 2003) [#9]
I've discovered this problem last year and posted some screenshots in the bugs forum. A lot of answers, even by Mark himself, but no solutions :-(

It only happens when you load a mesh, when you use CreateCube it will work correctly (maybe because a single side isn't build of two triangles?).

Can someone tell how to fix this problem by correcting the normals or whatever? Would be really great!

Btw, unfortunately I cannot find the old thread, seems to be archived elsewhere.


Sweenie(Posted 2003) [#10]
Well a blitzcube has 24 vertices and 12 triangles.
I believe every triangle in a blitzcube has one "private vertex" and shares it's other two vertices with the triangle lying on the same plane.

However, a cube made in for example 3DS Max, usually have 8 vertices, therefor each vertexnormal will be averaged using the normals of all the triangles it belong to and the lightning will look like crap.

I don't remember if you can "tell" 3d studio to let every face has it's own vertices or not.


John Blackledge(Posted 2003) [#11]
@bot builder: Thanks. Doh!
@skidracer: EntityFx ,16 seems to try to present both faces simultaneously to the camera. Lots of stripey bitmap!
@iret: 'A lot of answers, even by Mark himself, but no solutions' kinda says it all.
@Sweenie: I use Metasequoia, but export as .X so the modeller as such doesn't matter.

I've ended up modeling a very thin cube and retextured. It's ok. Thanks to you all for putting your minds to this.
It's great to get so much constructive feedback on a problem. Still, it would be nice to find another solution (every fence now has 6 faces, not 2).


skidracer(Posted 2003) [#12]
EntityFx ,16 seems to try to present both faces simultaneously to the camera. Lots of stripey bitmap!

It sounds like you are still exporting as a double sided plane.


John Blackledge(Posted 2003) [#13]
Ah, I see your point.
Yes, I'll try that. Thanks.


Bot Builder(Posted 2003) [#14]
couldn't you do it so that there are 8 vertices, 4 tiangles??? twice as many vertices sure, but you have the same number of faces.


John Blackledge(Posted 2003) [#15]
@skidracer:
A single one-sided plane (2 triangles) works as you say if you use EntityFX ,16 - visually its ok, but, hardly a surprise, you can walk through it from the other side. Not important in some cases, but for a fence....
Anyway, I modelled a thin cube then deleted the sides, top and bottom faces. Now it works fine, and only uses 2 faces.
Thanks to you all for spending time on getting to the bottom of this problem.