]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - shader_hlsl.h
r_water, MODE_REFRACTION: support alphaGen vertex for fading out water
[xonotic/darkplaces.git] / shader_hlsl.h
index 78f291c619449265a5aed050caafe5f586188f05..d09307cfcf57e671e6f6a2c61fecd2cb607533f1 100644 (file)
 "(\n"
 "float4 gl_Vertex : POSITION,\n"
 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
+"#ifdef USEALPHAGENVERTEX\n"
+"float4 gl_Color : COLOR0,\n"
+"#endif\n"
 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
 "uniform float4x4 TexMatrix : register(c0),\n"
 "uniform float3 EyePosition : register(c24),\n"
+"#ifdef USEALPHAGENVERTEX\n"
+"out float4 gl_FrontColor : COLOR,\n"
+"#endif\n"
 "out float4 gl_Position : POSITION,\n"
 "out float2 TexCoord : TEXCOORD0,\n"
 "out float3 EyeVector : TEXCOORD1,\n"
 "out float4 ModelViewProjectionPosition : TEXCOORD2\n"
 ")\n"
 "{\n"
+"#ifdef USEALPHAGENVERTEX\n"
+"      gl_FrontColor = gl_Color;\n"
+"#endif\n"
 "      TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n"
 "      gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n"
 "      ModelViewProjectionPosition = gl_Position;\n"
 "#ifdef FRAGMENT_SHADER\n"
 "void main\n"
 "(\n"
+"#ifdef USEALPHAGENVERTEX\n"
+"float4 gl_FrontColor : COLOR,\n"
+"#endif\n"
 "float2 TexCoord : TEXCOORD0,\n"
 "float3 EyeVector : TEXCOORD1,\n"
 "float4 ModelViewProjectionPosition : TEXCOORD2,\n"
 "      float2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n"
 "      //float2 ScreenTexCoord = (ModelViewProjectionPosition.xy + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy * DistortScaleRefractReflect.xy * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n"
 "      float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n"
-"      float2 ScreenTexCoord = SafeScreenTexCoord + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy * DistortScaleRefractReflect.xy;\n"
+"#ifdef USEALPHAGENVERTEX\n"
+"      float2 distort = DistortScaleRefractReflect.xy * gl_FrontColor.a;\n"
+"      float4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), gl_FrontColor.a);\n"
+"#else\n"
+"      float2 distort = DistortScaleRefractReflect.xy;\n"
+"      float4 refractcolor = RefractColor;\n"
+"#endif\n"
+"      float2 ScreenTexCoord = SafeScreenTexCoord + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy * distort;\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"
 "      f      *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n"
 "      f      *= min(1.0, length(tex2D(Texture_Refraction, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n"
 "      ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n"
-"      dp_FragColor = float4(tex2D(Texture_Refraction, ScreenTexCoord).rgb, 1) * RefractColor;\n"
+"      dp_FragColor = float4(tex2D(Texture_Refraction, ScreenTexCoord).rgb, 1) * refractcolor;\n"
 "}\n"
 "#endif\n"
 "#else // !MODE_REFRACTION\n"
 "(\n"
 "float4 gl_Vertex : POSITION,\n"
 "uniform float4x4 ModelViewProjectionMatrix : register(c8),\n"
+"#ifdef USEALPHAGENVERTEX\n"
+"float4 gl_Color : COLOR0,\n"
+"#endif\n"
 "float4 gl_MultiTexCoord0 : TEXCOORD0,\n"
 "float4 gl_MultiTexCoord1 : TEXCOORD1,\n"
 "float4 gl_MultiTexCoord2 : TEXCOORD2,\n"
 "float4 gl_MultiTexCoord3 : TEXCOORD3,\n"
 "uniform float4x4 TexMatrix : register(c0),\n"
 "uniform float3 EyePosition : register(c24),\n"
+"#ifdef USEALPHAGENVERTEX\n"
+"out float4 gl_FrontColor : COLOR,\n"
+"#endif\n"
 "out float4 gl_Position : POSITION,\n"
 "out float2 TexCoord : TEXCOORD0,\n"
 "out float3 EyeVector : TEXCOORD1,\n"
 "out float4 ModelViewProjectionPosition : TEXCOORD2\n"
 ")\n"
 "{\n"
+"#ifdef USEALPHAGENVERTEX\n"
+"      gl_FrontColor = gl_Color;\n"
+"#endif\n"
 "      TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n"
 "      float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n"
 "      EyeVector = float3(dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz), dot(EyeVectorModelSpace, gl_MultiTexCoord3.xyz));\n"
 "#ifdef FRAGMENT_SHADER\n"
 "void main\n"
 "(\n"
+"#ifdef USEALPHAGENVERTEX\n"
+"float4 gl_FrontColor : COLOR,\n"
+"#endif\n"
 "float2 TexCoord : TEXCOORD0,\n"
 "float3 EyeVector : TEXCOORD1,\n"
 "float4 ModelViewProjectionPosition : TEXCOORD2,\n"
 "      //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
 "      float4 SafeScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n"
 "      //SafeScreenTexCoord = gl_FragCoord.xyxy * float4(1.0 / 1920.0, 1.0 / 1200.0, 1.0 / 1920.0, 1.0 / 1200.0);\n"
-"      float4 ScreenTexCoord = SafeScreenTexCoord + float2(normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy).xyxy * DistortScaleRefractReflect;\n"
+"#ifdef USEALPHAGENVERTEX\n"
+"      float4 distort = DistortScaleRefractReflect * gl_FrontColor.a;\n"
+"      float reflectoffset = ReflectOffset * gl_FrontColor.a;\n"
+"      float reflectfactor = ReflectFactor * gl_FrontColor.a;\n"
+"      float4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), gl_FrontColor.a);\n"
+"#else\n"
+"      float4 distort = DistortScaleRefractReflect;\n"
+"      float reflectoffset = ReflectOffset;\n"
+"      float reflectfactor = ReflectFactor;\n"
+"      float4 refractcolor = RefractColor;\n"
+"#endif\n"
+"      float4 ScreenTexCoord = SafeScreenTexCoord + float2(normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy).xyxy * distort;\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"
 "      f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(-0.01, 0.01)).rgb) / 0.05);\n"
 "      f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord.zw + float2(-0.01, -0.01)).rgb) / 0.05);\n"
 "      ScreenTexCoord.zw = lerp(SafeScreenTexCoord.zw, ScreenTexCoord.zw, f);\n"
-"      float Fresnel = pow(min(1.0, 1.0 - float(normalize(EyeVector).z)), 2.0) * ReflectFactor + ReflectOffset;\n"
-"      dp_FragColor = lerp(float4(tex2D(Texture_Refraction, ScreenTexCoord.xy).rgb, 1) * RefractColor, float4(tex2D(Texture_Reflection, ScreenTexCoord.zw).rgb, 1) * ReflectColor, Fresnel);\n"
+"      float Fresnel = pow(min(1.0, 1.0 - float(normalize(EyeVector).z)), 2.0) * reflectfactor + reflectoffset;\n"
+"      dp_FragColor = lerp(float4(tex2D(Texture_Refraction, ScreenTexCoord.xy).rgb, 1) * refractcolor, float4(tex2D(Texture_Reflection, ScreenTexCoord.zw).rgb, 1) * ReflectColor, Fresnel);\n"
 "}\n"
 "#endif\n"
 "#else // !MODE_WATER\n"