Changeset 8482 in orxonox.OLD for branches/water/src/world_entities/environments/mapped_water.cc
- Timestamp:
- Jun 15, 2006, 5:14:35 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/water/src/world_entities/environments/mapped_water.cc
r8477 r8482 23 23 CREATE_FACTORY(MappedWater, CL_MAPPED_WATER); 24 24 25 25 /** 26 * @brief constructor 27 * @param root xml data 28 */ 26 29 MappedWater::MappedWater(const TiXmlElement* root) 27 30 { … … 32 35 this->loadParams(root); 33 36 34 //PRINTF(0)("MaxTextureUnits: %i\n", Material::getMaxTextureUnits());35 36 // TODO rename texture to reflection texture37 37 /// loads the textures 38 38 // set up refleciton texture … … 105 105 /// initialization of the texture coords, speeds etc... 106 106 this->move = 0.0f; 107 this->g_WaterUV = 35.0f;108 107 this->kNormalMapScale = 0.25f; 109 this->g_WaterFlow = 0.0015f; 108 110 109 111 110 /// initialization of the shaders … … 132 131 133 132 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(); 137 136 fog->setFogColor(0.1f, 0.2f, 0.4f); 138 137 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 */ 142 144 MappedWater::~MappedWater() 143 145 { … … 147 149 } 148 150 151 /** 152 * @brief ends the refraction and saves the graphic buffer into a texture 153 * @param root xml data 154 */ 149 155 void MappedWater::loadParams(const TiXmlElement* root) 150 156 { … … 154 160 LoadParam(root, "watersize", this, MappedWater, setWaterSize); 155 161 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 */ 159 169 void MappedWater::draw() const 160 170 { … … 164 174 glTranslatef(this->waterPos.x,this->waterPos.y,this->waterPos.z); 165 175 166 /////????//mat.unselect();167 176 mat.select(); 168 177 … … 173 182 cam_uni->set(pos.x, pos.y, pos.z, 1.0f); 174 183 175 //glDisable(GL_BLEND);176 177 184 glBegin(GL_QUADS); 178 185 // The back left vertice for the water 179 // glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0);//g_WaterUV); // Reflection texture180 // glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 0);//refrUV - move); // Refraction texture181 186 glMultiTexCoord2f(GL_TEXTURE0, 0.0f, g_WaterUV); // Reflection texture 182 187 glMultiTexCoord2f(GL_TEXTURE1, 0.0f, refrUV - move); // Refraction texture 183 188 glMultiTexCoord2f(GL_TEXTURE2, 0.0f, normalUV + move2); // Normal map texture 184 189 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 185 //glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture186 190 glVertex3f(0.0f, this->waterPos.y, 0.0f); 187 191 188 192 // The front left vertice for the water 189 // glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 1);//0.0f); // Reflection texture190 // glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 1);//0.0f - move); // Refraction texture191 193 glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f); // Reflection texture 192 194 glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 0.0f - move); // Refraction texture 193 195 glMultiTexCoord2f(GL_TEXTURE2, 0.0f, 0.0f + move2); // Normal map texture 194 196 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 195 //glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture196 197 glVertex3f(0.0f, this->waterPos.y, this->zWidth); 197 198 198 199 // The front right vertice for the water 199 // glMultiTexCoord2f(GL_TEXTURE0, 1,1); //g_WaterUV, 0.0f); // Reflection texture200 // glMultiTexCoord2f(GL_TEXTURE1, 1,1);//refrUV, 0.0f - move); // Refraction texture201 200 glMultiTexCoord2f(GL_TEXTURE0, g_WaterUV, 0.0f); // Reflection texture 202 201 glMultiTexCoord2f(GL_TEXTURE1, refrUV, 0.0f - move); // Refraction texture 203 202 glMultiTexCoord2f(GL_TEXTURE2, normalUV, 0.0f + move2); // Normal map texture 204 203 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 205 //glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture206 204 glVertex3f(this->xWidth, this->waterPos.y, this->zWidth); 207 205 208 206 // The back right vertice for the water 209 // glMultiTexCoord2f(GL_TEXTURE0, 1,0);//g_WaterUV, g_WaterUV); // Reflection texture210 // glMultiTexCoord2f(GL_TEXTURE1, 1,0);//refrUV, refrUV - move); // Refraction texture211 207 glMultiTexCoord2f(GL_TEXTURE0, g_WaterUV, g_WaterUV); // Reflection texture 212 208 glMultiTexCoord2f(GL_TEXTURE1, refrUV, refrUV - move); // Refraction texture 213 209 glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2); // Normal map texture 214 210 glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture 215 //glMultiTexCoord2f(GL_TEXTURE4, 0, 0); // Depth texture216 211 glVertex3f(this->xWidth, this->waterPos.y, 0.0f); 217 212 glEnd(); … … 221 216 mat.unselect(); 222 217 223 if(pos.y < this->waterPos.y)218 /*if(pos.y < this->waterPos.y) 224 219 { 225 220 // draw some fog … … 229 224 { 230 225 this->fog->deactivate(); 231 } 226 }*/ 232 227 233 228 glPopMatrix(); 234 229 } 235 230 231 /** 232 * @brief tick tack, calculates the flow of the water 233 */ 236 234 void MappedWater::tick(float dt) 237 235 { … … 243 241 } 244 242 243 /** 244 * @brief prepares everything to render the reflection texutre 245 */ 245 246 void MappedWater::activateReflection() 246 247 { 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 247 258 // save viewport matrix and change the viewport size 248 259 glPushAttrib(GL_VIEWPORT_BIT); … … 257 268 glEnable(GL_CLIP_PLANE0); 258 269 Vector pos = State::getCameraNode()->getAbsCoor(); 259 //pos.debug(); 260 //PRINTF(0)("waterheight: %f\n", waterHeight); 270 261 271 if(pos.y > waterPos.y) 262 272 { … … 281 291 } 282 292 283 293 /** 294 * @brief ends the reflection and saves the graphic buffer into a texture 295 */ 284 296 void MappedWater::deactivateReflection() 285 297 { … … 287 299 glCullFace(GL_BACK); 288 300 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 294 301 glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0)); 295 302 … … 297 304 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize); 298 305 299 300 306 glPopMatrix(); 301 307 glPopAttrib(); 302 308 } 303 309 310 /** 311 * @brief prepares everything to render the refraction texutre 312 */ 304 313 void 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 { 342 315 // To create the refraction and depth textures we do the same thing 343 316 // we did for the reflection texture, except we don't need to turn … … 375 348 } 376 349 350 /** 351 * @brief ends the refraction and saves the graphic buffer into a texture 352 */ 377 353 void MappedWater::deactivateRefraction() 378 354 { … … 380 356 glCullFace(GL_BACK); 381 357 382 383 358 glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1)); 384 359 … … 388 363 glPopMatrix(); 389 364 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 }
Note: See TracChangeset
for help on using the changeset viewer.