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.
This commit is contained in:
Clément Foucault 2017-06-23 19:19:19 +02:00
parent 1111e64c72
commit 5e3f902eaa
2 changed files with 8 additions and 2 deletions

View File

@ -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);
}
}

View File

@ -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