]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
changed reflect/refract keywords to
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 7 Oct 2007 09:04:05 +0000 (09:04 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 7 Oct 2007 09:04:05 +0000 (09:04 +0000)
  dp_reflect <r> <g> <b>
  dp_refract <reflectmin> <reflectmax> <distort> <r> <g> <b>
made dp_reflect work additively again (so perfect mirrors shall use a black texture)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7606 d7cf8633-e32d-0410-b094-e92efae38249

darkplaces.txt
gl_rmain.c
model_brush.c
model_shared.c
model_shared.h
render.h

index 3ecf90a4ab7a5f9def4f0205754a85b498b711c2..666475e40ab706312781877201f03a53dc9bd43a 100644 (file)
@@ -1312,12 +1312,16 @@ Ludwig Nussel for the ~/.games/darkplaces/ user directory support on non-Windows
 \r
 \r
 Shader parameters for DP's own features:\r
 \r
 \r
 Shader parameters for DP's own features:\r
-- dp_reflect <factor> <r> <g> <b>\r
-  Makes surfaces of this shader reflective with r_glsl_water. Factor is a\r
-  reflectiveness factor from 0 to 1, the rest is the color of the reflection.\r
-  Unspecified values get set to 1 (that is, standard water parameters).\r
-- dp_refract <factor> <r> <g> <b>\r
+- dp_reflect <r> <g> <b>\r
+  Makes surfaces of this shader reflective with r_glsl_water. The reflection is\r
+  additive. When the color isn't specified, it defaults to white (full\r
+  reflection). If only one color component is specified, it counts as a grey\r
+  value.\r
+- dp_refract <reflectmin> <reflectmax> <distort> <r> <g> <b>\r
   Marks a surface as "water" for r_glsl_water, that is, add a refraction\r
   Marks a surface as "water" for r_glsl_water, that is, add a refraction\r
-  component too. The factor defines how strong the distorts by the refraction\r
-  are (default: 1.0). Unspecified values get set to 1 (that is, standard water\r
-  parameters).\r
+  component too. The reflection amount (see dp_reflect) is at least reflectmin\r
+  (when looking straight into it) and at most reflectmax (when looking parallel\r
+  to thhe surface). The default distort is multiplied by distort. The color\r
+  modulates the refraction component. reflectmin defaults to 0 when unspecified,\r
+  all others default to 1. If only one color component is specified, it counts\r
+  as a grey value.\r
index b1f55d19284187c5ec3c524479924ce0f0fb4dea..50b1d41cc42e3949fbd421002a2edc5c08bef1ff 100644 (file)
@@ -572,6 +572,7 @@ static const char *builtinshaderstring =
 "uniform myhvec3 RefractColor;\n"
 "uniform myhvec3 ReflectColor;\n"
 "uniform myhalf ReflectFactor;\n"
 "uniform myhvec3 RefractColor;\n"
 "uniform myhvec3 ReflectColor;\n"
 "uniform myhalf ReflectFactor;\n"
+"uniform myhalf ReflectOffset;\n"
 "//#else\n"
 "//# ifdef USEREFLECTION\n"
 "//uniform vec4 DistortScaleRefractReflect;\n"
 "//#else\n"
 "//# ifdef USEREFLECTION\n"
 "//uniform vec4 DistortScaleRefractReflect;\n"
@@ -779,14 +780,14 @@ static const char *builtinshaderstring =
 "      vec4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n"
 "      //vec4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(myhvec3(texture2D(Texture_Normal, TexCoord)) - myhvec3(0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
 "      vec4 ScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect + vec3(normalize(myhvec3(texture2D(Texture_Normal, TexCoord)) - myhvec3(0.5))).xyxy * DistortScaleRefractReflect;\n"
 "      vec4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n"
 "      //vec4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(myhvec3(texture2D(Texture_Normal, TexCoord)) - myhvec3(0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
 "      vec4 ScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect + vec3(normalize(myhvec3(texture2D(Texture_Normal, TexCoord)) - myhvec3(0.5))).xyxy * DistortScaleRefractReflect;\n"
-"      myhalf Fresnel = myhalf(pow(min(1.0, 1.0 - float(normalize(EyeVector).z)), 2.0)) * ReflectFactor;\n"
+"      myhalf Fresnel = myhalf(pow(min(1.0, 1.0 - float(normalize(EyeVector).z)), 2.0)) * ReflectFactor + ReflectOffset;\n"
 "      color.rgb = mix(mix(myhvec3(texture2D(Texture_Refraction, ScreenTexCoord.xy)) * RefractColor, myhvec3(texture2D(Texture_Reflection, ScreenTexCoord.zw)) * ReflectColor, Fresnel), color.rgb, color.a);\n"
 "# else\n"
 "#  ifdef USEREFLECTION\n"
 "      vec4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n"
 "      //vec4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(myhvec3(texture2D(Texture_Normal, TexCoord)) - myhvec3(0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
 "      vec4 ScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect + vec3(normalize(myhvec3(texture2D(Texture_Normal, TexCoord)) - myhvec3(0.5))).xyxy * DistortScaleRefractReflect;\n"
 "      color.rgb = mix(mix(myhvec3(texture2D(Texture_Refraction, ScreenTexCoord.xy)) * RefractColor, myhvec3(texture2D(Texture_Reflection, ScreenTexCoord.zw)) * ReflectColor, Fresnel), color.rgb, color.a);\n"
 "# else\n"
 "#  ifdef USEREFLECTION\n"
 "      vec4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n"
 "      //vec4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(myhvec3(texture2D(Texture_Normal, TexCoord)) - myhvec3(0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
 "      vec4 ScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect + vec3(normalize(myhvec3(texture2D(Texture_Normal, TexCoord)) - myhvec3(0.5))).xyxy * DistortScaleRefractReflect;\n"
-"      color.rgb = mix(color.rgb, myhvec3(texture2D(Texture_Reflection, ScreenTexCoord.zw)), ReflectFactor);\n"
+"      color.rgb += myhvec3(texture2D(Texture_Reflection, ScreenTexCoord.zw)) * ReflectColor;\n"
 "#  endif\n"
 "# endif\n"
 "#endif\n"
 "#  endif\n"
 "# endif\n"
 "#endif\n"
@@ -947,6 +948,7 @@ void R_GLSL_CompilePermutation(const char *filename, int permutation)
                p->loc_RefractColor        = qglGetUniformLocationARB(p->program, "RefractColor");
                p->loc_ReflectColor        = qglGetUniformLocationARB(p->program, "ReflectColor");
                p->loc_ReflectFactor       = qglGetUniformLocationARB(p->program, "ReflectFactor");
                p->loc_RefractColor        = qglGetUniformLocationARB(p->program, "RefractColor");
                p->loc_ReflectColor        = qglGetUniformLocationARB(p->program, "ReflectColor");
                p->loc_ReflectFactor       = qglGetUniformLocationARB(p->program, "ReflectFactor");
+               p->loc_ReflectOffset       = qglGetUniformLocationARB(p->program, "ReflectOffset");
                // initialize the samplers to refer to the texture units we use
                if (p->loc_Texture_Normal >= 0)    qglUniform1iARB(p->loc_Texture_Normal, 0);
                if (p->loc_Texture_Color >= 0)     qglUniform1iARB(p->loc_Texture_Color, 1);
                // initialize the samplers to refer to the texture units we use
                if (p->loc_Texture_Normal >= 0)    qglUniform1iARB(p->loc_Texture_Normal, 0);
                if (p->loc_Texture_Color >= 0)     qglUniform1iARB(p->loc_Texture_Color, 1);
@@ -1273,7 +1275,8 @@ int R_SetupSurfaceShader(const vec3_t lightcolorbase, qboolean modellighting, fl
        if (r_glsl_permutation->loc_ScreenCenterRefractReflect >= 0) qglUniform4fARB(r_glsl_permutation->loc_ScreenCenterRefractReflect, r_waterstate.screencenter[0], r_waterstate.screencenter[1], r_waterstate.screencenter[0], r_waterstate.screencenter[1]);
        if (r_glsl_permutation->loc_RefractColor >= 0) qglUniform3fvARB(r_glsl_permutation->loc_RefractColor, 1, rsurface.texture->refractcolor);
        if (r_glsl_permutation->loc_ReflectColor >= 0) qglUniform3fvARB(r_glsl_permutation->loc_ReflectColor, 1, rsurface.texture->reflectcolor);
        if (r_glsl_permutation->loc_ScreenCenterRefractReflect >= 0) qglUniform4fARB(r_glsl_permutation->loc_ScreenCenterRefractReflect, r_waterstate.screencenter[0], r_waterstate.screencenter[1], r_waterstate.screencenter[0], r_waterstate.screencenter[1]);
        if (r_glsl_permutation->loc_RefractColor >= 0) qglUniform3fvARB(r_glsl_permutation->loc_RefractColor, 1, rsurface.texture->refractcolor);
        if (r_glsl_permutation->loc_ReflectColor >= 0) qglUniform3fvARB(r_glsl_permutation->loc_ReflectColor, 1, rsurface.texture->reflectcolor);
-       if (r_glsl_permutation->loc_ReflectFactor >= 0) qglUniform1fARB(r_glsl_permutation->loc_ReflectFactor, rsurface.texture->reflectfactor);
+       if (r_glsl_permutation->loc_ReflectFactor >= 0) qglUniform1fARB(r_glsl_permutation->loc_ReflectFactor, rsurface.texture->reflectmax - rsurface.texture->reflectmin);
+       if (r_glsl_permutation->loc_ReflectOffset >= 0) qglUniform1fARB(r_glsl_permutation->loc_ReflectOffset, rsurface.texture->reflectmin);
        CHECKGLERROR
        return permutation;
 }
        CHECKGLERROR
        return permutation;
 }
index a2bac292786ef0a77ce0ba5fbe1ce00e114177f9..3fe4577751edec9c78cf43e30047b491bc5bcb07 100644 (file)
@@ -1541,7 +1541,8 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                                        tx->basematerialflags |= MATERIALFLAG_WATERALPHA | MATERIALFLAG_NOSHADOW | MATERIALFLAG_WATERSHADER;
                                        VectorSet(tx->reflectcolor, 1, 1, 1);
                                        VectorSet(tx->refractcolor, 1, 1, 1);
                                        tx->basematerialflags |= MATERIALFLAG_WATERALPHA | MATERIALFLAG_NOSHADOW | MATERIALFLAG_WATERSHADER;
                                        VectorSet(tx->reflectcolor, 1, 1, 1);
                                        VectorSet(tx->refractcolor, 1, 1, 1);
-                                       tx->reflectfactor = 1;
+                                       tx->reflectmin = 0;
+                                       tx->reflectmax = 1;
                                        tx->refractfactor = 1;
                                }
                                tx->basematerialflags |= MATERIALFLAG_WATER | MATERIALFLAG_LIGHTBOTHSIDES | MATERIALFLAG_NOSHADOW;
                                        tx->refractfactor = 1;
                                }
                                tx->basematerialflags |= MATERIALFLAG_WATER | MATERIALFLAG_LIGHTBOTHSIDES | MATERIALFLAG_NOSHADOW;
index 655132e785c8ee5b8aa21e99750950e4afa17a04..40673a65461321a6b0ca340a555e3f46c9dfcaf4 100644 (file)
@@ -1137,7 +1137,8 @@ void Mod_LoadQ3Shaders(void)
                        memset(shader, 0, sizeof(*shader));
                        VectorSet(shader->reflectcolor, 1, 1, 1);
                        VectorSet(shader->refractcolor, 1, 1, 1);
                        memset(shader, 0, sizeof(*shader));
                        VectorSet(shader->reflectcolor, 1, 1, 1);
                        VectorSet(shader->refractcolor, 1, 1, 1);
-                       shader->reflectfactor = 1;
+                       shader->reflectmin = 0;
+                       shader->reflectmax = 1;
                        shader->refractfactor = 1;
 
                        strlcpy(shader->name, com_token, sizeof(shader->name));
                        shader->refractfactor = 1;
 
                        strlcpy(shader->name, com_token, sizeof(shader->name));
@@ -1500,17 +1501,23 @@ void Mod_LoadQ3Shaders(void)
                                {
                                        shader->textureflags |= Q3TEXTUREFLAG_REFLECTION;
                                        if(numparameters >= 2)
                                {
                                        shader->textureflags |= Q3TEXTUREFLAG_REFLECTION;
                                        if(numparameters >= 2)
-                                               shader->reflectfactor = atof(parameter[1]);
-                                       if(numparameters >= 5)
-                                               VectorSet(shader->reflectcolor, atof(parameter[2]), atof(parameter[3]), atof(parameter[4]));
+                                               VectorSet(shader->reflectcolor, atof(parameter[1]), atof(parameter[1]), atof(parameter[1])); // grey
+                                       if(numparameters >= 4)
+                                               VectorSet(shader->reflectcolor, atof(parameter[1]), atof(parameter[2]), atof(parameter[3]));
                                }
                                else if (!strcasecmp(parameter[0], "dp_refract"))
                                {
                                        shader->textureflags |= Q3TEXTUREFLAG_WATERSHADER;
                                        if(numparameters >= 2)
                                }
                                else if (!strcasecmp(parameter[0], "dp_refract"))
                                {
                                        shader->textureflags |= Q3TEXTUREFLAG_WATERSHADER;
                                        if(numparameters >= 2)
-                                               shader->refractfactor = atof(parameter[1]);
+                                               shader->reflectmin = atof(parameter[1]);
+                                       if(numparameters >= 3)
+                                               shader->reflectmax = atof(parameter[2]);
+                                       if(numparameters >= 4)
+                                               shader->refractfactor = atof(parameter[3]);
                                        if(numparameters >= 5)
                                        if(numparameters >= 5)
-                                               VectorSet(shader->refractcolor, atof(parameter[2]), atof(parameter[3]), atof(parameter[4]));
+                                               VectorSet(shader->refractcolor, atof(parameter[4]), atof(parameter[4]), atof(parameter[4])); // grey
+                                       if(numparameters >= 7)
+                                               VectorSet(shader->refractcolor, atof(parameter[4]), atof(parameter[5]), atof(parameter[6]));
                                }
                                else if (!strcasecmp(parameter[0], "deformvertexes") && numparameters >= 2)
                                {
                                }
                                else if (!strcasecmp(parameter[0], "deformvertexes") && numparameters >= 2)
                                {
@@ -1715,7 +1722,8 @@ nothing                GL_ZERO GL_ONE
                        }
                }
                memcpy(texture->deforms, shader->deforms, sizeof(texture->deforms));
                        }
                }
                memcpy(texture->deforms, shader->deforms, sizeof(texture->deforms));
-               texture->reflectfactor = shader->reflectfactor;
+               texture->reflectmin = shader->reflectmin;
+               texture->reflectmax = shader->reflectmax;
                texture->refractfactor = shader->refractfactor;
                VectorCopy(shader->reflectcolor, texture->reflectcolor);
                VectorCopy(shader->refractcolor, texture->refractcolor);
                texture->refractfactor = shader->refractfactor;
                VectorCopy(shader->reflectcolor, texture->reflectcolor);
                VectorCopy(shader->refractcolor, texture->refractcolor);
index c4b6fe912ad90857818f121771de51575a9b2614..9c22db62acecfa8754483b930c991e29ed663ad6 100644 (file)
@@ -366,7 +366,8 @@ typedef struct q3shaderinfo_s
        q3shaderinfo_deform_t deforms[Q3MAXDEFORMS];
 
        vec3_t reflectcolor, refractcolor;
        q3shaderinfo_deform_t deforms[Q3MAXDEFORMS];
 
        vec3_t reflectcolor, refractcolor;
-       float reflectfactor; // amount of reflection (1.0 = full, can't be larger)
+       float reflectmin; // when refraction is used, minimum amount of reflection (when looking straight down)
+       float reflectmax; // when refraction is used, maximum amount of reflection (when looking parallel to water)
        float refractfactor; // amount of refraction distort (1.0 = like the cvar specifies; note that reflection distort is not configurable because that's what the bumpmap should do)
 }
 q3shaderinfo_t;
        float refractfactor; // amount of refraction distort (1.0 = like the cvar specifies; note that reflection distort is not configurable because that's what the bumpmap should do)
 }
 q3shaderinfo_t;
@@ -483,7 +484,8 @@ typedef struct texture_s
 
        // reflection
        vec3_t reflectcolor, refractcolor;
 
        // reflection
        vec3_t reflectcolor, refractcolor;
-       float reflectfactor; // amount of reflection (1.0 = full, can't be larger)
+       float reflectmin; // when refraction is used, minimum amount of reflection (when looking straight down)
+       float reflectmax; // when refraction is used, maximum amount of reflection (when looking parallel to water)
        float refractfactor; // amount of refraction distort (1.0 = like the cvar specifies; note that reflection distort is not configurable because that's what the bumpmap should do)
 }
 texture_t;
        float refractfactor; // amount of refraction distort (1.0 = like the cvar specifies; note that reflection distort is not configurable because that's what the bumpmap should do)
 }
 texture_t;
index fa024207b144bc2d0c0de8c1da46c4c90ff187ae..35e52c2e2e0c20fedbe5ffec1df6cdc85177ffb5 100644 (file)
--- a/render.h
+++ b/render.h
@@ -428,6 +428,7 @@ typedef struct r_glsl_permutation_s
        int loc_RefractColor;
        int loc_ReflectColor;
        int loc_ReflectFactor;
        int loc_RefractColor;
        int loc_ReflectColor;
        int loc_ReflectFactor;
+       int loc_ReflectOffset;
 }
 r_glsl_permutation_t;
 
 }
 r_glsl_permutation_t;