int loc_DeferredMod_Specular;
int loc_DistortScaleRefractReflect;
int loc_EyePosition;
+ int loc_EyeDirection;
int loc_FogColor;
int loc_FogHeightFade;
int loc_FogPlane;
p->loc_DeferredMod_Specular = qglGetUniformLocation(p->program, "DeferredMod_Specular");
p->loc_DistortScaleRefractReflect = qglGetUniformLocation(p->program, "DistortScaleRefractReflect");
p->loc_EyePosition = qglGetUniformLocation(p->program, "EyePosition");
+ p->loc_EyeDirection = qglGetUniformLocation(p->program, "EyeDirection");
p->loc_FogColor = qglGetUniformLocation(p->program, "FogColor");
p->loc_FogHeightFade = qglGetUniformLocation(p->program, "FogHeightFade");
p->loc_FogPlane = qglGetUniformLocation(p->program, "FogPlane");
if (r_glsl_permutation->loc_Color_Glow >= 0) qglUniform3f(r_glsl_permutation->loc_Color_Glow, rsurface.glowmod[0], rsurface.glowmod[1], rsurface.glowmod[2]);
if (r_glsl_permutation->loc_Alpha >= 0) qglUniform1f(r_glsl_permutation->loc_Alpha, rsurface.texture->lightmapcolor[3] * ((rsurface.texture->basematerialflags & MATERIALFLAG_WATERSHADER && r_fb.water.enabled && !r_refdef.view.isoverlay) ? rsurface.texture->r_water_wateralpha : 1));
if (r_glsl_permutation->loc_EyePosition >= 0) qglUniform3f(r_glsl_permutation->loc_EyePosition, rsurface.localvieworigin[0], rsurface.localvieworigin[1], rsurface.localvieworigin[2]);
+ if (r_glsl_permutation->loc_EyeDirection >= 0) qglUniform3f(r_glsl_permutation->loc_EyeDirection, rsurface.localviewdirection[0], rsurface.localviewdirection[1], rsurface.localviewdirection[2]);
if (r_glsl_permutation->loc_Color_Pants >= 0)
{
if (rsurface.texture->pantstexture)
static void R_View_Update(void)
{
- R_Main_ResizeViewCache();
- R_View_SetFrustum(NULL);
- R_View_WorldVisibility(r_refdef.view.useclipplane);
- R_View_UpdateEntityVisible();
- R_View_UpdateEntityLighting();
+ R_View_UpdateWithScissor(NULL);
}
float viewscalefpsadjusted = 1.0f;
// update the r_refdef.view.origin because otherwise the sky renders at the wrong location (amongst other problems)
Matrix4x4_OriginFromMatrix(&r_refdef.view.matrix, r_refdef.view.origin);
r_refdef.view.clipplane = p->plane;
+
+ float dotProduct = DotProduct(p->plane.normal, r_refdef.view.origin);
+ float normalLength = VectorLength(p->plane.normal);
+ float planeDist = dotProduct/normalLength - p->plane.dist;
+ if(planeDist > 100)
+ r_refdef.view.clipplane.dist += 100.0;
+ else if(planeDist < -100)
+ r_refdef.view.clipplane.dist -= 100.0;
+ else
+ r_refdef.view.clipplane.dist += 0.95*planeDist;
+
// reverse the cullface settings for this render
r_refdef.view.cullface_front = GL_FRONT;
r_refdef.view.cullface_back = GL_BACK;
r_refdef.view.clipplane = p->plane;
VectorNegate(r_refdef.view.clipplane.normal, r_refdef.view.clipplane.normal);
r_refdef.view.clipplane.dist = -r_refdef.view.clipplane.dist;
+ float dotProduct = DotProduct(p->plane.normal, r_refdef.view.origin);
+ float normalLength = VectorLength(p->plane.normal);
+ float planeDist = dotProduct/normalLength - p->plane.dist;
+ if(planeDist > 100)
+ r_refdef.view.clipplane.dist -= 100.0;
+ else if(planeDist < -100)
+ r_refdef.view.clipplane.dist += 100.0;
+ else
+ r_refdef.view.clipplane.dist -= 0.95*planeDist;
if((p->materialflags & MATERIALFLAG_CAMERA) && p->camera_entity)
{
rsurface.inversematrixscale = 1;
R_EntityMatrix(&identitymatrix);
VectorCopy(r_refdef.view.origin, rsurface.localvieworigin);
+ VectorCopy(r_refdef.view.forward, rsurface.localviewdirection);
Vector4Copy(r_refdef.fogplane, rsurface.fogplane);
rsurface.fograngerecip = r_refdef.fograngerecip;
rsurface.fogheightfade = r_refdef.fogheightfade;
rsurface.inversematrixscale = 1.0f / rsurface.matrixscale;
R_EntityMatrix(&rsurface.matrix);
Matrix4x4_Transform(&rsurface.inversematrix, r_refdef.view.origin, rsurface.localvieworigin);
+ Matrix4x4_Transform(&rsurface.inversematrix, r_refdef.view.forward, rsurface.localviewdirection);
Matrix4x4_TransformStandardPlane(&rsurface.inversematrix, r_refdef.fogplane[0], r_refdef.fogplane[1], r_refdef.fogplane[2], r_refdef.fogplane[3], rsurface.fogplane);
rsurface.fogplaneviewdist *= rsurface.inversematrixscale;
rsurface.fograngerecip = r_refdef.fograngerecip * rsurface.matrixscale;
rsurface.inversematrixscale = 1.0f / rsurface.matrixscale;
R_EntityMatrix(&rsurface.matrix);
Matrix4x4_Transform(&rsurface.inversematrix, r_refdef.view.origin, rsurface.localvieworigin);
+ Matrix4x4_Transform(&rsurface.inversematrix, r_refdef.view.forward, rsurface.localviewdirection);
Matrix4x4_TransformStandardPlane(&rsurface.inversematrix, r_refdef.fogplane[0], r_refdef.fogplane[1], r_refdef.fogplane[2], r_refdef.fogplane[3], rsurface.fogplane);
rsurface.fogplaneviewdist *= rsurface.inversematrixscale;
rsurface.fograngerecip = r_refdef.fograngerecip * rsurface.matrixscale;
"\n",
"#ifdef FRAGMENT_SHADER\n",
"uniform sampler2D Texture_Normal;\n",
+"uniform vec3 EyeDirection;\n",
"uniform sampler2D Texture_Refraction;\n",
"uniform sampler2D Texture_Reflection;\n",
"\n",
"\n",
"void main(void)\n",
"{\n",
+" // correctly shift and scale the texture coordinates\n",
" vec4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n",
-" //vec4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(vec3(dp_texture2D(Texture_Normal, TexCoord)) - vec3(0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\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 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 * distort;\n",
-" #else\n",
-" vec4 ScreenTexCoord = SafeScreenTexCoord + vec2(normalize(vec3(dp_texture2D(Texture_Normal, TexCoord)) - vec3(0.5))).xyxy * distort;\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 * distort;\n",
+//" #else\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",
" // content.\n",
" // Remove this 'ack once we have a better way to stop this thing from\n",
" // 'appening.\n",
-" float f = min(1.0, length(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(0.005, 0.01)).rgb) / 0.002);\n",
-" f *= min(1.0, length(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(0.005, -0.01)).rgb) / 0.002);\n",
-" f *= min(1.0, length(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(-0.005, 0.01)).rgb) / 0.002);\n",
-" f *= min(1.0, length(dp_texture2D(Texture_Refraction, ScreenTexCoord.xy + vec2(-0.005, -0.01)).rgb) / 0.002);\n",
-" ScreenTexCoord.xy = mix(SafeScreenTexCoord.xy, ScreenTexCoord.xy, f);\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",
-" 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",
+" vec4 ScreenTexCoord = SafeScreenTexCoord;\n",
+" vec3 normal = normalize(vec3(dp_texture2D(Texture_Normal, TexCoord.xy))) - vec3(0.5, 0.5, 0.5);\n",
+" normal = normalize(normal);\n",
+" vec3 refrNorm = normal * vec3(0.05, 0.05, 1.0);\n",
+" vec3 reflNorm = normal * vec3(0.02, 0.02, 1.0);\n",
+" vec4 refl = vec4(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw + reflNorm.xy).rgb, 1.0);\n",
+" vec4 refr = vec4(dp_texture2D(Texture_Refraction, ScreenTexCoord.zw + refrNorm.xy).rgb, 1.0);\n",
+" vec4 reflN = vec4(dp_texture2D(Texture_Reflection, ScreenTexCoord.zw - reflNorm.xy).rgb, 1.0);\n",
+" vec4 refrN = vec4(dp_texture2D(Texture_Refraction, ScreenTexCoord.zw - refrNorm.xy).rgb, 1.0);\n",
+" float f = min(1.0, length(refl.rgb) / 0.0002);\n",
+" refl = mix(reflN, refl, f);\n",
+" f = min(1.0, length(refr.rgb) / 0.0002);\n",
+" refr = mix(refrN, refr, f);\n",
+" float dotProduct = abs(dot(EyeDirection, reflNorm));\n",
+" float Fresnel = 0.02f+max(0, 0.97f*pow((1-dotProduct),5));\n",
+" Fresnel = clamp(Fresnel, 0.2, 0.8);\n"
+" dp_FragColor = mix(refr, refl, Fresnel);\n",
"}\n",
"#endif\n",
"#else // !MODE_WATER\n",