Some water-related bug fixes:
- Underwater tiles will be tested against the frustum with a bounding box including the water surface, so the water gets drawn even if the terrain is off-screen. - Transparent objects (e.g. trees) should now interact with water properly. I did this by rendering them twice, first before the water, so it overlaps the underwater pieces, then after, so the above-water pieces overlap the water (the water now writes Z as well as colour to allow this). Before, only the first pass was done, so the tops of trees were covered by water. There might be more efficient ways of doing this - the best could be for the transparent objects to be drawn with a shader that always either discards a pixel or writes alpha of 1.0 instead of using 2-pass depth write then colour write. This was SVN commit r3904.
This commit is contained in:
parent
7ac2fc94a9
commit
1a8cb85e08
@ -287,7 +287,15 @@ void CGameView::RenderTerrain(CTerrain *pTerrain)
|
||||
for (uint j=0; j<patchesPerSide; j++) {
|
||||
for (uint i=0; i<patchesPerSide; i++) {
|
||||
CPatch* patch=pTerrain->GetPatch(i,j);
|
||||
if (frustum.IsBoxVisible (CVector3D(0,0,0),patch->GetBounds())) {
|
||||
|
||||
// If the patch is underwater, calculate a bounding box that also contains the water plane
|
||||
CBound bounds = patch->GetBounds();
|
||||
float waterHeight = g_Renderer.GetWaterManager()->m_WaterHeight + 0.001f;
|
||||
if(bounds[1].Y < waterHeight) {
|
||||
bounds[1].Y = waterHeight;
|
||||
}
|
||||
|
||||
if (frustum.IsBoxVisible (CVector3D(0,0,0), bounds)) {
|
||||
g_Renderer.Submit(patch);
|
||||
}
|
||||
}
|
||||
|
@ -1176,7 +1176,7 @@ void CRenderer::FlushFrame()
|
||||
|
||||
oglCheck();
|
||||
|
||||
if(m_Options.m_FancyWater)
|
||||
if(m_WaterManager->m_RenderWater && m_Options.m_FancyWater)
|
||||
{
|
||||
// render reflected and refracted scenes, then re-clear the screen
|
||||
RenderReflections();
|
||||
@ -1208,19 +1208,22 @@ void CRenderer::FlushFrame()
|
||||
RenderModels();
|
||||
oglCheck();
|
||||
|
||||
// call on the transparency renderer to render all the transparent stuff
|
||||
// render transparent stuff
|
||||
MICROLOG(L"render transparent");
|
||||
RenderTransparentModels();
|
||||
oglCheck();
|
||||
|
||||
// render water (note: we're assuming there's no transparent stuff over water...
|
||||
// we could also do this above render transparent if we assume there's no transparent
|
||||
// stuff underwater)
|
||||
// render water
|
||||
if (m_WaterManager->m_RenderWater)
|
||||
{
|
||||
MICROLOG(L"render water");
|
||||
m->terrainRenderer->RenderWater();
|
||||
oglCheck();
|
||||
|
||||
// render transparent stuff again, so it can overlap the water
|
||||
MICROLOG(L"render transparent 2");
|
||||
RenderTransparentModels();
|
||||
oglCheck();
|
||||
}
|
||||
|
||||
// Clean up texture blend mode so particles and other things render OK
|
||||
|
@ -391,7 +391,6 @@ void TerrainRenderer::RenderWater()
|
||||
if(fancy && !m->fancyWaterShader)
|
||||
{
|
||||
m->fancyWaterShader = ogl_program_load( "shaders/water_high.xml" );
|
||||
//debug_printf("Loaded the water shader!!\n");
|
||||
}
|
||||
|
||||
//(Crappy) fresnel effect
|
||||
@ -409,7 +408,8 @@ void TerrainRenderer::RenderWater()
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDepthMask(GL_FALSE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
double time = WaterMgr->m_WaterTexTimer;
|
||||
|
||||
@ -599,7 +599,6 @@ void TerrainRenderer::RenderWater()
|
||||
}
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
@ -546,6 +546,9 @@ u32 TransparentRenderModifier::BeginPass(uint pass)
|
||||
{
|
||||
// First pass: Put down Z for opaque parts of the model,
|
||||
// don't touch the color buffer.
|
||||
|
||||
glDepthMask(1);
|
||||
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_CONSTANT);
|
||||
|
Loading…
Reference in New Issue
Block a user