From 30115b3a83815b83a72c82f1b1a912c3c32305a0 Mon Sep 17 00:00:00 2001 From: divverent Date: Fri, 25 Sep 2009 20:58:44 +0000 Subject: [PATCH] add an ugly hack to reflections/refractions to "behave" when otherwise black edges would appear git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9234 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rmain.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/gl_rmain.c b/gl_rmain.c index a30e6e60..33a255ba 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -1065,7 +1065,24 @@ static const char *builtinshaderstring = "\n" " vec4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n" " //vec4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(myhalf3(texture2D(Texture_Normal, TexCoord)) - myhalf3(0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n" -" vec4 ScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect + vec2(normalize(myhalf3(texture2D(Texture_Normal, TexCoord)) - myhalf3(0.5))).xyxy * DistortScaleRefractReflect;\n" +" vec4 SafeScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n" +" vec4 ScreenTexCoord = SafeScreenTexCoord + vec2(normalize(myhalf3(texture2D(Texture_Normal, TexCoord)) - myhalf3(0.5))).xyxy * DistortScaleRefractReflect;\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" +" // Remove this 'ack once we have a better way to stop this thing from\n" +" // 'appening.\n" +" float f = 1;\n" +" f *= min(1, length(texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(0.05, 0.05))) / 0.02);\n" +" f *= min(1, length(texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(0.05, -0.05))) / 0.02);\n" +" f *= min(1, length(texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(-0.05, 0.05))) / 0.02);\n" +" f *= min(1, length(texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(-0.05, -0.05))) / 0.02);\n" +" f *= min(1, length(texture2D(Texture_Reflection, ScreenTexCoord.zw + vec2(0.05, 0.05))) / 0.02);\n" +" f *= min(1, length(texture2D(Texture_Reflection, ScreenTexCoord.zw + vec2(0.05, -0.05))) / 0.02);\n" +" f *= min(1, length(texture2D(Texture_Reflection, ScreenTexCoord.zw + vec2(-0.05, 0.05))) / 0.02);\n" +" f *= min(1, length(texture2D(Texture_Reflection, ScreenTexCoord.zw + vec2(-0.05, -0.05))) / 0.02);\n" +" ScreenTexCoord = mix(SafeScreenTexCoord, ScreenTexCoord, f);\n" +" // END OF UGLY UGLY UGLY HACK\n" " float Fresnel = pow(min(1.0, 1.0 - float(normalize(EyeVector).z)), 2.0) * ReflectFactor + ReflectOffset;\n" " gl_FragColor = mix(texture2D(Texture_Refraction, ScreenTexCoord.xy) * RefractColor, texture2D(Texture_Reflection, ScreenTexCoord.zw) * ReflectColor, Fresnel);\n" "}\n" -- 2.39.2