FlipMesh Lighting Issue
Blitz3D Forums/Blitz3D Beginners Area/FlipMesh Lighting Issue
| ||
I've been doing pretty good learning Blitz3D without any help but I've come across something I'm just plain not figuring out. I have "Earth" as a sphere with a second sphere in the same spot but larger and Alpha'd for a cheap atmosphere/clouds effect. However when I FlipMesh upon the camera entering the "atmosphere", the light from the "sun" is on the wrong side of the planet...is there a way to correct this? RotateEntity, TurnEntity, and UpdateNormals all seemed to not work. Am I just messing up? Thanks for any input. |
| ||
You have to flip the normals. The only way to do this is to loop through each vertex in the mesh, and get it's normal, and the multiply the X, Y, and Z of the normal each by -1, then reset the vertex normal with this new normal. |
| ||
an other method would be to make an exact copy of the mesh by recursively going trough all childs,surfaces and tris, but then use the order of vertices of the tris in the opposite way of the original, and then updatenormals. Well, in theory this should work. |
| ||
Do it sswifts way, JFK doubt yours would work... wouldnt it just be the same as flipmesh? |
| ||
maybe :) but then I ask myself why flipmesh doesn't automaticly invert the normals. |
| ||
Thanks for your responses...I'll let you know what happens! |
| ||
Wouldn't a RotateMesh sort this? |
| ||
Believe it or not I think I tried that too. I'm thinking maybe my thinking might be wrong. Once you enter the atmosphere and FlipMesh occurs, the other side of the atmosphere IS the side that is facing the light(sun). I can RotateMesh, RotateEntity, TurnEntity all I want but the light SHOULD be falling on the other side of the atmosphere. So I guess the question is, without lightmapping it, (because I'm using AmbientLight 2,2,0-it's SPACE :) ) can I spin the lit side of an entity around or will the light always fall where it should? |
| ||
Here's some example code to help you guys see my lighting problem :Graphics3D 640,480 SetBuffer BackBuffer() Global earthAtmosFlipped = 0 Global speed# = 0 Global camera=CreateCamera() CameraRange camera, 1,3000 Global light=CreateLight() AmbientLight 2,2,0 Global earth=CreateSphere(100) Global earthAtmos=CreateSphere(100) ScaleEntity earth, 200,200,200 ScaleEntity earthAtmos, 300,300,300 PositionEntity earth,0,0,1000 PositionEntity earthAtmos,0,0,1000 EntityAlpha earthAtmos,.25 While Not KeyDown(1) atmosFlip() controlCamera() UpdateWorld RenderWorld Text 10,10, "[a] and [z] controls speed," Text 10,25, "arrow keys To turn camera/ship," Text 10,40, "NumPad 0 To stop" Text 10,55, "speed: "+speed# Text 10,70, "Enter the atmosphere and then go to the other side" Text 10,85, "of the planet to see my lighting dilemma" Flip Wend End Function atmosFlip() If EntityDistance (camera,earth)-200 < 50 And earthAtmosFlipped = 0 Then FlipMesh earthAtmos earthAtmosFlipped = 1 EndIf If EntityDistance (camera,earth)-200 > 50 And earthAtmosFlipped = 1 Then FlipMesh earthAtmos earthAtmosFlipped = 0 EndIf End Function Function controlCamera() If KeyDown(205) TurnEntity camera,0,-.5,0 EndIf If KeyDown(203) TurnEntity camera,0,.5,0 EndIf If KeyDown(200) TurnEntity camera,-.5,0,0 EndIf If KeyDown(208) TurnEntity camera,.5,0,0 EndIf If KeyDown(30) speed# = speed# + .1 EndIf If KeyDown(44) speed# = speed# - .1 EndIf If KeyDown(82) speed# = 0 EndIf MoveEntity camera,0,0,speed# End Function Is there a way to spin the lit side around or will the light always behave like it should and not the way I want? :) |
| ||
"maybe :) but then I ask myself why flipmesh doesn't automaticly invert the normals." It does. That's the problem. He is inside a sphere which he is using as an atmosphere. It is transparent. Imagine the sun is to the right of his planet. He has two spheres. One, the planet, which is opaque. It is lit from the right side. Then he has another, the atmosphere, slightly bigger, and semi transparent. Also lit from the right, with faces facing outwards. When his ship enters the atmosphere, he flips the atmosphere sphere, so that he can see the atmosphere behind the planet. But this also flips the normals. So now, the atmosphere is lit as if it is the inside side of a two sided sphere shell. Which it is. But that means that the light from the sun now falls on the atmosphere which is to the left in the image, and that on the right is in shadow, because those faces face away from the sun. So he needs to flip the normals so they face the WRONG WAY to create the effect he wants to see. An alternative to this Blitzed, would be to set the EntityFX flag which makes an entity two sided. This would make it so you don't need to flip the sphere when you enter it. It will always have two sides, and always be lit with the normals on the outside. |
| ||
An alternative to this Blitzed, would be to set the EntityFX flag which makes an entity two sided. This would make it so you don't need to flip the sphere when you enter it. It will always have two sides, and always be lit with the normals on the outside. That was a smart suggestion! |
| ||
EntityFX earthAtmos,16 Yeah I think that's going to be the best solution for the time being. Thanks sswift and everyone! BTW, the community here is awesome...to think I was THIS --------> <-------- close to buying DarkBasic Professional before I found Blitz3D. I'll be here for a long time. |
| ||
and remember to use UPDATENORMALS |