From: vortex Date: Wed, 13 Oct 2010 22:00:16 +0000 (+0000) Subject: Added dp_waterscroll shader keyword as simple simulation of water... X-Git-Tag: xonotic-v0.1.0preview~123 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=14b74355cc0617d6f02ad26d4221523e76df3e3f;p=xonotic%2Fdarkplaces.git Added dp_waterscroll shader keyword as simple simulation of water movement, use with dp_water. Works only with r_water 1. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10530 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=c5ff9341efbe92ce3c66b5c6f744a6efe49823fa --- diff --git a/gl_rmain.c b/gl_rmain.c index 12d225c7..bf1c1f13 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -937,6 +937,9 @@ static const char *builtinshaderstring = "uniform float ReflectFactor;\n" "uniform float ReflectOffset;\n" "uniform float ClientTime;\n" +"#ifdef USENORMALMAPSCROLLBLEND\n" +"uniform vec2 NormalmapScrollBlend;\n" +"#endif\n" "\n" "void main(void)\n" "{\n" @@ -945,9 +948,13 @@ static const char *builtinshaderstring = " vec4 SafeScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n" " //SafeScreenTexCoord = gl_FragCoord.xyxy * vec4(1.0 / 1920.0, 1.0 / 1200.0, 1.0 / 1920.0, 1.0 / 1200.0);\n" " // slight water animation via 2 layer scrolling (todo: tweak)\n" -" vec3 normal = texture2D(Texture_Normal, TexCoord + vec2(0.08, 0.08)*ClientTime*0.5).rgb - vec3(1.0);\n" -" normal += texture2D(Texture_Normal, (TexCoord + vec2(-0.06, -0.09)*ClientTime)*0.75).rgb;\n" -" vec4 ScreenTexCoord = SafeScreenTexCoord + vec2(normalize(normal) + vec3(0.15)).xyxy * DistortScaleRefractReflect;\n" +" #ifdef USENORMALMAPSCROLLBLEND\n" +" vec3 normal = texture2D(Texture_Normal, (TexCoord + vec2(0.08, 0.08)*ClientTime*NormalmapScrollBlend.x*0.5)*NormalmapScrollBlend.y).rgb - vec3(1.0);\n" +" normal += texture2D(Texture_Normal, (TexCoord + vec2(-0.06, -0.09)*ClientTime*NormalmapScrollBlend.x)*NormalmapScrollBlend.y*0.75).rgb;\n" +" vec4 ScreenTexCoord = SafeScreenTexCoord + vec2(normalize(normal) + vec3(0.15)).xyxy * DistortScaleRefractReflect;\n" +" #else\n" +" vec4 ScreenTexCoord = SafeScreenTexCoord + vec2(normalize(vec3(texture2D(Texture_Normal, TexCoord)) - vec3(0.5))).xyxy * DistortScaleRefractReflect;\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" @@ -3411,8 +3418,9 @@ typedef enum shaderpermutation_e SHADERPERMUTATION_DEFERREDLIGHTMAP = 1<<26, ///< (lightmap) read Texture_ScreenDiffuse/Specular textures and add them on top of lightmapping SHADERPERMUTATION_ALPHAKILL = 1<<27, ///< (deferredgeometry) discard pixel if diffuse texture alpha below 0.5 SHADERPERMUTATION_REFLECTCUBE = 1<<28, ///< fake reflections using global cubemap (not HDRI light probe) - SHADERPERMUTATION_LIMIT = 1<<29, ///< size of permutations array - SHADERPERMUTATION_COUNT = 29 ///< size of shaderpermutationinfo array + SHADERPERMUTATION_NORMALMAPSCROLLBLEND = 1<<29, // (water) counter-direction normalmaps scrolling + SHADERPERMUTATION_LIMIT = 1<<30, ///< size of permutations array + SHADERPERMUTATION_COUNT = 30 ///< size of shaderpermutationinfo array } shaderpermutation_t; @@ -3448,6 +3456,7 @@ shaderpermutationinfo_t shaderpermutationinfo[SHADERPERMUTATION_COUNT] = {"#define USEDEFERREDLIGHTMAP\n", " deferredlightmap"}, {"#define USEALPHAKILL\n", " alphakill"}, {"#define USEREFLECTCUBE\n", " reflectcube"}, + {"#define USENORMALMAPSCROLLBLEND\n", " normalmapscrollblend"}, }; /// this enum is multiplied by SHADERPERMUTATION_MODEBASE @@ -3611,6 +3620,7 @@ typedef struct r_glsl_permutation_s int loc_PixelToScreenTexCoord; int loc_ModelToReflectCube; int loc_ShadowMapMatrix; + int loc_NormalmapScrollBlend; } r_glsl_permutation_t; @@ -3853,6 +3863,7 @@ static void R_GLSL_CompilePermutation(r_glsl_permutation_t *p, unsigned int mode p->loc_PixelToScreenTexCoord = qglGetUniformLocationARB(p->program, "PixelToScreenTexCoord"); p->loc_ModelToReflectCube = qglGetUniformLocationARB(p->program, "ModelToReflectCube"); p->loc_ShadowMapMatrix = qglGetUniformLocationARB(p->program, "ShadowMapMatrix"); + p->loc_NormalmapScrollBlend = qglGetUniformLocationARB(p->program, "NormalmapScrollBlend"); // initialize the samplers to refer to the texture units we use if (p->loc_Texture_First >= 0) qglUniform1iARB(p->loc_Texture_First , GL20TU_FIRST); if (p->loc_Texture_Second >= 0) qglUniform1iARB(p->loc_Texture_Second , GL20TU_SECOND); @@ -4047,6 +4058,7 @@ typedef struct r_cg_permutation_s CGparameter fp_ViewToLight; CGparameter fp_PixelToScreenTexCoord; CGparameter fp_ModelToReflectCube; + CGparameter fp_NormalmapScrollBlend; } r_cg_permutation_t; @@ -4349,6 +4361,7 @@ static void R_CG_CompilePermutation(r_cg_permutation_t *p, unsigned int mode, un p->fp_ViewToLight = cgGetNamedParameter(p->fprogram, "ViewToLight"); p->fp_PixelToScreenTexCoord = cgGetNamedParameter(p->fprogram, "PixelToScreenTexCoord"); p->fp_ModelToReflectCube = cgGetNamedParameter(p->fprogram, "ModelToReflectCube"); + p->fp_NormalmapScrollBlend = cgGetNamedParameter(p->fprogram, "NormalmapScrollBlend"); CHECKCGERROR } @@ -4759,6 +4772,8 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, 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; GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); allow_colormod = R_BlendFuncAllowsColormod(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } @@ -5293,6 +5308,7 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, 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); if (r_glsl_permutation->loc_SpecularPower >= 0) qglUniform1fARB(r_glsl_permutation->loc_SpecularPower, rsurface.texture->specularpower * ((permutation & SHADERPERMUTATION_EXACTSPECULARMATH) ? 0.25f : 1.0f)); + if (r_glsl_permutation->loc_NormalmapScrollBlend >= 0) qglUniform2fARB(r_glsl_permutation->loc_NormalmapScrollBlend, rsurface.texture->r_water_waterscroll[0], rsurface.texture->r_water_waterscroll[1]); } if (r_glsl_permutation->loc_TexMatrix >= 0) {Matrix4x4_ToArrayFloatGL(&rsurface.texture->currenttexmatrix, m16f);qglUniformMatrix4fvARB(r_glsl_permutation->loc_TexMatrix, 1, false, m16f);} if (r_glsl_permutation->loc_BackgroundTexMatrix >= 0) {Matrix4x4_ToArrayFloatGL(&rsurface.texture->currentbackgroundtexmatrix, m16f);qglUniformMatrix4fvARB(r_glsl_permutation->loc_BackgroundTexMatrix, 1, false, m16f);} @@ -5441,6 +5457,7 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, if (r_cg_permutation->fp_ReflectFactor) cgGLSetParameter1f(r_cg_permutation->fp_ReflectFactor, rsurface.texture->reflectmax - rsurface.texture->reflectmin);CHECKCGERROR if (r_cg_permutation->fp_ReflectOffset) cgGLSetParameter1f(r_cg_permutation->fp_ReflectOffset, rsurface.texture->reflectmin);CHECKCGERROR if (r_cg_permutation->fp_SpecularPower) cgGLSetParameter1f(r_cg_permutation->fp_SpecularPower, rsurface.texture->specularpower * ((permutation & SHADERPERMUTATION_EXACTSPECULARMATH) ? 0.25f : 1.0f));CHECKCGERROR + if (r_cg_permutation->fp_NormalmapScrollBlend) cgGLSetParameter2f(r_cg_permutation->fp_NormalmapScrollBlend, rsurface.texture->r_water_waterscroll[0], rsurface.texture->r_water_waterscroll[1]); } if (r_cg_permutation->fp_ShadowMap_TextureScale) cgGLSetParameter2f(r_cg_permutation->fp_ShadowMap_TextureScale, r_shadow_shadowmap_texturescale[0], r_shadow_shadowmap_texturescale[1]);CHECKCGERROR if (r_cg_permutation->fp_ShadowMap_Parameters) cgGLSetParameter4f(r_cg_permutation->fp_ShadowMap_Parameters, r_shadow_shadowmap_parameters[0], r_shadow_shadowmap_parameters[1], r_shadow_shadowmap_parameters[2], r_shadow_shadowmap_parameters[3]);CHECKCGERROR diff --git a/model_shared.c b/model_shared.c index 9374b669..400dfc57 100644 --- a/model_shared.c +++ b/model_shared.c @@ -2070,6 +2070,11 @@ void Mod_LoadQ3Shaders(void) Vector4Set(shader.reflectcolor4f, atof(parameter[8]), atof(parameter[9]), atof(parameter[10]), 1); shader.r_water_wateralpha = atof(parameter[11]); } + else if (!strcasecmp(parameter[0], "dpwaterscroll") && numparameters >= 3) + { + shader.r_water_waterscroll[0] = 1/atof(parameter[1]); + shader.r_water_waterscroll[1] = 1/atof(parameter[2]); + } else if (!strcasecmp(parameter[0], "dpglossintensitymod") && numparameters >= 2) { shader.specularscalemod = atof(parameter[1]); @@ -2350,6 +2355,7 @@ nothing GL_ZERO GL_ONE texture->reflectfactor = shader->reflectfactor; Vector4Copy(shader->reflectcolor4f, texture->reflectcolor4f); texture->r_water_wateralpha = shader->r_water_wateralpha; + Vector2Copy(shader->r_water_waterscroll, texture->r_water_waterscroll); texture->offsetmapping = shader->offsetmapping; texture->offsetscale = shader->offsetscale; texture->specularscalemod = shader->specularscalemod; diff --git a/model_shared.h b/model_shared.h index a49de9fd..2f8cc01f 100644 --- a/model_shared.h +++ b/model_shared.h @@ -419,6 +419,7 @@ typedef struct q3shaderinfo_s float reflectfactor; // amount of reflection distort (1.0 = like the cvar specifies) vec4_t reflectcolor4f; // color tint of reflection (including alpha factor) float r_water_wateralpha; // additional wateralpha to apply when r_water is active + float r_water_waterscroll[2]; // water normalmapscrollblend - scale and speed // offsetmapping dpoffsetmapping_technique_t offsetmapping; @@ -555,6 +556,7 @@ typedef struct texture_s float reflectfactor; // amount of reflection distort (1.0 = like the cvar specifies) vec4_t reflectcolor4f; // color tint of reflection (including alpha factor) float r_water_wateralpha; // additional wateralpha to apply when r_water is active + float r_water_waterscroll[2]; // scale and speed int camera_entity; // entity number for use by cameras // offsetmapping