Game Development Community

water block holes?

by Desmond Fletcher · in Torque Game Engine · 01/19/2002 (3:14 pm) · 76 replies

Anybody have an idea why sections of the water block might disappear?

holodeck.st.usm.edu/vrcomputing/waterhole.jpg
Page «Previous 1 2 3 4 Last »
#1
01/19/2002 (3:31 pm)
Is the water block dissapearing, or is it never rendered to start with? When the water is dropped into the mission, it tests to see whether any of it's squares are underground, if they are they are turned off (no sense rendering water you can't see).

If you edit the terrain you can see a number of non-rendering water squares. Those will go away if you reload the mission (moving the water might also cause it to re-test it's squares).

If the artifact is permanent, then it could be some error in the "underground detection" code. Maybe a precision problem, as it looks like the water is pretty close to the ground in your screenshot.

Also looks like you have some z-buffer precision problems on the water-terrian boundry. Your probably running a 16 bit zbuffer on your card, might want to upping that to 32 bits.
#2
01/20/2002 (9:57 am)
I don't think this is a prob with the code. Here is a sequence dropping the waterblock into the terrain; how can I control the edges? Do I need a steeper dropoff at the edges?

holodeck.st.usm.edu/vrcomputing/wh1.jpg
holodeck.st.usm.edu/vrcomputing/wh2.jpg
holodeck.st.usm.edu/vrcomputing/wh3.jpg
holodeck.st.usm.edu/vrcomputing/wh4.jpg

P.S. There also seems to be a prob with the rotation of the waterblock; changing the rotation vector and angle (for example: 0 0 1 20) does not appear to rotate the waterblock.

P.S.S. I'm using a GF2 vidcard on this machine. Do you know how to increase from 16 to 32 on the Zbuffer issue? I played with a few of the setings and it wouldn't let Torque load.
#3
01/20/2002 (10:28 am)
Ahhhh, I just found a thread from Chris talking about something similar; I forgot to mention that I changed my terrain squaresize to 4. There is definitely a conflict between the terrain and water square sizes at squaresizes other than 8.

www.garagegames.com/index.php?sec=mg&mod=forums&page=result.thread&qt=2957
----------------------------------------------------
Update: In waterblock.cc I found this comment:

//We need to get the translation to be expressed in "terrain square" terms. The terrain offset is always -1024,-1024.

So there is currently no linkage to the current terrain size.

Also, I could find no reference to rotation in the code, just to position and scale. So I guess that either needs to be added or the editor reference removed.

----------------------------------------------------
Also, from engineoverview.txt, I find:

"...the actual coverage of the water area can be set to seed fill from a point on the surface, allowing the water to fill a mountain crater, for example, without leaking outside the corner edges."

Anybody know how to set these paramters?
#4
01/20/2002 (11:14 am)
Ok, here's the hack to fix the waterblock:

In waterblock.cc, change all references to the worldsize from 1024 to match the current terrain squaresize:

IF

terrain square size = 8
worldsize = 1024
waterblock P.x, P.y = 1024

IF

terrain square size = 4
worldsize = 512
waterblock P.x, P.y = 512

etc....

//df about line 98
//P.x += 1024.0f;
//P.y += 1024.0f;
P.x += 512.0f;
P.y += 512.0f;

//df about line 113
//P.x -= 1024.0f;
//P.y -= 1024.0f;
P.x -= 512.0f;
P.y -= 512.0f;

//df about line 651
//Pos.x += 1024.0f;
//Pos.y += 1024.0f;
Pos.x += 512.0f;
Pos.y += 512.0f;


Here is the result:
holodeck.st.usm.edu/vrcomputing/whfixed.jpg

Now we need to make this dynamic by accessing the current worldsize (terrain squaresize parameter??) However, I've also noticed that leaving the waterblock at 512 works fine even if terrain squaresize is 8.
#5
01/20/2002 (6:38 pm)
Are you sure those are the only changes?

They don't work for me.

I changed the terrain size to 4, and made the exact same changes you did. It still screwed up. Then I changed EVERY 1024 in waterblock.cc to 512, still doesn't work.

I tried this once before with no luck.


Dark
#6
01/20/2002 (8:11 pm)
That's all I did to get it working.
#7
02/21/2002 (5:24 pm)
iv tried this too to the letter ant it doesnot work there must be somthing missing
#8
02/21/2002 (7:11 pm)
These are the only changes I've made to the fluid system; I haven't had a chance to look at making the system look for the terrain squareSize yet.

In fluidRender.cc-------------------------

fluid::Render
//glColor4f ( 1.0f, 1.0f, 1.0f, 1.0f );
//glBindTexture ( GL_TEXTURE_2D, m_LightMapTexture.getGLName() );
glColor4f ( 1.0f, 1.0f, 1.0f, m_EnvMapIntensity ); 
glBindTexture ( GL_TEXTURE_2D, m_EnvMapTexture.getGLName() );

In waterBlock.cc--------------------------

WaterBlock::UpdateFluidRegion
//P.x += 1024.0f;
//P.y += 1024.0f;
P.x += 512.0f;
P.y += 512.0f;
//P.x -= 1024.0f;
//P.y -= 1024.0f;
P.x -= 512.0f;
P.y -= 512.0f;

WaterBlock::renderObject

//Point3F W2Lv(  1024.0f,  1024.0f, 0.0f );           
//Point3F L2Wv( -1024.0f, -1024.0f, 0.0f );   
Point3F W2Lv(  512.0f,  512.0f, 0.0f );   
Point3F L2Wv( -512.0f, -512.0f, 0.0f );


WaterBlock::isPointSubmergedSimple
//Pos.x += 1024.0f;
//Pos.y += 1024.0f;
Pos.x += 512.0f;
Pos.y += 512.0f;

I left this last section in WaterBlock::castRay as is:
X = (x * mObjScale.x) + Pos.x + 1024.0f;
Y = (y * mObjScale.y) + Pos.y + 1024.0f;
//X = (x * mObjScale.x) + Pos.x + 512.0f;
//Y = (y * mObjScale.y) + Pos.y + 512.0f;
#9
02/22/2002 (1:05 pm)
I did a little hack to stop checking for the terrain completely.

Does your above post fix the water problem?
#10
02/23/2002 (12:25 pm)
It's working for me (at least for terrain squareSize=4); I have been looking at making the waterblock get the squareSize and change these values based on terrain size but had other things on the burner.

What hack did you come up with Chris?
#11
02/22/2003 (1:18 pm)
chris where did you stub out the check?

-brad
#12
02/28/2003 (5:00 pm)
Desmond are your changes against HEAD? There are 2 more places there are offsets mentioned that you didn't change. Also in fluidRender.cc there is...



f32 Q2 = 1.0f / 2048.0f; // This is the size of the terrain.


-brad
#13
09/20/2005 (1:35 pm)
I hate to open up an old thread... but with Torque 1.4 coming out soon, should this issue not be resolved? This seems like a fairly major bug (essentially the squareSize of the terrain cannot be modified because of this) without any work-arounds or fixes. The above suggestions do not seem to work at all.

Is everyone else still having this issue? Or is it just me? If anyone has any ideas/suggestions/solutions, please share them here. Any help for this issue would be great!

Thank you in advance.
#14
09/21/2005 (5:08 am)
It's a little late - we're already in the final Q&A phases, so major changes like this are probably not going to be making it in. We've had people make a few attempts in the past but nothing really solid has come of it, so for now it'll stay as is. If you do have a fix (or anyone else in the community), I'd love to see it!
#15
09/21/2005 (1:53 pm)
Alright then... here's what I've got so far... anyone else, please jump in and let's try and get this thing sorted out so we can all have better terrain texture resolution!

I believe a lot of the problems are happening in this function: void fluid::RebuildMasks(void) in fluidSupport.cc. It is here that the fluid level is compared to the terrain and it is decided (I think?) whether to throw out a fluid block or not...

Does anyone know exactly what 'SquaresPerBlock' represents? Is it the number of terrain squares per fluid block? The number of fluid squares per fuild block? Don't you love variables just thrown in there without any comments? :)

Anybody else with any ideas, please come forward now!

Stephane
#16
09/22/2005 (8:31 am)
Alright... I believe I have a fix for this. The following code is applied to Torque 1.3, but I have (briefly, mind you) looked at the code in 1.4 and things should work fine there too.

In WaterBlock.h:

- In the 'private:' area of class WaterBlock, add the following:
///< The offset for the terrain (based on square size)
S32 mTerrainOffset;
///< The squaresize of the terrain
S32 mSquareSize;

cont'd...
#17
09/22/2005 (8:32 am)
In WaterBlock.cc:

- In WaterBlock::WaterBlock() add the following:
// Stephane - By default, assume a terrain square size of 8, unless told otherwise
// by the terrain itself
mSquareSize = 8;
// Stephane - The offset to get our waterblock into world space is simply the square
// size multiplied by 128
mTerrainOffset = mSquareSize << 7;

- In WaterBlock::UpdateFluidRegion() change the following:
//P.x += 1024.0f;
//P.y += 1024.0f;
// Stephane - Get our water block into world space
P.x += mTerrainOffset;
P.y += mTerrainOffset;

//mFluid.SetInfo(P.x, P.y, mObjScale.x, mObjScale.y, mSurfaceZ, mWaveMagnitude,
//mSurfaceOpacity,   mEnvMapIntensity, mRemoveWetEdges,  mUseDepthMap,
//mTessellationSurface, mTessellationShore, mSurfaceParallax, mFlowAngle, mFlowRate,
//mDistortGridScale, mDistortMagnitude, mDistortTime, mSpecColor, mSpecPower);

// Stephane - Pass the terrain square size to the fluid stuff
mFluid.SetInfo(P.x, P.y, mObjScale.x, mObjScale.y, mSurfaceZ, mWaveMagnitude,
mSurfaceOpacity, mEnvMapIntensity, mRemoveWetEdges,  mUseDepthMap,
mTessellationSurface, mTessellationShore, mSurfaceParallax, mFlowAngle, mFlowRate, mDistortGridScale, mDistortMagnitude, 	mDistortTime, mSpecColor, mSpecPower, mSquareSize);

//P.x -= 1024.0f;
//P.y -= 1024.0f;

// Stephane - Put the waterblock back into terrain space...
P.x -= mTerrainOffset;
P.y -= mTerrainOffset;

- In WaterBlock::GenerateDepthTextures() change the following:
// Change Spaces.
//TerrainPos.x += 1024.0f;
//TerrainPos.y += 1024.0f;

// Change Spaces (Stephane - Changing to world space)
TerrainPos.x += mTerrainOffset;
TerrainPos.y += mTerrainOffset;

- In WaterBlock::onAdd() simply comment out the following as we now do this in onSceneAdd():
/*if (!isClientObject()) 
{
   // Make sure that the Fluid has had a chance to tweak the values.
   UpdateFluidRegion();
}*/

- In WaterBlock::onSceneAdd() change the following:
/*if( mpTerrain )
{
   mFluid.SetTerrainData( mpTerrain->heightMap );
   // MM: Calculate Depth Maps.
   if (isClientObject()) CalculateDepthMaps();
}*/
if (mpTerrain)
{
   // Stephane - Grab the current terrain square size straight from the horse's mouth and save it...
   mSquareSize = mpTerrain->getSquareSize();
   // Stephane - Store the terrain offset too... saves us some calculating in the future...
   mTerrainOffset = mSquareSize << 7;
   mFluid.SetTerrainData(mpTerrain->heightMap);
   // MM: Calculate Depth Maps.
   if (isClientObject())
      CalculateDepthMaps();
   // Stephane - Give the fluid a chance to update its values (since we took this out of the onAdd()
   // function above, this gives the server a chance to update its values...)
   UpdateFluidRegion();
}

- In WaterBlock::prepRenderImage(...) change the following:
/*if( mpTerrain )
{
   mFluid.SetTerrainData( mpTerrain->heightMap );
   // MM: Calculate Depth Maps.
   if (isClientObject()) CalculateDepthMaps();
}*/
if (mpTerrain)
{
   // Stephane - Grab the current terrain square size straight from the horse's mouth and save it...
   mSquareSize = mpTerrain->getSquareSize();
   // Stephane - Store the terrain offset too... saves us some calculating in the future...
   mTerrainOffset = mSquareSize << 7;
   mFluid.SetTerrainData(mpTerrain->heightMap);
   // MM: Calculate Depth Maps.
   if (isClientObject())
      CalculateDepthMaps();
   // Stephane - Give the fluid a chance to update its values (this should now give the client a chance
   //to update its fluid region since the server never calls prepRenderImage())
   UpdateFluidRegion();
}

cont'd...
#18
09/22/2005 (8:33 am)
- In WaterBlock::renderObject() change the following:
// World to Local vector
//Point3F W2Lv(  1024.0f,  1024.0f, 0.0f );
// Local to World vector
//Point3F L2Wv( -1024.0f, -1024.0f, 0.0f );
// Stephane - Using the terrain offset to initialize the world to local vector and the local
// to world vector
Point3F W2Lv(mTerrainOffset, mTerrainOffset, 0.0f);
Point3F L2Wv(-mTerrainOffset, -mTerrainOffset, 0.0f);

- In WaterBlock::isPointSubmergedSimple(...) change the following:
//Pos.x += 1024.0f;
//Pos.y += 1024.0f;
// Stephane - If they want it in world-space, give it to them in world-space!
Pos.x += mTerrainOffset;
Pos.y += mTerrainOffset;

- In WaterBlock::castRay(...) change the following:
//X = (x * mObjScale.x) + Pos.x + 1024.0f;
//Y = (y * mObjScale.y) + Pos.y + 1024.0f;
// Stephane - Once again, get our values in world-space...
X = (x * mObjScale.x) + Pos.x + mTerrainOffset;
Y = (y * mObjScale.y) + Pos.y + mTerrainOffset;

In fluid.h:

- In the 'public:' functions section, change the following:
//void SetInfo(f32& X0, f32& Y0, f32& SizeX, f32& SizeY, f32  SurfaceZ, f32  WaveAmplitude,
//f32& Opacity, f32& EnvMapIntensity, s32  RemoveWetEdges, bool UseDepthMap,
//f32 TessellationSurface, f32 TessellationShore, f32 SurfaceParallax, f32 FlowAngle, f32 FlowRate,
//f32 DistortGridScale, f32 DistortMagnitude, f32 DistortTime, ColorF SpecColor, f32  SpecPower);

void SetInfo(f32& X0, f32& Y0, f32& SizeX, f32& SizeY, f32  SurfaceZ, f32  WaveAmplitude,
f32& Opacity, f32& EnvMapIntensity, s32  RemoveWetEdges, bool UseDepthMap,
f32 TessellationSurface, f32 TessellationShore, f32 SurfaceParallax, f32 FlowAngle, f32 FlowRate,
f32 DistortGridScale, f32 DistortMagnitude, f32 DistortTime, ColorF SpecColor, f32  SpecPower,
s32 SquareSize);

- In the 'public:' variables section, add the following:
// Stephane - The terrain's squaresize (used to create masks)
s32 m_SquareSize;

cont'd...
#19
09/22/2005 (8:33 am)
In FluidSupport.cc:

- In fluid::fluid(void), add the following:
// Stephane - The default square size
m_SquareSize = 8;

- In fluid::RebuildMasks(void), change the following:
//s32 SquaresPerBlock = m_HighResMode ? 4 : 8;
//s32 ShiftPerBlock = m_HighResMode ? 2 : 3;

// Get the inverse of the square size
f32 inverseSS = 1.0f / m_SquareSize;
// Sets the number of squares per block based on the terrain's square size
s32 SquaresPerBlock = m_HighResMode ? (s32)(inverseSS * 32.0f) : (s32)(inverseSS * 64.0f);
// Sets the size of the shifts that are going to be applied later on
s32 ShiftPerBlock = (s32)(mLog((f32)SquaresPerBlock) / mLog(2.0f));

/*if( m_pTerrain )
{
   u16 FluidLevel = (u16)((m_SurfaceZ + (m_WaveAmplitude/2.0f)) * 32.0f);

   pG = pGrid;
   for( Y = 0; Y < m_SquaresInY+1; Y++ )
   for( X = 0; X < m_SquaresInX+1; X++ )
   {
      i = (((m_SquareY0+Y) & 255) << 8) + ((m_SquareX0+X) & 255);
      *pG = (u8)(FluidLevel > m_pTerrain[i]);
      pG++;
   }
}*/

if (m_pTerrain)
{
   // Stephane - Grab the height of the fluid level
   U16 FluidLevel = (U16)((m_SurfaceZ + (m_WaveAmplitude / 2.0f)) * (inverseSS * 256.0f));
   // Stephane - Get a pointer to our 'Reject' grid
   pG = pGrid;
   
   // Stephane - For each fluid square...
   for (Y = 0; Y < m_SquaresInY + 1; Y++)
   {
      for (X = 0; X < m_SquaresInX + 1; X++)
      {
         // Stephane - Figure out which terrain block we are looking at in the height-map
         i = (((m_SquareY0 + Y) & 255) << m_SquareSize) + ((m_SquareX0 + X) & 255);
         // Stephane - Compare our fluid's height to the terrain height and put the result in our
         // 'Reject' grid
         *pG = (U8)(FluidLevel > m_pTerrain[i]);
         // Stephane - Increment the 'Reject' grid
         pG++;
      }
   }
}

- In fluid::setInfo(...), the following needs to be changed and added:
//void fluid::SetInfo(f32& X0, f32& Y0, f32& SizeX, f32& SizeY, f32  SurfaceZ,
//f32  WaveAmplitude, f32& Opacity, f32& EnvMapIntensity, s32  RemoveWetEdges,
//bool UseDepthMap, f32  TessellationSurface, f32  TessellationShore, f32  SurfaceParallax,
//f32  FlowAngle, f32  FlowRate, f32  mDistortGridScale, f32  mDistortMagnitude,
//f32  mDistortTime, ColorF SpecColor, f32 SpecPower)

void fluid::SetInfo(f32& X0, f32& Y0, f32& SizeX, f32& SizeY, f32  SurfaceZ,
f32  WaveAmplitude, f32& Opacity, f32& EnvMapIntensity, s32  RemoveWetEdges,
bool UseDepthMap, f32  TessellationSurface, f32  TessellationShore, f32  SurfaceParallax,
f32  FlowAngle, f32  FlowRate, f32  mDistortGridScale, f32  mDistortMagnitude,
f32  mDistortTime, ColorF SpecColor, f32 SpecPower, s32 SquareSize)

m_WaveFactor = m_WaveAmplitude * 0.25f;

// Place the "min" corner.
m_SquareX0 = (S32)((X0 / 8.0f) + 0.5f);
m_SquareY0 = (S32)((Y0 / 8.0f) + 0.5f);

[b]Becomes:[/b]
m_WaveFactor = m_WaveAmplitude * 0.25f;

// Stephane - Store the square size of the terrain
m_SquareSize = SquareSize;

// Place the "min" corner.
m_SquareX0 = (S32)((X0 / 8.0f) + 0.5f);
m_SquareY0 = (S32)((Y0 / 8.0f) + 0.5f);

Finally, In FluidRender.cc:

- In fluid::Render(bool& EyeSubmerged), change the following:
// This is the size of the terrain.
//F32 Q2 = 1.0f / 2048.0f;
// This is the size of the terrain.
F32 Q2 = 1.0f / 1024.0f;

That should be all the changes. I would really like to get this bug fixed, so if anyone could test this out on other squareSizes, that would be great! I have tested it thoroughly on squareSize 4, but not really on anything else (including the regular squareSize of 8), so it would be good if we could get the other squareSizes tested and all the bugs out so perhaps Ben can even get this into 1.4... :)

Enjoy!

Stephane
#20
09/22/2005 (8:45 am)
Just did a test at a square size of 8 and things seem to be still working fine, so it looks like 4 and 8 work side-by-side with this code. It would be interesting to see if things break at 2 or 16...
Page «Previous 1 2 3 4 Last »