Tomaz's new water effect has been added and looks very nice
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 22 Sep 2003 20:55:31 +0000 (20:55 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 22 Sep 2003 20:55:31 +0000 (20:55 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3505 d7cf8633-e32d-0410-b094-e92efae38249

gl_rsurf.c
menu.c
model_shared.c
model_shared.h

index d0c048e..5008610 100644 (file)
@@ -760,15 +760,17 @@ static void RSurfShader_Water_Callback(const void *calldata1, int calldata2)
        matrix4x4_t tempmatrix;
        float   args[4] = {0.05f,0,0,0.04f};
 
-       if (r_waterscroll.value)
+       if (gl_textureshader && r_watershader.value && !fogenabled)
+       {
+               Matrix4x4_CreateTranslate(&tempmatrix, sin(cl.time) * 0.025 * r_waterscroll.value, sin(cl.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
+               R_Mesh_TextureMatrix(1, &tempmatrix);
+               Matrix4x4_CreateFromQuakeEntity(&tempmatrix, 0, 0, 0, 0, 0, 0, r_watershader.value);
+               R_Mesh_TextureMatrix(0, &tempmatrix);
+       }
+       else if (r_waterscroll.value)
        {
                // scrolling in texture matrix
                Matrix4x4_CreateTranslate(&tempmatrix, sin(cl.time) * 0.025 * r_waterscroll.value, sin(cl.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
-               if (gl_textureshader && r_watershader.integer && !fogenabled)
-               {
-                       R_Mesh_TextureMatrix(1, &tempmatrix);
-                       Matrix4x4_CreateTranslate(&tempmatrix, -sin(cl.time) * 0.025 * r_waterscroll.value, -sin(cl.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
-               }
                R_Mesh_TextureMatrix(0, &tempmatrix);
        }
 
@@ -793,9 +795,9 @@ static void RSurfShader_Water_Callback(const void *calldata1, int calldata2)
                GL_BlendFunc(GL_ONE, GL_ZERO);
                GL_DepthMask(true);
        }
-       if (gl_textureshader && r_watershader.integer && !fogenabled)
+       if (gl_textureshader && r_watershader.value && !fogenabled)
        {
-               m.tex[0] = R_GetTexture(mod_shared_distorttexture);
+               m.tex[0] = R_GetTexture(mod_shared_distorttexture[(int)(cl.time * 16)&63]);
                m.tex[1] = R_GetTexture(texture->skin.base);
        }
        else
@@ -805,7 +807,7 @@ static void RSurfShader_Water_Callback(const void *calldata1, int calldata2)
                GL_ColorPointer(varray_color4f);
        else
                GL_Color(1, 1, 1, alpha);
-       if (gl_textureshader && r_watershader.integer && !fogenabled)
+       if (gl_textureshader && r_watershader.value && !fogenabled)
        {
                GL_ActiveTexture (0);
                qglTexEnvi (GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
@@ -829,7 +831,7 @@ static void RSurfShader_Water_Callback(const void *calldata1, int calldata2)
        }
        R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
 
-       if (gl_textureshader && r_watershader.integer && !fogenabled)
+       if (gl_textureshader && r_watershader.value && !fogenabled)
        {
                qglDisable (GL_TEXTURE_SHADER_NV);
                GL_ActiveTexture (0);
@@ -850,7 +852,7 @@ static void RSurfShader_Water_Callback(const void *calldata1, int calldata2)
                R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
        }
 
-       if (r_waterscroll.value)
+       if ((gl_textureshader && r_watershader.value && !fogenabled) || r_waterscroll.value)
        {
                Matrix4x4_CreateIdentity(&tempmatrix);
                R_Mesh_TextureMatrix(0, &tempmatrix);
diff --git a/menu.c b/menu.c
index eb91659..825aaa7 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -1430,7 +1430,7 @@ void M_Menu_Options_Effects_AdjustSliders (int dir)
        else if (options_effects_cursor == optnum++)
                Cvar_SetValueQuick (&r_waterscroll, bound(0, r_waterscroll.value + dir * 0.5, 10));
        else if (options_effects_cursor == optnum++)
-               Cvar_SetValueQuick (&r_watershader, !r_watershader.integer);
+               Cvar_SetValueQuick (&r_watershader, bound(0, r_watershader.value + dir * 0.25, 10));
 }
 
 void M_Options_Effects_Draw (void)
@@ -1468,7 +1468,7 @@ void M_Options_Effects_Draw (void)
        M_Options_PrintCheckbox("   Model Interpolation", true, r_lerpmodels.integer);
        M_Options_PrintCheckbox("  Sprite Interpolation", true, r_lerpsprites.integer);
        M_Options_PrintSlider(  "        Water Movement", true, r_waterscroll.value, 0, 10);
-       M_Options_PrintCheckbox(" GeForce3 Water Shader", true, r_watershader.integer);
+       M_Options_PrintSlider(  " GeForce3 Water Shader", true, r_watershader.value, 0, 10);
 }
 
 
index 4126b4a..ebcdc6a 100644 (file)
@@ -37,7 +37,7 @@ static model_t mod_known[MAX_MOD_KNOWN];
 rtexturepool_t *mod_shared_texturepool;
 rtexture_t *r_notexture;
 rtexture_t *mod_shared_detailtextures[NUM_DETAILTEXTURES];
-rtexture_t *mod_shared_distorttexture;
+rtexture_t *mod_shared_distorttexture[64];
 
 void Mod_BuildDetailTextures (void)
 {
@@ -79,21 +79,55 @@ void Mod_BuildDetailTextures (void)
        }
 }
 
+qbyte Mod_MorphDistortTexture (double y0, double y1, double y2, double y3, double morph)
+{
+       int     value = (int)(((y1 + y3 - (y0 + y2)) * morph * morph * morph) +
+                               ((2 * (y0 - y1) + y2 - y3) * morph * morph) +
+                               ((y2 - y0) * morph) +
+                               (y1));
+
+       if (value > 255)
+               value = 255;
+       if (value < 0)
+               value = 0;
+
+       return (qbyte)value;
+}
+
 void Mod_BuildDistortTexture (void)
 {
-       int x, y;
+       int x, y, i, j;
 #define DISTORTRESOLUTION 32
-       qbyte data[DISTORTRESOLUTION][DISTORTRESOLUTION][2];
-       for (y=0; y<DISTORTRESOLUTION; y++)
+       qbyte data[5][DISTORTRESOLUTION][DISTORTRESOLUTION][2];
+
+       for (i=0; i<4; i++)
+       {
+               for (y=0; y<DISTORTRESOLUTION; y++)
+               {
+                       for (x=0; x<DISTORTRESOLUTION; x++)
+                       {
+                               data[i][y][x][0] = rand () & 255;
+                               data[i][y][x][1] = rand () & 255;
+                       }
+               }
+       }
+
+       for (i=0; i<4; i++)
        {
-               for (x=0; x<DISTORTRESOLUTION; x++)
+               for (j=0; j<16; j++)
                {
-                       data[y][x][0] = rand () & 255;
-                       data[y][x][1] = rand () & 255;
+                       for (y=0; y<DISTORTRESOLUTION; y++)
+                       {
+                               for (x=0; x<DISTORTRESOLUTION; x++)
+                               {
+                                       data[4][y][x][0] = Mod_MorphDistortTexture (data[(i-1)&3][y][x][0], data[i][y][x][0], data[(i+1)&3][y][x][0], data[(i+2)&3][y][x][0], 0.0625*j);
+                                       data[4][y][x][1] = Mod_MorphDistortTexture (data[(i-1)&3][y][x][1], data[i][y][x][1], data[(i+1)&3][y][x][1], data[(i+2)&3][y][x][1], 0.0625*j);
+                               }
+                       }
+                       mod_shared_distorttexture[i*16+j] = R_LoadTexture2D(mod_shared_texturepool, va("distorttexture%i", i*16+j), DISTORTRESOLUTION, DISTORTRESOLUTION, &data[4][0][0][0], TEXTYPE_DSDT, TEXF_PRECACHE, NULL);
                }
        }
 
-       mod_shared_distorttexture = R_LoadTexture2D(mod_shared_texturepool, "distorttexture", DISTORTRESOLUTION, DISTORTRESOLUTION, &data[0][0][0], TEXTYPE_DSDT, TEXF_PRECACHE, NULL);
        return;
 }
 
index 92a42ae..d1d11e2 100644 (file)
@@ -540,7 +540,7 @@ extern rtexture_t *mod_shared_detailtextures[NUM_DETAILTEXTURES];
 // every texture must be in a pool...
 extern rtexturepool_t *mod_shared_texturepool;
 
-extern rtexture_t *mod_shared_distorttexture;
+extern rtexture_t *mod_shared_distorttexture[64];
 
 // model loading
 extern model_t *loadmodel;