From: vortex Date: Tue, 22 Mar 2011 15:15:59 +0000 (+0000) Subject: GLSL shader: make dp_waterscroll work with dp_reflect and dp_refract X-Git-Tag: xonotic-v0.6.0~163^2~588 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=dbd8e60c7e473f960271f3f52d66382e205001db;p=xonotic%2Fdarkplaces.git GLSL shader: make dp_waterscroll work with dp_reflect and dp_refract git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10958 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/gl_rmain.c b/gl_rmain.c index 5ea6bb04..f60e7e2b 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -2072,14 +2072,14 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, r_waterstate_waterplane_t *waterplane = (r_waterstate_waterplane_t *)surfacewaterplane; if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST) permutation |= SHADERPERMUTATION_ALPHAKILL; + if (rsurface.texture->r_water_waterscroll[0] && rsurface.texture->r_water_waterscroll[1]) + permutation |= SHADERPERMUTATION_NORMALMAPSCROLLBLEND; // todo: make generic if (rsurfacepass == RSURFPASS_BACKGROUND) { // distorted background if (rsurface.texture->currentmaterialflags & MATERIALFLAG_WATERSHADER) { mode = SHADERMODE_WATER; - if (rsurface.texture->r_water_waterscroll[0] && rsurface.texture->r_water_waterscroll[1]) - permutation |= SHADERPERMUTATION_NORMALMAPSCROLLBLEND; if((r_wateralpha.value < 1) && (rsurface.texture->currentmaterialflags & MATERIALFLAG_WATERALPHA)) { // this is the right thing to do for wateralpha diff --git a/shader_glsl.h b/shader_glsl.h index 0d4d3b5f..1b0c1b18 100644 --- a/shader_glsl.h +++ b/shader_glsl.h @@ -355,13 +355,23 @@ "uniform mediump vec4 ReflectColor;\n" "uniform mediump float ReflectFactor;\n" "uniform mediump float ReflectOffset;\n" +"uniform highp float ClientTime;\n" +"#ifdef USENORMALMAPSCROLLBLEND\n" +"uniform highp vec2 NormalmapScrollBlend;\n" +"#endif\n" "\n" "void main(void)\n" "{\n" " vec2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n" " //vec2 ScreenTexCoord = (ModelViewProjectionPosition.xy + normalize(vec3(dp_texture2D(Texture_Normal, TexCoord)) - vec3(0.5)).xy * DistortScaleRefractReflect.xy * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n" " vec2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n" -" vec2 ScreenTexCoord = SafeScreenTexCoord + vec2(normalize(vec3(dp_texture2D(Texture_Normal, TexCoord)) - vec3(0.5))).xy * DistortScaleRefractReflect.xy;\n" +" #ifdef USENORMALMAPSCROLLBLEND\n" +" vec3 normal = dp_texture2D(Texture_Normal, (TexCoord + vec2(0.08, 0.08)*ClientTime*NormalmapScrollBlend.x*0.5)*NormalmapScrollBlend.y).rgb - vec3(1.0);\n" +" normal += dp_texture2D(Texture_Normal, (TexCoord + vec2(-0.06, -0.09)*ClientTime*NormalmapScrollBlend.x)*NormalmapScrollBlend.y*0.75).rgb;\n" +" vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(myhalf3(normal))).xy * DistortScaleRefractReflect.zw;\n" +" #else\n" +" vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(myhalf3(offsetMappedTexture2D(Texture_Normal)) - myhalf3(0.5))).xy * DistortScaleRefractReflect.zw;\n" +" #endif\n" " // FIXME temporary hack to detect the case that the reflection\n" " // gets blackened at edges due to leaving the area that contains actual\n" " // content.\n" @@ -1064,6 +1074,10 @@ "uniform sampler3D Texture_BounceGrid;\n" "uniform float BounceGridIntensity;\n" "#endif\n" +"uniform highp float ClientTime;\n" +"#ifdef USENORMALMAPSCROLLBLEND\n" +"uniform highp vec2 NormalmapScrollBlend;\n" +"#endif\n" "void main(void)\n" "{\n" "#ifdef USEOFFSETMAPPING\n" @@ -1072,8 +1086,10 @@ " vec2 dPdy = dp_offsetmapping_dFdy(TexCoordSurfaceLightmap.xy);\n" " vec2 TexCoordOffset = OffsetMapping(TexCoordSurfaceLightmap.xy, dPdx, dPdy);\n" "# define offsetMappedTexture2D(t) dp_textureGrad(t, TexCoordOffset, dPdx, dPdy)\n" +"# define TexCoord TexCoordOffset\n" "#else\n" "# define offsetMappedTexture2D(t) dp_texture2D(t, TexCoordSurfaceLightmap.xy)\n" +"# define TexCoord TexCoordSurfaceLightmap.xy\n" "#endif\n" "\n" " // combine the diffuse textures (base, pants, shirt)\n" @@ -1281,7 +1297,13 @@ " vec4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n" " //vec4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(myhalf3(offsetMappedTexture2D(Texture_Normal)) - myhalf3(0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n" " vec2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW.zw + ScreenCenterRefractReflect.zw;\n" -" vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(myhalf3(offsetMappedTexture2D(Texture_Normal)) - myhalf3(0.5))).xy * DistortScaleRefractReflect.zw;\n" +" #ifdef USENORMALMAPSCROLLBLEND\n" +" vec3 normal = dp_texture2D(Texture_Normal, (TexCoord + vec2(0.08, 0.08)*ClientTime*NormalmapScrollBlend.x*0.5)*NormalmapScrollBlend.y).rgb - vec3(1.0);\n" +" normal += dp_texture2D(Texture_Normal, (TexCoord + vec2(-0.06, -0.09)*ClientTime*NormalmapScrollBlend.x)*NormalmapScrollBlend.y*0.75).rgb;\n" +" vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(myhalf3(normal))).xy * DistortScaleRefractReflect.zw;\n" +" #else\n" +" vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(myhalf3(offsetMappedTexture2D(Texture_Normal)) - myhalf3(0.5))).xy * DistortScaleRefractReflect.zw;\n" +" #endif\n" " // FIXME temporary hack to detect the case that the reflection\n" " // gets blackened at edges due to leaving the area that contains actual\n" " // content.\n"