Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 21 Mar 2008
Offline Last Active Sep 19 2012 01:40 PM

Topics I've Started

shadow map appears from opposite direction (glsl)

11 September 2012 - 02:50 AM

I've been trying to implement shadow mapping in my project. Most of it is working as it should, that means the depth texture generation is about right and shadow coordinates are saved in the texture matrix to be accessed in the shader. As a base I've used the tutorial at http://fabiensanglard.net/shadowmapping/index.php

I had some trouble to get it working but basically now the code is very similar to the one in the tutorial. I even use the same texture units, etc. I can post some code later if it matters. Now here is the result I got:

Posted Image

What do you see here: The white plane is my terrain/ground. On the left of it there is a textured sphere sunk in the ground. Red sphere on the left is my light source directed towards the sphere. The Shadow that is generated looks about right but it is on the opposite direction of the sphere that it should be.

I've read some forum posts and other tutorials and some of them talk about the generation of an inverted camera matrix. Now I've already tried that and the result was absolutely wrong or did not work in the slightest way. Also I'm not really sure if my problem is a result from that. And then again I'm wondering why there is no such inversion in the tutorial. It would be great if someone was able to enlight me about this....

simple collision with terrain

27 March 2008 - 08:56 PM

The most simple collision detection with a terrain I know is getting the current Height value using the camera coordinates. This method suits me pretty good and it works just great if my heightmap scale is 1. (I scale my each vertex value by a constant factor on heightmap creation). The movement is smooth. Now when I set the scaling factor to 100 for example the heightmap is of course 100 bigger on screen. The pixel data is still the same. I simply get the Height like this: NewPos = Height(CamX/100,CamZ/100)*100 + SomeValueForCameraHeight; Before trying it I would guess that this is choppy. And of course it is choppy when walking over the terrain. The Collision is correct. Well, I'm not really interested in implementing some advanced collision method. Isn't there a simple "hack" to stop the chopyness? I could scale the whole heightmap by the factor and run a gaussian blur over it. But that would use up huge amounts of memory and I dont like it. Has anyone got a better idea to make this interpolation a bit more smooth? thanks.

terrain normals

22 March 2008 - 12:08 AM

Hi, long time since I programmed game related stuff. Anyway I had some spare time and wrote up a heightmapping demo that uses glsl, splatting and per-pixel lighting. It works pretty good already but i have a VERY small problem with the normal calculation: The terrain is split up in triangles. Each iteration of the grid has 2 triangles. Now I go and calculate the normal like this:
  for(int c=0;c<m_totalTriangles;c++) {
	   CVector3 Triangle[3];

	   Triangle[0].x = m_vertex[i++];
	   Triangle[0].y = m_vertex[i++];
	   Triangle[0].z = m_vertex[i++];

	   Triangle[1].x = m_vertex[i++];
	   Triangle[1].y = m_vertex[i++];
	   Triangle[1].z = m_vertex[i++];

	   Triangle[2].x = m_vertex[i++];
	   Triangle[2].y = m_vertex[i++];
	   Triangle[2].z = m_vertex[i++];

	   CVector3 Normals[c] = Normal(Triangle);

Each Triangle has a calculated normal, the face normal of this triangle is calulcated so:
CVector3 Normal(CVector3 vTriangle[])
	CVector3 vVector1 = Vector(vTriangle[2], vTriangle[0]);
	CVector3 vVector2 = Vector(vTriangle[1], vTriangle[0]);
	CVector3 vNormal = Cross(vVector1, vVector2);
	vNormal = Normalize(vNormal);
	return vNormal;	

Now to the problem: When I draw the normals using lines from the center of each triangle you already see something is wrong. In some Triangles the line goes up as it should and it others it faces downwards. I know its a problem coming from the cross product (right hand rule). But how do I fix it? My lighting calculation in the shader is right, but as you can see in this image, its just the same as above. Would be cool if anyone has an idea about how I can fix this :).