diff options
author | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
commit | cd17687f01420952712a500107e0f93e7ab8d5f8 (patch) | |
tree | ce48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/newview/lldrawpoolwater.cpp | |
parent | Second Life viewer sources 1.19.0.5 (diff) | |
download | meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2 meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz |
Second Life viewer sources 1.19.1.0
Diffstat (limited to '')
-rw-r--r-- | linden/indra/newview/lldrawpoolwater.cpp | 393 |
1 files changed, 156 insertions, 237 deletions
diff --git a/linden/indra/newview/lldrawpoolwater.cpp b/linden/indra/newview/lldrawpoolwater.cpp index e796d56..ed0077a 100644 --- a/linden/indra/newview/lldrawpoolwater.cpp +++ b/linden/indra/newview/lldrawpoolwater.cpp | |||
@@ -51,12 +51,16 @@ | |||
51 | #include "llworld.h" | 51 | #include "llworld.h" |
52 | #include "pipeline.h" | 52 | #include "pipeline.h" |
53 | #include "llglslshader.h" | 53 | #include "llglslshader.h" |
54 | #include "llwaterparammanager.h" | ||
54 | 55 | ||
55 | const LLUUID WATER_TEST("2bfd3884-7e27-69b9-ba3a-3e673f680004"); | 56 | const LLUUID WATER_TEST("2bfd3884-7e27-69b9-ba3a-3e673f680004"); |
56 | 57 | ||
57 | static float sTime; | 58 | static float sTime; |
58 | 59 | ||
59 | BOOL LLDrawPoolWater::sSkipScreenCopy = FALSE; | 60 | BOOL LLDrawPoolWater::sSkipScreenCopy = FALSE; |
61 | BOOL LLDrawPoolWater::sNeedsReflectionUpdate = TRUE; | ||
62 | LLColor4 LLDrawPoolWater::sWaterFogColor = LLColor4(0.2f, 0.5f, 0.5f, 0.f); | ||
63 | LLVector3 LLDrawPoolWater::sLightDir; | ||
60 | 64 | ||
61 | LLDrawPoolWater::LLDrawPoolWater() : | 65 | LLDrawPoolWater::LLDrawPoolWater() : |
62 | LLFacePool(POOL_WATER) | 66 | LLFacePool(POOL_WATER) |
@@ -70,7 +74,8 @@ LLDrawPoolWater::LLDrawPoolWater() : | |||
70 | mHBTex[1]->setClamp(TRUE, TRUE); | 74 | mHBTex[1]->setClamp(TRUE, TRUE); |
71 | 75 | ||
72 | mWaterImagep = gImageList.getImage(WATER_TEST); | 76 | mWaterImagep = gImageList.getImage(WATER_TEST); |
73 | mWaterNormp = gImageList.getImage(LLUUID(gViewerArt.getString("water_normal.tga"))); | 77 | //mWaterNormp = gImageList.getImage(LLUUID(gViewerArt.getString("water_normal.tga"))); |
78 | mWaterNormp = gImageList.getImage(LLWaterParamManager::instance()->getNormalMapID()); | ||
74 | 79 | ||
75 | restoreGL(); | 80 | restoreGL(); |
76 | } | 81 | } |
@@ -94,12 +99,25 @@ LLDrawPool *LLDrawPoolWater::instancePool() | |||
94 | 99 | ||
95 | void LLDrawPoolWater::prerender() | 100 | void LLDrawPoolWater::prerender() |
96 | { | 101 | { |
97 | mVertexShaderLevel = (gSavedSettings.getBOOL("RenderRippleWater") && gGLManager.mHasCubeMap && gFeatureManagerp->isFeatureAvailable("RenderCubeMap")) ? | 102 | mVertexShaderLevel = (gGLManager.mHasCubeMap && gFeatureManagerp->isFeatureAvailable("RenderCubeMap")) ? |
98 | LLShaderMgr::getVertexShaderLevel(LLShaderMgr::SHADER_ENVIRONMENT) : 0; | 103 | LLShaderMgr::getVertexShaderLevel(LLShaderMgr::SHADER_WATER) : 0; |
104 | |||
105 | // got rid of modulation by light color since it got a little too | ||
106 | // green at sunset and sl-57047 (underwater turns black at 8:00) | ||
107 | sWaterFogColor = LLWaterParamManager::instance()->getFogColor(); | ||
108 | sWaterFogColor.mV[3] = 0; | ||
99 | 109 | ||
100 | } | 110 | } |
101 | 111 | ||
102 | extern LLColor4U MAX_WATER_COLOR; | 112 | S32 LLDrawPoolWater::getNumPasses() |
113 | { | ||
114 | if (gCamera->getOrigin().mV[2] < 1024.f) | ||
115 | { | ||
116 | return 1; | ||
117 | } | ||
118 | |||
119 | return 0; | ||
120 | } | ||
103 | 121 | ||
104 | void LLDrawPoolWater::render(S32 pass) | 122 | void LLDrawPoolWater::render(S32 pass) |
105 | { | 123 | { |
@@ -121,18 +139,12 @@ void LLDrawPoolWater::render(S32 pass) | |||
121 | 139 | ||
122 | LLGLEnable blend(GL_BLEND); | 140 | LLGLEnable blend(GL_BLEND); |
123 | 141 | ||
124 | if ((mVertexShaderLevel >= SHADER_LEVEL_RIPPLE)) | 142 | if ((mVertexShaderLevel > 0) && !sSkipScreenCopy) |
125 | { | 143 | { |
126 | shade(); | 144 | shade(); |
127 | return; | 145 | return; |
128 | } | 146 | } |
129 | 147 | ||
130 | if ((mVertexShaderLevel > 0)) | ||
131 | { | ||
132 | renderShaderSimple(); | ||
133 | return; | ||
134 | } | ||
135 | |||
136 | LLVOSky *voskyp = gSky.mVOSkyp; | 148 | LLVOSky *voskyp = gSky.mVOSkyp; |
137 | 149 | ||
138 | stop_glerror(); | 150 | stop_glerror(); |
@@ -229,9 +241,9 @@ void LLDrawPoolWater::render(S32 pass) | |||
229 | glClientActiveTextureARB(GL_TEXTURE1_ARB); | 241 | glClientActiveTextureARB(GL_TEXTURE1_ARB); |
230 | glActiveTextureARB(GL_TEXTURE1_ARB); | 242 | glActiveTextureARB(GL_TEXTURE1_ARB); |
231 | glDisable(GL_TEXTURE_2D); // Texture unit 1 | 243 | glDisable(GL_TEXTURE_2D); // Texture unit 1 |
232 | LLImageGL::unbindTexture(1, GL_TEXTURE_2D); | ||
233 | glDisable(GL_TEXTURE_GEN_S); //texture unit 1 | 244 | glDisable(GL_TEXTURE_GEN_S); //texture unit 1 |
234 | glDisable(GL_TEXTURE_GEN_T); //texture unit 1 | 245 | glDisable(GL_TEXTURE_GEN_T); //texture unit 1 |
246 | LLImageGL::unbindTexture(1, GL_TEXTURE_2D); | ||
235 | 247 | ||
236 | // Disable texture coordinate and color arrays | 248 | // Disable texture coordinate and color arrays |
237 | glClientActiveTextureARB(GL_TEXTURE0_ARB); | 249 | glClientActiveTextureARB(GL_TEXTURE0_ARB); |
@@ -259,17 +271,6 @@ void LLDrawPoolWater::render(S32 pass) | |||
259 | 271 | ||
260 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | 272 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
261 | 273 | ||
262 | /*glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); | ||
263 | glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD); | ||
264 | glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE); | ||
265 | |||
266 | glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB); | ||
267 | glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); | ||
268 | glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE); | ||
269 | glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR); | ||
270 | glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS_ARB); | ||
271 | glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);*/ | ||
272 | |||
273 | for (std::vector<LLFace*>::iterator iter = mDrawFace.begin(); | 274 | for (std::vector<LLFace*>::iterator iter = mDrawFace.begin(); |
274 | iter != mDrawFace.end(); iter++) | 275 | iter != mDrawFace.end(); iter++) |
275 | { | 276 | { |
@@ -315,153 +316,6 @@ void LLDrawPoolWater::render(S32 pass) | |||
315 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | 316 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
316 | } | 317 | } |
317 | 318 | ||
318 | |||
319 | void LLDrawPoolWater::renderShaderSimple() | ||
320 | { | ||
321 | LLVOSky *voskyp = gSky.mVOSkyp; | ||
322 | |||
323 | stop_glerror(); | ||
324 | |||
325 | if (!gGLManager.mHasMultitexture) | ||
326 | { | ||
327 | // Ack! No multitexture! Bail! | ||
328 | return; | ||
329 | } | ||
330 | |||
331 | LLFace* refl_face = voskyp->getReflFace(); | ||
332 | |||
333 | LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); | ||
334 | |||
335 | LLGLDisable cullFace(GL_CULL_FACE); | ||
336 | |||
337 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); | ||
338 | glEnableClientState(GL_VERTEX_ARRAY); | ||
339 | glEnableClientState(GL_NORMAL_ARRAY); | ||
340 | |||
341 | // Set up second pass first | ||
342 | S32 bumpTex = gWaterProgram.enableTexture(LLShaderMgr::BUMP_MAP); | ||
343 | mWaterImagep->addTextureStats(1024.f*1024.f); | ||
344 | mWaterImagep->bind(bumpTex); | ||
345 | |||
346 | glClientActiveTextureARB(GL_TEXTURE1_ARB); | ||
347 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); | ||
348 | |||
349 | LLVector3 camera_up = gCamera->getUpAxis(); | ||
350 | F32 up_dot = camera_up * LLVector3::z_axis; | ||
351 | |||
352 | LLColor4 water_color; | ||
353 | if (gCamera->cameraUnderWater()) | ||
354 | { | ||
355 | water_color.setVec(1.f, 1.f, 1.f, 0.4f); | ||
356 | } | ||
357 | else | ||
358 | { | ||
359 | water_color.setVec(1.f, 1.f, 1.f, 0.5f*(1.f + up_dot)); | ||
360 | } | ||
361 | |||
362 | glColor4fv(water_color.mV); | ||
363 | |||
364 | // Automatically generate texture coords for detail map | ||
365 | glActiveTextureARB(GL_TEXTURE1_ARB); | ||
366 | glEnable(GL_TEXTURE_GEN_S); //texture unit 1 | ||
367 | glEnable(GL_TEXTURE_GEN_T); //texture unit 1 | ||
368 | glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); | ||
369 | glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); | ||
370 | |||
371 | // Slowly move over time. | ||
372 | F32 offset = fmod(gFrameTimeSeconds*2.f, 100.f); | ||
373 | F32 tp0[4] = {16.f/256.f, 0.0f, 0.0f, offset*0.01f}; | ||
374 | F32 tp1[4] = {0.0f, 16.f/256.f, 0.0f, offset*0.01f}; | ||
375 | glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0); | ||
376 | glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1); | ||
377 | |||
378 | glClientActiveTextureARB(GL_TEXTURE0_ARB); | ||
379 | glActiveTextureARB(GL_TEXTURE0_ARB); | ||
380 | |||
381 | glClearStencil(1); | ||
382 | glClear(GL_STENCIL_BUFFER_BIT); | ||
383 | LLGLEnable gls_stencil(GL_STENCIL_TEST); | ||
384 | glStencilOp(GL_KEEP, GL_REPLACE, GL_KEEP); | ||
385 | glStencilFunc(GL_ALWAYS, 0, 0xFFFFFFFF); | ||
386 | |||
387 | S32 envTex = -1; | ||
388 | |||
389 | if (gSky.mVOSkyp->getCubeMap()) | ||
390 | { | ||
391 | envTex = gWaterProgram.enableTexture(LLShaderMgr::ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB); | ||
392 | gSky.mVOSkyp->getCubeMap()->bind(); | ||
393 | |||
394 | glMatrixMode(GL_TEXTURE); | ||
395 | glLoadIdentity(); | ||
396 | LLMatrix4 camera_mat = gCamera->getModelview(); | ||
397 | LLMatrix4 camera_rot(camera_mat.getMat3()); | ||
398 | camera_rot.invert(); | ||
399 | |||
400 | glLoadMatrixf((F32 *)camera_rot.mMatrix); | ||
401 | |||
402 | glMatrixMode(GL_MODELVIEW); | ||
403 | } | ||
404 | |||
405 | S32 diffTex = gWaterProgram.enableTexture(LLShaderMgr::DIFFUSE_MAP); | ||
406 | |||
407 | gWaterProgram.bind(); | ||
408 | |||
409 | for (std::vector<LLFace*>::iterator iter = mDrawFace.begin(); | ||
410 | iter != mDrawFace.end(); iter++) | ||
411 | { | ||
412 | LLFace *face = *iter; | ||
413 | if (voskyp->isReflFace(face)) | ||
414 | { | ||
415 | continue; | ||
416 | } | ||
417 | face->bindTexture(diffTex); | ||
418 | face->renderIndexed(); | ||
419 | mIndicesDrawn += face->getIndicesCount(); | ||
420 | } | ||
421 | |||
422 | if (gSky.mVOSkyp->getCubeMap()) | ||
423 | { | ||
424 | gWaterProgram.disableTexture(LLShaderMgr::ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB); | ||
425 | glMatrixMode(GL_TEXTURE); | ||
426 | glLoadIdentity(); | ||
427 | glMatrixMode(GL_MODELVIEW); | ||
428 | } | ||
429 | |||
430 | // Now, disable texture coord generation on texture state 1 | ||
431 | gWaterProgram.disableTexture(LLShaderMgr::BUMP_MAP); | ||
432 | LLImageGL::unbindTexture(bumpTex, GL_TEXTURE_2D); | ||
433 | |||
434 | glActiveTextureARB(GL_TEXTURE1_ARB); | ||
435 | glDisable(GL_TEXTURE_GEN_S); //texture unit 1 | ||
436 | glDisable(GL_TEXTURE_GEN_T); //texture unit 1 | ||
437 | |||
438 | gWaterProgram.disableTexture(LLShaderMgr::DIFFUSE_MAP); | ||
439 | |||
440 | // Disable texture coordinate and color arrays | ||
441 | LLImageGL::unbindTexture(diffTex, GL_TEXTURE_2D); | ||
442 | |||
443 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); | ||
444 | stop_glerror(); | ||
445 | |||
446 | glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); | ||
447 | |||
448 | glUseProgramObjectARB(0); | ||
449 | gPipeline.disableLights(); | ||
450 | |||
451 | glActiveTextureARB(GL_TEXTURE0_ARB); | ||
452 | glClientActiveTextureARB(GL_TEXTURE0_ARB); | ||
453 | glEnable(GL_TEXTURE_2D); | ||
454 | |||
455 | if (refl_face) | ||
456 | { | ||
457 | glStencilFunc(GL_NOTEQUAL, 0, 0xFFFFFFFF); | ||
458 | renderReflection(refl_face); | ||
459 | } | ||
460 | |||
461 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); | ||
462 | glDisableClientState(GL_NORMAL_ARRAY); | ||
463 | } | ||
464 | |||
465 | void LLDrawPoolWater::renderReflection(LLFace* face) | 319 | void LLDrawPoolWater::renderReflection(LLFace* face) |
466 | { | 320 | { |
467 | LLVOSky *voskyp = gSky.mVOSkyp; | 321 | LLVOSky *voskyp = gSky.mVOSkyp; |
@@ -500,47 +354,33 @@ void LLDrawPoolWater::shade() | |||
500 | { | 354 | { |
501 | glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); | 355 | glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); |
502 | 356 | ||
503 | static LLVector2 d1( 0.5f, -0.17f ); | ||
504 | static LLVector2 d2( 0.58f, -0.67f ); | ||
505 | static LLVector2 d3( 0.5f, 0.25f ); | ||
506 | |||
507 | static LLVector3 wave1(1,0.42f,1); | ||
508 | static LLVector3 wave2(0.58f,0.42f,0.17f); | ||
509 | static LLVector3 wave3(0.42f,0.67f,0.33f); | ||
510 | |||
511 | /*static LLVector2 d1( 0.83f, -1 ); | ||
512 | static LLVector2 d2( 0.58f, 1 ); | ||
513 | static LLVector2 d3( 1, -0.88f ); | ||
514 | |||
515 | static LLVector4 wave1(0.75f,0.08f,0.5f,0.67f); | ||
516 | static LLVector4 wave2(0.17f,0.33f,0.53f,0.62f); | ||
517 | static LLVector4 wave3(0.17f,0.6f,0.67f,1);*/ | ||
518 | |||
519 | /*LLDebugVarMessageBox::show("Wave Direction 1", &d1, LLVector2(1,1), LLVector2(0.01f, 0.01f)); | ||
520 | LLDebugVarMessageBox::show("Wave Direction 2", &d2, LLVector2(1,1), LLVector2(0.01f, 0.01f)); | ||
521 | LLDebugVarMessageBox::show("Wave Direction 3", &d3, LLVector2(1,1), LLVector2(0.01f, 0.01f)); | ||
522 | |||
523 | LLDebugVarMessageBox::show("Wave 1", &wave1, LLVector3(2,1,4), LLVector3(0.01f, 0.01f, 0.01f)); | ||
524 | LLDebugVarMessageBox::show("Wave 2", &wave2, LLVector3(2,1,4), LLVector3(0.01f, 0.01f, 0.01f)); | ||
525 | LLDebugVarMessageBox::show("Wave 3", &wave3, LLVector3(2,1,4), LLVector3(0.01f, 0.01f, 0.01f));*/ | ||
526 | |||
527 | LLVOSky *voskyp = gSky.mVOSkyp; | 357 | LLVOSky *voskyp = gSky.mVOSkyp; |
528 | 358 | ||
359 | if(voskyp == NULL) | ||
360 | { | ||
361 | return; | ||
362 | } | ||
363 | |||
529 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); | 364 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
530 | glEnableClientState(GL_VERTEX_ARRAY); | 365 | glEnableClientState(GL_VERTEX_ARRAY); |
531 | glEnableClientState(GL_NORMAL_ARRAY); | 366 | glEnableClientState(GL_NORMAL_ARRAY); |
367 | |||
532 | LLGLDisable blend(GL_BLEND); | 368 | LLGLDisable blend(GL_BLEND); |
533 | 369 | ||
534 | LLColor3 light_diffuse(0,0,0); | 370 | LLColor3 light_diffuse(0,0,0); |
535 | F32 light_exp = 0.0f; | 371 | F32 light_exp = 0.0f; |
536 | LLVector3 light_dir; | 372 | LLVector3 light_dir; |
373 | LLColor3 light_color; | ||
537 | 374 | ||
538 | if (gSky.getSunDirection().mV[2] > NIGHTTIME_ELEVATION_COS) | 375 | if (gSky.getSunDirection().mV[2] > NIGHTTIME_ELEVATION_COS) |
539 | { | 376 | { |
540 | light_dir = gSky.getSunDirection(); | 377 | light_dir = gSky.getSunDirection(); |
541 | light_dir.normVec(); | 378 | light_dir.normVec(); |
542 | light_diffuse = gSky.mVOSkyp->getSun().getColorCached(); | 379 | light_color = gSky.getSunDiffuseColor(); |
543 | light_diffuse.normVec(); | 380 | if(gSky.mVOSkyp) { |
381 | light_diffuse = gSky.mVOSkyp->getSun().getColorCached(); | ||
382 | light_diffuse.normVec(); | ||
383 | } | ||
544 | light_exp = light_dir * LLVector3(light_dir.mV[0], light_dir.mV[1], 0); | 384 | light_exp = light_dir * LLVector3(light_dir.mV[0], light_dir.mV[1], 0); |
545 | light_diffuse *= light_exp + 0.25f; | 385 | light_diffuse *= light_exp + 0.25f; |
546 | } | 386 | } |
@@ -548,6 +388,7 @@ void LLDrawPoolWater::shade() | |||
548 | { | 388 | { |
549 | light_dir = gSky.getMoonDirection(); | 389 | light_dir = gSky.getMoonDirection(); |
550 | light_dir.normVec(); | 390 | light_dir.normVec(); |
391 | light_color = gSky.getMoonDiffuseColor(); | ||
551 | light_diffuse = gSky.mVOSkyp->getMoon().getColorCached(); | 392 | light_diffuse = gSky.mVOSkyp->getMoon().getColorCached(); |
552 | light_diffuse.normVec(); | 393 | light_diffuse.normVec(); |
553 | light_diffuse *= 0.5f; | 394 | light_diffuse *= 0.5f; |
@@ -558,57 +399,112 @@ void LLDrawPoolWater::shade() | |||
558 | light_exp *= light_exp; | 399 | light_exp *= light_exp; |
559 | light_exp *= light_exp; | 400 | light_exp *= light_exp; |
560 | light_exp *= light_exp; | 401 | light_exp *= light_exp; |
561 | light_exp *= light_exp; | 402 | light_exp *= 256.f; |
562 | light_exp *= 512.f; | ||
563 | light_exp = light_exp > 32.f ? light_exp : 32.f; | 403 | light_exp = light_exp > 32.f ? light_exp : 32.f; |
564 | 404 | ||
565 | sTime = (F32)LLFrameTimer::getElapsedSeconds()*0.5f; | 405 | LLGLSLShader* shader; |
566 | |||
567 | LLCubeMap* skyMap = gSky.mVOSkyp->getCubeMap(); | ||
568 | |||
569 | gWaterProgram.enableTexture(LLShaderMgr::ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB); | ||
570 | 406 | ||
571 | if (skyMap) | 407 | F32 eyedepth = gCamera->getOrigin().mV[2] - gAgent.getRegion()->getWaterHeight(); |
408 | |||
409 | if (eyedepth < 0.f && LLPipeline::sWaterReflections) | ||
572 | { | 410 | { |
573 | skyMap->bind(); | 411 | shader = &gUnderWaterProgram; |
574 | } | 412 | } |
575 | else | 413 | else |
576 | { | 414 | { |
577 | llwarns << "NULL gSky.mVOSkyp->getCubeMap(), not binding." << llendl; | 415 | shader = &gWaterProgram; |
578 | } | 416 | } |
579 | 417 | ||
418 | sTime = (F32)LLFrameTimer::getElapsedSeconds()*0.5f; | ||
419 | |||
420 | S32 reftex = shader->enableTexture(LLShaderMgr::WATER_REFTEX); | ||
421 | |||
422 | if (reftex > -1) | ||
423 | { | ||
424 | glActiveTextureARB(GL_TEXTURE0_ARB+reftex); | ||
425 | gPipeline.mWaterRef.bindTexture(); | ||
426 | glActiveTextureARB(GL_TEXTURE0_ARB); | ||
427 | } | ||
428 | |||
580 | //bind normal map | 429 | //bind normal map |
581 | S32 bumpTex = gWaterProgram.enableTexture(LLShaderMgr::BUMP_MAP); | 430 | S32 bumpTex = shader->enableTexture(LLShaderMgr::BUMP_MAP); |
431 | |||
432 | LLWaterParamManager * param_mgr = LLWaterParamManager::instance(); | ||
433 | |||
434 | // change mWaterNormp if needed | ||
435 | if (mWaterNormp->getID() != param_mgr->getNormalMapID()) | ||
436 | { | ||
437 | mWaterNormp = gImageList.getImage(param_mgr->getNormalMapID()); | ||
438 | } | ||
439 | |||
582 | mWaterNormp->addTextureStats(1024.f*1024.f); | 440 | mWaterNormp->addTextureStats(1024.f*1024.f); |
583 | mWaterNormp->bind(bumpTex); | 441 | mWaterNormp->bind(bumpTex); |
584 | 442 | if (!gSavedSettings.getBOOL("RenderWaterMipNormal")) | |
585 | gWaterProgram.enableTexture(LLShaderMgr::WATER_SCREENTEX); | ||
586 | |||
587 | gWaterProgram.bind(); | ||
588 | |||
589 | if (!sSkipScreenCopy) | ||
590 | { | 443 | { |
591 | gPipeline.bindScreenToTexture(); | 444 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
592 | } | 445 | } |
593 | else | 446 | else |
594 | { | 447 | { |
595 | glBindTexture(GL_TEXTURE_2D, 0); | 448 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
596 | } | 449 | } |
597 | 450 | ||
598 | glUniform2fvARB(gWaterProgram.mUniform[LLShaderMgr::WATER_FBSCALE], 1, | 451 | S32 screentex = shader->enableTexture(LLShaderMgr::WATER_SCREENTEX); |
599 | gPipeline.mScreenScale.mV); | 452 | stop_glerror(); |
453 | |||
454 | shader->bind(); | ||
600 | 455 | ||
601 | S32 diffTex = gWaterProgram.enableTexture(LLShaderMgr::DIFFUSE_MAP); | 456 | if (screentex > -1) |
457 | { | ||
458 | shader->uniform4fv(LLShaderMgr::WATER_FOGCOLOR, 1, sWaterFogColor.mV); | ||
459 | shader->uniform1f(LLShaderMgr::WATER_FOGDENSITY, | ||
460 | param_mgr->getFogDensity()); | ||
461 | } | ||
602 | 462 | ||
603 | LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); | 463 | gPipeline.mWaterDis.bindTexture(); |
604 | 464 | ||
605 | glUniform1fARB(gWaterProgram.mUniform[LLShaderMgr::WATER_TIME], sTime); | 465 | if (mVertexShaderLevel == 1) |
606 | glUniform3fvARB(gWaterProgram.mUniform[LLShaderMgr::WATER_SPECULAR], 1, light_diffuse.mV); | 466 | { |
607 | glUniform1fARB(gWaterProgram.mUniform[LLShaderMgr::WATER_SPECULAR_EXP], light_exp); | 467 | sWaterFogColor.mV[3] = param_mgr->mDensitySliderValue; |
608 | glUniform3fvARB(gWaterProgram.mUniform[LLShaderMgr::WATER_EYEVEC], 1, (GLfloat *)(gCamera->getOrigin().mV)); | 468 | shader->uniform4fv(LLShaderMgr::WATER_FOGCOLOR, 1, sWaterFogColor.mV); |
609 | glUniform2fvARB(gWaterProgram.mUniform[LLShaderMgr::WATER_WAVE_DIR1], 1, d1.mV); | 469 | } |
610 | glUniform2fvARB(gWaterProgram.mUniform[LLShaderMgr::WATER_WAVE_DIR2], 1, d2.mV); | 470 | |
611 | glUniform3fvARB(gWaterProgram.mUniform[LLShaderMgr::WATER_LIGHT_DIR], 1, light_dir.mV); | 471 | F32 screenRes[] = |
472 | { | ||
473 | 1.f/gGLViewport[2], | ||
474 | 1.f/gGLViewport[3] | ||
475 | }; | ||
476 | shader->uniform2fv("screenRes", 1, screenRes); | ||
477 | stop_glerror(); | ||
478 | |||
479 | S32 diffTex = shader->enableTexture(LLShaderMgr::DIFFUSE_MAP); | ||
480 | stop_glerror(); | ||
481 | |||
482 | light_dir.normVec(); | ||
483 | sLightDir = light_dir; | ||
484 | |||
485 | light_diffuse *= 6.f; | ||
486 | |||
487 | //shader->uniformMatrix4fv("inverse_ref", 1, GL_FALSE, (GLfloat*) gGLObliqueProjectionInverse.mMatrix); | ||
488 | shader->uniform1f(LLShaderMgr::WATER_WATERHEIGHT, eyedepth); | ||
489 | shader->uniform1f(LLShaderMgr::WATER_TIME, sTime); | ||
490 | shader->uniform3fv(LLShaderMgr::WATER_EYEVEC, 1, gCamera->getOrigin().mV); | ||
491 | shader->uniform3fv(LLShaderMgr::WATER_SPECULAR, 1, light_diffuse.mV); | ||
492 | shader->uniform1f(LLShaderMgr::WATER_SPECULAR_EXP, light_exp); | ||
493 | shader->uniform2fv(LLShaderMgr::WATER_WAVE_DIR1, 1, param_mgr->getWave1Dir().mV); | ||
494 | shader->uniform2fv(LLShaderMgr::WATER_WAVE_DIR2, 1, param_mgr->getWave2Dir().mV); | ||
495 | shader->uniform3fv(LLShaderMgr::WATER_LIGHT_DIR, 1, light_dir.mV); | ||
496 | |||
497 | shader->uniform3fv("normScale", 1, param_mgr->getNormalScale().mV); | ||
498 | shader->uniform1f("fresnelScale", param_mgr->getFresnelScale()); | ||
499 | shader->uniform1f("fresnelOffset", param_mgr->getFresnelOffset()); | ||
500 | shader->uniform1f("blurMultiplier", param_mgr->getBlurMultiplier()); | ||
501 | |||
502 | F32 sunAngle = llmax(0.f, light_dir.mV[2]); | ||
503 | F32 scaledAngle = 1.f - sunAngle; | ||
504 | |||
505 | shader->uniform1f("sunAngle", sunAngle); | ||
506 | shader->uniform1f("scaledAngle", scaledAngle); | ||
507 | shader->uniform1f("sunAngle2", 0.1f + 0.2f*sunAngle); | ||
612 | 508 | ||
613 | LLColor4 water_color; | 509 | LLColor4 water_color; |
614 | LLVector3 camera_up = gCamera->getUpAxis(); | 510 | LLVector3 camera_up = gCamera->getUpAxis(); |
@@ -616,13 +512,14 @@ void LLDrawPoolWater::shade() | |||
616 | if (gCamera->cameraUnderWater()) | 512 | if (gCamera->cameraUnderWater()) |
617 | { | 513 | { |
618 | water_color.setVec(1.f, 1.f, 1.f, 0.4f); | 514 | water_color.setVec(1.f, 1.f, 1.f, 0.4f); |
619 | glUniform1fARB(gWaterProgram.mUniform[LLShaderMgr::WATER_REFSCALE], 0.25f); | 515 | shader->uniform1f(LLShaderMgr::WATER_REFSCALE, param_mgr->getScaleBelow()); |
620 | } | 516 | } |
621 | else | 517 | else |
622 | { | 518 | { |
623 | water_color.setVec(1.f, 1.f, 1.f, 0.5f*(1.f + up_dot)); | 519 | water_color.setVec(1.f, 1.f, 1.f, 0.5f*(1.f + up_dot)); |
624 | glUniform1fARB(gWaterProgram.mUniform[LLShaderMgr::WATER_REFSCALE], 0.01f); | 520 | shader->uniform1f(LLShaderMgr::WATER_REFSCALE, param_mgr->getScaleAbove()); |
625 | } | 521 | } |
522 | |||
626 | if (water_color.mV[3] > 0.9f) | 523 | if (water_color.mV[3] > 0.9f) |
627 | { | 524 | { |
628 | water_color.mV[3] = 0.9f; | 525 | water_color.mV[3] = 0.9f; |
@@ -642,24 +539,46 @@ void LLDrawPoolWater::shade() | |||
642 | continue; | 539 | continue; |
643 | } | 540 | } |
644 | 541 | ||
542 | LLVOWater* water = (LLVOWater*) face->getViewerObject(); | ||
645 | face->bindTexture(diffTex); | 543 | face->bindTexture(diffTex); |
646 | face->renderIndexed(); | 544 | |
545 | sNeedsReflectionUpdate = TRUE; | ||
546 | |||
547 | if (water->getUseTexture()) | ||
548 | { | ||
549 | face->renderIndexed(); | ||
550 | } | ||
551 | else | ||
552 | { //smash background faces to far clip plane | ||
553 | if (water->getIsEdgePatch()) | ||
554 | { | ||
555 | LLGLClampToFarClip far_clip(glh_get_current_projection()); | ||
556 | face->renderIndexed(); | ||
557 | } | ||
558 | else | ||
559 | { | ||
560 | face->renderIndexed(); | ||
561 | } | ||
562 | } | ||
563 | |||
647 | mIndicesDrawn += face->getIndicesCount(); | 564 | mIndicesDrawn += face->getIndicesCount(); |
648 | } | 565 | } |
649 | } | 566 | } |
650 | 567 | ||
651 | gWaterProgram.disableTexture(LLShaderMgr::ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB); | 568 | shader->disableTexture(LLShaderMgr::ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB); |
652 | gWaterProgram.disableTexture(LLShaderMgr::WATER_SCREENTEX); | 569 | shader->disableTexture(LLShaderMgr::WATER_SCREENTEX); |
653 | gWaterProgram.disableTexture(LLShaderMgr::BUMP_MAP); | 570 | shader->disableTexture(LLShaderMgr::BUMP_MAP); |
654 | gWaterProgram.disableTexture(LLShaderMgr::DIFFUSE_MAP); | 571 | shader->disableTexture(LLShaderMgr::DIFFUSE_MAP); |
572 | shader->disableTexture(LLShaderMgr::WATER_REFTEX); | ||
573 | shader->disableTexture(LLShaderMgr::WATER_SCREENDEPTH); | ||
574 | shader->unbind(); | ||
655 | 575 | ||
656 | glActiveTextureARB(GL_TEXTURE0_ARB); | 576 | glActiveTextureARB(GL_TEXTURE0_ARB); |
657 | glEnable(GL_TEXTURE_2D); | ||
658 | glUseProgramObjectARB(0); | ||
659 | |||
660 | glClientActiveTextureARB(GL_TEXTURE0_ARB); | 577 | glClientActiveTextureARB(GL_TEXTURE0_ARB); |
661 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); | 578 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
579 | glEnable(GL_TEXTURE_2D); | ||
662 | glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_FALSE); | 580 | glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_FALSE); |
581 | |||
663 | } | 582 | } |
664 | 583 | ||
665 | void LLDrawPoolWater::renderForSelect() | 584 | void LLDrawPoolWater::renderForSelect() |