[7796] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Stefan Lienard |
---|
| 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #include "mapped_water.h" |
---|
| 17 | #include "util/loading/load_param.h" |
---|
| 18 | #include "util/loading/factory.h" |
---|
| 19 | #include "util/loading/resource_manager.h" |
---|
[8037] | 20 | #include "state.h" |
---|
[8884] | 21 | #include "t_animation.h" |
---|
[8792] | 22 | #include "math.h" |
---|
[8906] | 23 | #include "glgui.h" |
---|
| 24 | #include "shell_command.h" |
---|
| 25 | |
---|
[7796] | 26 | CREATE_FACTORY(MappedWater, CL_MAPPED_WATER); |
---|
| 27 | |
---|
[8906] | 28 | SHELL_COMMAND(gui, MappedWater, openGui); |
---|
| 29 | |
---|
[8719] | 30 | /** |
---|
| 31 | * @brief constructor |
---|
| 32 | * @param root xml data |
---|
| 33 | */ |
---|
[7796] | 34 | MappedWater::MappedWater(const TiXmlElement* root) |
---|
| 35 | { |
---|
| 36 | this->setClassID(CL_MAPPED_WATER, "MappedWater"); |
---|
| 37 | this->toList(OM_ENVIRON); |
---|
| 38 | |
---|
[8719] | 39 | /// sets start values and parameters |
---|
| 40 | this->initParams(); |
---|
| 41 | // now the standard values were loaded, if the values are specified in the .oxw file |
---|
| 42 | // loadParams will overwrite the standard values with the specified values |
---|
[7796] | 43 | if (root != NULL) |
---|
| 44 | this->loadParams(root); |
---|
| 45 | |
---|
[8719] | 46 | /// initialization of the textures |
---|
| 47 | this->initTextures(); |
---|
[8037] | 48 | |
---|
[8719] | 49 | /// initialization of the shaders |
---|
| 50 | this->initShaders(); |
---|
[8848] | 51 | |
---|
| 52 | /// calculation of the 4 verts of the water quad |
---|
[8859] | 53 | this->calcVerts(); |
---|
[8848] | 54 | |
---|
[8918] | 55 | // init gui |
---|
[8906] | 56 | this->box = NULL; |
---|
[8719] | 57 | } |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * @brief deltes shader and the uniform used by the camera |
---|
| 61 | */ |
---|
| 62 | MappedWater::~MappedWater() |
---|
| 63 | { |
---|
| 64 | delete shader; |
---|
| 65 | delete cam_uni; |
---|
[8792] | 66 | delete color_uni; |
---|
| 67 | delete light_uni; |
---|
[8866] | 68 | delete shineSize_uni; |
---|
| 69 | delete shineStrength_uni; |
---|
[8867] | 70 | delete reflStrength_uni; |
---|
[8866] | 71 | delete refr_uni; |
---|
[8719] | 72 | } |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | * @brief initialization of loadable parameters, sets start standard values |
---|
| 76 | */ |
---|
| 77 | void MappedWater::initParams() |
---|
| 78 | { |
---|
| 79 | // those standardvalues will be overwritten if they're also set in the oxw file |
---|
| 80 | this->setWaterPos(0, 0, 0); |
---|
| 81 | this->setWaterSize(100, 100); |
---|
| 82 | this->setWaterUV(9); |
---|
[8867] | 83 | this->setWaterFlow(0.08f); |
---|
[8719] | 84 | this->setLightPos(0, 10, 0); |
---|
| 85 | this->setWaterAngle(0); |
---|
| 86 | this->setNormalMapScale(0.25f); |
---|
[8792] | 87 | this->setWaterColor(0.1f, 0.2f, 0.4f); |
---|
[8866] | 88 | this->setShineSize(128); |
---|
[8867] | 89 | this->setShineStrength(0.7f); |
---|
| 90 | this->setReflStrength(1.0f); |
---|
[8866] | 91 | this->setRefraction(0.009f); |
---|
[8719] | 92 | |
---|
| 93 | // initialization of the texture coords, speeds etc... |
---|
| 94 | // normalUV wont change anymore |
---|
| 95 | this->normalUV = this->waterUV * this->kNormalMapScale; |
---|
| 96 | // move and move2 are used for the reflection and refraction, the values are changed in tick() |
---|
| 97 | this->move = 0; |
---|
| 98 | this->move2 = this->move * this->kNormalMapScale; |
---|
[8918] | 99 | |
---|
| 100 | // initalize fading bools |
---|
| 101 | this->bFadeWaterHeight = false; |
---|
| 102 | this->bFadeWaterUV = false; |
---|
| 103 | this->bFadeWaterFlow = false; |
---|
| 104 | this->bFadeShineSize = false; |
---|
| 105 | this->bFadeShineStrength = false; |
---|
| 106 | this->bFadeReflStrength = false; |
---|
| 107 | this->bFadeRefraction = false; |
---|
[8919] | 108 | this->bFadeWaterColor = false; |
---|
[8918] | 109 | |
---|
| 110 | this->tempcounter = 0; |
---|
[8719] | 111 | } |
---|
| 112 | |
---|
| 113 | /** |
---|
| 114 | * @brief initialization of the textures |
---|
| 115 | */ |
---|
| 116 | void MappedWater::initTextures() |
---|
| 117 | { |
---|
| 118 | // sets parameters for the textures |
---|
| 119 | this->textureSize = 512; |
---|
| 120 | unsigned int channels = 32; |
---|
| 121 | GLenum type = GL_RGBA; |
---|
| 122 | |
---|
[7796] | 123 | // set up refleciton texture |
---|
[8719] | 124 | Texture reflTex(GL_TEXTURE_2D, this->textureSize, this->textureSize, channels, type); |
---|
| 125 | mat.setDiffuseMap(reflTex, 0); |
---|
| 126 | // set up refraction texture |
---|
| 127 | Texture refrTex(GL_TEXTURE_2D, this->textureSize, this->textureSize, channels, type); |
---|
| 128 | mat.setDiffuseMap(refrTex, 1); |
---|
[7796] | 129 | // load normal map |
---|
[8821] | 130 | mat.setDiffuseMap("pictures/water_normalmap.bmp", GL_TEXTURE_2D, 2); |
---|
[7796] | 131 | // load dudv map |
---|
[8821] | 132 | mat.setDiffuseMap("pictures/water_dudvmap.bmp", GL_TEXTURE_2D, 3); |
---|
[7796] | 133 | |
---|
[8719] | 134 | // sets texture parameters for reflection texture |
---|
[8619] | 135 | glBindTexture(GL_TEXTURE_2D, this->mat.diffuseTextureID(0)); |
---|
[8312] | 136 | glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); |
---|
| 137 | glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); |
---|
| 138 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
---|
| 139 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
---|
[8719] | 140 | // sets texture parameters for refraction texture |
---|
[8619] | 141 | glBindTexture(GL_TEXTURE_2D, this->mat.diffuseTextureID(1)); |
---|
[7796] | 142 | glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); |
---|
| 143 | glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); |
---|
| 144 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
---|
| 145 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
---|
[8719] | 146 | } |
---|
[7796] | 147 | |
---|
[8719] | 148 | /** |
---|
| 149 | * @brief initialization of the shaders |
---|
| 150 | */ |
---|
| 151 | void MappedWater::initShaders() |
---|
| 152 | { |
---|
[8037] | 153 | // load shader files |
---|
[8312] | 154 | shader = new Shader( ResourceManager::getInstance()->getDataDir() + "/shaders/mapped_water.vert", ResourceManager::getInstance()->getDataDir() +"/shaders/mapped_water.frag"); |
---|
[8037] | 155 | |
---|
| 156 | this->shader->activateShader(); |
---|
| 157 | // Set the variable "reflection" to correspond to the first texture unit |
---|
| 158 | Shader::Uniform(shader, "reflection").set(0); |
---|
| 159 | // Set the variable "refraction" to correspond to the second texture unit |
---|
| 160 | Shader::Uniform(shader, "refraction").set(1); |
---|
| 161 | // Set the variable "normalMap" to correspond to the third texture unit |
---|
| 162 | Shader::Uniform(shader, "normalMap").set(2); |
---|
| 163 | // Set the variable "dudvMap" to correspond to the fourth texture unit |
---|
| 164 | Shader::Uniform(shader, "dudvMap").set(3); |
---|
| 165 | // Set the variable "depthMap" to correspond to the fifth texture unit |
---|
[8877] | 166 | Shader::Uniform(shader, "depthMap").set(1); |
---|
[8037] | 167 | // Give the variable "waterColor" a blue color |
---|
[8792] | 168 | color_uni = new Shader::Uniform(shader, "waterColor"); |
---|
| 169 | color_uni->set(waterColor.x, waterColor.y, waterColor.z, 1.0f); |
---|
[8037] | 170 | // Give the variable "lightPos" our hard coded light position |
---|
[8792] | 171 | light_uni = new Shader::Uniform(shader, "lightPos"); |
---|
| 172 | light_uni->set(lightPos.x, lightPos.y, lightPos.z, 1.0f); |
---|
| 173 | // Set the variable "shine" |
---|
[8866] | 174 | shineSize_uni = new Shader::Uniform(shader, "kShine"); |
---|
| 175 | shineSize_uni->set(this->shineSize); |
---|
| 176 | // Set the variable "shineStrength" |
---|
| 177 | shineStrength_uni = new Shader::Uniform(shader, "shineStrength"); |
---|
| 178 | shineStrength_uni->set(this->shineStrength); |
---|
[8867] | 179 | // Set the variable "reflStrength" |
---|
| 180 | reflStrength_uni = new Shader::Uniform(shader, "reflStrength"); |
---|
| 181 | reflStrength_uni->set(this->reflStrength); |
---|
[8866] | 182 | // Set the variable "refraction" |
---|
| 183 | refr_uni = new Shader::Uniform(shader, "kRefraction"); |
---|
| 184 | refr_uni->set(this->refraction); |
---|
[8037] | 185 | // uniform for the camera position |
---|
| 186 | cam_uni = new Shader::Uniform(shader, "cameraPos"); |
---|
| 187 | |
---|
[8312] | 188 | this->shader->deactivateShader(); |
---|
[7796] | 189 | } |
---|
| 190 | |
---|
[8719] | 191 | /** |
---|
[8916] | 192 | * @brief calculates the 4 verts of the water quad |
---|
[8859] | 193 | */ |
---|
| 194 | void MappedWater::calcVerts() |
---|
| 195 | { |
---|
| 196 | float deg2radtemp = this->waterAngle / 180 * PI; |
---|
| 197 | |
---|
| 198 | this->waterVerts[2] = this->waterVerts[0] + cos(deg2radtemp) * this->xWidth; |
---|
| 199 | this->waterVerts[3] = this->waterVerts[1] + sin(deg2radtemp) * this->xWidth; |
---|
| 200 | this->waterVerts[4] = this->waterVerts[0] + cos(deg2radtemp) * this->xWidth - sin(deg2radtemp) * this->zWidth; |
---|
| 201 | this->waterVerts[5] = this->waterVerts[1] + sin(deg2radtemp) * this->xWidth + cos(deg2radtemp) * this->zWidth; |
---|
| 202 | this->waterVerts[6] = this->waterVerts[0] - sin(deg2radtemp) * this->zWidth; |
---|
| 203 | this->waterVerts[7] = this->waterVerts[1] + cos(deg2radtemp) * this->zWidth; |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | /** |
---|
[8792] | 207 | * @brief resets the waterColor in the Shader |
---|
| 208 | * @param r new value for red |
---|
| 209 | * @param g new value for green |
---|
| 210 | * @param b new value for blue |
---|
| 211 | */ |
---|
| 212 | void MappedWater::resetWaterColor(float r, float g, float b) |
---|
| 213 | { |
---|
| 214 | this->shader->activateShader(); |
---|
| 215 | this->waterColor = Vector(r, g, b); |
---|
| 216 | |
---|
| 217 | // Give the variable "waterColor" a color |
---|
| 218 | color_uni->set(waterColor.x, waterColor.y, waterColor.z, 1.0f); |
---|
| 219 | |
---|
| 220 | this->shader->deactivateShader(); |
---|
[8866] | 221 | } |
---|
[8792] | 222 | |
---|
| 223 | /** |
---|
| 224 | * @brief resets the shininess in the Shader |
---|
| 225 | * @param shine new value for the shininess |
---|
| 226 | */ |
---|
[8866] | 227 | void MappedWater::resetShineSize(float shine) |
---|
[8792] | 228 | { |
---|
| 229 | this->shader->activateShader(); |
---|
[8866] | 230 | this->shineSize = shine; |
---|
[8792] | 231 | |
---|
| 232 | // Set the variable "shine" |
---|
[8866] | 233 | shineSize_uni->set(this->shineSize); |
---|
[8792] | 234 | |
---|
| 235 | this->shader->deactivateShader(); |
---|
[8866] | 236 | } |
---|
[8792] | 237 | |
---|
| 238 | /** |
---|
[8866] | 239 | * @brief resets the strength of the specular reflection in the Shader |
---|
| 240 | * @param strength new value for the strength of the specular reflection |
---|
| 241 | */ |
---|
| 242 | void MappedWater::resetShineStrength(float strength) |
---|
| 243 | { |
---|
| 244 | this->shader->activateShader(); |
---|
| 245 | this->shineStrength = strength; |
---|
| 246 | |
---|
| 247 | // Set the variable "shine" |
---|
| 248 | shineStrength_uni->set(this->shineStrength); |
---|
| 249 | |
---|
| 250 | this->shader->deactivateShader(); |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | /** |
---|
[8867] | 254 | * @brief resets the strength of the reflection in the Shader |
---|
| 255 | * @param strength new value for the strength of the reflection |
---|
| 256 | */ |
---|
| 257 | void MappedWater::resetReflStrength(float strength) |
---|
| 258 | { |
---|
| 259 | this->shader->activateShader(); |
---|
| 260 | this->reflStrength = strength; |
---|
| 261 | |
---|
| 262 | // Set the variable "shine" |
---|
| 263 | reflStrength_uni->set(this->reflStrength); |
---|
| 264 | |
---|
| 265 | this->shader->deactivateShader(); |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | /** |
---|
[8866] | 269 | * @brief resets the refraction in the Shader |
---|
| 270 | * @param refraction new value for the refraction |
---|
| 271 | */ |
---|
| 272 | void MappedWater::resetRefraction(float refraction) |
---|
| 273 | { |
---|
| 274 | this->shader->activateShader(); |
---|
| 275 | this->refraction = refraction; |
---|
| 276 | |
---|
| 277 | // Set the variable "shine" |
---|
| 278 | refr_uni->set(this->refraction); |
---|
| 279 | |
---|
| 280 | this->shader->deactivateShader(); |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | /** |
---|
[8792] | 284 | * @brief resets the lightPos in the Shader |
---|
| 285 | * @param x new x value |
---|
| 286 | * @param y new y value |
---|
| 287 | * @param z new z value |
---|
| 288 | */ |
---|
| 289 | void MappedWater::resetLightPos(float x, float y, float z) |
---|
| 290 | { |
---|
| 291 | this->shader->activateShader(); |
---|
| 292 | this->lightPos = Vector(x, y, z); |
---|
| 293 | |
---|
| 294 | // Give the variable "lightPos" our hard coded light position |
---|
| 295 | light_uni->set(lightPos.x, lightPos.y, lightPos.z, 1.0f); |
---|
| 296 | |
---|
| 297 | this->shader->deactivateShader(); |
---|
[8866] | 298 | } |
---|
[8792] | 299 | |
---|
| 300 | /** |
---|
[8719] | 301 | * @brief ends the refraction and saves the graphic buffer into a texture |
---|
| 302 | * @param root xml data |
---|
| 303 | */ |
---|
[7796] | 304 | void MappedWater::loadParams(const TiXmlElement* root) |
---|
| 305 | { |
---|
| 306 | WorldEntity::loadParams(root); |
---|
| 307 | |
---|
[8719] | 308 | LoadParam(root, "waterpos", this, MappedWater, setWaterPos); |
---|
| 309 | LoadParam(root, "watersize", this, MappedWater, setWaterSize); |
---|
| 310 | LoadParam(root, "lightpos", this, MappedWater, setLightPos); |
---|
| 311 | LoadParam(root, "wateruv", this, MappedWater, setWaterUV); |
---|
| 312 | LoadParam(root, "waterflow", this, MappedWater, setWaterFlow); |
---|
| 313 | LoadParam(root, "normalmapscale", this, MappedWater, setNormalMapScale); |
---|
| 314 | LoadParam(root, "waterangle", this, MappedWater, setWaterAngle); |
---|
[8792] | 315 | LoadParam(root, "watercolor", this, MappedWater, setWaterColor); |
---|
[8866] | 316 | LoadParam(root, "shinesize", this, MappedWater, setShineSize); |
---|
| 317 | LoadParam(root, "shinestrength", this, MappedWater, setShineStrength); |
---|
[8867] | 318 | LoadParam(root, "reflstrength", this, MappedWater, setReflStrength); |
---|
[8866] | 319 | LoadParam(root, "refraction", this, MappedWater, setRefraction); |
---|
[7796] | 320 | } |
---|
| 321 | |
---|
[8916] | 322 | /** |
---|
| 323 | * @brief starts the slider gui that lets you edit all water parameters |
---|
| 324 | */ |
---|
[8906] | 325 | void MappedWater::openGui() |
---|
| 326 | { |
---|
| 327 | if (this->box == NULL) |
---|
| 328 | { |
---|
| 329 | this->box = new OrxGui::GLGuiBox(OrxGui::Vertical); |
---|
| 330 | { |
---|
[8916] | 331 | OrxGui::GLGuiBox* waterColorBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
[8906] | 332 | { |
---|
[8916] | 333 | OrxGui::GLGuiInputLine* waterColorText = new OrxGui::GLGuiInputLine(); |
---|
[8918] | 334 | waterColorText->setText("WaterColor"); |
---|
[8916] | 335 | waterColorBox->pack(waterColorText); |
---|
[8906] | 336 | |
---|
| 337 | OrxGui::GLGuiSlider* waterColorR = new OrxGui::GLGuiSlider(); |
---|
[8916] | 338 | waterColorR->setRange(0, 1.0f); |
---|
[8906] | 339 | waterColorR->setValue(this->waterColor.x); |
---|
[8916] | 340 | waterColorR->setStep(0.1f); |
---|
[8906] | 341 | waterColorR->connect(SIGNAL(waterColorR, valueChanged), this, SLOT(MappedWater, resetWaterColorR)); |
---|
[8916] | 342 | waterColorBox->pack(waterColorR); |
---|
[8906] | 343 | |
---|
| 344 | OrxGui::GLGuiSlider* waterColorG = new OrxGui::GLGuiSlider(); |
---|
[8916] | 345 | waterColorG->setRange(0, 1.0f); |
---|
[8918] | 346 | waterColorG->setStep(0.1f); |
---|
[8906] | 347 | waterColorG->setValue(this->waterColor.y); |
---|
| 348 | waterColorG->connect(SIGNAL(waterColorG, valueChanged), this, SLOT(MappedWater, resetWaterColorG)); |
---|
[8916] | 349 | waterColorBox->pack(waterColorG); |
---|
[8906] | 350 | |
---|
| 351 | OrxGui::GLGuiSlider* waterColorB = new OrxGui::GLGuiSlider(); |
---|
[8916] | 352 | waterColorB->setRange(0, 1.0f); |
---|
[8918] | 353 | waterColorB->setStep(0.1f); |
---|
[8906] | 354 | waterColorB->setValue(this->waterColor.z); |
---|
| 355 | waterColorB->connect(SIGNAL(waterColorB, valueChanged), this, SLOT(MappedWater, resetWaterColorB)); |
---|
[8916] | 356 | waterColorBox->pack(waterColorB); |
---|
[8906] | 357 | } |
---|
[8916] | 358 | this->box->pack(waterColorBox); |
---|
[8906] | 359 | |
---|
[8916] | 360 | OrxGui::GLGuiBox* waterUVBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
| 361 | { |
---|
| 362 | OrxGui::GLGuiInputLine* waterUVText = new OrxGui::GLGuiInputLine(); |
---|
| 363 | waterUVText->setText("WaterUV"); |
---|
| 364 | waterUVBox->pack(waterUVText); |
---|
| 365 | |
---|
| 366 | OrxGui::GLGuiSlider* waterUV = new OrxGui::GLGuiSlider(); |
---|
| 367 | waterUV->setRange(1, 20); |
---|
| 368 | waterUV->setValue(this->waterUV); |
---|
| 369 | waterUV->setStep(1); |
---|
| 370 | waterUV->connect(SIGNAL(waterUV, valueChanged), this, SLOT(MappedWater, setWaterUV)); |
---|
| 371 | waterUVBox->pack(waterUV); |
---|
| 372 | } |
---|
| 373 | this->box->pack(waterUVBox); |
---|
| 374 | |
---|
| 375 | OrxGui::GLGuiBox* waterFlowBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
| 376 | { |
---|
| 377 | OrxGui::GLGuiInputLine* waterFlowText = new OrxGui::GLGuiInputLine(); |
---|
| 378 | waterFlowText->setText("WaterFlow"); |
---|
| 379 | waterFlowBox->pack(waterFlowText); |
---|
| 380 | |
---|
| 381 | OrxGui::GLGuiSlider* waterFlow = new OrxGui::GLGuiSlider(); |
---|
| 382 | waterFlow->setRange(0.01f, 2); |
---|
| 383 | waterFlow->setValue(this->waterFlow); |
---|
| 384 | waterFlow->setStep(0.02f); |
---|
| 385 | waterFlow->connect(SIGNAL(waterFlow, valueChanged), this, SLOT(MappedWater, setWaterFlow)); |
---|
| 386 | waterFlowBox->pack(waterFlow); |
---|
| 387 | } |
---|
| 388 | this->box->pack(waterFlowBox); |
---|
| 389 | |
---|
| 390 | OrxGui::GLGuiBox* shineSizeBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
| 391 | { |
---|
| 392 | OrxGui::GLGuiInputLine* shineSizeText = new OrxGui::GLGuiInputLine(); |
---|
| 393 | shineSizeText->setText("ShineSize"); |
---|
| 394 | shineSizeBox->pack(shineSizeText); |
---|
| 395 | |
---|
| 396 | OrxGui::GLGuiSlider* shineSize = new OrxGui::GLGuiSlider(); |
---|
| 397 | shineSize->setRange(1, 128); |
---|
| 398 | shineSize->setValue(this->shineSize); |
---|
| 399 | shineSize->setStep(1); |
---|
| 400 | shineSize->connect(SIGNAL(shineSize, valueChanged), this, SLOT(MappedWater, resetShineSize)); |
---|
| 401 | shineSizeBox->pack(shineSize); |
---|
| 402 | } |
---|
| 403 | this->box->pack(shineSizeBox); |
---|
| 404 | |
---|
| 405 | OrxGui::GLGuiBox* shineStrengthBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
| 406 | { |
---|
| 407 | OrxGui::GLGuiInputLine* shineStrengthText = new OrxGui::GLGuiInputLine(); |
---|
| 408 | shineStrengthText->setText("ShineStrength"); |
---|
| 409 | shineStrengthBox->pack(shineStrengthText); |
---|
| 410 | |
---|
| 411 | OrxGui::GLGuiSlider* shineStrength = new OrxGui::GLGuiSlider(); |
---|
| 412 | shineStrength->setRange(0, 1); |
---|
| 413 | shineStrength->setValue(this->shineStrength); |
---|
| 414 | shineStrength->setStep(0.1f); |
---|
| 415 | shineStrength->connect(SIGNAL(shineStrength, valueChanged), this, SLOT(MappedWater, resetShineStrength)); |
---|
| 416 | shineStrengthBox->pack(shineStrength); |
---|
| 417 | } |
---|
| 418 | this->box->pack(shineStrengthBox); |
---|
| 419 | |
---|
| 420 | OrxGui::GLGuiBox* reflStrengthBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
| 421 | { |
---|
| 422 | OrxGui::GLGuiInputLine* reflStrengthText = new OrxGui::GLGuiInputLine(); |
---|
| 423 | reflStrengthText->setText("ReflStrength"); |
---|
| 424 | reflStrengthBox->pack(reflStrengthText); |
---|
| 425 | |
---|
| 426 | OrxGui::GLGuiSlider* reflStrength = new OrxGui::GLGuiSlider(); |
---|
| 427 | reflStrength->setRange(0, 1); |
---|
| 428 | reflStrength->setValue(this->reflStrength); |
---|
| 429 | reflStrength->setStep(0.1f); |
---|
| 430 | reflStrength->connect(SIGNAL(reflStrength, valueChanged), this, SLOT(MappedWater, resetReflStrength)); |
---|
| 431 | reflStrengthBox->pack(reflStrength); |
---|
| 432 | } |
---|
| 433 | this->box->pack(reflStrengthBox); |
---|
| 434 | |
---|
| 435 | OrxGui::GLGuiBox* refractionBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
| 436 | { |
---|
| 437 | OrxGui::GLGuiInputLine* refractionText = new OrxGui::GLGuiInputLine(); |
---|
| 438 | refractionText->setText("Refraction"); |
---|
| 439 | refractionBox->pack(refractionText); |
---|
| 440 | |
---|
| 441 | OrxGui::GLGuiSlider* refraction = new OrxGui::GLGuiSlider(); |
---|
| 442 | refraction->setRange(0.001f, 0.1f); |
---|
| 443 | refraction->setValue(this->refraction); |
---|
| 444 | refraction->setStep(0.004f); |
---|
| 445 | refraction->connect(SIGNAL(refraction, valueChanged), this, SLOT(MappedWater, resetRefraction)); |
---|
| 446 | refractionBox->pack(refraction); |
---|
| 447 | } |
---|
| 448 | this->box->pack(refractionBox); |
---|
| 449 | |
---|
[8918] | 450 | OrxGui::GLGuiBox* lightPosBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
| 451 | { |
---|
| 452 | OrxGui::GLGuiInputLine* lightPosText = new OrxGui::GLGuiInputLine(); |
---|
| 453 | lightPosText->setText("LightPos"); |
---|
| 454 | lightPosBox->pack(lightPosText); |
---|
| 455 | |
---|
| 456 | OrxGui::GLGuiSlider* lightPosX = new OrxGui::GLGuiSlider(); |
---|
| 457 | lightPosX->setRange(-600, 600); |
---|
| 458 | lightPosX->setValue(this->lightPos.x); |
---|
| 459 | lightPosX->setStep(15); |
---|
| 460 | lightPosX->connect(SIGNAL(lightPosX, valueChanged), this, SLOT(MappedWater, resetLightPosX)); |
---|
| 461 | lightPosBox->pack(lightPosX); |
---|
| 462 | |
---|
| 463 | OrxGui::GLGuiSlider* lightPosY = new OrxGui::GLGuiSlider(); |
---|
| 464 | lightPosY->setRange(-600, 600); |
---|
| 465 | lightPosY->setStep(15); |
---|
| 466 | lightPosY->setValue(this->lightPos.y); |
---|
| 467 | lightPosY->connect(SIGNAL(lightPosY, valueChanged), this, SLOT(MappedWater, resetLightPosY)); |
---|
| 468 | lightPosBox->pack(lightPosY); |
---|
| 469 | |
---|
| 470 | OrxGui::GLGuiSlider* lightPosZ = new OrxGui::GLGuiSlider(); |
---|
| 471 | lightPosZ->setRange(-600, 600); |
---|
| 472 | lightPosZ->setStep(15); |
---|
| 473 | lightPosZ->setValue(this->lightPos.z); |
---|
| 474 | lightPosZ->connect(SIGNAL(lightPosZ, valueChanged), this, SLOT(MappedWater, resetLightPosZ)); |
---|
| 475 | lightPosBox->pack(lightPosZ); |
---|
| 476 | } |
---|
| 477 | this->box->pack(lightPosBox); |
---|
| 478 | |
---|
| 479 | OrxGui::GLGuiBox* waterHeightBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
| 480 | { |
---|
| 481 | OrxGui::GLGuiInputLine* waterHeightText = new OrxGui::GLGuiInputLine(); |
---|
| 482 | waterHeightText->setText("WaterHeight"); |
---|
| 483 | waterHeightBox->pack(waterHeightText); |
---|
| 484 | |
---|
| 485 | OrxGui::GLGuiSlider* waterHeight = new OrxGui::GLGuiSlider(); |
---|
| 486 | waterHeight->setRange(-500, 500); |
---|
| 487 | waterHeight->setValue(this->waterHeight); |
---|
| 488 | waterHeight->setStep(10); |
---|
| 489 | waterHeight->connect(SIGNAL(waterHeight, valueChanged), this, SLOT(MappedWater, setWaterHeight)); |
---|
| 490 | waterHeightBox->pack(waterHeight); |
---|
| 491 | } |
---|
| 492 | this->box->pack(waterHeightBox); |
---|
[8906] | 493 | } |
---|
[8918] | 494 | |
---|
[8906] | 495 | this->box->showAll(); |
---|
| 496 | this->box->setAbsCoor2D(300, 40); |
---|
| 497 | OrxGui::GLGuiHandler::getInstance()->activate(); |
---|
| 498 | OrxGui::GLGuiHandler::getInstance()->activateCursor(); |
---|
| 499 | } |
---|
| 500 | } |
---|
| 501 | |
---|
[8916] | 502 | /** |
---|
| 503 | * @brief closes the water gui |
---|
| 504 | */ |
---|
[8906] | 505 | void MappedWater::closeGui() |
---|
| 506 | { |
---|
| 507 | delete this->box; |
---|
| 508 | this->box = NULL; |
---|
| 509 | } |
---|
| 510 | |
---|
[8719] | 511 | /** |
---|
| 512 | * @brief activates the water shader and draws a quad with four textures on it |
---|
| 513 | */ |
---|
[7796] | 514 | void MappedWater::draw() const |
---|
| 515 | { |
---|
[8312] | 516 | glMatrixMode(GL_MODELVIEW); |
---|
[7796] | 517 | glPushMatrix(); |
---|
| 518 | |
---|
[8859] | 519 | // don't use glRotate or glTranslate here... the shader won't work anymore |
---|
| 520 | |
---|
[7796] | 521 | mat.select(); |
---|
| 522 | |
---|
[8312] | 523 | this->shader->activateShader(); |
---|
[7796] | 524 | |
---|
[8037] | 525 | // reset the camera uniform to the current cam position |
---|
| 526 | Vector pos = State::getCameraNode()->getAbsCoor(); |
---|
[8312] | 527 | cam_uni->set(pos.x, pos.y, pos.z, 1.0f); |
---|
[7796] | 528 | |
---|
[8719] | 529 | glDisable(GL_BLEND); |
---|
[8312] | 530 | |
---|
[8037] | 531 | glBegin(GL_QUADS); |
---|
| 532 | // The back left vertice for the water |
---|
[8821] | 533 | glMultiTexCoord2f(GL_TEXTURE0, 0, waterUV); // Reflection texture |
---|
| 534 | glMultiTexCoord2f(GL_TEXTURE1, 0, waterUV - move); // Refraction texture |
---|
| 535 | glMultiTexCoord2f(GL_TEXTURE2, 0, normalUV + move2); // Normal map texture |
---|
| 536 | glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture |
---|
[8859] | 537 | glVertex3f(this->waterVerts[0], this->waterHeight, this->waterVerts[1]); |
---|
[7796] | 538 | |
---|
[8037] | 539 | // The front left vertice for the water |
---|
[8821] | 540 | glMultiTexCoord2f(GL_TEXTURE0, 0, 0); // Reflection texture |
---|
| 541 | glMultiTexCoord2f(GL_TEXTURE1, 0, -move); // Refraction texture |
---|
| 542 | glMultiTexCoord2f(GL_TEXTURE2, 0, move2); // Normal map texture |
---|
| 543 | glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture |
---|
[8859] | 544 | glVertex3f(this->waterVerts[2], this->waterHeight, this->waterVerts[3]); |
---|
[7796] | 545 | |
---|
[8037] | 546 | // The front right vertice for the water |
---|
[8821] | 547 | glMultiTexCoord2f(GL_TEXTURE0, waterUV, 0); // Reflection texture |
---|
| 548 | glMultiTexCoord2f(GL_TEXTURE1, waterUV, -move); // Refraction texture |
---|
| 549 | glMultiTexCoord2f(GL_TEXTURE2, normalUV, move2); // Normal map texture |
---|
| 550 | glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture |
---|
[8859] | 551 | glVertex3f(this->waterVerts[4], this->waterHeight, this->waterVerts[5]); |
---|
[7796] | 552 | |
---|
[8037] | 553 | // The back right vertice for the water |
---|
[8821] | 554 | glMultiTexCoord2f(GL_TEXTURE0, waterUV, waterUV); // Reflection texture |
---|
| 555 | glMultiTexCoord2f(GL_TEXTURE1, waterUV, waterUV - move); // Refraction texture |
---|
| 556 | glMultiTexCoord2f(GL_TEXTURE2, normalUV, normalUV + move2); // Normal map texture |
---|
| 557 | glMultiTexCoord2f(GL_TEXTURE3, 0, 0); // DUDV map texture |
---|
[8859] | 558 | glVertex3f(this->waterVerts[6], this->waterHeight, this->waterVerts[7]); |
---|
[8037] | 559 | glEnd(); |
---|
[7796] | 560 | |
---|
[8312] | 561 | this->shader->deactivateShader(); |
---|
[7796] | 562 | |
---|
[8037] | 563 | mat.unselect(); |
---|
[7796] | 564 | |
---|
| 565 | glPopMatrix(); |
---|
| 566 | } |
---|
| 567 | |
---|
[8719] | 568 | /** |
---|
| 569 | * @brief tick tack, calculates the flow of the water |
---|
| 570 | */ |
---|
[7796] | 571 | void MappedWater::tick(float dt) |
---|
| 572 | { |
---|
[8037] | 573 | // makes the water flow |
---|
[8719] | 574 | this->move += this->waterFlow * dt; |
---|
[8037] | 575 | this->move2 = this->move * this->kNormalMapScale; |
---|
[8792] | 576 | |
---|
[8919] | 577 | // fading TODO fix this so it isnt hacky anymore |
---|
[8916] | 578 | if(bFadeWaterUV) |
---|
[8884] | 579 | { |
---|
[8916] | 580 | this->waterUVFader = new tAnimation<MappedWater>(this, &MappedWater::setWaterUV); |
---|
| 581 | this->waterUVFader->setInfinity(ANIM_INF_CONSTANT); |
---|
[8828] | 582 | |
---|
[8916] | 583 | this->waterUVFader->addKeyFrame(this->waterUV, this->waterUVFadeTime, ANIM_LINEAR); |
---|
| 584 | this->waterUVFader->addKeyFrame(this->newWaterUV, 0, ANIM_LINEAR); |
---|
[8884] | 585 | |
---|
[8916] | 586 | bFadeWaterUV = false; |
---|
| 587 | this->waterUVFader->replay(); |
---|
[8884] | 588 | } |
---|
| 589 | |
---|
[8916] | 590 | if(bFadeWaterFlow) |
---|
[8884] | 591 | { |
---|
[8916] | 592 | this->waterFlowFader = new tAnimation<MappedWater>(this, &MappedWater::setWaterFlow); |
---|
| 593 | this->waterFlowFader->setInfinity(ANIM_INF_CONSTANT); |
---|
| 594 | |
---|
| 595 | this->waterFlowFader->addKeyFrame(this->waterFlow, this->waterFlowFadeTime, ANIM_LINEAR); |
---|
| 596 | this->waterFlowFader->addKeyFrame(this->newWaterFlow, 0, ANIM_LINEAR); |
---|
| 597 | |
---|
| 598 | bFadeWaterFlow = false; |
---|
| 599 | this->waterFlowFader->replay(); |
---|
[8884] | 600 | } |
---|
[8916] | 601 | |
---|
| 602 | if(bFadeShineSize) |
---|
| 603 | { |
---|
| 604 | this->shineSizeFader = new tAnimation<MappedWater>(this, &MappedWater::resetShineSize); |
---|
| 605 | this->shineSizeFader->setInfinity(ANIM_INF_CONSTANT); |
---|
| 606 | |
---|
| 607 | this->shineSizeFader->addKeyFrame(this->shineSize, this->shineSizeFadeTime, ANIM_LINEAR); |
---|
| 608 | this->shineSizeFader->addKeyFrame(this->newShineSize, 0, ANIM_LINEAR); |
---|
| 609 | |
---|
| 610 | bFadeShineSize = false; |
---|
| 611 | this->shineSizeFader->replay(); |
---|
| 612 | } |
---|
| 613 | |
---|
| 614 | if(bFadeShineStrength) |
---|
| 615 | { |
---|
| 616 | this->shineStrengthFader = new tAnimation<MappedWater>(this, &MappedWater::resetShineStrength); |
---|
| 617 | this->shineStrengthFader->setInfinity(ANIM_INF_CONSTANT); |
---|
| 618 | |
---|
| 619 | this->shineStrengthFader->addKeyFrame(this->shineStrength, this->shineStrengthFadeTime, ANIM_LINEAR); |
---|
| 620 | this->shineStrengthFader->addKeyFrame(this->newShineStrength, 0, ANIM_LINEAR); |
---|
| 621 | |
---|
| 622 | bFadeShineStrength = false; |
---|
| 623 | this->shineStrengthFader->replay(); |
---|
| 624 | } |
---|
| 625 | |
---|
| 626 | if(bFadeReflStrength) |
---|
| 627 | { |
---|
| 628 | this->reflStrengthFader = new tAnimation<MappedWater>(this, &MappedWater::resetReflStrength); |
---|
| 629 | this->reflStrengthFader->setInfinity(ANIM_INF_CONSTANT); |
---|
| 630 | |
---|
| 631 | this->reflStrengthFader->addKeyFrame(this->reflStrength, this->reflStrengthFadeTime, ANIM_LINEAR); |
---|
| 632 | this->reflStrengthFader->addKeyFrame(this->newReflStrength, 0, ANIM_LINEAR); |
---|
| 633 | |
---|
| 634 | bFadeReflStrength = false; |
---|
| 635 | this->reflStrengthFader->replay(); |
---|
| 636 | } |
---|
| 637 | |
---|
| 638 | if(bFadeRefraction) |
---|
| 639 | { |
---|
| 640 | this->refractionFader = new tAnimation<MappedWater>(this, &MappedWater::resetRefraction); |
---|
| 641 | this->refractionFader->setInfinity(ANIM_INF_CONSTANT); |
---|
| 642 | |
---|
| 643 | this->refractionFader->addKeyFrame(this->refraction, this->refractionFadeTime, ANIM_LINEAR); |
---|
| 644 | this->refractionFader->addKeyFrame(this->newRefraction, 0, ANIM_LINEAR); |
---|
| 645 | |
---|
| 646 | bFadeRefraction = false; |
---|
| 647 | this->refractionFader->replay(); |
---|
| 648 | } |
---|
| 649 | |
---|
[8918] | 650 | if(bFadeWaterHeight) |
---|
| 651 | { |
---|
| 652 | this->waterHeightFader = new tAnimation<MappedWater>(this, &MappedWater::setWaterHeight); |
---|
| 653 | this->waterHeightFader->setInfinity(ANIM_INF_CONSTANT); |
---|
[8916] | 654 | |
---|
[8918] | 655 | this->waterHeightFader->addKeyFrame(this->waterHeight, this->waterHeightFadeTime, ANIM_LINEAR); |
---|
| 656 | this->waterHeightFader->addKeyFrame(this->newWaterHeight, 0, ANIM_LINEAR); |
---|
| 657 | |
---|
| 658 | bFadeWaterHeight = false; |
---|
| 659 | this->waterHeightFader->replay(); |
---|
| 660 | } |
---|
| 661 | |
---|
[8919] | 662 | if(bFadeWaterColor) |
---|
| 663 | { |
---|
| 664 | this->waterColorRFader = new tAnimation<MappedWater>(this, &MappedWater::resetWaterColorR); |
---|
| 665 | this->waterColorRFader->setInfinity(ANIM_INF_CONSTANT); |
---|
[8918] | 666 | |
---|
[8919] | 667 | this->waterColorRFader->addKeyFrame(this->waterColor.x, this->waterColorFadeTime, ANIM_LINEAR); |
---|
| 668 | this->waterColorRFader->addKeyFrame(this->newWaterColor.x, 0, ANIM_LINEAR); |
---|
| 669 | |
---|
| 670 | this->waterColorRFader->replay(); |
---|
| 671 | |
---|
| 672 | this->waterColorGFader = new tAnimation<MappedWater>(this, &MappedWater::resetWaterColorG); |
---|
| 673 | this->waterColorGFader->setInfinity(ANIM_INF_CONSTANT); |
---|
| 674 | |
---|
| 675 | this->waterColorGFader->addKeyFrame(this->waterColor.x, this->waterColorFadeTime, ANIM_LINEAR); |
---|
| 676 | this->waterColorGFader->addKeyFrame(this->newWaterColor.x, 0, ANIM_LINEAR); |
---|
| 677 | |
---|
| 678 | this->waterColorGFader->replay(); |
---|
| 679 | |
---|
| 680 | this->waterColorBFader = new tAnimation<MappedWater>(this, &MappedWater::resetWaterColorB); |
---|
| 681 | this->waterColorBFader->setInfinity(ANIM_INF_CONSTANT); |
---|
| 682 | |
---|
| 683 | this->waterColorBFader->addKeyFrame(this->waterColor.x, this->waterColorFadeTime, ANIM_LINEAR); |
---|
| 684 | this->waterColorBFader->addKeyFrame(this->newWaterColor.x, 0, ANIM_LINEAR); |
---|
| 685 | |
---|
| 686 | this->waterColorBFader->replay(); |
---|
| 687 | |
---|
| 688 | bFadeWaterColor = false; |
---|
| 689 | } |
---|
| 690 | |
---|
[8918] | 691 | if(this->tempcounter == 100) |
---|
| 692 | { |
---|
| 693 | PRINTF(0)("\n\n\n\n\n\n///////////////////////test waterchangecolor/////////////////////\n\n\n\n\n\n"); |
---|
[8919] | 694 | this->fadeWaterColor(1, 0, 1, 15); |
---|
[8918] | 695 | } |
---|
[8884] | 696 | //PRINTF(0)("counter %i/n", tempcounter); |
---|
| 697 | tempcounter++; |
---|
[7796] | 698 | } |
---|
| 699 | |
---|
[8719] | 700 | /** |
---|
| 701 | * @brief prepares everything to render the reflection texutre |
---|
| 702 | */ |
---|
| 703 | void MappedWater::activateReflection() |
---|
[7796] | 704 | { |
---|
[8719] | 705 | // To create the reflection texture we just need to set the view port |
---|
| 706 | // to our texture map size, then render the current scene our camera |
---|
| 707 | // is looking at to the already allocated texture unit. Since this |
---|
| 708 | // is a reflection of the top of the water surface we use clipping |
---|
| 709 | // planes to only render the top of the world as a reflection. If |
---|
| 710 | // we are below the water we don't flip the reflection but just use |
---|
| 711 | // the current view of the top as we are seeing through the water. |
---|
| 712 | // When you look through water at the surface it isn't really reflected, |
---|
| 713 | // only when looking down from above the water on the surface. |
---|
[7796] | 714 | |
---|
[8037] | 715 | // save viewport matrix and change the viewport size |
---|
[7796] | 716 | glPushAttrib(GL_VIEWPORT_BIT); |
---|
| 717 | glViewport(0,0, textureSize, textureSize); |
---|
| 718 | |
---|
[8312] | 719 | glMatrixMode(GL_MODELVIEW); |
---|
[8037] | 720 | glPushMatrix(); |
---|
[7796] | 721 | |
---|
| 722 | // If our camera is above the water we will render the scene flipped upside down. |
---|
| 723 | // In order to line up the reflection nicely with the world we have to translate |
---|
| 724 | // the world to the position of our reflected surface, multiplied by two. |
---|
[8037] | 725 | glEnable(GL_CLIP_PLANE0); |
---|
| 726 | Vector pos = State::getCameraNode()->getAbsCoor(); |
---|
[8719] | 727 | |
---|
[8859] | 728 | if(pos.y > waterHeight) |
---|
[8037] | 729 | { |
---|
| 730 | // Translate the world, then flip it upside down |
---|
[8859] | 731 | glTranslatef(0, waterHeight * 2, 0); |
---|
[8719] | 732 | glScalef(1, -1, 1); |
---|
[7796] | 733 | |
---|
[8037] | 734 | // Since the world is updside down we need to change the culling to FRONT |
---|
| 735 | glCullFace(GL_FRONT); |
---|
[7796] | 736 | |
---|
[8037] | 737 | // Set our plane equation and turn clipping on |
---|
[8859] | 738 | double plane[4] = {0, 1, 0, -waterHeight}; |
---|
[8037] | 739 | glClipPlane(GL_CLIP_PLANE0, plane); |
---|
| 740 | } |
---|
| 741 | else |
---|
[7796] | 742 | { |
---|
[8037] | 743 | // If the camera is below the water we don't want to flip the world, |
---|
| 744 | // but just render it clipped so only the top is drawn. |
---|
[8859] | 745 | double plane[4] = {0, 1, 0, waterHeight}; |
---|
[8037] | 746 | glClipPlane(GL_CLIP_PLANE0, plane); |
---|
| 747 | } |
---|
[7796] | 748 | } |
---|
| 749 | |
---|
[8719] | 750 | /** |
---|
| 751 | * @brief ends the reflection and saves the graphic buffer into a texture |
---|
| 752 | */ |
---|
[7796] | 753 | void MappedWater::deactivateReflection() |
---|
| 754 | { |
---|
[8037] | 755 | glDisable(GL_CLIP_PLANE0); |
---|
| 756 | glCullFace(GL_BACK); |
---|
[7796] | 757 | |
---|
[8312] | 758 | // Create the texture and store it on the video card |
---|
[8719] | 759 | mat.renderToTexture(0, GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize); |
---|
[8312] | 760 | |
---|
[8037] | 761 | glPopMatrix(); |
---|
[7796] | 762 | glPopAttrib(); |
---|
| 763 | } |
---|
| 764 | |
---|
[8719] | 765 | /** |
---|
| 766 | * @brief prepares everything to render the refraction texutre |
---|
| 767 | */ |
---|
[7796] | 768 | void MappedWater::activateRefraction() |
---|
[8719] | 769 | { |
---|
[8037] | 770 | // To create the refraction and depth textures we do the same thing |
---|
| 771 | // we did for the reflection texture, except we don't need to turn |
---|
| 772 | // the world upside down. We want to find the depth of the water, |
---|
| 773 | // not the depth of the sky and above water terrain. |
---|
| 774 | |
---|
| 775 | // save viewport matrix and change the viewport size |
---|
| 776 | glPushAttrib(GL_VIEWPORT_BIT); |
---|
| 777 | glViewport(0,0, textureSize, textureSize); |
---|
| 778 | |
---|
[8312] | 779 | glMatrixMode(GL_MODELVIEW); |
---|
[8037] | 780 | glPushMatrix(); |
---|
| 781 | |
---|
| 782 | // If our camera is above the water we will render only the parts that |
---|
| 783 | // are under the water. If the camera is below the water we render |
---|
| 784 | // only the stuff above the water. Like the reflection texture, we |
---|
| 785 | // incorporate clipping planes to only render what we need. |
---|
| 786 | |
---|
| 787 | // If the camera is above water, render the data below the water |
---|
| 788 | glEnable(GL_CLIP_PLANE0); |
---|
| 789 | Vector pos = State::getCameraNode()->getAbsCoor(); |
---|
[8859] | 790 | if(pos.y > waterHeight) |
---|
[8037] | 791 | { |
---|
[8859] | 792 | double plane[4] = {0, -1, 0, waterHeight}; |
---|
[8037] | 793 | glClipPlane(GL_CLIP_PLANE0, plane); |
---|
| 794 | } |
---|
| 795 | // If the camera is below the water, only render the data above the water |
---|
| 796 | else |
---|
| 797 | { |
---|
| 798 | glCullFace(GL_FRONT); |
---|
[8859] | 799 | double plane[4] = {0, 1, 0, -waterHeight}; |
---|
[8037] | 800 | glClipPlane(GL_CLIP_PLANE0, plane); |
---|
| 801 | } |
---|
[7796] | 802 | } |
---|
| 803 | |
---|
[8719] | 804 | /** |
---|
| 805 | * @brief ends the refraction and saves the graphic buffer into a texture |
---|
| 806 | */ |
---|
[7796] | 807 | void MappedWater::deactivateRefraction() |
---|
| 808 | { |
---|
[8037] | 809 | glDisable(GL_CLIP_PLANE0); |
---|
| 810 | glCullFace(GL_BACK); |
---|
| 811 | |
---|
[8312] | 812 | // Create the texture and store it on the video card |
---|
[8719] | 813 | mat.renderToTexture(1, GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize); |
---|
[8312] | 814 | |
---|
| 815 | glPopMatrix(); |
---|
| 816 | glPopAttrib(); |
---|
[7796] | 817 | } |
---|