[Bf-blender-cvs] [5e3f902eaa3] blender2.8: Eevee: Planar Reflection: Fix precision issue near cliplane.

Clément Foucault noreply at git.blender.org
Fri Jun 23 22:51:44 CEST 2017


Commit: 5e3f902eaa35aaba8e6d27dc9d39fdf4d9a37e3e
Author: Clément Foucault
Date:   Fri Jun 23 19:19:19 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB5e3f902eaa35aaba8e6d27dc9d39fdf4d9a37e3e

Eevee: Planar Reflection: Fix precision issue near cliplane.

The problem was that the depth prepass was using the clip plane but not the shading pass.

During the clipping stage, the triangle is converted to a quad clipped to the given clip plane.
But this introduce subtle changes in the depth when this new geometry is rasterized. Since the shading pass was using an EQUAL depth test, the depth values from the shading pass were not always equal to the depth prepass.

Enabling clipping in the shading vertex shader has a too small impact to require a dedicated shader.

===================================================================

M	source/blender/draw/engines/eevee/eevee_materials.c
M	source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl

===================================================================

diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c
index f4901ed0c55..035766de911 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -430,7 +430,7 @@ static struct DRWShadingGroup *EEVEE_default_shading_group_get(
 	}
 
 	if (vedata->psl->default_pass[options] == NULL) {
-		DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_WIRE;
+		DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_CLIP_PLANES | DRW_STATE_WIRE;
 		vedata->psl->default_pass[options] = DRW_pass_create("Default Lit Pass", state);
 
 		DRWShadingGroup *shgrp = DRW_shgroup_create(e_data.default_lit[options], vedata->psl->default_pass[options]);
@@ -517,7 +517,7 @@ void EEVEE_materials_cache_init(EEVEE_Data *vedata)
 	}
 
 	{
-		DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_WIRE;
+		DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_CLIP_PLANES | DRW_STATE_WIRE;
 		psl->material_pass = DRW_pass_create("Material Shader Pass", state);
 	}
 }
diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
index cf5c8a311f1..998ccfa453a 100644
--- a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
@@ -13,6 +13,9 @@ in vec3 nor;
 out vec3 worldPosition;
 out vec3 viewPosition;
 
+/* Used for planar reflections */
+uniform vec4 ClipPlanes[1];
+
 #ifdef USE_FLAT_NORMAL
 flat out vec3 worldNormal;
 flat out vec3 viewNormal;
@@ -28,6 +31,9 @@ void main() {
 	viewNormal = normalize(NormalMatrix * nor);
 	worldNormal = normalize(WorldNormalMatrix * nor);
 
+	/* Used for planar reflections */
+	gl_ClipDistance[0] = dot(vec4(worldPosition, 1.0), ClipPlanes[0]);
+
 #ifdef ATTRIB
 	pass_attrib(pos);
 #endif




More information about the Bf-blender-cvs mailing list