From: vortex Date: Sun, 31 Jul 2011 21:54:13 +0000 (+0000) Subject: r_glsl_deluxemapping 2 support for vertexlit surfaces, deluxemap forced surfaces... X-Git-Tag: xonotic-v0.6.0~163^2~290 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a14d8ac6ca1ca641b68a666983531298ee036576;p=xonotic%2Fdarkplaces.git r_glsl_deluxemapping 2 support for vertexlit surfaces, deluxemap forced surfaces no longer use texture2d(deluxemap). Attempt to fix '2D pics GLSL gamma with sRGB', added v_glslgamma_2d (default 0). New "dprtlightambient" shader keyword which adds ambient rtlight to surface, useful on lowpoly harsh entities (like grass bushes) for smoother rtlightning. New trick: CSQC sound/pointsound plugins take "#sound_index" which can be returned by precache_sound. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11262 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/dpsoftrast.h b/dpsoftrast.h index 3f267a2e..1d2f4d7c 100644 --- a/dpsoftrast.h +++ b/dpsoftrast.h @@ -151,6 +151,8 @@ typedef enum shadermode_e SHADERMODE_FAKELIGHT, ///< (fakelight) modulate texture by "fake" lighting (no lightmaps, no nothing) SHADERMODE_LIGHTDIRECTIONMAP_MODELSPACE, ///< (lightmap) use directional pixel shading from texture containing modelspace light directions (q3bsp deluxemap) SHADERMODE_LIGHTDIRECTIONMAP_TANGENTSPACE, ///< (lightmap) use directional pixel shading from texture containing tangentspace light directions (q1bsp deluxemap) + SHADERMODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP, // forced deluxemapping for lightmapped surfaces + SHADERMODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR, // forced deluxemapping for vertexlit surfaces SHADERMODE_LIGHTDIRECTION, ///< (lightmap) use directional pixel shading from fixed light direction (q3bsp) SHADERMODE_LIGHTSOURCE, ///< (lightsource) use directional pixel shading from light source (rtlight) SHADERMODE_REFRACTION, ///< refract background (the material is rendered normally after this pass) diff --git a/gl_rmain.c b/gl_rmain.c index b5faeb34..383be057 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -220,6 +220,7 @@ cvar_t r_glsl_vertextextureblend_usebothalphas = {CVAR_SAVE, "r_glsl_vertextextu cvar_t r_framedatasize = {CVAR_SAVE, "r_framedatasize", "0.5", "size of renderer data cache used during one frame (for skeletal animation caching, light processing, etc)"}; extern cvar_t v_glslgamma; +extern cvar_t v_glslgamma_2d; extern qboolean v_flipped_state; @@ -690,6 +691,8 @@ shadermodeinfo_t glslshadermodeinfo[SHADERMODE_COUNT] = {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_FAKELIGHT\n", " fakelight"}, {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_LIGHTDIRECTIONMAP_MODELSPACE\n", " lightdirectionmap_modelspace"}, {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n", " lightdirectionmap_tangentspace"}, + {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP\n", " lightdirectionmap_forced_lightmap"}, + {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR\n", " lightdirectionmap_forced_vertexcolor"}, {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_LIGHTDIRECTION\n", " lightdirection"}, {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_LIGHTSOURCE\n", " lightsource"}, {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_REFRACTION\n", " refraction"}, @@ -710,6 +713,8 @@ shadermodeinfo_t hlslshadermodeinfo[SHADERMODE_COUNT] = {"hlsl/default.hlsl", NULL, "hlsl/default.hlsl", "#define MODE_FAKELIGHT\n", " fakelight"}, {"hlsl/default.hlsl", NULL, "hlsl/default.hlsl", "#define MODE_LIGHTDIRECTIONMAP_MODELSPACE\n", " lightdirectionmap_modelspace"}, {"hlsl/default.hlsl", NULL, "hlsl/default.hlsl", "#define MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n", " lightdirectionmap_tangentspace"}, + {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP\n", " lightdirectionmap_forced_lightmap"}, + {"glsl/default.glsl", NULL, "glsl/default.glsl", "#define MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR\n", " lightdirectionmap_forced_vertexcolor"}, {"hlsl/default.hlsl", NULL, "hlsl/default.hlsl", "#define MODE_LIGHTDIRECTION\n", " lightdirection"}, {"hlsl/default.hlsl", NULL, "hlsl/default.hlsl", "#define MODE_LIGHTSOURCE\n", " lightsource"}, {"hlsl/default.hlsl", NULL, "hlsl/default.hlsl", "#define MODE_REFRACTION\n", " refraction"}, @@ -1910,9 +1915,8 @@ void R_SetupShader_Generic(rtexture_t *first, rtexture_t *second, int texturemod permutation |= SHADERPERMUTATION_SPECULAR; if (texturemode == GL_MODULATE) permutation |= SHADERPERMUTATION_COLORMAPPING; -// LordHavoc: VorteX broke the game by doing this, and did not cvar it properly, and did not add the proper checks (r_texture_sRGB_2d.integer would need to be checked), and it breaks with vid_sRGB where the gamma ramps are altered... -// if (usegamma && r_texture_gammaramps && v_glslgamma.integer && !vid_gammatables_trivial) -// permutation |= SHADERPERMUTATION_GAMMARAMPS; + if (usegamma && v_glslgamma.integer && v_glslgamma_2d.integer && !vid.sRGB2D && r_texture_gammaramps && !vid_gammatables_trivial) + permutation |= SHADERPERMUTATION_GAMMARAMPS; else if (texturemode == GL_ADD) permutation |= SHADERPERMUTATION_GLOW; else if (texturemode == GL_DECAL) @@ -2465,10 +2469,13 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, if (specularscale > 0) permutation |= SHADERPERMUTATION_SPECULAR | SHADERPERMUTATION_DIFFUSE; } - else if (r_glsl_deluxemapping.integer >= 2 && rsurface.uselightmaptexture) + else if (r_glsl_deluxemapping.integer >= 2) { // fake deluxemapping (uniform light direction in tangentspace) - mode = SHADERMODE_LIGHTDIRECTIONMAP_TANGENTSPACE; + if (rsurface.uselightmaptexture) + mode = SHADERMODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP; + else + mode = SHADERMODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR; permutation |= SHADERPERMUTATION_DIFFUSE; if (specularscale > 0) permutation |= SHADERPERMUTATION_SPECULAR | SHADERPERMUTATION_DIFFUSE; diff --git a/model_shared.c b/model_shared.c index d4021ee0..0fc77282 100644 --- a/model_shared.c +++ b/model_shared.c @@ -2155,6 +2155,10 @@ void Mod_LoadQ3Shaders(void) { shader.specularpowermod = atof(parameter[1]); } + else if (!strcasecmp(parameter[0], "dprtlightambient") && numparameters >= 2) + { + shader.rtlightambient = atof(parameter[1]); + } else if (!strcasecmp(parameter[0], "dpoffsetmapping") && numparameters >= 3) { if (!strcasecmp(parameter[1], "disable") || !strcasecmp(parameter[1], "none") || !strcasecmp(parameter[1], "off")) @@ -2437,6 +2441,7 @@ nothing GL_ZERO GL_ONE texture->offsetscale = shader->offsetscale; texture->specularscalemod = shader->specularscalemod; texture->specularpowermod = shader->specularpowermod; + texture->rtlightambient = shader->rtlightambient; if (shader->dpreflectcube[0]) texture->reflectcubetexture = R_GetCubemap(shader->dpreflectcube); diff --git a/model_shared.h b/model_shared.h index c34890ca..8b73377e 100644 --- a/model_shared.h +++ b/model_shared.h @@ -475,6 +475,9 @@ typedef struct q3shaderinfo_s // gloss float specularscalemod; float specularpowermod; + + // rtlightning ambient addition + float rtlightambient; #define Q3SHADERINFO_COMPARE_END specularpowermod } q3shaderinfo_t; @@ -613,6 +616,9 @@ typedef struct texture_s // gloss float specularscalemod; float specularpowermod; + + // diffuse and ambient + float rtlightambient; } texture_t; diff --git a/r_shadow.c b/r_shadow.c index 5e7c5eb7..0e2ba506 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -3321,8 +3321,8 @@ void R_Shadow_RenderLighting(int texturenumsurfaces, const msurface_t **textures qboolean negated; float lightcolor[3]; VectorCopy(rsurface.rtlight->currentcolor, lightcolor); - ambientscale = rsurface.rtlight->ambientscale; - diffusescale = rsurface.rtlight->diffusescale; + ambientscale = rsurface.rtlight->ambientscale + rsurface.texture->rtlightambient; + diffusescale = rsurface.rtlight->diffusescale * max(0, 1.0 - rsurface.texture->rtlightambient); specularscale = rsurface.rtlight->specularscale * rsurface.texture->specularscale; if (!r_shadow_usenormalmap.integer) { diff --git a/shader_glsl.h b/shader_glsl.h index 570b6748..9f9387b6 100644 --- a/shader_glsl.h +++ b/shader_glsl.h @@ -57,7 +57,7 @@ "#if defined(USEFOGINSIDE) || defined(USEFOGOUTSIDE) || defined(USEFOGHEIGHTTEXTURE)\n" "# define USEFOG\n" "#endif\n" -"#if defined(MODE_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n" +"#if defined(MODE_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP)\n" "# define USELIGHTMAP\n" "#endif\n" "#if defined(USESPECULAR) || defined(USEOFFSETMAPPING) || defined(USEREFLECTCUBE) || defined(MODE_FAKELIGHT) || defined(USEFOG)\n" @@ -1007,7 +1007,7 @@ "#endif\n" "void main(void)\n" "{\n" -"#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND)\n" +"#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n" " VertexColor = Attrib_Color;\n" "#endif\n" " // copy the surface texcoord\n" @@ -1236,14 +1236,14 @@ "\n" "\n" "#ifdef MODE_LIGHTDIRECTION\n" -"#define SHADING\n" -"#ifdef USEDIFFUSE\n" -" myhalf3 lightnormal = myhalf3(normalize(LightVector));\n" -"#endif\n" -"#define lightcolor LightColor\n" +" #define SHADING\n" +" #ifdef USEDIFFUSE\n" +" myhalf3 lightnormal = myhalf3(normalize(LightVector));\n" +" #endif\n" +" #define lightcolor LightColor\n" "#endif // MODE_LIGHTDIRECTION\n" "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n" -"#define SHADING\n" +" #define SHADING\n" " // deluxemap lightmapping using light vectors in modelspace (q3map2 -light -deluxe)\n" " myhalf3 lightnormal_modelspace = myhalf3(dp_texture2D(Texture_Deluxemap, TexCoordSurfaceLightmap.zw)) * 2.0 + myhalf3(-1.0, -1.0, -1.0);\n" " myhalf3 lightcolor = myhalf3(dp_texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw));\n" @@ -1265,19 +1265,25 @@ " lightcolor *= 1.0 / max(0.25, lightnormal.z);\n" "#endif // MODE_LIGHTDIRECTIONMAP_MODELSPACE\n" "#ifdef MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n" -"#define SHADING\n" +" #define SHADING\n" " // deluxemap lightmapping using light vectors in tangentspace (hmap2 -light)\n" " myhalf3 lightnormal = myhalf3(dp_texture2D(Texture_Deluxemap, TexCoordSurfaceLightmap.zw)) * 2.0 + myhalf3(-1.0, -1.0, -1.0);\n" " myhalf3 lightcolor = myhalf3(dp_texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw));\n" "#endif\n" -"\n" -"\n" -"\n" -"\n" +"#if defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n" +" #define SHADING\n" +" // forced deluxemap on lightmapped/vertexlit surfaces\n" +" myhalf3 lightnormal = myhalf3(0.0, 0.0, 1.0);\n" +" #ifdef USELIGHTMAP\n" +" myhalf3 lightcolor = myhalf3(dp_texture2D(Texture_Lightmap, TexCoordSurfaceLightmap.zw));\n" +" #else\n" +" myhalf3 lightcolor = myhalf3(VertexColor.rgb);\n" +" #endif\n" +"#endif\n" "#ifdef MODE_FAKELIGHT\n" -"#define SHADING\n" -"myhalf3 lightnormal = myhalf3(normalize(EyeVectorFogDepth.xyz));\n" -"myhalf3 lightcolor = myhalf3(1.0);\n" +" #define SHADING\n" +" myhalf3 lightnormal = myhalf3(normalize(EyeVectorFogDepth.xyz));\n" +" myhalf3 lightcolor = myhalf3(1.0);\n" "#endif // MODE_FAKELIGHT\n" "\n" "\n" diff --git a/shader_hlsl.h b/shader_hlsl.h index 32261175..96566f2c 100644 --- a/shader_hlsl.h +++ b/shader_hlsl.h @@ -10,7 +10,7 @@ "#if defined(USEFOGINSIDE) || defined(USEFOGOUTSIDE) || defined(USEFOGHEIGHTTEXTURE)\n" "# define USEFOG\n" "#endif\n" -"#if defined(MODE_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n" +"#if defined(MODE_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP)\n" "#define USELIGHTMAP\n" "#endif\n" "#if defined(USESPECULAR) || defined(USEOFFSETMAPPING) || defined(USEREFLECTCUBE) || defined(MODE_FAKELIGHT)\n" @@ -979,7 +979,7 @@ "(\n" "float4 gl_Vertex : POSITION,\n" "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n" -"#if defined(USEVERTEXTEXTUREBLEND) || defined(MODE_VERTEXCOLOR)\n" +"#if defined(USEVERTEXTEXTUREBLEND) || defined(MODE_VERTEXCOLOR) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n" "float4 gl_Color : COLOR0,\n" "#endif\n" "float4 gl_MultiTexCoord0 : TEXCOORD0,\n" @@ -1403,14 +1403,14 @@ "\n" "\n" "#ifdef MODE_LIGHTDIRECTION\n" -"#define SHADING\n" -"#ifdef USEDIFFUSE\n" -" half3 lightnormal = half3(normalize(LightVector));\n" -"#endif\n" -"#define lightcolor LightColor\n" +" #define SHADING\n" +" #ifdef USEDIFFUSE\n" +" half3 lightnormal = half3(normalize(LightVector));\n" +" #endif\n" +" #define lightcolor LightColor\n" "#endif // MODE_LIGHTDIRECTION\n" "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n" -"#define SHADING\n" +" #define SHADING\n" " // deluxemap lightmapping using light vectors in modelspace (q3map2 -light -deluxe)\n" " half3 lightnormal_modelspace = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n" " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n" @@ -1431,19 +1431,25 @@ " lightcolor *= 1.0 / max(0.25, lightnormal.z);\n" "#endif // MODE_LIGHTDIRECTIONMAP_MODELSPACE\n" "#ifdef MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n" -"#define SHADING\n" +" #define SHADING\n" " // deluxemap lightmapping using light vectors in tangentspace (hmap2 -light)\n" " half3 lightnormal = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n" " half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n" "#endif\n" -"\n" -"\n" -"\n" -"\n" +"#if defined(MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n" +" #define SHADING\n" +" // forced deluxemap on lightmapped/vertexlit surfaces\n" +" half3 lightnormal = half3(0.0, 0.0, 1.0);\n" +" #ifdef USELIGHTMAP\n" +" half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n" +" #else\n" +" half3 lightcolor = half3(gl_FrontColor.rgb);\n" +" #endif\n" +"#endif\n" "#ifdef MODE_FAKELIGHT\n" -"#define SHADING\n" -"half3 lightnormal = half3(normalize(EyeVector));\n" -"half3 lightcolor = half3(1.0,1.0,1.0);\n" +" #define SHADING\n" +" half3 lightnormal = half3(normalize(EyeVector));\n" +" half3 lightcolor = half3(1.0,1.0,1.0);\n" "#endif // MODE_FAKELIGHT\n" "\n" "\n" diff --git a/snd_main.c b/snd_main.c index e537d838..8376007a 100644 --- a/snd_main.c +++ b/snd_main.c @@ -977,6 +977,15 @@ sfx_t *S_FindName (const char *name) if(!strcmp (sfx->name, name)) return sfx; + // check for # in the beginning, try lookup by soundindex + if (name[0] == '#' && name[1]) + { + int soundindex = atoi(name + 1); + if (soundindex > 0 && soundindex < MAX_SOUNDS) + if (cl.sound_precache[soundindex]->name[0]) + return cl.sound_precache[soundindex]; + } + // Add a sfx_t struct for this sound sfx = (sfx_t *)Mem_Alloc (snd_mempool, sizeof (*sfx)); memset (sfx, 0, sizeof(*sfx)); diff --git a/vid_shared.c b/vid_shared.c index c34f1c82..e6259b65 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -198,6 +198,8 @@ cvar_t v_color_white_g = {CVAR_SAVE, "v_color_white_g", "1", "desired color of w cvar_t v_color_white_b = {CVAR_SAVE, "v_color_white_b", "1", "desired color of white"}; cvar_t v_hwgamma = {CVAR_SAVE, "v_hwgamma", "0", "enables use of hardware gamma correction ramps if available (note: does not work very well on Windows2000 and above), values are 0 = off, 1 = attempt to use hardware gamma, 2 = use hardware gamma whether it works or not"}; cvar_t v_glslgamma = {CVAR_SAVE, "v_glslgamma", "1", "enables use of GLSL to apply gamma correction ramps if available (note: overrides v_hwgamma)"}; +cvar_t v_glslgamma_2d = {CVAR_SAVE, "v_glslgamma_2d", "0", "applies GLSL gamma to 2d pictures (HUD, fonts)"}; + cvar_t v_psycho = {0, "v_psycho", "0", "easter egg"}; // brand of graphics chip @@ -1649,6 +1651,7 @@ void VID_Shared_Init(void) Cvar_RegisterVariable(&v_hwgamma); Cvar_RegisterVariable(&v_glslgamma); + Cvar_RegisterVariable(&v_glslgamma_2d); Cvar_RegisterVariable(&v_psycho);