From aedfdd0cff82513661894fbf7c696f5922171d85 Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 19 Apr 2007 12:50:45 +0000 Subject: [PATCH] significant cleanup of reliefmapping shader, now uses step() function instead of if's, this might improve compatibility with ATI cards, but not sure, in any case I improved the stepping math a little bit which saves some time, minor fps improvement on reliefmapping compared to before git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7142 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rmain.c | 71 +++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/gl_rmain.c b/gl_rmain.c index bfef3c49..dd059df3 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -147,9 +147,6 @@ r_glsl_permutation_t r_glsl_permutations[SHADERPERMUTATION_MAX]; // currently selected permutation r_glsl_permutation_t *r_glsl_permutation; -// temporary variable used by a macro -int fogtableindex; - // vertex coordinates for a quad that covers the screen exactly const static float r_screenvertex3f[12] = { @@ -511,50 +508,55 @@ static const char *builtinshaderstring = "uniform myhalf SpecularScale;\n" "uniform myhalf SpecularPower;\n" "\n" +"#ifdef USEOFFSETMAPPING\n" "vec2 OffsetMapping(vec2 TexCoord)\n" "{\n" -" vec3 eyedir = vec3(normalize(EyeVector));\n" -" float depthbias = 1.0 - eyedir.z; // should this be a -?\n" -" depthbias = 1.0 - depthbias * depthbias;\n" -"\n" "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n" " // 14 sample relief mapping: linear search and then binary search\n" -" //vec3 OffsetVector = vec3(EyeVector.xy * (1.0 / EyeVector.z) * depthbias * OffsetMapping_Scale * vec2(-0.1, 0.1), -0.1);\n" -" //vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMapping_Scale * vec2(-0.1, 0.1), -0.1);\n" -" vec3 OffsetVector = vec3(eyedir.xy * OffsetMapping_Scale * vec2(-0.1, 0.1), -0.1);\n" -" vec3 RT = vec3(TexCoord - OffsetVector.xy * 10.0, 1.0) + OffsetVector;\n" -" if (RT.z > texture2D(Texture_Normal, RT.xy).a) RT += OffsetVector;\n" -" if (RT.z > texture2D(Texture_Normal, RT.xy).a) RT += OffsetVector;\n" -" if (RT.z > texture2D(Texture_Normal, RT.xy).a) RT += OffsetVector;\n" -" if (RT.z > texture2D(Texture_Normal, RT.xy).a) RT += OffsetVector;\n" -" if (RT.z > texture2D(Texture_Normal, RT.xy).a) RT += OffsetVector;\n" -" if (RT.z > texture2D(Texture_Normal, RT.xy).a) RT += OffsetVector;\n" -" if (RT.z > texture2D(Texture_Normal, RT.xy).a) RT += OffsetVector;\n" -" if (RT.z > texture2D(Texture_Normal, RT.xy).a) RT += OffsetVector;\n" -" if (RT.z > texture2D(Texture_Normal, RT.xy).a) RT += OffsetVector;OffsetVector *= 0.5;RT -= OffsetVector;\n" -" if (RT.z > texture2D(Texture_Normal, RT.xy).a) RT += OffsetVector;OffsetVector *= 0.5;RT -= OffsetVector;\n" -" if (RT.z > texture2D(Texture_Normal, RT.xy).a) RT += OffsetVector;OffsetVector *= 0.5;RT -= OffsetVector;\n" -" if (RT.z > texture2D(Texture_Normal, RT.xy).a) RT += OffsetVector;OffsetVector *= 0.5;RT -= OffsetVector;\n" -" if (RT.z > texture2D(Texture_Normal, RT.xy).a) RT += OffsetVector;OffsetVector *= 0.5;RT -= OffsetVector;\n" -" if (RT.z > texture2D(Texture_Normal, RT.xy).a) RT += OffsetVector;OffsetVector *= 0.5;RT -= OffsetVector;\n" -" TexCoord = RT.xy;\n" +" // this basically steps forward a small amount repeatedly until it finds\n" +" // itself inside solid, then jitters forward and back using decreasing\n" +" // amounts to find the impact\n" +" //vec3 OffsetVector = vec3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMapping_Scale) * vec2(-1, 1), -1);\n" +" //vec3 OffsetVector = vec3(normalize(EyeVector.xy) * OffsetMapping_Scale * vec2(-1, 1), -1);\n" +" vec3 OffsetVector = vec3(normalize(EyeVector).xy * OffsetMapping_Scale * vec2(-1, 1), -1);\n" +" vec3 RT = vec3(TexCoord, 1);\n" +" OffsetVector *= 0.1;\n" +" RT += OffsetVector * step(texture2D(Texture_Normal, RT.xy).a, RT.z);\n" +" RT += OffsetVector * step(texture2D(Texture_Normal, RT.xy).a, RT.z);\n" +" RT += OffsetVector * step(texture2D(Texture_Normal, RT.xy).a, RT.z);\n" +" RT += OffsetVector * step(texture2D(Texture_Normal, RT.xy).a, RT.z);\n" +" RT += OffsetVector * step(texture2D(Texture_Normal, RT.xy).a, RT.z);\n" +" RT += OffsetVector * step(texture2D(Texture_Normal, RT.xy).a, RT.z);\n" +" RT += OffsetVector * step(texture2D(Texture_Normal, RT.xy).a, RT.z);\n" +" RT += OffsetVector * step(texture2D(Texture_Normal, RT.xy).a, RT.z);\n" +" RT += OffsetVector * step(texture2D(Texture_Normal, RT.xy).a, RT.z);\n" +" RT += OffsetVector * (step(texture2D(Texture_Normal, RT.xy).a, RT.z) - 0.5);\n" +" RT += OffsetVector * (step(texture2D(Texture_Normal, RT.xy).a, RT.z) * 0.5 - 0.25);\n" +" RT += OffsetVector * (step(texture2D(Texture_Normal, RT.xy).a, RT.z) * 0.25 - 0.125);\n" +" RT += OffsetVector * (step(texture2D(Texture_Normal, RT.xy).a, RT.z) * 0.125 - 0.0625);\n" +" RT += OffsetVector * (step(texture2D(Texture_Normal, RT.xy).a, RT.z) * 0.0625 - 0.03125);\n" +" return RT.xy;\n" "#else\n" " // 3 sample offset mapping (only 3 samples because of ATI Radeon 9500-9800/X300 limits)\n" -" //vec2 OffsetVector = vec2(EyeVector.xy * (1.0 / EyeVector.z) * depthbias) * OffsetMapping_Scale * vec2(-0.333, 0.333);\n" -" //vec2 OffsetVector = vec2(normalize(EyeVector.xy)) * OffsetMapping_Scale * vec2(-0.333, 0.333);\n" -" vec2 OffsetVector = vec2(eyedir.xy) * OffsetMapping_Scale * vec2(-0.333, 0.333);\n" -" //TexCoord += OffsetVector * 3.0;\n" +" // this basically moves forward the full distance, and then backs up based\n" +" // on height of samples\n" +" //vec2 OffsetVector = vec2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMapping_Scale) * vec2(-1, 1));\n" +" //vec2 OffsetVector = vec2(normalize(EyeVector.xy) * OffsetMapping_Scale * vec2(-1, 1));\n" +" vec2 OffsetVector = vec2(normalize(EyeVector).xy * OffsetMapping_Scale * vec2(-1, 1));\n" +" TexCoord += OffsetVector;\n" +" OffsetVector *= 0.333;\n" " TexCoord -= OffsetVector * texture2D(Texture_Normal, TexCoord).a;\n" " TexCoord -= OffsetVector * texture2D(Texture_Normal, TexCoord).a;\n" " TexCoord -= OffsetVector * texture2D(Texture_Normal, TexCoord).a;\n" -"#endif\n" " return TexCoord;\n" +"#endif\n" "}\n" +"#endif\n" "\n" "void main(void)\n" "{\n" -" // apply offsetmapping\n" "#ifdef USEOFFSETMAPPING\n" +" // apply offsetmapping\n" " vec2 TexCoordOffset = OffsetMapping(TexCoord);\n" "#define TexCoord TexCoordOffset\n" "#endif\n" @@ -588,7 +590,7 @@ static const char *builtinshaderstring = " myhvec3 diffusenormal = myhvec3(normalize(LightVector));\n" "\n" " // calculate directional shading\n" -" color.rgb = LightColor * myhalf(texture2D(Texture_Attenuation, vec2(length(CubeVector), 0.0))) * color.rgb * (AmbientScale + DiffuseScale * myhalf(max(float(dot(surfacenormal, diffusenormal)), 0.0)));\n" +" color.rgb = color.rgb * LightColor * (myhalf(texture2D(Texture_Attenuation, vec2(length(CubeVector), 0.0))) * (AmbientScale + DiffuseScale * myhalf(max(float(dot(surfacenormal, diffusenormal)), 0.0))));\n" "#else\n" " // calculate directionless shading\n" " color.rgb = color.rgb * LightColor * myhalf(texture2D(Texture_Attenuation, vec2(length(CubeVector), 0.0)));\n" @@ -657,8 +659,7 @@ static const char *builtinshaderstring = "\n" "#ifdef USEFOG\n" " // apply fog\n" -" myhalf fog = myhalf(texture2D(Texture_FogMask, myhvec2(length(EyeVectorModelSpace)*FogRangeRecip, 0.0)).x);\n" -" color.rgb = color.rgb * fog + FogColor * (1.0 - fog);\n" +" color.rgb = mix(FogColor, color.rgb, myhalf(texture2D(Texture_FogMask, myhvec2(length(EyeVectorModelSpace)*FogRangeRecip, 0.0))));\n" "#endif\n" "\n" " color.rgb *= SceneBrightness;\n" -- 2.39.2