From: eihrul Date: Tue, 13 Sep 2011 16:52:33 +0000 (+0000) Subject: slightly better non-VSDCT shadowmap code X-Git-Tag: xonotic-v0.6.0~163^2~205 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=52e7c8b0b218a1f791f63ef396291b440094bcf3;p=xonotic%2Fdarkplaces.git slightly better non-VSDCT shadowmap code git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11347 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/shader_glsl.h b/shader_glsl.h index b4f43c2c..4e37e273 100644 --- a/shader_glsl.h +++ b/shader_glsl.h @@ -748,18 +748,19 @@ "vec3 GetShadowMapTC2D(vec3 dir)\n" "{\n" " vec3 adir = abs(dir);\n" -" vec2 aparams = ShadowMap_Parameters.xy / max(max(adir.x, adir.y), adir.z);\n" +" vec2 mparams = ShadowMap_Parameters.xy / max(max(adir.x, adir.y), adir.z);\n" " vec4 proj = dp_textureCube(Texture_CubeProjection, dir);\n" -" return vec3(mix(dir.xy, dir.zz, proj.xy) * aparams.x + proj.zw * ShadowMap_Parameters.z, aparams.y + ShadowMap_Parameters.w);\n" +" return vec3(mix(dir.xy, dir.zz, proj.xy) * mparams.x + proj.zw * ShadowMap_Parameters.z, mparams.y + ShadowMap_Parameters.w);\n" "}\n" "# else\n" "vec3 GetShadowMapTC2D(vec3 dir)\n" "{\n" -" vec3 adir = abs(dir);\n" -" vec2 aparams = ShadowMap_Parameters.xy / max(max(adir.x, adir.y), adir.z);\n" -" vec4 proj = adir.x > adir.y ? (adir.x > adir.z ? vec4(dir.zy, dir.x < 0.0 ? 1.5 : 0.5, 0.5) : vec4(dir.xy, dir.z < 0.0 ? 1.5 : 0.5, 2.5)) :\n" -" (adir.y > adir.z ? vec4(dir.xz, dir.y < 0.0 ? 1.5 : 0.5, 1.5) : vec4(dir.xy, dir.z < 0.0 ? 1.5 : 0.5, 2.5));\n" -" return vec3(proj.xy * aparams.x + proj.zw * ShadowMap_Parameters.z, aparams.y + ShadowMap_Parameters.w);\n" +" vec3 adir = abs(dir);\n" +" float m; vec4 proj;\n" +" if (adir.x > adir.y) { m = adir.x; proj = vec4(dir.zyx, 0.5); } else { m = adir.y; proj = vec4(dir.xzy, 1.5); }\n" +" if (adir.z > m) { m = adir.z; proj = vec4(dir, 2.5); }\n" +" vec2 mparams = ShadowMap_Parameters.xy / m;\n" +" return vec3(proj.xy * mparams.x + vec2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, mparams.y + ShadowMap_Parameters.w);\n" "}\n" "# endif\n" "# endif\n" diff --git a/shader_hlsl.h b/shader_hlsl.h index 4f73330f..4b6da04e 100644 --- a/shader_hlsl.h +++ b/shader_hlsl.h @@ -589,23 +589,22 @@ "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters, samplerCUBE Texture_CubeProjection)\n" "{\n" " float3 adir = abs(dir);\n" -" float2 aparams = ShadowMap_Parameters.xy / max(max(adir.x, adir.y), adir.z);\n" +" float2 mparams = ShadowMap_Parameters.xy / max(max(adir.x, adir.y), adir.z);\n" " float4 proj = texCUBE(Texture_CubeProjection, dir);\n" -" return float3(lerp(dir.xy, dir.zz, proj.xy) * aparams.x + proj.zw * ShadowMap_Parameters.z, aparams.y + ShadowMap_Parameters.w);\n" +" return float3(lerp(dir.xy, dir.zz, proj.xy) * mparams.x + proj.zw * ShadowMap_Parameters.z, mparams.y + ShadowMap_Parameters.w);\n" "}\n" "# else\n" "float3 GetShadowMapTC2D(float3 dir, float4 ShadowMap_Parameters)\n" "{\n" " float3 adir = abs(dir);\n" -" float ma = adir.z;\n" -" float4 proj = float4(dir, 2.5);\n" -" if (adir.x > ma) { ma = adir.x; proj = float4(dir.zyx, 0.5); }\n" -" if (adir.y > ma) { ma = adir.y; proj = float4(dir.xzy, 1.5); }\n" +" float m; float4 proj;\n" +" if (adir.x > adir.y) { m = adir.x; proj = float4(dir.zyx, 0.5); } else { m = adir.y; proj = float4(dir.xzy, 1.5); }\n" +" if (adir.z > m) { m = adir.z; proj = float4(dir, 2.5); }\n" "#ifdef HLSL\n" -" return float3(proj.xy * ShadowMap_Parameters.x / ma + float2(0.5,0.5) + float2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, ma + 64 * ShadowMap_Parameters.w);\n" +" return float3(proj.xy * ShadowMap_Parameters.x / m + float2(0.5,0.5) + float2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, m + 64 * ShadowMap_Parameters.w);\n" "#else\n" -" float2 aparams = ShadowMap_Parameters.xy / ma;\n" -" return float3(proj.xy * aparams.x + float2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, aparams.y + ShadowMap_Parameters.w);\n" +" float2 mparams = ShadowMap_Parameters.xy / m;\n" +" return float3(proj.xy * mparams.x + float2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, mparams.y + ShadowMap_Parameters.w);\n" "#endif\n" "}\n" "# endif\n"