Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 15, 2006, 5:14:35 PM (18 years ago)
Author:
stefalie
Message:

water: general cleanup

Location:
branches/water/src/world_entities/environments
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/water/src/world_entities/environments/mapped_water.cc

    r8477 r8482  
    2323CREATE_FACTORY(MappedWater, CL_MAPPED_WATER);
    2424
    25 
     25/**
     26 * @brief constructor
     27 * @param root xml data
     28 */
    2629MappedWater::MappedWater(const TiXmlElement* root)
    2730{
     
    3235    this->loadParams(root);
    3336
    34   //PRINTF(0)("MaxTextureUnits: %i\n", Material::getMaxTextureUnits());
    35 
    36   // TODO rename texture to reflection texture
    3737  /// loads the textures
    3838  // set up refleciton texture
     
    105105  /// initialization of the texture coords, speeds etc...
    106106  this->move = 0.0f;
    107   this->g_WaterUV = 35.0f;
    108107  this->kNormalMapScale = 0.25f;
    109   this->g_WaterFlow = 0.0015f;
     108
    110109
    111110  /// initialization of the shaders
     
    132131
    133132  this->shader->deactivateShader();
    134  
    135  
    136   this->fog = new FogEffect();
     133
     134  /// fog, doesnt work the way i want it to work
     135  /*this->fog = new FogEffect();
    137136  fog->setFogColor(0.1f, 0.2f, 0.4f);
    138137  fog->setFogRange(0.0f, 500.0f);
    139   fog->setFogDensity(0.03f);
    140 }
    141 
     138  fog->setFogDensity(0.03f);*/
     139}
     140
     141/**
     142 * @brief deltes shader and the uniform used by the camera
     143 */
    142144MappedWater::~MappedWater()
    143145{
     
    147149}
    148150
     151/**
     152 * @brief ends the refraction and saves the graphic buffer into a texture
     153 * @param root xml data
     154 */
    149155void MappedWater::loadParams(const TiXmlElement* root)
    150156{
     
    154160  LoadParam(root, "watersize", this, MappedWater, setWaterSize);
    155161  LoadParam(root, "lightpos", this, MappedWater, setLightPosition);
    156 }
    157 
    158 
     162  LoadParam(root, "wateruv", this, MappedWater, setWaterUV);
     163  LoadParam(root, "waterflow", this, MappedWater, setWaterFlow);
     164}
     165
     166/**
     167 * @brief activates the water shader and draws a quad with four textures on it
     168 */
    159169void MappedWater::draw() const
    160170{
     
    164174  glTranslatef(this->waterPos.x,this->waterPos.y,this->waterPos.z);
    165175
    166   /////????//mat.unselect();
    167176  mat.select();
    168177
     
    173182  cam_uni->set(pos.x, pos.y, pos.z, 1.0f);
    174183
    175   //glDisable(GL_BLEND);
    176 
    177184  glBegin(GL_QUADS);
    178185  // The back left vertice for the water
    179  // glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0);//g_WaterUV);            // Reflection texture
    180  // glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 0);//refrUV - move);        // Refraction texture
    181186  glMultiTexCoord2f(GL_TEXTURE0, 0.0f, g_WaterUV);            // Reflection texture
    182187  glMultiTexCoord2f(GL_TEXTURE1, 0.0f, refrUV - move);        // Refraction texture
    183188  glMultiTexCoord2f(GL_TEXTURE2, 0.0f, normalUV + move2);     // Normal map texture
    184189  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                       // DUDV map texture
    185   //glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                       // Depth texture
    186190  glVertex3f(0.0f, this->waterPos.y, 0.0f);
    187191
    188192  // The front left vertice for the water
    189  // glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 1);//0.0f);                  // Reflection texture
    190  // glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 1);//0.0f - move);           // Refraction texture
    191193  glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f);                  // Reflection texture
    192194  glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 0.0f - move);           // Refraction texture
    193195  glMultiTexCoord2f(GL_TEXTURE2, 0.0f, 0.0f + move2);          // Normal map texture
    194196  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
    195   //glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
    196197  glVertex3f(0.0f, this->waterPos.y, this->zWidth);
    197198
    198199  // The front right vertice for the water
    199 //  glMultiTexCoord2f(GL_TEXTURE0, 1,1); //g_WaterUV, 0.0f);             // Reflection texture
    200  // glMultiTexCoord2f(GL_TEXTURE1, 1,1);//refrUV, 0.0f - move);         // Refraction texture
    201200  glMultiTexCoord2f(GL_TEXTURE0, g_WaterUV, 0.0f);             // Reflection texture
    202201  glMultiTexCoord2f(GL_TEXTURE1, refrUV, 0.0f - move);         // Refraction texture
    203202  glMultiTexCoord2f(GL_TEXTURE2, normalUV, 0.0f + move2);      // Normal map texture
    204203  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
    205   //glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
    206204  glVertex3f(this->xWidth, this->waterPos.y, this->zWidth);
    207205
    208206  // The back right vertice for the water
    209  // glMultiTexCoord2f(GL_TEXTURE0, 1,0);//g_WaterUV, g_WaterUV);        // Reflection texture
    210  // glMultiTexCoord2f(GL_TEXTURE1, 1,0);//refrUV, refrUV - move);       // Refraction texture
    211207  glMultiTexCoord2f(GL_TEXTURE0, g_WaterUV, g_WaterUV);        // Reflection texture
    212208  glMultiTexCoord2f(GL_TEXTURE1, refrUV, refrUV - move);       // Refraction texture
    213209  glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2);  // Normal map texture
    214210  glMultiTexCoord2f(GL_TEXTURE3, 0, 0);                        // DUDV map texture
    215   //glMultiTexCoord2f(GL_TEXTURE4, 0, 0);                        // Depth texture
    216211  glVertex3f(this->xWidth, this->waterPos.y, 0.0f);
    217212  glEnd();
     
    221216  mat.unselect();
    222217
    223   if(pos.y < this->waterPos.y)
     218  /*if(pos.y < this->waterPos.y)
    224219  {
    225220    // draw some fog
     
    229224  {
    230225    this->fog->deactivate();
    231   }
     226  }*/
    232227
    233228  glPopMatrix();
    234229}
    235230
     231/**
     232 * @brief tick tack, calculates the flow of the water
     233 */
    236234void MappedWater::tick(float dt)
    237235{
     
    243241}
    244242
     243/**
     244 * @brief prepares everything to render the reflection texutre
     245 */
    245246void MappedWater::activateReflection()
    246247{
     248  // To create the reflection texture we just need to set the view port
     249  // to our texture map size, then render the current scene our camera
     250  // is looking at to the already allocated texture unit.  Since this
     251  // is a reflection of the top of the water surface we use clipping
     252  // planes to only render the top of the world as a reflection.  If
     253  // we are below the water we don't flip the reflection but just use
     254  // the current view of the top as we are seeing through the water.
     255  // When you look through water at the surface it isn't really reflected,
     256  // only when looking down from above the water on the surface.
     257
    247258  // save viewport matrix and change the viewport size
    248259  glPushAttrib(GL_VIEWPORT_BIT);
     
    257268  glEnable(GL_CLIP_PLANE0);
    258269  Vector pos = State::getCameraNode()->getAbsCoor();
    259   //pos.debug();
    260   //PRINTF(0)("waterheight: %f\n", waterHeight);
     270
    261271  if(pos.y > waterPos.y)
    262272  {
     
    281291}
    282292
    283 
     293/**
     294 * @brief ends the reflection and saves the graphic buffer into a texture
     295 */
    284296void MappedWater::deactivateReflection()
    285297{
     
    287299  glCullFace(GL_BACK);
    288300
    289   //mat.select();
    290   /////glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
    291   ///mat.renderToTexture(0, GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
    292   ///
    293 
    294301  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
    295302
     
    297304  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
    298305
    299 
    300306  glPopMatrix();
    301307  glPopAttrib();
    302308}
    303309
     310/**
     311 * @brief prepares everything to render the refraction texutre
     312 */
    304313void MappedWater::activateRefraction()
    305 {/*
    306   // save viewport matrix and change the viewport size
    307   glPushAttrib(GL_VIEWPORT_BIT);
    308   glViewport(0,0, textureSize, textureSize);
    309 
    310   glMatrixMode(GL_MODELVIEW);
    311   glPushMatrix();
    312 
    313   // If our camera is above the water we will render the scene flipped upside down.
    314   // In order to line up the reflection nicely with the world we have to translate
    315   // the world to the position of our reflected surface, multiplied by two.
    316   glEnable(GL_CLIP_PLANE0);
    317   Vector pos = State::getCameraNode()->getAbsCoor();
    318   //pos.debug();
    319   //PRINTF(0)("waterheight: %f\n", waterHeight);
    320   if(pos.y > waterHeight)
    321   {
    322     // Translate the world, then flip it upside down
    323     glTranslatef(0.0f, waterHeight*2.0f, 0.0f);
    324     glScalef(1.0, -1.0, 1.0);
    325 
    326     // Since the world is updside down we need to change the culling to FRONT
    327     glCullFace(GL_FRONT);
    328 
    329     // Set our plane equation and turn clipping on
    330     double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
    331     glClipPlane(GL_CLIP_PLANE0, plane);
    332   }
    333   else
    334   {
    335     // If the camera is below the water we don't want to flip the world,
    336     // but just render it clipped so only the top is drawn.
    337     double plane[4] = {0.0, 1.0, 0.0, waterHeight};
    338     glClipPlane(GL_CLIP_PLANE0, plane);
    339   }
    340 */
    341 
     314{
    342315  // To create the refraction and depth textures we do the same thing
    343316  // we did for the reflection texture, except we don't need to turn
     
    375348}
    376349
     350/**
     351 * @brief ends the refraction and saves the graphic buffer into a texture
     352 */
    377353void MappedWater::deactivateRefraction()
    378354{
     
    380356  glCullFace(GL_BACK);
    381357
    382 
    383358  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1));
    384359
     
    388363  glPopMatrix();
    389364  glPopAttrib();
    390 
    391   // Bind the current scene to our refraction texture
    392 //  glBindTexture(GL_TEXTURE_2D, g_Texture[REFRACTION_ID]);
    393 //  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
    394 
    395   // Bind the current scene to our depth texture
    396 //  glBindTexture(GL_TEXTURE_2D, g_Texture[DEPTH_ID]);
    397 //  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, textureSize, textureSize, 0);
    398 
    399 }
     365}
  • branches/water/src/world_entities/environments/mapped_water.h

    r8477 r8482  
    33 *
    44*/
     5/* example input in .oxw file
     6<MappedWater>
     7  <waterpos>-500,0,-500</waterpos>
     8  <watersize>1000,1000</watersize>
     9  <wateruv>10</wateruv>
     10  <waterflow>0.003</waterflow>
     11  <lightpos>100,150,100</lightpos>
     12</MappedWater> */
     13
     14
    515
    616#ifndef _MAPPED_WATER_H
     
    3141    void tick(float dt);
    3242
    33   private:
     43    // functions to set parameters for the water, usually they're called through loadparam
    3444    void setLightPosition(float x, float y, float z) { this->lightPos = Vector(x,y,z); };
    3545    void setWaterPos(float x, float y, float z) { this->waterPos = Vector(x,y,z); };
    3646    void setWaterSize(float x, float z) { this->xWidth = x; this->zWidth = z; };
     47    void setWaterUV(float uv) { this->g_WaterUV = uv; };
     48    void setWaterFlow(float flow) { this->g_WaterFlow = flow; };
    3749
    3850  private:
     
    5466    Shader::Uniform*    cam_uni;                    //!< uniform that is used for the camera position
    5567
    56     FogEffect*          fog;
     68    //FogEffect*          fog;
    5769
    5870};
Note: See TracChangeset for help on using the changeset viewer.