X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=shader_hlsl.h;h=a1d537d4bc3faeb358e40961eedcca577fe50eba;hb=50f9c996dedd089ca65ae38bc2439ee67a189412;hp=74a02eef4ab69e705b2d8f01956caebdc4010ff8;hpb=bc5edff053bc9907f378d57ebbce782c54aa6268;p=xonotic%2Fdarkplaces.git diff --git a/shader_hlsl.h b/shader_hlsl.h index 74a02eef..a1d537d4 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" @@ -27,6 +27,32 @@ "#endif\n" "#endif\n" "\n" +"#ifdef VERTEX_SHADER\n" +"#ifdef USETRIPPY\n" +"// LordHavoc: based on shader code linked at: http://www.youtube.com/watch?v=JpksyojwqzE\n" +"// tweaked scale\n" +"float4 TrippyVertex(float4 position)\n" +"(\n" +"uniform float ClientTime : register(c2)\n" +")\n" +"{\n" +" float worldTime = ClientTime;\n" +" // tweaked for Quake\n" +" worldTime *= 10.0;\n" +" position *= 0.125;\n" +" //~tweaked for Quake\n" +" float distanceSquared = (position.x * position.x + position.z * position.z);\n" +" position.y += 5.0*sin(distanceSquared*sin(worldTime/143.0)/1000.0);\n" +" float y = position.y;\n" +" float x = position.x;\n" +" float om = sin(distanceSquared*sin(worldTime/256.0)/5000.0) * sin(worldTime/200.0);\n" +" position.y = x*sin(om)+y*cos(om);\n" +" position.x = x*cos(om)-y*sin(om);\n" +" return position;\n" +"}\n" +"#endif\n" +"#endif\n" +"\n" "#ifdef MODE_DEPTH_OR_SHADOW\n" "#ifdef VERTEX_SHADER\n" "void main\n" @@ -38,6 +64,9 @@ ")\n" "{\n" " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n" +"#ifdef USETRIPPY\n" +" gl_Position = TrippyVertex(gl_Position);\n" +"#endif\n" " Depth = gl_Position.z;\n" "}\n" "#endif\n" @@ -72,6 +101,9 @@ ")\n" "{\n" " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n" +"#ifdef USETRIPPY\n" +" gl_Position = TrippyVertex(gl_Position);\n" +"#endif\n" " gl_FrontColor = float4(gl_Position.z, gl_Position.z, gl_Position.z, 1.0);\n" "}\n" "#endif\n" @@ -244,6 +276,9 @@ " TexCoord2 = gl_MultiTexCoord1.xy;\n" "#endif\n" " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n" +"#ifdef USETRIPPY\n" +" gl_Position = TrippyVertex(gl_Position);\n" +"#endif\n" "}\n" "#endif\n" "\n" @@ -260,6 +295,9 @@ "#ifdef USESPECULAR\n" "uniform sampler Texture_Second : register(s1),\n" "#endif\n" +"#ifdef USEGAMMARAMPS\n" +"uniform sampler Texture_GammaRamps : register(s2),\n" +"#endif\n" "out float4 gl_FragColor : COLOR\n" ")\n" "{\n" @@ -269,7 +307,12 @@ " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n" "#endif\n" "#ifdef USEDIFFUSE\n" +"# ifdef USEREFLECTCUBE\n" +" // suppress texture alpha\n" +" dp_FragColor.rgb *= tex2D(Texture_First, TexCoord1).rgb;\n" +"# else\n" " gl_FragColor *= tex2D(Texture_First, TexCoord1);\n" +"# endif\n" "#endif\n" "\n" "#ifdef USESPECULAR\n" @@ -284,6 +327,11 @@ " gl_FragColor = lerp(gl_FragColor, tex2, tex2.a);\n" "# endif\n" "#endif\n" +"#ifdef USEGAMMARAMPS\n" +" dp_FragColor.r = tex2D(Texture_GammaRamps, vec2(dp_FragColor.r, 0)).r;\n" +" dp_FragColor.g = tex2D(Texture_GammaRamps, vec2(dp_FragColor.g, 0)).g;\n" +" dp_FragColor.b = tex2D(Texture_GammaRamps, vec2(dp_FragColor.b, 0)).b;\n" +"#endif\n" "}\n" "#endif\n" "#else // !MODE_GENERIC\n" @@ -348,6 +396,9 @@ " TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n" " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n" " ModelViewProjectionPosition = gl_Position;\n" +"#ifdef USETRIPPY\n" +" gl_Position = TrippyVertex(gl_Position);\n" +"#endif\n" "}\n" "#endif\n" "\n" @@ -410,11 +461,12 @@ "{\n" " TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n" " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n" -" EyeVector.x = dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz);\n" -" EyeVector.y = dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz);\n" -" EyeVector.z = dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz);\n" +" EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n" " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n" " ModelViewProjectionPosition = gl_Position;\n" +"#ifdef USETRIPPY\n" +" gl_Position = TrippyVertex(gl_Position);\n" +"#endif\n" "}\n" "#endif\n" "\n" @@ -472,60 +524,62 @@ "#ifdef FRAGMENT_SHADER\n" "\n" "#ifdef USEFOG\n" -"float3 FogVertex(float3 surfacecolor, float3 FogColor, float3 EyeVectorModelSpace, float FogPlaneVertexDist, float FogRangeRecip, float FogPlaneViewDist, float FogHeightFade, sampler Texture_FogMask, sampler Texture_FogHeightTexture)\n" +"float3 FogVertex(float4 surfacecolor, float3 FogColor, float3 EyeVectorModelSpace, float FogPlaneVertexDist, float FogRangeRecip, float FogPlaneViewDist, float FogHeightFade, sampler Texture_FogMask, sampler Texture_FogHeightTexture)\n" "{\n" " float fogfrac;\n" +" float3 fc = FogColor;\n" +"#ifdef USEFOGALPHAHACK\n" +" fc *= surfacecolor.a;\n" +"#endif\n" "#ifdef USEFOGHEIGHTTEXTURE\n" " float4 fogheightpixel = tex2D(Texture_FogHeightTexture, float2(1,1) + float2(FogPlaneVertexDist, FogPlaneViewDist) * (-2.0 * FogHeightFade));\n" " fogfrac = fogheightpixel.a;\n" -" return lerp(fogheightpixel.rgb * FogColor, surfacecolor, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n" +" return lerp(fogheightpixel.rgb * fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n" "#else\n" "# ifdef USEFOGOUTSIDE\n" " fogfrac = min(0.0, FogPlaneVertexDist) / (FogPlaneVertexDist - FogPlaneViewDist) * min(1.0, min(0.0, FogPlaneVertexDist) * FogHeightFade);\n" "# else\n" " fogfrac = FogPlaneViewDist / (FogPlaneViewDist - max(0.0, FogPlaneVertexDist)) * min(1.0, (min(0.0, FogPlaneVertexDist) + FogPlaneViewDist) * FogHeightFade);\n" "# endif\n" -" return lerp(FogColor, surfacecolor, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n" +" return lerp(fc, surfacecolor.rgb, tex2D(Texture_FogMask, float2(length(EyeVectorModelSpace)*fogfrac*FogRangeRecip, 0.0)).r);\n" "#endif\n" "}\n" "#endif\n" "\n" "#ifdef USEOFFSETMAPPING\n" -"float2 OffsetMapping(float2 TexCoord, float OffsetMapping_Scale, float3 EyeVector, sampler Texture_Normal)\n" +"float2 OffsetMapping(float2 TexCoord, float4 OffsetMapping_ScaleSteps, float OffsetMapping_Bias, float OffsetMapping_LodDistance, float3 EyeVector, sampler Texture_Normal, float2 dPdx, float2 dPdy)\n" "{\n" +" float i;\n" +" // distance-based LOD\n" +"#ifdef USEOFFSETMAPPING_LOD\n" +" float LODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n" +" mediump vec4 ScaleSteps = float4(OffsetMapping_ScaleSteps.x, OffsetMapping_ScaleSteps.y * LODFactor, OffsetMapping_ScaleSteps.z / LODFactor, OffsetMapping_ScaleSteps.w * LODFactor);\n" +"#else\n" +" #define ScaleSteps OffsetMapping_ScaleSteps\n" +"#endif\n" "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n" " // 14 sample relief mapping: linear search and then binary search\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" -" //float3 OffsetVector = float3(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMapping_Scale) * float2(-1, 1), -1);\n" -" //float3 OffsetVector = float3(normalize(EyeVector.xy) * OffsetMapping_Scale * float2(-1, 1), -1);\n" -" float3 OffsetVector = float3(normalize(EyeVector).xy * OffsetMapping_Scale * float2(-1, 1), -1);\n" -" float3 RT = float3(TexCoord, 1);\n" -" OffsetVector *= 0.1;\n" -" RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n" -" RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n" -" RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n" -" RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n" -" RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n" -" RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n" -" RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n" -" RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n" -" RT += OffsetVector * step(tex2D(Texture_Normal, RT.xy).a, RT.z);\n" -" RT += OffsetVector * (step(tex2D(Texture_Normal, RT.xy).a, RT.z) - 0.5);\n" -" RT += OffsetVector * (step(tex2D(Texture_Normal, RT.xy).a, RT.z) * 0.5 - 0.25);\n" -" RT += OffsetVector * (step(tex2D(Texture_Normal, RT.xy).a, RT.z) * 0.25 - 0.125);\n" -" RT += OffsetVector * (step(tex2D(Texture_Normal, RT.xy).a, RT.z) * 0.125 - 0.0625);\n" -" RT += OffsetVector * (step(tex2D(Texture_Normal, RT.xy).a, RT.z) * 0.0625 - 0.03125);\n" +" //float3 OffsetVector = float3(EyeVector.xy * ((1.0 / EyeVector.z) * ScaleSteps.x) * float2(-1, 1), -1);\n" +" //float3 OffsetVector = float3(normalize(EyeVector.xy) * ScaleSteps.x * float2(-1, 1), -1);\n" +" float3 OffsetVector = float3(normalize(EyeVector).xy * ScaleSteps.x * float2(-1, 1), -1);\n" +" float3 RT = float3(float2(TexCoord.xy - OffsetVector.xy*OffsetMapping_Bias), 1);\n" +" OffsetVector *= ScaleSteps.z;\n" +" for(i = 1.0; i < ScaleSteps.y; ++i)\n" +" RT += OffsetVector * step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z);\n" +" for(i = 0.0, f = 1.0; i < ScaleSteps.w; ++i, f *= 0.5)\n" +" RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * f - 0.5 * f);\n" " return RT.xy;\n" "#else\n" " // 2 sample offset mapping (only 2 samples because of ATI Radeon 9500-9800/X300 limits)\n" -" //float2 OffsetVector = float2(EyeVector.xy * ((1.0 / EyeVector.z) * OffsetMapping_Scale) * float2(-1, 1));\n" -" //float2 OffsetVector = float2(normalize(EyeVector.xy) * OffsetMapping_Scale * float2(-1, 1));\n" -" float2 OffsetVector = float2(normalize(EyeVector).xy * OffsetMapping_Scale * float2(-1, 1));\n" -" OffsetVector *= 0.5;\n" -" TexCoord += OffsetVector * (1.0 - tex2D(Texture_Normal, TexCoord).a);\n" -" TexCoord += OffsetVector * (1.0 - tex2D(Texture_Normal, TexCoord).a);\n" +" //float2 OffsetVector = float2(EyeVector.xy * ((1.0 / EyeVector.z) * ScaleSteps.x) * float2(-1, 1));\n" +" //float2 OffsetVector = float2(normalize(EyeVector.xy) * ScaleSteps.x * float2(-1, 1));\n" +" float2 OffsetVector = float2(normalize(EyeVector).xy * ScaleSteps.x * float2(-1, 1));\n" +" OffsetVector *= ScaleSteps.z;\n" +" for(i = 0.0; i < ScaleSteps.y; ++i)\n" +" TexCoord += OffsetVector * ((1.0 - OffsetMapping_Bias) - tex2Dgrad(Texture_Normal, TexCoord, dPdx, dPdy).a);\n" " return TexCoord;\n" "#endif\n" "}\n" @@ -540,23 +594,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" @@ -707,15 +760,16 @@ " // transform unnormalized eye direction into tangent space\n" "#ifdef USEOFFSETMAPPING\n" " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n" -" EyeVector.x = dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz);\n" -" EyeVector.y = dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz);\n" -" EyeVector.z = dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz);\n" +" EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n" "#endif\n" "\n" " VectorS = mul(ModelViewMatrix, float4(gl_MultiTexCoord1.xyz, 0)).xyz;\n" " VectorT = mul(ModelViewMatrix, float4(gl_MultiTexCoord2.xyz, 0)).xyz;\n" " VectorR.xyz = mul(ModelViewMatrix, float4(gl_MultiTexCoord3.xyz, 0)).xyz;\n" " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n" +"#ifdef USETRIPPY\n" +" gl_Position = TrippyVertex(gl_Position);\n" +"#endif\n" " VectorR.w = gl_Position.z;\n" "}\n" "#endif // VERTEX_SHADER\n" @@ -738,7 +792,9 @@ "uniform sampler Texture_SecondaryGloss : register(s6),\n" "#endif\n" "#ifdef USEOFFSETMAPPING\n" -"uniform float OffsetMapping_Scale : register(c24),\n" +"uniform float4 OffsetMapping_ScaleSteps : register(c24),\n" +"uniform float4 OffsetMapping_LodDistance : register(c53),\n" +"uniform float OffsetMapping_Bias : register(c54),\n" "#endif\n" "uniform half SpecularPower : register(c36),\n" "#ifdef HLSL\n" @@ -752,28 +808,32 @@ " float2 TexCoord = TexCoordBoth.xy;\n" "#ifdef USEOFFSETMAPPING\n" " // apply offsetmapping\n" -" float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_Scale, EyeVector, Texture_Normal);\n" -"#define TexCoord TexCoordOffset\n" +" float2 dPdx = ddx(TexCoord);\n" +" float2 dPdy = ddy(TexCoord);\n" +" float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, OffsetMapping_Bias, OffsetMapping_LodDistance, EyeVector, Texture_Normal, dPdx, dPdy);\n" +"# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n" +"#else\n" +"# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n" "#endif\n" "\n" "#ifdef USEALPHAKILL\n" -" if (tex2D(Texture_Color, TexCoord).a < 0.5)\n" +" if (offsetMappedTexture2D(Texture_Color).a < 0.5)\n" " discard;\n" "#endif\n" "\n" "#ifdef USEVERTEXTEXTUREBLEND\n" -" float alpha = tex2D(Texture_Color, TexCoord).a;\n" +" float alpha = offsetMappedTexture2D(Texture_Color).a;\n" " float terrainblend = clamp(float(gl_FrontColor.a) * alpha * 2.0 - 0.5, float(0.0), float(1.0));\n" " //float terrainblend = min(float(gl_FrontColor.a) * alpha * 2.0, float(1.0));\n" " //float terrainblend = float(gl_FrontColor.a) * alpha > 0.5;\n" "#endif\n" "\n" "#ifdef USEVERTEXTEXTUREBLEND\n" -" float3 surfacenormal = lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, tex2D(Texture_Normal, TexCoord).rgb, terrainblend) - float3(0.5, 0.5, 0.5);\n" -" float a = lerp(tex2D(Texture_SecondaryGloss, TexCoord2).a, tex2D(Texture_Gloss, TexCoord).a, terrainblend);\n" +" float3 surfacenormal = lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend) - float3(0.5, 0.5, 0.5);\n" +" float a = lerp(tex2D(Texture_SecondaryGloss, TexCoord2).a, offsetMappedTexture2D(Texture_Gloss).a, terrainblend);\n" "#else\n" -" float3 surfacenormal = tex2D(Texture_Normal, TexCoord).rgb - float3(0.5, 0.5, 0.5);\n" -" float a = tex2D(Texture_Gloss, TexCoord).a;\n" +" float3 surfacenormal = offsetMappedTexture2D(Texture_Normal).rgb - float3(0.5, 0.5, 0.5);\n" +" float a = offsetMappedTexture2D(Texture_Gloss).a;\n" "#endif\n" "\n" "#ifdef HLSL\n" @@ -885,10 +945,10 @@ " // calculate directional shading\n" " float3 eyevector = position * -1.0;\n" "# ifdef USEEXACTSPECULARMATH\n" -" half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, 0.0)), SpecularPower * normalmap.a));\n" +" half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, 0.0)), 1.0 + SpecularPower * normalmap.a));\n" "# else\n" " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(eyevector))));\n" -" half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * normalmap.a));\n" +" half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * normalmap.a));\n" "# endif\n" "#endif\n" "\n" @@ -928,7 +988,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" @@ -1013,24 +1073,18 @@ " // (we use unnormalized to ensure that it interpolates correctly and then\n" " // normalize it per pixel)\n" " float3 lightminusvertex = LightPosition - gl_Vertex.xyz;\n" -" LightVector.x = dot(lightminusvertex, gl_MultiTexCoord1.xyz);\n" -" LightVector.y = dot(lightminusvertex, gl_MultiTexCoord2.xyz);\n" -" LightVector.z = dot(lightminusvertex, gl_MultiTexCoord3.xyz);\n" +" LightVector = float3(dot(lightminusvertex, gl_MultiTexCoord1.xyz), dot(lightminusvertex, gl_MultiTexCoord2.xyz), dot(lightminusvertex, gl_MultiTexCoord3.xyz));\n" "# endif\n" "#endif\n" "\n" "#if defined(MODE_LIGHTDIRECTION) && defined(USEDIFFUSE)\n" -" LightVector.x = dot(LightDir, gl_MultiTexCoord1.xyz);\n" -" LightVector.y = dot(LightDir, gl_MultiTexCoord2.xyz);\n" -" LightVector.z = dot(LightDir, gl_MultiTexCoord3.xyz);\n" +" LightVector = float3(dot(LightDir, gl_MultiTexCoord1.xyz), dot(LightDir, gl_MultiTexCoord2.xyz), dot(LightDir, gl_MultiTexCoord3.xyz));\n" "#endif\n" "\n" " // transform unnormalized eye direction into tangent space\n" "#ifdef USEEYEVECTOR\n" " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n" -" EyeVector.x = dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz);\n" -" EyeVector.y = dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz);\n" -" EyeVector.z = dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz);\n" +" EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n" "#endif\n" "\n" "#ifdef USEFOG\n" @@ -1054,6 +1108,9 @@ "#ifdef USEREFLECTION\n" " ModelViewProjectionPosition = gl_Position;\n" "#endif\n" +"#ifdef USETRIPPY\n" +" gl_Position = TrippyVertex(gl_Position);\n" +"#endif\n" "}\n" "#endif // VERTEX_SHADER\n" "\n" @@ -1161,7 +1218,8 @@ "#endif\n" "\n" "#ifdef USEOFFSETMAPPING\n" -"uniform float OffsetMapping_Scale : register(c24),\n" +"uniform float4 OffsetMapping_ScaleSteps : register(c24),\n" +"uniform float OffsetMapping_Bias : register(c54),\n" "#endif\n" "\n" "#ifdef USEDEFERREDLIGHTMAP\n" @@ -1229,21 +1287,30 @@ "#endif\n" "#ifdef USEOFFSETMAPPING\n" " // apply offsetmapping\n" -" float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_Scale, EyeVector, Texture_Normal);\n" -"#define TexCoord TexCoordOffset\n" +" float2 dPdx = ddx(TexCoord);\n" +" float2 dPdy = ddy(TexCoord);\n" +" float2 TexCoordOffset = OffsetMapping(TexCoord, OffsetMapping_ScaleSteps, OffsetMapping_Bias, OffsetMapping_LodDistance, EyeVector, Texture_Normal, dPdx, dPdy);\n" +"# define offsetMappedTexture2D(t) tex2Dgrad(t, TexCoordOffset, dPdx, dPdy)\n" +"#else\n" +"# define offsetMappedTexture2D(t) tex2D(t, TexCoord)\n" "#endif\n" "\n" " // combine the diffuse textures (base, pants, shirt)\n" -" half4 color = half4(tex2D(Texture_Color, TexCoord));\n" +" half4 color = half4(offsetMappedTexture2D(Texture_Color));\n" "#ifdef USEALPHAKILL\n" " if (color.a < 0.5)\n" " discard;\n" "#endif\n" " color.a *= Alpha;\n" "#ifdef USECOLORMAPPING\n" -" color.rgb += half3(tex2D(Texture_Pants, TexCoord).rgb) * Color_Pants + half3(tex2D(Texture_Shirt, TexCoord).rgb) * Color_Shirt;\n" +" color.rgb += half3(offsetMappedTexture2D(Texture_Pants).rgb) * Color_Pants + half3(offsetMappedTexture2D(Texture_Shirt).rgb) * Color_Shirt;\n" "#endif\n" "#ifdef USEVERTEXTEXTUREBLEND\n" +"#ifdef USEBOTHALPHAS\n" +" half4 color2 = half4(tex2D(Texture_SecondaryColor, TexCoord2));\n" +" half terrainblend = clamp(half(gl_FrontColor.a) * color.a, half(1.0 - color2.a), half(1.0));\n" +" color.rgb = lerp(color2.rgb, color.rgb, terrainblend);\n" +"#else\n" " half terrainblend = clamp(half(gl_FrontColor.a) * color.a * 2.0 - 0.5, half(0.0), half(1.0));\n" " //half terrainblend = min(half(gl_FrontColor.a) * color.a * 2.0, half(1.0));\n" " //half terrainblend = half(gl_FrontColor.a) * color.a > 0.5;\n" @@ -1251,21 +1318,22 @@ " color.a = 1.0;\n" " //color = half4(lerp(float4(1, 0, 0, 1), color, terrainblend));\n" "#endif\n" +"#endif\n" "\n" " // get the surface normal\n" "#ifdef USEVERTEXTEXTUREBLEND\n" -" half3 surfacenormal = normalize(half3(lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, tex2D(Texture_Normal, TexCoord).rgb, terrainblend)) - half3(0.5, 0.5, 0.5));\n" +" half3 surfacenormal = normalize(half3(lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, offsetMappedTexture2D(Texture_Normal).rgb, terrainblend)) - half3(0.5, 0.5, 0.5));\n" "#else\n" -" half3 surfacenormal = half3(normalize(half3(tex2D(Texture_Normal, TexCoord).rgb) - half3(0.5, 0.5, 0.5)));\n" +" half3 surfacenormal = half3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5, 0.5, 0.5)));\n" "#endif\n" "\n" " // get the material colors\n" " half3 diffusetex = color.rgb;\n" "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n" "# ifdef USEVERTEXTEXTUREBLEND\n" -" half4 glosstex = half4(lerp(tex2D(Texture_SecondaryGloss, TexCoord2), tex2D(Texture_Gloss, TexCoord), terrainblend));\n" +" half4 glosstex = half4(lerp(tex2D(Texture_SecondaryGloss, TexCoord2), offsetMappedTexture2D(Texture_Gloss), terrainblend));\n" "# else\n" -" half4 glosstex = half4(tex2D(Texture_Gloss, TexCoord));\n" +" half4 glosstex = half4(offsetMappedTexture2D(Texture_Gloss));\n" "# endif\n" "#endif\n" "\n" @@ -1273,7 +1341,7 @@ " float3 TangentReflectVector = reflect(-EyeVector, surfacenormal);\n" " float3 ModelReflectVector = TangentReflectVector.x * VectorS + TangentReflectVector.y * VectorT + TangentReflectVector.z * VectorR;\n" " float3 ReflectCubeTexCoord = mul(ModelToReflectCube, float4(ModelReflectVector, 0)).xyz;\n" -" diffusetex += half3(tex2D(Texture_ReflectMask, TexCoord).rgb) * half3(texCUBE(Texture_ReflectCube, ReflectCubeTexCoord).rgb);\n" +" diffusetex += half3(offsetMappedTexture2D(Texture_ReflectMask).rgb) * half3(texCUBE(Texture_ReflectCube, ReflectCubeTexCoord).rgb);\n" "#endif\n" "\n" "\n" @@ -1287,10 +1355,10 @@ " color.rgb = diffusetex * (Color_Ambient + diffuse * Color_Diffuse);\n" "#ifdef USESPECULAR\n" "#ifdef USEEXACTSPECULARMATH\n" -" half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower * glosstex.a));\n" +" half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), 1.0 + SpecularPower * glosstex.a));\n" "#else\n" " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n" -" half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a));\n" +" half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * glosstex.a));\n" "#endif\n" " color.rgb += glosstex.rgb * (specular * Color_Specular);\n" "#endif\n" @@ -1339,22 +1407,19 @@ "\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" " // convert modelspace light vector to tangentspace\n" -" half3 lightnormal;\n" -" lightnormal.x = dot(lightnormal_modelspace, half3(VectorS));\n" -" lightnormal.y = dot(lightnormal_modelspace, half3(VectorT));\n" -" lightnormal.z = dot(lightnormal_modelspace, half3(VectorR));\n" +" half3 lightnormal = half3(dot(lightnormal_modelspace, half3(VectorS)), dot(lightnormal_modelspace, half3(VectorT)), dot(lightnormal_modelspace, half3(VectorR)));\n" " // calculate directional shading (and undoing the existing angle attenuation on the lightmap by the division)\n" " // note that q3map2 is too stupid to calculate proper surface normals when q3map_nonplanar\n" " // is used (the lightmap and deluxemap coords correspond to virtually random coordinates\n" @@ -1367,19 +1432,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" @@ -1403,10 +1474,10 @@ " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n" "# ifdef USESPECULAR\n" "# ifdef USEEXACTSPECULARMATH\n" -" half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower * glosstex.a));\n" +" half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), 1.0 + SpecularPower * glosstex.a));\n" "# else\n" " half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n" -" half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a));\n" +" half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), 1.0 + SpecularPower * glosstex.a));\n" "# endif\n" " color.rgb = diffusetex * Color_Ambient + (diffusetex * Color_Diffuse * diffuse + glosstex.rgb * Color_Specular * specular) * lightcolor;\n" "# else\n" @@ -1431,22 +1502,22 @@ "\n" "#ifdef USEGLOW\n" "#ifdef USEVERTEXTEXTUREBLEND\n" -" color.rgb += half3(lerp(tex2D(Texture_SecondaryGlow, TexCoord2).rgb, tex2D(Texture_Glow, TexCoord).rgb, terrainblend)) * Color_Glow;\n" +" color.rgb += half3(lerp(tex2D(Texture_SecondaryGlow, TexCoord2).rgb, offsetMappedTexture2D(Texture_Glow).rgb, terrainblend)) * Color_Glow;\n" "#else\n" -" color.rgb += half3(tex2D(Texture_Glow, TexCoord).rgb) * Color_Glow;\n" +" color.rgb += half3(offsetMappedTexture2D(Texture_Glow).rgb) * Color_Glow;\n" "#endif\n" "#endif\n" "\n" "#ifdef USEFOG\n" -" color.rgb = FogVertex(color.rgb, FogColor, EyeVectorModelSpaceFogPlaneVertexDist.xyz, EyeVectorModelSpaceFogPlaneVertexDist.w, FogRangeRecip, FogPlaneViewDist, FogHeightFade, Texture_FogMask, Texture_FogHeightTexture);\n" +" color.rgb = half3(FogVertex(color, FogColor, EyeVectorModelSpaceFogPlaneVertexDist.xyz, EyeVectorModelSpaceFogPlaneVertexDist.w, FogRangeRecip, FogPlaneViewDist, FogHeightFade, Texture_FogMask, Texture_FogHeightTexture));\n" "#endif\n" "\n" " // reflection must come last because it already contains exactly the correct fog (the reflection render preserves camera distance from the plane, it only flips the side) and ContrastBoost/SceneBrightness\n" "#ifdef USEREFLECTION\n" " float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n" -" //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(half3(tex2D(Texture_Normal, TexCoord).rgb) - half3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n" +" //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n" " float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW.zw + ScreenCenterRefractReflect.zw;\n" -" float2 ScreenTexCoord = SafeScreenTexCoord + float3(normalize(half3(tex2D(Texture_Normal, TexCoord).rgb) - half3(0.5,0.5,0.5))).xy * DistortScaleRefractReflect.zw;\n" +" float2 ScreenTexCoord = SafeScreenTexCoord + float3(normalize(half3(offsetMappedTexture2D(Texture_Normal).rgb) - half3(0.5,0.5,0.5))).xy * DistortScaleRefractReflect.zw;\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"