Water Light map effect
by Olivier Arguimbau · in Torque Game Engine · 01/04/2002 (7:03 am) · 11 replies
Hi.
I look at the fluirender.cc file and i found a commented code about light map on water.
I commented out this code and add a texture to enable it and it seems to work...
My question is why this code has been disabled ?
I look at the fluirender.cc file and i found a commented code about light map on water.
I commented out this code and add a texture to enable it and it seems to work...
My question is why this code has been disabled ?
About the author
#2
01/04/2002 (9:15 am)
Yes, a pic would be nice.
#3
Here are the pics :
Normal water rendering
The envmap (sunset_007)
[image]antsoft.multimania.com/files/avec envmap.jpg[/image]
Envmap water rendering
Finally i use sunset_007.png for the LIGHTMAP too (i disabled the envmap but you can enable both at same time)
LIGHTMAP Water rendering
So, it seems to work, and it look pretty usefull.
Any idea why it has been disabled ?
(Hope the image links work...)
01/04/2002 (10:07 am)
Hi.Here are the pics :
Normal water rendering
The envmap (sunset_007)[image]antsoft.multimania.com/files/avec envmap.jpg[/image]
Envmap water rendering
Finally i use sunset_007.png for the LIGHTMAP too (i disabled the envmap but you can enable both at same time)
LIGHTMAP Water renderingSo, it seems to work, and it look pretty usefull.
Any idea why it has been disabled ?
(Hope the image links work...)
#4
Here is the link directly :
Normal:
http://antsoft.multimania.com/files/avant.jpg
EnvMap texture:
http://antsoft.multimania.com/files/minisunset.jpg
Water with envmap:
http://antsoft.multimania.com/files/avec%20envmap.jpg
Water with LIGHTMAP and without envmap:
http://antsoft.multimania.com/files/apres.jpg
....
01/04/2002 (10:10 am)
The images didn't seems to work....Here is the link directly :
Normal:
http://antsoft.multimania.com/files/avant.jpg
EnvMap texture:
http://antsoft.multimania.com/files/minisunset.jpg
Water with envmap:
http://antsoft.multimania.com/files/avec%20envmap.jpg
Water with LIGHTMAP and without envmap:
http://antsoft.multimania.com/files/apres.jpg
....
#5
01/04/2002 (10:10 am)
links not working
#6
01/04/2002 (10:34 am)
Links seem to be working now, basically with the changes described the water becomes much prettier - taking on, in this case, the same color range as the sky.
#7
01/04/2002 (7:58 pm)
Looks nice--in the last image where are the apparent shadows on the water coming from? Or is that just terrain showing through shallower water? What does it look like if you delete the terrain block?
#8
01/04/2002 (9:43 pm)
Wow, that's beautiful...nice effect. Do you notice a drop in framerates at all? Perhaps you could post a tutorial on how to do this.
#9
The LightMap like the name says, affect the lights on the surface of the waterblock.
It's act (in theory, not sure it's really what happens in Torque engine) like an alpha channel but instead of adjusting transparence it affects brightness...
I think you can manage "real" lightmapping using a grayscale texture for lightmap, i'll try.
If it appears usefull i'll post a tutorial.
If you want to try "at hand" just open fluidrender.cc
and search for " light map "
comment out all the lines, and replace
m_LightMapTexture.getGLName()
with
m_EnvMapTexture.getGLName()
and
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
with
glColor4f( 1.0f, 1.0f, 1.0f, m_EnvMapIntensity );
then comment the envmap management
from
glEnableClientState ( GL_TEXTURE_COORD_ARRAY );
to
if( m_ShowEnvMap )
{
glDrawElements ( GL_TRIANGLES, m_IUsed, GL_UNSIGNED_SHORT, m_pIndex );
}
this will disable envmap, enable lightmap and use the envmap parameters for lightmap feature.
After that you can (like me) add the lightmap properly by creating a new property for waterblock...
If there's no side effects (and if it's usefull) i'll post how to do this.
So i repeat my question: Why that code was commented ?
01/05/2002 (4:04 am)
First: Sorry for my bad english, i'm french...The LightMap like the name says, affect the lights on the surface of the waterblock.
It's act (in theory, not sure it's really what happens in Torque engine) like an alpha channel but instead of adjusting transparence it affects brightness...
I think you can manage "real" lightmapping using a grayscale texture for lightmap, i'll try.
If it appears usefull i'll post a tutorial.
If you want to try "at hand" just open fluidrender.cc
and search for " light map "
comment out all the lines, and replace
m_LightMapTexture.getGLName()
with
m_EnvMapTexture.getGLName()
and
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
with
glColor4f( 1.0f, 1.0f, 1.0f, m_EnvMapIntensity );
then comment the envmap management
from
glEnableClientState ( GL_TEXTURE_COORD_ARRAY );
to
if( m_ShowEnvMap )
{
glDrawElements ( GL_TRIANGLES, m_IUsed, GL_UNSIGNED_SHORT, m_pIndex );
}
this will disable envmap, enable lightmap and use the envmap parameters for lightmap feature.
After that you can (like me) add the lightmap properly by creating a new property for waterblock...
If there's no side effects (and if it's usefull) i'll post how to do this.
So i repeat my question: Why that code was commented ?
#10
if( m_ShowEnvMap )
{
glDrawElements ( GL_TRIANGLES, m_IUsed, GL_UNSIGNED_SHORT, m_pIndex );
}
in the Render Phase 3 area. But you seem to suggest adding this earlier in the code.
This seems to work better:
// glColor4f ( 1.0f, 1.0f, 1.0f, 1.0f );
// glBindTexture ( GL_TEXTURE_2D, m_LightMapTexture.getGLName() );
//df change above to lines to:
glColor4f( 1.0f, 1.0f, 1.0f, m_EnvMapIntensity );
glBindTexture ( GL_TEXTURE_2D, m_EnvMapTexture.getGLName() );
//df end
//df these were commented out
glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glBlendFunc ( GL_DST_COLOR, GL_ZERO );
glMatrixMode ( GL_TEXTURE );
glPushMatrix ();
glLoadIdentity ();
glTexGenfv ( GL_S, GL_OBJECT_PLANE, SLMap );
glTexGenfv ( GL_T, GL_OBJECT_PLANE, TLMap );
//---------------------------------
//-- Render Phase 2 - light map
if( m_ShowLightMap )
{
glDrawElements ( GL_TRIANGLES, m_IUsed, GL_UNSIGNED_SHORT, m_pIndex );
}
//----------------------------------
//-- Cleanup from Phase 2 - light map
glPopMatrix ();
//df end of uncommented section
01/05/2002 (9:42 am)
Would you mind showing that entire section of commented/uncommented changes? There is already a section for: if( m_ShowEnvMap )
{
glDrawElements ( GL_TRIANGLES, m_IUsed, GL_UNSIGNED_SHORT, m_pIndex );
}
in the Render Phase 3 area. But you seem to suggest adding this earlier in the code.
This seems to work better:
// glColor4f ( 1.0f, 1.0f, 1.0f, 1.0f );
// glBindTexture ( GL_TEXTURE_2D, m_LightMapTexture.getGLName() );
//df change above to lines to:
glColor4f( 1.0f, 1.0f, 1.0f, m_EnvMapIntensity );
glBindTexture ( GL_TEXTURE_2D, m_EnvMapTexture.getGLName() );
//df end
//df these were commented out
glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glBlendFunc ( GL_DST_COLOR, GL_ZERO );
glMatrixMode ( GL_TEXTURE );
glPushMatrix ();
glLoadIdentity ();
glTexGenfv ( GL_S, GL_OBJECT_PLANE, SLMap );
glTexGenfv ( GL_T, GL_OBJECT_PLANE, TLMap );
//---------------------------------
//-- Render Phase 2 - light map
if( m_ShowLightMap )
{
glDrawElements ( GL_TRIANGLES, m_IUsed, GL_UNSIGNED_SHORT, m_pIndex );
}
//----------------------------------
//-- Cleanup from Phase 2 - light map
glPopMatrix ();
//df end of uncommented section
#11
here is my FINAL code (with implementation of properties for lightmap feature)
In waterblock.h, add :
-"just after TextureHandle mEnvMapTexture;":
TextureHandle mLightMapTexture;
-"just after F32 mEnvMapIntensity;":
StringTableEntry mLightMapName;
F32 mLightMapIntensity;
In fluidsupport.cc
-"just after m_EnvMapIntensity = 1.0f;":
m_LightMapIntensity = 1.0f;
-"in function SetInfo" change parameters list to:
void fluid::SetInfo( f32& X0,
f32& Y0,
f32& SizeX,
f32& SizeY,
f32 SurfaceZ,
f32 WaveAmplitude,
f32& Opacity,
f32& EnvMapIntensity,
f32& LightMapIntensity,
s32 RemoveWetEdges )
-"and add the following in the begining of the function":
if( LightMapIntensity > 1.0f ) LightMapIntensity = 1.0f;
if( LightMapIntensity < 0.0f ) LightMapIntensity = 0.0f;
m_LightMapIntensity = LightMapIntensity;
-"in fluidrender.cc" search for "light map" and change the code to:
//--------------------------------------------------------------------------
//-- Cleanup from Phase 1 - base textures
glDisableClientState( GL_COLOR_ARRAY );
glPopMatrix ();
//--------------------------------------------------------------------------
//-- Initializations for Phase 2 - light map
if ((m_ShowLightMap) && (m_LightMapTexture.getGLName() != 0))
{
glColor4f ( 1.0f, 1.0f, 1.0f, m_LightMapIntensity );
glBindTexture ( GL_TEXTURE_2D, m_LightMapTexture.getGLName() );
glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glBlendFunc ( GL_DST_COLOR, GL_ZERO );
glMatrixMode ( GL_TEXTURE );
glPushMatrix ();
glLoadIdentity ();
glTexGenfv ( GL_S, GL_OBJECT_PLANE, SLMap );
glTexGenfv ( GL_T, GL_OBJECT_PLANE, TLMap );
//--------------------------------------------------------------------------
//-- Render Phase 2 - light map
glDrawElements ( GL_TRIANGLES, m_IUsed, GL_UNSIGNED_SHORT, m_pIndex );
//--------------------------------------------------------------------------
//-- Cleanup from Phase 2 - light map
glPopMatrix ();
}
glMatrixMode ( GL_MODELVIEW );
glDisable ( GL_TEXTURE_GEN_S );
glDisable ( GL_TEXTURE_GEN_T );
//--------------------------------------------------------------------------
//-- Initializations for Phase 3 - environment map
-"in waterblock.cc after mEnvMapIntensity = 1.0f;":
mLightMapTexture = TextureHandle();
mLightMapIntensity = 1.0f;
mLightMapName = NULL;
-"search for a function call to mFluid.SetInfo and add the lightmap param":
mFluid.SetInfo( P.x, P.y,
mObjScale.x, mObjScale.y,
mSurfaceZ,
mWaveMagnitude,
mSurfaceOpacity,
mEnvMapIntensity,
mLightMapIntensity,
mRemoveWetEdges );
-"add after mEnvMapTexture = TextureHandle(mEnvMapName,MeshTexture );":
mLightMapTexture = TextureHandle(mLightMapName,MeshTexture);
-"after // Register these textures with the Fluid.
mFluid.SetTextures( mSurfaceTexture,mEnvMapTexture );":
mFluid.SetLightMapTexture(mLightMapTexture);
-"after addField( "envMapIntensity", TypeF32, Offset( mEnvMapIntensity, WaterBlock ) );":
addField( "lightMapTexture", TypeFilename, Offset( mLightMapName, WaterBlock ) );
addField( "lightMapIntensity", TypeF32, Offset( mLightMapIntensity, WaterBlock ) );
-"after stream->writeString( mEnvMapName );":
stream->writeString( mLightMapName );
-"after stream->write( mEnvMapIntensity );":
stream->write( mLightMapIntensity );
-"after mEnvMapName = stream->readSTString();":
mLightMapName = stream->readSTString();
-"after stream->read( &mEnvMapIntensity );":
stream->read( &mLightMapIntensity );
-"in fluid.h change prototype of function SetInfo":
void SetInfo ( f32& X0,
f32& Y0,
f32& SizeX,
f32& SizeY,
f32 SurfaceZ,
f32 WaveAmplitude,
f32& Opacity,
f32& EnvMapIntensity,
f32& LightMapIntensity,
s32 RemoveWetEdges );
-"after f32 m_EnvMapIntensity;":
f32 m_LightMapIntensity;
TextureHandle m_LightMapTexture;
-and.... that's all :) hope i didn't forget something...
oh....delete the .ml files of your missions before trying..
If it crash it's because i forgot a modification....if you have to correct it, just search in all files "envmap" and copy it to "lightmap", every variables, every init..., etc.
Bye.
01/05/2002 (1:44 pm)
You got the idea.here is my FINAL code (with implementation of properties for lightmap feature)
In waterblock.h, add :
-"just after TextureHandle mEnvMapTexture;":
TextureHandle mLightMapTexture;
-"just after F32 mEnvMapIntensity;":
StringTableEntry mLightMapName;
F32 mLightMapIntensity;
In fluidsupport.cc
-"just after m_EnvMapIntensity = 1.0f;":
m_LightMapIntensity = 1.0f;
-"in function SetInfo" change parameters list to:
void fluid::SetInfo( f32& X0,
f32& Y0,
f32& SizeX,
f32& SizeY,
f32 SurfaceZ,
f32 WaveAmplitude,
f32& Opacity,
f32& EnvMapIntensity,
f32& LightMapIntensity,
s32 RemoveWetEdges )
-"and add the following in the begining of the function":
if( LightMapIntensity > 1.0f ) LightMapIntensity = 1.0f;
if( LightMapIntensity < 0.0f ) LightMapIntensity = 0.0f;
m_LightMapIntensity = LightMapIntensity;
-"in fluidrender.cc" search for "light map" and change the code to:
//--------------------------------------------------------------------------
//-- Cleanup from Phase 1 - base textures
glDisableClientState( GL_COLOR_ARRAY );
glPopMatrix ();
//--------------------------------------------------------------------------
//-- Initializations for Phase 2 - light map
if ((m_ShowLightMap) && (m_LightMapTexture.getGLName() != 0))
{
glColor4f ( 1.0f, 1.0f, 1.0f, m_LightMapIntensity );
glBindTexture ( GL_TEXTURE_2D, m_LightMapTexture.getGLName() );
glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glBlendFunc ( GL_DST_COLOR, GL_ZERO );
glMatrixMode ( GL_TEXTURE );
glPushMatrix ();
glLoadIdentity ();
glTexGenfv ( GL_S, GL_OBJECT_PLANE, SLMap );
glTexGenfv ( GL_T, GL_OBJECT_PLANE, TLMap );
//--------------------------------------------------------------------------
//-- Render Phase 2 - light map
glDrawElements ( GL_TRIANGLES, m_IUsed, GL_UNSIGNED_SHORT, m_pIndex );
//--------------------------------------------------------------------------
//-- Cleanup from Phase 2 - light map
glPopMatrix ();
}
glMatrixMode ( GL_MODELVIEW );
glDisable ( GL_TEXTURE_GEN_S );
glDisable ( GL_TEXTURE_GEN_T );
//--------------------------------------------------------------------------
//-- Initializations for Phase 3 - environment map
-"in waterblock.cc after mEnvMapIntensity = 1.0f;":
mLightMapTexture = TextureHandle();
mLightMapIntensity = 1.0f;
mLightMapName = NULL;
-"search for a function call to mFluid.SetInfo and add the lightmap param":
mFluid.SetInfo( P.x, P.y,
mObjScale.x, mObjScale.y,
mSurfaceZ,
mWaveMagnitude,
mSurfaceOpacity,
mEnvMapIntensity,
mLightMapIntensity,
mRemoveWetEdges );
-"add after mEnvMapTexture = TextureHandle(mEnvMapName,MeshTexture );":
mLightMapTexture = TextureHandle(mLightMapName,MeshTexture);
-"after // Register these textures with the Fluid.
mFluid.SetTextures( mSurfaceTexture,mEnvMapTexture );":
mFluid.SetLightMapTexture(mLightMapTexture);
-"after addField( "envMapIntensity", TypeF32, Offset( mEnvMapIntensity, WaterBlock ) );":
addField( "lightMapTexture", TypeFilename, Offset( mLightMapName, WaterBlock ) );
addField( "lightMapIntensity", TypeF32, Offset( mLightMapIntensity, WaterBlock ) );
-"after stream->writeString( mEnvMapName );":
stream->writeString( mLightMapName );
-"after stream->write( mEnvMapIntensity );":
stream->write( mLightMapIntensity );
-"after mEnvMapName = stream->readSTString();":
mLightMapName = stream->readSTString();
-"after stream->read( &mEnvMapIntensity );":
stream->read( &mLightMapIntensity );
-"in fluid.h change prototype of function SetInfo":
void SetInfo ( f32& X0,
f32& Y0,
f32& SizeX,
f32& SizeY,
f32 SurfaceZ,
f32 WaveAmplitude,
f32& Opacity,
f32& EnvMapIntensity,
f32& LightMapIntensity,
s32 RemoveWetEdges );
-"after f32 m_EnvMapIntensity;":
f32 m_LightMapIntensity;
TextureHandle m_LightMapTexture;
-and.... that's all :) hope i didn't forget something...
oh....delete the .ml files of your missions before trying..
If it crash it's because i forgot a modification....if you have to correct it, just search in all files "envmap" and copy it to "lightmap", every variables, every init..., etc.
Bye.
Torque Owner Karsten "Clocks" Viese
Maybe psot a pic.
// Clocks out