X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=shader_glsl.h;h=41dac64ef0f84762f7ae4d98eddee39658042fd5;hb=69dc4995cec1bc75263e25dec4ba53356988b62d;hp=aa962c850ac8eff6930cdedb3537e915aab59bf4;hpb=a619c1e537ba00a90fe28e07baf4ecdece222659;p=xonotic%2Fdarkplaces.git diff --git a/shader_glsl.h b/shader_glsl.h index aa962c85..41dac64e 100644 --- a/shader_glsl.h +++ b/shader_glsl.h @@ -310,6 +310,7 @@ "#ifdef USESPECULAR\n" "dp_varying mediump vec2 TexCoord2;\n" "#endif\n" +"uniform myhalf Alpha;\n" "#ifdef VERTEX_SHADER\n" "void main(void)\n" "{\n" @@ -371,6 +372,9 @@ " dp_FragColor.g = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.g, 0)).g;\n" " dp_FragColor.b = dp_texture2D(Texture_GammaRamps, vec2(dp_FragColor.b, 0)).b;\n" "#endif\n" +"#ifdef USEALPHAKILL\n" +" dp_FragColor.a *= Alpha;\n" +"#endif\n" "}\n" "#endif\n" "#else // !MODE_GENERIC\n" @@ -416,6 +420,9 @@ "\n" "void main(void)\n" "{\n" +"#ifdef USEALPHAGENVERTEX\n" +" VertexColor = Attrib_Color;\n" +"#endif\n" " TexCoord = vec2(TexMatrix * Attrib_TexCoord0);\n" " gl_Position = ModelViewProjectionMatrix * Attrib_Position;\n" " ModelViewProjectionPosition = gl_Position;\n" @@ -444,12 +451,19 @@ " vec2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n" " //vec2 ScreenTexCoord = (ModelViewProjectionPosition.xy + normalize(vec3(dp_texture2D(Texture_Normal, TexCoord)) - vec3(0.5)).xy * DistortScaleRefractReflect.xy * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n" " vec2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n" +"#ifdef USEALPHAGENVERTEX\n" +" vec2 distort = DistortScaleRefractReflect.xy * VertexColor.a;\n" +" vec4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), VertexColor.a);\n" +"#else\n" +" vec2 distort = DistortScaleRefractReflect.xy;\n" +" vec4 refractcolor = RefractColor;\n" +"#endif\n" " #ifdef USENORMALMAPSCROLLBLEND\n" " vec3 normal = dp_texture2D(Texture_Normal, (TexCoord + vec2(0.08, 0.08)*ClientTime*NormalmapScrollBlend.x*0.5)*NormalmapScrollBlend.y).rgb - vec3(1.0);\n" " normal += dp_texture2D(Texture_Normal, (TexCoord + vec2(-0.06, -0.09)*ClientTime*NormalmapScrollBlend.x)*NormalmapScrollBlend.y*0.75).rgb;\n" -" vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(cast_myhalf3(normal))).xy * DistortScaleRefractReflect.xy;\n" +" vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(cast_myhalf3(normal))).xy * distort;\n" " #else\n" -" vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(cast_myhalf3(dp_texture2D(Texture_Normal, TexCoord)) - cast_myhalf3(0.5))).xy * DistortScaleRefractReflect.xy;\n" +" vec2 ScreenTexCoord = SafeScreenTexCoord + vec3(normalize(cast_myhalf3(dp_texture2D(Texture_Normal, TexCoord)) - cast_myhalf3(0.5))).xy * distort;\n" " #endif\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" @@ -461,7 +475,7 @@ " f *= min(1.0, length(dp_texture2D(Texture_Refraction, ScreenTexCoord + vec2(-0.01, 0.01)).rgb) / 0.05);\n" " f *= min(1.0, length(dp_texture2D(Texture_Refraction, ScreenTexCoord + vec2(-0.01, -0.01)).rgb) / 0.05);\n" " ScreenTexCoord = mix(SafeScreenTexCoord, ScreenTexCoord, f);\n" -" dp_FragColor = vec4(dp_texture2D(Texture_Refraction, ScreenTexCoord).rgb, 1.0) * RefractColor;\n" +" dp_FragColor = vec4(dp_texture2D(Texture_Refraction, ScreenTexCoord).rgb, 1.0) * refractcolor;\n" "}\n" "#endif\n" "#else // !MODE_REFRACTION\n" @@ -479,6 +493,9 @@ "\n" "void main(void)\n" "{\n" +"#ifdef USEALPHAGENVERTEX\n" +" VertexColor = Attrib_Color;\n" +"#endif\n" " TexCoord = vec2(TexMatrix * Attrib_TexCoord0);\n" " vec3 EyeRelative = EyePosition - Attrib_Position.xyz;\n" " EyeVector.x = dot(EyeRelative, Attrib_TexCoord1.xyz);\n" @@ -516,12 +533,23 @@ " vec4 SafeScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n" " //SafeScreenTexCoord = gl_FragCoord.xyxy * vec4(1.0 / 1920.0, 1.0 / 1200.0, 1.0 / 1920.0, 1.0 / 1200.0);\n" " // slight water animation via 2 layer scrolling (todo: tweak)\n" +"#ifdef USEALPHAGENVERTEX\n" +" vec4 distort = DistortScaleRefractReflect * VertexColor.a;\n" +" float reflectoffset = ReflectOffset * VertexColor.a;\n" +" float reflectfactor = ReflectFactor * VertexColor.a;\n" +" vec4 refractcolor = mix(RefractColor, vec4(1.0, 1.0, 1.0, 1.0), VertexColor.a);\n" +"#else\n" +" vec4 distort = DistortScaleRefractReflect;\n" +" float reflectoffset = ReflectOffset;\n" +" float reflectfactor = ReflectFactor;\n" +" vec4 refractcolor = RefractColor;\n" +"#endif\n" " #ifdef USENORMALMAPSCROLLBLEND\n" " vec3 normal = dp_texture2D(Texture_Normal, (TexCoord + vec2(0.08, 0.08)*ClientTime*NormalmapScrollBlend.x*0.5)*NormalmapScrollBlend.y).rgb - vec3(1.0);\n" " normal += dp_texture2D(Texture_Normal, (TexCoord + vec2(-0.06, -0.09)*ClientTime*NormalmapScrollBlend.x)*NormalmapScrollBlend.y*0.75).rgb;\n" -" vec4 ScreenTexCoord = SafeScreenTexCoord + vec2(normalize(normal) + vec3(0.15)).xyxy * DistortScaleRefractReflect;\n" +" vec4 ScreenTexCoord = SafeScreenTexCoord + vec2(normalize(normal) + vec3(0.15)).xyxy * distort;\n" " #else\n" -" vec4 ScreenTexCoord = SafeScreenTexCoord + vec2(normalize(vec3(dp_texture2D(Texture_Normal, TexCoord)) - vec3(0.5))).xyxy * DistortScaleRefractReflect;\n" +" vec4 ScreenTexCoord = SafeScreenTexCoord + vec2(normalize(vec3(dp_texture2D(Texture_Normal, TexCoord)) - vec3(0.5))).xyxy * distort;\n" " #endif\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" @@ -538,8 +566,8 @@ " f *= min(1.0, length(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw + vec2(-0.005, 0.005)).rgb) / 0.002);\n" " f *= min(1.0, length(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw + vec2(-0.005, -0.005)).rgb) / 0.002);\n" " ScreenTexCoord.zw = mix(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 = mix(vec4(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy).rgb, 1) * RefractColor, vec4(dp_texture2D(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 = mix(vec4(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy).rgb, 1) * refractcolor, vec4(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw).rgb, 1) * ReflectColor, Fresnel);\n" "}\n" "#endif\n" "#else // !MODE_WATER\n" @@ -702,8 +730,17 @@ " float i;\n" " // distance-based LOD\n" "#ifdef USEOFFSETMAPPING_LOD\n" -" mediump float LODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n" -" mediump vec4 ScaleSteps = vec4(OffsetMapping_ScaleSteps.x, OffsetMapping_ScaleSteps.y * LODFactor, OffsetMapping_ScaleSteps.z / LODFactor, OffsetMapping_ScaleSteps.w * LODFactor);\n" +" //mediump float LODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n" +" //mediump vec4 ScaleSteps = vec4(OffsetMapping_ScaleSteps.x, OffsetMapping_ScaleSteps.y * LODFactor, OffsetMapping_ScaleSteps.z / LODFactor, OffsetMapping_ScaleSteps.w * LODFactor);\n" +" mediump float GuessLODFactor = min(1.0, OffsetMapping_LodDistance / EyeVectorFogDepth.z);\n" +"#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n" +" // stupid workaround because 1-step and 2-step reliefmapping is void\n" +" mediump float LODSteps = max(3.0, ceil(GuessLODFactor * OffsetMapping_ScaleSteps.y));\n" +"#else\n" +" mediump float LODSteps = ceil(GuessLODFactor * OffsetMapping_ScaleSteps.y);\n" +"#endif\n" +" mediump float LODFactor = LODSteps / OffsetMapping_ScaleSteps.y;\n" +" mediump vec4 ScaleSteps = vec4(OffsetMapping_ScaleSteps.x, LODSteps, 1.0 / LODSteps, OffsetMapping_ScaleSteps.w * LODFactor);\n" "#else\n" " #define ScaleSteps OffsetMapping_ScaleSteps\n" "#endif\n"