Terrain shadows

Started by
18 comments, last by DanielH 21 years, 5 months ago
I know how to get the normal now, but i cant find any information about calculating the angle between the vector and the sunlight
Advertisement
quote:Original post by DanielH
I know how to get the normal now, but i cant find any information about calculating the angle between the vector and the sunlight

Dotproduct: intensity of point = Normal DOT Sunlight direction. DOT is the dotproduct, ie: intensity = N.x * S.x + N.y * S.y + N.z * S.z; Both normal and sunlight direction need to be normalized for it to work. intensity will range from -1 to 1. Clamp everything less than 0 to 0: intensity = max(0, intensity).
the dotproduct is the cosinus of the angle you are looking for
http://www.8ung.at/basiror/theironcross.html
For some reason just every other triangle get shaded and the other is black!

What am i doing wrong?

procedure TOctree.CalculateShadows(pNode: TOctree);type  TVectorArray = array[0..0] of TVectorEX;var  i: Cardinal;  pVertices: ^TVectorArray;  vNormal: TVector3;  intensity : GLfloat;  Color : TRGB;begin	if pNode = nil then Exit;	if pNode.SubDivided then	begin		CalculateShadows(pNode.FOctreeNodes[TOP_LEFT_FRONT]);		CalculateShadows(pNode.FOctreeNodes[TOP_LEFT_BACK]);		CalculateShadows(pNode.FOctreeNodes[TOP_RIGHT_BACK]);		CalculateShadows(pNode.FOctreeNodes[TOP_RIGHT_FRONT]);		CalculateShadows(pNode.FOctreeNodes[BOTTOM_LEFT_FRONT]);		CalculateShadows(pNode.FOctreeNodes[BOTTOM_LEFT_BACK]);		CalculateShadows(pNode.FOctreeNodes[BOTTOM_RIGHT_BACK]);		CalculateShadows(pNode.FOctreeNodes[BOTTOM_RIGHT_FRONT]);	end	else	begin		// Make sure we have valid vertices assigned to this node		if pNode.FVertices = nil then Exit;		// Store the vertices in a local pointer to keep code more clean		pVertices := @pNode.FVertices[0];		// Go through all of the vertices (the number of triangles * 3)    i := 0;    while i < pNode.TriangleCount * 3 do    begin      vNormal := Normal(pVertices.PosVector, pVertices[i+1].PosVector, pVertices[i+2].PosVector);      intensity := vNormal.x * g_Sun.x + vNormal.y * g_Sun.y + vNormal.z * g_Sun.z;      if intensity < 0.1 then intensity := 0.1;      Color.r := intensity; Color.g := intensity; Color.b := intensity;      pVertices.Color := Color;<br>      pVertices.Color := Color;<br>      pVertices.Color := Color;<br><br>        Inc(i, 3);<br>    end;<br><br>	end;<br>end;<br><br> </pre>   </i>   
quote:Original post by griffenjam
Original post by Raduprv
Just do some raytracing, after you build your height map, and store the result (shaded or not shaded) on each vertex. Then, when you render it, use a different color (maybe 0.5,0.5,0.5) to blend with the current texture.


Do you have some source code for this?

I am trying to get this working but for some reason my ray-poly colision detection isn''t working.
I''m not expiranced with 3D stuff, and I''m just using the collision detection tutorials from www.gametutorials.com. I don''t know if I using the collision detections functions wrong, or if they arn''t working.


I don''t have any C source code, I did that looong time ago, in ASM, and it looked good. But it was a vertex engine, so I don''t know exactly how it looks with vertex shades (but I guess it looks better than nothing)

Hey! I still need help!
Possibly, the normals are facing the wrong direction.
How can i do so the normals dont face the wrong direction then?
Maybe you should play with the light source possition, until you find out where your normals are, and then adjust them properly.
If you are calculating your normals by taking three points from your poly and doing the crossproduct the order of the points matters. Depending on which order you choose your points you can get the normal pointing "up" or "down". If you arent consistent then you get some pointing one way and some the other and you end up with some triangles properly shaded and others black because OpenGL treats them like they are facing the wrong way.

If you have questions about the math involved you should post your questions to the Math forum here, you might get a more technical response.

To do shadows on your terrain have you looked into shadow maps? Try www.vterrain.org they have links to some good papers which deal with this.

This topic is closed to new replies.

Advertisement