]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - shader_hlsl.h
avoid bugs introduced by the attempt to skip image processing - a closer
[xonotic/darkplaces.git] / shader_hlsl.h
index f5d1dd8a9e915815dbfba4627613ab966877df53..5e271ce942029f8cc21066878cce4ae298ef54dd 100644 (file)
 "#endif\n"
 "\n"
 "#ifdef USEOFFSETMAPPING\n"
-"float2 OffsetMapping(float2 TexCoord, float3 OffsetMapping_ScaleSteps, float3 EyeVector, sampler Texture_Normal, float2 dPdx, float2 dPdy)\n"
+"float2 OffsetMapping(float2 TexCoord, float4 OffsetMapping_ScaleSteps, float3 EyeVector, sampler Texture_Normal, float2 dPdx, float2 dPdy)\n"
 "{\n"
 "      float i;\n"
 "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n"
 "      OffsetVector *= OffsetMapping_ScaleSteps.z;\n"
 "      for(i = 1.0; i < OffsetMapping_ScaleSteps.y; ++i)\n"
 "              RT += OffsetVector *  step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z);\n"
-"      RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z)          - 0.5);\n"
-"      RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * 0.5    - 0.25);\n"
-"      RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * 0.25   - 0.125);\n"
-"      RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * 0.125  - 0.0625);\n"
-"      RT += OffsetVector * (step(tex2Dgrad(Texture_Normal, RT.xy, dPdx, dPdy).a, RT.z) * 0.0625 - 0.03125);\n"
+"      for(i = 0.0, f = 1.0; i < OffsetMapping_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"
 "uniform sampler Texture_SecondaryGloss : register(s6),\n"
 "#endif\n"
 "#ifdef USEOFFSETMAPPING\n"
-"uniform float3 OffsetMapping_ScaleSteps : register(c24),\n"
+"uniform float4 OffsetMapping_ScaleSteps : register(c24),\n"
 "#endif\n"
 "uniform half SpecularPower : register(c36),\n"
 "#ifdef HLSL\n"
 "#endif\n"
 "\n"
 "#ifdef USEOFFSETMAPPING\n"
-"uniform float3 OffsetMapping_ScaleSteps : register(c24),\n"
+"uniform float4 OffsetMapping_ScaleSteps : register(c24),\n"
 "#endif\n"
 "\n"
 "#ifdef USEDEFERREDLIGHTMAP\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"
 "      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"