Directional light not affecting a CreateMesh mesh

Blitz3D Forums/Blitz3D Beginners Area/Directional light not affecting a CreateMesh mesh

fox95871(Posted 2009) [#1]
Is it true a custom mesh can only be lit by ambient light? Here I was thinking I knew everything, then I reallized no matter what I did I couldn't get the directional light to have any affect on the mesh I made!




GfK(Posted 2009) [#2]
Pretty sure you need to call UpdateNormals() for the created mesh when you're done adding vertices.


big10p(Posted 2009) [#3]
Yeah, you haven't set any normals so it can't be affected by light. You can normally use UpdateNormals() to set them for you but since you're creating a cube this wont work correctly, as it smoothes normals. You need to set the normals manually using VertexNormal().


fox95871(Posted 2009) [#4]
Hmm... well it's different, but not quite what I meant. It should be just like the one on the left:



Kind of reminds me of me trying to fit in! :D Or those impersonators on the elevator near the end of Chrono Trigger. Not even close to convincing, but you can tell they're trying, and that's what...scares people. Okay, probably not a reference everyone knows about! But if you get the chance, I recommend playing it to find out. And don't just look it up on youtube, that ruins it.

Anyway, so it's not lit now, but it's...close? Semi close? Weirdly similar to close? ..."Almost but not quite entirely unlike tea?"

Hope someone can help again :)

Big, I just saw your suggestion today, so I'll try that tonight. Thanks.


Santiworld(Posted 2009) [#5]
if you want to remove the face light smooth, you must to create 4 vertex for each side, if you use one vertex to create triangles, this triangles have the same smooth light effect... and you dont see the edges becouse that..

4 vertex for side, 6 sides for a cube..

each corner of the box, must to have 3 vertex in the same xyz

i hope this help... (sorry my english)


fox95871(Posted 2009) [#6]
Okay, I'll try that.

Big, VertexNormal? The docs aren't exactly helpful with that command. What's the range for the three settings? 0-360? I tried messing around with the numbers, but I can't just guess when I have no idea what command's even supposed to be doing! :)

Can you give me an example please?


Warner(Posted 2009) [#7]
You could maybe use the MESHNormals function:

Note that the mesh needs to be unwelded first, that is, each triangle should use it's own three vertices:
http://www.blitzbasic.com/codearcs/codearcs.php?code=422


big10p(Posted 2009) [#8]
OK, each vertex has a normal (a vector of length 1) which simply indicates which direction that vertex is pointing. These normal vectors are used to calculate how to light the pixels across each triangle, when they're rendered.

Consider a simple quad (made of 2 triangles) that faces the camera head on, with a directional light pointing in the same direction the camera is. Each of the vertex normals of this quad would be x=0, y=0, z=-1. That is, all the vertex normals would be pointing in the direction the quad is facing; directly at the camera (and light) in this case.

Now we know which direction the quad is facing and which direction the light is pointing, a calculation (called the dot product) can be made to see how similar these two are, and light the quad (2 triangles) accordingly. In this example, the quad is directly facing the light so the quad will be fully lit.


fox95871(Posted 2009) [#9]
Have to wait on this for now. Thanks for all the help so far though. I'll post my finished one after I've had some time to figure it out.