]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
first part of fog changes: no longer use a complex glsl equation; modify the table...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 22 Dec 2007 13:50:39 +0000 (13:50 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 22 Dec 2007 13:50:39 +0000 (13:50 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7838 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
cl_parse.c
client.h
gl_rmain.c
r_sky.c

index 717f156cc6e79830de937609ea43d4f7fe82ae0d..2f78af6ba6d6f142363f854640e0937582eef025 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -1845,11 +1845,11 @@ static void CL_Fog_f (void)
 {
        if (Cmd_Argc () == 1)
        {
-               Con_Printf("\"fog\" is \"%f %f %f %f %f %f\"\n", r_refdef.fog_density, r_refdef.fog_red, r_refdef.fog_green, r_refdef.fog_blue, r_refdef.fog_start, r_refdef.fog_end);
+               Con_Printf("\"fog\" is \"%f %f %f %f %f %f\"\n", r_refdef.fog_density, r_refdef.fog_red, r_refdef.fog_green, r_refdef.fog_blue, r_refdef.fog_start, r_refdef.fog_alpha);
                return;
        }
        r_refdef.fog_start = 0;
-       r_refdef.fog_end = 1000000000;
+       r_refdef.fog_alpha = 1;
        if(Cmd_Argc() > 1)
                r_refdef.fog_density = atof(Cmd_Argv(1));
        if(Cmd_Argc() > 2)
@@ -1861,7 +1861,7 @@ static void CL_Fog_f (void)
        if(Cmd_Argc() > 5)
                r_refdef.fog_start = atof(Cmd_Argv(5));
        if(Cmd_Argc() > 6)
-               r_refdef.fog_end = atof(Cmd_Argv(6));
+               r_refdef.fog_alpha = atof(Cmd_Argv(6));
 }
 
 /*
@@ -2286,7 +2286,7 @@ void CL_Init (void)
        Cvar_RegisterVariable (&cl_autodemo);
        Cvar_RegisterVariable (&cl_autodemo_nameformat);
 
-       Cmd_AddCommand ("fog", CL_Fog_f, "set global fog parameters (density red green blue)");
+       Cmd_AddCommand ("fog", CL_Fog_f, "set global fog parameters (density red green blue mindist alpha)");
 
        // LordHavoc: added pausedemo
        Cmd_AddCommand ("pausedemo", CL_PauseDemo_f, "pause demo playback (can also safely pause demo recording if using QUAKE, QUAKEDP or NEHAHRAMOVIE protocol, useful for making movies)");
index 97ec02351b7ec4fd8a145f2da5adbd08da8380e4..e3b39714052c87c76037be074430e53df38fe4b6 100644 (file)
@@ -364,8 +364,8 @@ void CL_ParseEntityLump(char *entdata)
                else if (!strcmp("fog", key))
                {
                        r_refdef.fog_start = 0;
-                       r_refdef.fog_end = 1000000000;
-                       sscanf(value, "%f %f %f %f %f %f", &r_refdef.fog_density, &r_refdef.fog_red, &r_refdef.fog_green, &r_refdef.fog_blue, &r_refdef.fog_start, &r_refdef.fog_end);
+                       r_refdef.fog_alpha = 1;
+                       sscanf(value, "%f %f %f %f %f %f", &r_refdef.fog_density, &r_refdef.fog_red, &r_refdef.fog_green, &r_refdef.fog_blue, &r_refdef.fog_start, &r_refdef.fog_alpha);
                }
                else if (!strcmp("fog_density", key))
                        r_refdef.fog_density = atof(value);
index 7afb64ed91e4853bd8a0cc8c1e1acde4eef75f84..8c3522363fd24dd53056037a07abc29924bc5bae 100644 (file)
--- a/client.h
+++ b/client.h
@@ -1403,7 +1403,7 @@ typedef struct r_refdef_s
        float fog_red;
        float fog_green;
        float fog_blue;
-       float fog_start, fog_end;
+       float fog_start, fog_alpha;
        qboolean fogenabled;
        qboolean oldgl_fogenable;
 
index 280cedfb0fcc215253d26655dceaf8b1f26e795c..bd002566bcbb9253aee75fb0d8659bcb7da513c9 100644 (file)
@@ -248,12 +248,12 @@ void FOG_clear(void)
        }
        r_refdef.fog_density = r_refdef.fog_red = r_refdef.fog_green = r_refdef.fog_blue = 0.0f;
        r_refdef.fog_start = 0;
-       r_refdef.fog_end = 1000000000;
+       r_refdef.fog_alpha = 1;
 }
 
 float FogForDistance(vec_t dist)
 {
-       unsigned int fogmasktableindex = (unsigned int)(bound(0, dist - r_refdef.fog_start, r_refdef.fog_end - r_refdef.fog_start) * r_refdef.fogmasktabledistmultiplier);
+       unsigned int fogmasktableindex = (unsigned int)(dist * r_refdef.fogmasktabledistmultiplier);
        return r_refdef.fogmasktable[min(fogmasktableindex, FOGMASKTABLEWIDTH - 1)];
 }
 
@@ -610,8 +610,6 @@ static const char *builtinshaderstring =
 "uniform float OffsetMapping_Scale;\n"
 "uniform float OffsetMapping_Bias;\n"
 "uniform float FogRangeRecip;\n"
-"uniform float FogStart;\n"
-"uniform float FogLength;\n"
 "\n"
 "uniform myhalf AmbientScale;\n"
 "uniform myhalf DiffuseScale;\n"
@@ -863,8 +861,7 @@ static const char *builtinshaderstring =
 "\n"
 "#ifdef USEFOG\n"
 "      // apply fog\n"
-"      color.rgb = mix(FogColor, color.rgb, myhalf(texture2D(Texture_FogMask, myhvec2(max(0.0, min(length(EyeVectorModelSpace) - FogStart, FogLength))*FogRangeRecip, 0.0))));\n"
-//"      color.rgb = mix(FogColor, color.rgb, myhalf(texture2D(Texture_FogMask, myhvec2(length(EyeVectorModelSpace)*FogRangeRecip, 0.0))));\n"
+"      color.rgb = mix(FogColor, color.rgb, myhalf(texture2D(Texture_FogMask, myhvec2(length(EyeVectorModelSpace)*FogRangeRecip, 0.0))));\n"
 "#endif\n"
 "\n"
 "      gl_FragColor = vec4(color);\n"
@@ -959,8 +956,6 @@ typedef struct r_glsl_permutation_s
        int loc_Color_Pants;
        int loc_Color_Shirt;
        int loc_FogRangeRecip;
-       int loc_FogStart;
-       int loc_FogLength;
        int loc_AmbientScale;
        int loc_DiffuseScale;
        int loc_SpecularScale;
@@ -1092,8 +1087,6 @@ static void R_GLSL_CompilePermutation(const char *filename, int permutation, int
                p->loc_Color_Pants         = qglGetUniformLocationARB(p->program, "Color_Pants");
                p->loc_Color_Shirt         = qglGetUniformLocationARB(p->program, "Color_Shirt");
                p->loc_FogRangeRecip       = qglGetUniformLocationARB(p->program, "FogRangeRecip");
-               p->loc_FogStart            = qglGetUniformLocationARB(p->program, "FogStart");
-               p->loc_FogLength           = qglGetUniformLocationARB(p->program, "FogLength");
                p->loc_AmbientScale        = qglGetUniformLocationARB(p->program, "AmbientScale");
                p->loc_DiffuseScale        = qglGetUniformLocationARB(p->program, "DiffuseScale");
                p->loc_SpecularPower       = qglGetUniformLocationARB(p->program, "SpecularPower");
@@ -1424,8 +1417,6 @@ int R_SetupSurfaceShader(const vec3_t lightcolorbase, qboolean modellighting, fl
                        qglUniform3fARB(r_glsl_permutation->loc_Color_Shirt, 0, 0, 0);
        }
        if (r_glsl_permutation->loc_FogRangeRecip >= 0) qglUniform1fARB(r_glsl_permutation->loc_FogRangeRecip, r_refdef.fograngerecip);
-       if (r_glsl_permutation->loc_FogStart >= 0) qglUniform1fARB(r_glsl_permutation->loc_FogStart, r_refdef.fog_start);
-       if (r_glsl_permutation->loc_FogLength >= 0) qglUniform1fARB(r_glsl_permutation->loc_FogLength, r_refdef.fog_end - r_refdef.fog_start);
        if (r_glsl_permutation->loc_SpecularPower >= 0) qglUniform1fARB(r_glsl_permutation->loc_SpecularPower, rsurface.texture->specularpower);
        if (r_glsl_permutation->loc_OffsetMapping_Scale >= 0) qglUniform1fARB(r_glsl_permutation->loc_OffsetMapping_Scale, r_glsl_offsetmapping_scale.value);
        if (r_glsl_permutation->loc_DistortScaleRefractReflect >= 0) qglUniform4fARB(r_glsl_permutation->loc_DistortScaleRefractReflect, r_water_refractdistort.value * rsurface.texture->refractfactor, r_water_refractdistort.value * rsurface.texture->refractfactor, r_water_reflectdistort.value * rsurface.texture->reflectfactor, r_water_reflectdistort.value * rsurface.texture->reflectfactor);
@@ -3256,12 +3247,8 @@ void R_UpdateVariables(void)
                }
        }
 
-       if (r_refdef.fog_start >= r_refdef.fog_end || r_refdef.fog_start < 0)
-       {
-               r_refdef.fog_start = 0;
-               r_refdef.fog_end = 1000000000;
-               // TODO update fog cvars here too
-       }
+       r_refdef.fog_alpha = min(1, r_refdef.fog_alpha);
+       r_refdef.fog_start = max(0, r_refdef.fog_start);
 
        R_UpdateFogColor();
 
diff --git a/r_sky.c b/r_sky.c
index d897fe398331191a7bdac4543ebb9423347b25b3..449adb88d66b11631c997b2f9442c1a07a89d261 100644 (file)
--- a/r_sky.c
+++ b/r_sky.c
@@ -56,7 +56,7 @@ void R_SkyStartFrame(void)
        skyrendersphere = false;
        skyrenderbox = false;
        skyrendermasked = false;
-       if (r_sky.integer && !(r_refdef.fogenabled && r_refdef.fog_end >= 1000000000))
+       if (r_sky.integer && !(r_refdef.fogenabled && r_refdef.fog_alpha < 1))
        {
                if (skyboxside[0] || skyboxside[1] || skyboxside[2] || skyboxside[3] || skyboxside[4] || skyboxside[5])
                        skyrenderbox = true;
@@ -290,7 +290,7 @@ static void R_SkyBox(void)
        if(r_refdef.fogenabled)
        {
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-               GL_Color(r_refdef.fogcolor[0], r_refdef.fogcolor[1], r_refdef.fogcolor[2], 1 - FogForDistance(r_refdef.fog_end));
+               GL_Color(r_refdef.fogcolor[0], r_refdef.fogcolor[1], r_refdef.fogcolor[2], r_refdef.fog_alpha);
                for (i = 0;i < 6;i++)
                {
                        R_Mesh_TexBind(0, 0);
@@ -425,7 +425,7 @@ static void R_SkySphere(void)
        {
                R_Mesh_TexBind(0, 0);
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-               GL_Color(r_refdef.fogcolor[0], r_refdef.fogcolor[1], r_refdef.fogcolor[2], 1 - FogForDistance(r_refdef.fog_end));
+               GL_Color(r_refdef.fogcolor[0], r_refdef.fogcolor[1], r_refdef.fogcolor[2], r_refdef.fog_alpha);
                GL_LockArrays(0, skysphere_numverts);
                R_Mesh_Draw(0, skysphere_numverts, skysphere_numtriangles, skysphere_element3i, 0, 0);
                GL_LockArrays(0, 0);