Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl')
-rw-r--r--source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl54
1 files changed, 34 insertions, 20 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
index 53f1517505c..3774054659d 100644
--- a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
@@ -144,14 +144,12 @@ void CLOSURE_NAME(vec3 N
,
float ior
#endif
+ ,
+ const bool use_contact_shadows
#ifdef CLOSURE_DIFFUSE
,
out vec3 out_diff
#endif
-#ifdef CLOSURE_SUBSURFACE
- ,
- out vec3 out_trans
-#endif
#ifdef CLOSURE_GLOSSY
,
out vec3 out_spec
@@ -170,10 +168,6 @@ void CLOSURE_NAME(vec3 N
out_diff = vec3(0.0);
#endif
-#ifdef CLOSURE_SUBSURFACE
- out_trans = vec3(0.0);
-#endif
-
#ifdef CLOSURE_GLOSSY
out_spec = vec3(0.0);
#endif
@@ -230,14 +224,31 @@ void CLOSURE_NAME(vec3 N
vec3 out_spec_clear = vec3(0.0);
# endif
- for (int i = 0; i < MAX_LIGHT && i < laNumLight; ++i) {
+ float tracing_depth = gl_FragCoord.z;
+ /* Constant bias (due to depth buffer precision) */
+ /* Magic numbers for 24bits of precision.
+ * From http://terathon.com/gdc07_lengyel.pdf (slide 26) */
+ tracing_depth -= mix(2.4e-7, 4.8e-7, gl_FragCoord.z);
+ /* Convert to view Z. */
+ tracing_depth = get_view_z_from_depth(tracing_depth);
+
+ vec3 true_normal = normalize(cross(dFdx(viewPosition), dFdy(viewPosition)));
+
+ for (int i = 0; i < MAX_LIGHT && i < laNumLight; i++) {
LightData ld = lights_data[i];
vec4 l_vector; /* Non-Normalized Light Vector with length in last component. */
l_vector.xyz = ld.l_position - worldPosition;
l_vector.w = length(l_vector.xyz);
- float l_vis = light_visibility(ld, worldPosition, viewPosition, viewNormal, l_vector);
+ float l_vis = light_visibility(ld,
+ worldPosition,
+ viewPosition,
+ tracing_depth,
+ true_normal,
+ rand.x,
+ use_contact_shadows,
+ l_vector);
if (l_vis < 1e-8) {
continue;
@@ -249,10 +260,6 @@ void CLOSURE_NAME(vec3 N
out_diff += l_color_vis * light_diffuse(ld, N, V, l_vector);
# endif
-# ifdef CLOSURE_SUBSURFACE
- out_trans += ld.l_color * light_translucent(ld, worldPosition, -N, l_vector, sss_scale);
-# endif
-
# ifdef CLOSURE_GLOSSY
out_spec += l_color_vis * light_specular(ld, ltc_mat, N, V, l_vector) * ld.l_spec;
# endif
@@ -297,7 +304,7 @@ void CLOSURE_NAME(vec3 N
/* Planar Reflections */
/* ---------------------------- */
- for (int i = 0; i < MAX_PLANAR && i < prbNumPlanar && spec_accum.a < 0.999; ++i) {
+ for (int i = 0; i < MAX_PLANAR && i < prbNumPlanar && spec_accum.a < 0.999; i++) {
PlanarData pd = planars_data[i];
/* Fade on geometric normal. */
@@ -373,7 +380,7 @@ void CLOSURE_NAME(vec3 N
# endif
/* Starts at 1 because 0 is world probe */
- for (int i = 1; ACCUM < 0.999 && i < prbNumRenderCube && i < MAX_PROBE; ++i) {
+ for (int i = 1; ACCUM < 0.999 && i < prbNumRenderCube && i < MAX_PROBE; i++) {
float fade = probe_attenuation_cube(i, worldPosition);
if (fade > 0.0) {
@@ -441,10 +448,17 @@ void CLOSURE_NAME(vec3 N
/* Ambient Occlusion */
/* ---------------------------- */
# if defined(CLOSURE_GLOSSY) || defined(CLOSURE_DIFFUSE)
- /* HACK: Fix for translucent BSDF. (see T65631) */
- bool same_side = dot((gl_FrontFacing) ? worldNormal : -worldNormal, N) > 0.0;
+ if (!use_contact_shadows) {
+ /* HACK: Fix for translucent BSDF. (see T65631) */
+ N = -N;
+ }
vec3 bent_normal;
- float final_ao = occlusion_compute(same_side ? N : -N, viewPosition, ao, rand, bent_normal);
+ float final_ao = occlusion_compute(N, viewPosition, ao, rand, bent_normal);
+ if (!use_contact_shadows) {
+ N = -N;
+ /* Bypass bent normal. */
+ bent_normal = N;
+ }
# endif
/* ---------------------------- */
@@ -501,7 +515,7 @@ void CLOSURE_NAME(vec3 N
/* Irradiance Grids */
/* ---------------------------- */
/* Start at 1 because 0 is world irradiance */
- for (int i = 1; i < MAX_GRID && i < prbNumRenderGrid && diff_accum.a < 0.999; ++i) {
+ for (int i = 1; i < MAX_GRID && i < prbNumRenderGrid && diff_accum.a < 0.999; i++) {
GridData gd = grids_data[i];
vec3 localpos;