Hi all,
I having trouble getting the terrain mesh size in world space which I need to do some distance calculations in the vertex shader.
I have the following code in TerrainRender.cpp which I though would work, but doesn't...
shaderSolid->Uniform("meshSize", (float)(g_Game->GetWorld()->GetTerrain()->GetTilesPerSide() * TERRAIN_TILE_SIZE));
Basically what I need it for is to range the vertices e.g. -1 to 1, or 0 to 1 say.
Any ideas?
Also, is there some kind of radius or diameter used for circular terrain's? if I could grab that information as well that would help me a lot.
thanks in advance
Michael
Terrain Mesh Size or Terrain Diameter
Started by
mpatton
, Apr 18 2012 11:26 AM
3 replies to this topic
#1
Posted 18 April 2012 - 11:26 AM
#2
Posted 19 April 2012 - 03:49 PM
That looks like the right calculation to do. But techSolid/shaderSolid are used for the solid black sides of the map, not for the actual terrain tiles - you should specify the uniform inside TerrainRenderer::PrepareShader so that it's available to all the base/blend/decal terrain rendering calls.
Circular terrain is just square terrain with permanent shroud-of-darkness around the corners, so GetTilesPerSide() gives you the diameter.
Circular terrain is just square terrain with permanent shroud-of-darkness around the corners, so GetTilesPerSide() gives you the diameter.
Philip Taylor [aka Ykkrosh]
Wildfire Games Programmer
Contact me: philip@wildfiregames.com
Wildfire Games Programmer
Contact me: philip@wildfiregames.com
#3
Posted 23 April 2012 - 09:10 AM
Cool thanks for that. My problem must now be with the way I get the camera normal matrix or world origin position for it, though they look correct to me...
I'm going to post my calculations here, if anyone can spot a problem with what I'm doing any help would be greatly appreciated
/*Camera Normal Matrix*/
CMatrix3D cameraInverse;
glGetFloatv(GL_MODELVIEW_MATRIX, cameraInverse._data);
CMatrix3D cameraNormalMatrix = cameraInverse.GetInverse().GetTranspose();
/*World Origin*/
CVector4D worldOrigin;
worldOrigin.X = CVector4D(cameraInverse._11, cameraInverse._12, cameraInverse._13, cameraInverse._14).Dot(CVector4D(0.0, 0.0, 0.0, 1.0));
worldOrigin.Y = CVector4D(cameraInverse._21, cameraInverse._22, cameraInverse._23, cameraInverse._44).Dot(CVector4D(0.0, 0.0, 0.0, 1.0));
worldOrigin.Z = CVector4D(cameraInverse._31, cameraInverse._32, cameraInverse._33, cameraInverse._44).Dot(CVector4D(0.0, 0.0, 0.0, 1.0));
worldOrigin.W = CVector4D(cameraInverse._41, cameraInverse._42, cameraInverse._43, cameraInverse._44).Dot(CVector4D(0.0, 0.0, 0.0, 1.0));
Ideally here I would have like to have just done cameraNormalMatrix * CVector4D(0.0, 0.0, 0.0, 1.0);
however I could not see any function to do this calculation. Is there one?
thanks in advance
Michael
I'm going to post my calculations here, if anyone can spot a problem with what I'm doing any help would be greatly appreciated
/*Camera Normal Matrix*/
CMatrix3D cameraInverse;
glGetFloatv(GL_MODELVIEW_MATRIX, cameraInverse._data);
CMatrix3D cameraNormalMatrix = cameraInverse.GetInverse().GetTranspose();
/*World Origin*/
CVector4D worldOrigin;
worldOrigin.X = CVector4D(cameraInverse._11, cameraInverse._12, cameraInverse._13, cameraInverse._14).Dot(CVector4D(0.0, 0.0, 0.0, 1.0));
worldOrigin.Y = CVector4D(cameraInverse._21, cameraInverse._22, cameraInverse._23, cameraInverse._44).Dot(CVector4D(0.0, 0.0, 0.0, 1.0));
worldOrigin.Z = CVector4D(cameraInverse._31, cameraInverse._32, cameraInverse._33, cameraInverse._44).Dot(CVector4D(0.0, 0.0, 0.0, 1.0));
worldOrigin.W = CVector4D(cameraInverse._41, cameraInverse._42, cameraInverse._43, cameraInverse._44).Dot(CVector4D(0.0, 0.0, 0.0, 1.0));
Ideally here I would have like to have just done cameraNormalMatrix * CVector4D(0.0, 0.0, 0.0, 1.0);
however I could not see any function to do this calculation. Is there one?
thanks in advance
Michael
Edited by mpatton, 23 April 2012 - 09:13 AM.
#4
Posted 23 April 2012 - 02:00 PM
GL_MODELVIEW_MATRIX might not always be set up correctly - the current version of the renderer tries to do everything with local per-shader transform matrices instead of the global GL state. Better to use g_Renderer.GetViewCamera().GetOrientation().GetTranslation() to get the world-space camera position (or use the g_Renderer.GetViewCamera().GetOrientation() matrix in other ways).
Philip Taylor [aka Ykkrosh]
Wildfire Games Programmer
Contact me: philip@wildfiregames.com
Wildfire Games Programmer
Contact me: philip@wildfiregames.com
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











