]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - shader_glsl.h
remove PRECACHE_PIC_NOCLAMP because it currently has no chance to work
[xonotic/darkplaces.git] / shader_glsl.h
index 8c13a2a6e5e599e68b331a9867b250305f7dfab3..c7b5ebffb698690a7b9952f862f3c9fbf7c009c2 100644 (file)
 "\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"
 "      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"
 "      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"
 "\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"
 "      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"
 "      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"
 "      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"
 "#endif\n"
 "void main(void)\n"
 "{\n"
-"#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n"
+"#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n"
 "      VertexColor = Attrib_Color;\n"
 "#endif\n"
 "      // copy the surface texcoord\n"
 "      color.a = 1.0;\n"
 "      //color = mix(cast_myhalf4(1, 0, 0, 1), color, terrainblend);\n"
 "#endif\n"
+"#ifdef USEALPHAGENVERTEX\n"
+"      color.a *= VertexColor.a;\n"
+"#endif\n"
 "\n"
 "      // get the surface normal\n"
 "#ifdef USEVERTEXTEXTUREBLEND\n"