Eevee: Small code codestyle and fixes.
Rename get_specular_dominant_dir to get_specular_reflection_dominant_dir. Add Zero length N check everywhere.
This commit is contained in:
parent
8e36089e41
commit
aaa469a403
|
@ -281,7 +281,7 @@ vec3 get_world_space_from_depth(vec2 uvcoords, float depth)
|
|||
return (ViewMatrixInverse * vec4(get_view_space_from_depth(uvcoords, depth), 1.0)).xyz;
|
||||
}
|
||||
|
||||
vec3 get_specular_dominant_dir(vec3 N, vec3 V, float roughness)
|
||||
vec3 get_specular_reflection_dominant_dir(vec3 N, vec3 V, float roughness)
|
||||
{
|
||||
vec3 R = -reflect(V, N);
|
||||
float smoothness = 1.0 - roughness;
|
||||
|
@ -334,7 +334,7 @@ vec3 F_area(vec3 f0, vec2 lut)
|
|||
return saturate(50.0 * dot(f0, vec3(0.3, 0.6, 0.1))) * fac.y + fac.x * f0;
|
||||
}
|
||||
|
||||
/* Fresnel approximation for LTC area lights (not MRP) */
|
||||
/* Fresnel approximation for IBL */
|
||||
vec3 F_ibl(vec3 f0, vec2 lut)
|
||||
{
|
||||
/* Unreal specular matching : if specular color is below 2% intensity,
|
||||
|
|
|
@ -105,7 +105,7 @@ vec3 direct_ggx_sun(LightData ld, vec3 N, vec3 V, float roughness, vec3 f0)
|
|||
vec3 direct_ggx_sphere(LightData ld, vec3 N, vec3 V, vec4 l_vector, float roughness, vec3 f0)
|
||||
{
|
||||
vec3 L = l_vector.xyz / l_vector.w;
|
||||
vec3 spec_dir = get_specular_dominant_dir(N, V, roughness);
|
||||
vec3 spec_dir = get_specular_reflection_dominant_dir(N, V, roughness);
|
||||
vec3 P = line_aligned_plane_intersect(vec3(0.0), spec_dir, l_vector.xyz);
|
||||
|
||||
vec3 Px = normalize(P - l_vector.xyz) * ld.l_radius;
|
||||
|
|
|
@ -6,12 +6,16 @@ uniform float invSampleCount;
|
|||
|
||||
vec2 jitternoise = vec2(0.0);
|
||||
|
||||
#ifdef NOISE_SIZE
|
||||
#ifndef UTIL_TEX
|
||||
#define UTIL_TEX
|
||||
uniform sampler2DArray utilTex;
|
||||
#endif /* UTIL_TEX */
|
||||
|
||||
void setup_noise(void)
|
||||
{
|
||||
jitternoise = texture(texJitter, gl_FragCoord.xy / NOISE_SIZE).rg; /* Global variable */
|
||||
jitternoise = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0)).rg; /* Global variable */
|
||||
jitternoise.g = (jitternoise.g - 0.5) * 2.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAMMERSLEY_SIZE
|
||||
vec3 hammersley_3d(float i, float invsamplenbr)
|
||||
|
|
|
@ -191,7 +191,7 @@ out vec4 fragColor;
|
|||
void fallback_cubemap(vec3 N, vec3 V, vec3 W, float roughness, float roughnessSquared, inout vec4 spec_accum)
|
||||
{
|
||||
/* Specular probes */
|
||||
vec3 spec_dir = get_specular_dominant_dir(N, V, roughnessSquared);
|
||||
vec3 spec_dir = get_specular_reflection_dominant_dir(N, V, roughnessSquared);
|
||||
|
||||
/* Starts at 1 because 0 is world probe */
|
||||
for (int i = 1; i < MAX_PROBE && i < probe_count && spec_accum.a < 0.999; ++i) {
|
||||
|
|
|
@ -167,8 +167,7 @@ vec3 probe_evaluate_world_spec(vec3 R, float roughness)
|
|||
|
||||
vec3 probe_evaluate_planar(
|
||||
float id, PlanarData pd, vec3 W, vec3 N, vec3 V,
|
||||
float rand, float roughness,
|
||||
inout float fade)
|
||||
float roughness, inout float fade)
|
||||
{
|
||||
/* Find view vector / reflection plane intersection. */
|
||||
vec3 point_on_plane = line_plane_intersect(W, V, pd.pl_plane_eq);
|
||||
|
|
|
@ -45,8 +45,6 @@ vec3 eevee_surface_lit(vec3 N, vec3 albedo, vec3 f0, float roughness, float ao,
|
|||
|
||||
vec3 V = cameraVec;
|
||||
|
||||
vec4 rand = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0));
|
||||
|
||||
/* ---------------- SCENE LAMPS LIGHTING ----------------- */
|
||||
|
||||
#ifdef HAIR_SHADER
|
||||
|
@ -99,13 +97,13 @@ vec3 eevee_surface_lit(vec3 N, vec3 albedo, vec3 f0, float roughness, float ao,
|
|||
float fade = probe_attenuation_planar(pd, worldPosition, N, roughness);
|
||||
|
||||
if (fade > 0.0) {
|
||||
vec3 spec = probe_evaluate_planar(float(i), pd, worldPosition, N, V, rand.r, roughness, fade);
|
||||
vec3 spec = probe_evaluate_planar(float(i), pd, worldPosition, N, V, roughness, fade);
|
||||
accumulate_light(spec, fade, spec_accum);
|
||||
}
|
||||
}
|
||||
|
||||
/* Specular probes */
|
||||
vec3 spec_dir = get_specular_dominant_dir(N, V, roughnessSquared);
|
||||
vec3 spec_dir = get_specular_reflection_dominant_dir(N, V, roughnessSquared);
|
||||
|
||||
/* Starts at 1 because 0 is world probe */
|
||||
for (int i = 1; i < MAX_PROBE && i < probe_count && spec_accum.a < 0.999; ++i) {
|
||||
|
@ -126,6 +124,8 @@ vec3 eevee_surface_lit(vec3 N, vec3 albedo, vec3 f0, float roughness, float ao,
|
|||
}
|
||||
}
|
||||
|
||||
vec4 rand = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0));
|
||||
|
||||
/* Ambient Occlusion */
|
||||
vec3 bent_normal;
|
||||
float final_ao = occlusion_compute(N, viewPosition, ao, rand.rg, bent_normal);
|
||||
|
@ -178,11 +178,27 @@ vec3 eevee_surface_clearcoat_lit(
|
|||
C_roughness = clamp(C_roughness, 1e-8, 0.9999);
|
||||
float C_roughnessSquared = C_roughness * C_roughness;
|
||||
|
||||
vec3 V = cameraVec;
|
||||
/* Zero length vectors cause issues, see: T51979. */
|
||||
#if 0
|
||||
N = normalize(N);
|
||||
C_N = normalize(C_N);
|
||||
#else
|
||||
{
|
||||
float len = length(N);
|
||||
if (isnan(len)) {
|
||||
return vec3(0.0);
|
||||
}
|
||||
N /= len;
|
||||
|
||||
vec4 rand = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0));
|
||||
len = length(C_N);
|
||||
if (isnan(len)) {
|
||||
return vec3(0.0);
|
||||
}
|
||||
C_N /= len;
|
||||
}
|
||||
#endif
|
||||
|
||||
vec3 V = cameraVec;
|
||||
|
||||
/* ---------------- SCENE LAMPS LIGHTING ----------------- */
|
||||
|
||||
|
@ -239,18 +255,18 @@ vec3 eevee_surface_clearcoat_lit(
|
|||
|
||||
if (fade > 0.0) {
|
||||
if (!(ssrToggle && ssr_id == outputSsrId)) {
|
||||
vec3 spec = probe_evaluate_planar(float(i), pd, worldPosition, N, V, rand.r, roughness, fade);
|
||||
vec3 spec = probe_evaluate_planar(float(i), pd, worldPosition, N, V, roughness, fade);
|
||||
accumulate_light(spec, fade, spec_accum);
|
||||
}
|
||||
|
||||
vec3 C_spec = probe_evaluate_planar(float(i), pd, worldPosition, C_N, V, rand.r, C_roughness, fade);
|
||||
vec3 C_spec = probe_evaluate_planar(float(i), pd, worldPosition, C_N, V, C_roughness, fade);
|
||||
accumulate_light(C_spec, fade, C_spec_accum);
|
||||
}
|
||||
}
|
||||
|
||||
/* Specular probes */
|
||||
vec3 spec_dir = get_specular_dominant_dir(N, V, roughnessSquared);
|
||||
vec3 C_spec_dir = get_specular_dominant_dir(C_N, V, C_roughnessSquared);
|
||||
vec3 spec_dir = get_specular_reflection_dominant_dir(N, V, roughnessSquared);
|
||||
vec3 C_spec_dir = get_specular_reflection_dominant_dir(C_N, V, C_roughnessSquared);
|
||||
|
||||
/* Starts at 1 because 0 is world probe */
|
||||
for (int i = 1; i < MAX_PROBE && i < probe_count && spec_accum.a < 0.999; ++i) {
|
||||
|
@ -280,6 +296,8 @@ vec3 eevee_surface_clearcoat_lit(
|
|||
accumulate_light(C_spec, 1.0, C_spec_accum);
|
||||
}
|
||||
|
||||
vec4 rand = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0));
|
||||
|
||||
/* Ambient Occlusion */
|
||||
vec3 bent_normal;
|
||||
float final_ao = occlusion_compute(N, viewPosition, ao, rand.rg, bent_normal);
|
||||
|
@ -330,9 +348,19 @@ vec3 eevee_surface_clearcoat_lit(
|
|||
vec3 eevee_surface_diffuse_lit(vec3 N, vec3 albedo, float ao)
|
||||
{
|
||||
vec3 V = cameraVec;
|
||||
N = normalize(N);
|
||||
|
||||
vec4 rand = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0));
|
||||
/* Zero length vectors cause issues, see: T51979. */
|
||||
#if 0
|
||||
N = normalize(N);
|
||||
#else
|
||||
{
|
||||
float len = length(N);
|
||||
if (isnan(len)) {
|
||||
return vec3(0.0);
|
||||
}
|
||||
N /= len;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ---------------- SCENE LAMPS LIGHTING ----------------- */
|
||||
|
||||
|
@ -371,6 +399,8 @@ vec3 eevee_surface_diffuse_lit(vec3 N, vec3 albedo, float ao)
|
|||
|
||||
/* ---------------- DIFFUSE ENVIRONMENT LIGHTING ----------------- */
|
||||
|
||||
vec4 rand = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0));
|
||||
|
||||
/* Ambient Occlusion */
|
||||
vec3 bent_normal;
|
||||
float final_ao = occlusion_compute(N, viewPosition, ao, rand.rg, bent_normal);
|
||||
|
@ -410,9 +440,19 @@ vec3 eevee_surface_glossy_lit(vec3 N, vec3 f0, float roughness, float ao, int ss
|
|||
float roughnessSquared = roughness * roughness;
|
||||
|
||||
vec3 V = cameraVec;
|
||||
N = normalize(N);
|
||||
|
||||
vec4 rand = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0));
|
||||
/* Zero length vectors cause issues, see: T51979. */
|
||||
#if 0
|
||||
N = normalize(N);
|
||||
#else
|
||||
{
|
||||
float len = length(N);
|
||||
if (isnan(len)) {
|
||||
return vec3(0.0);
|
||||
}
|
||||
N /= len;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ---------------- SCENE LAMPS LIGHTING ----------------- */
|
||||
|
||||
|
@ -462,13 +502,13 @@ vec3 eevee_surface_glossy_lit(vec3 N, vec3 f0, float roughness, float ao, int ss
|
|||
float fade = probe_attenuation_planar(pd, worldPosition, N, roughness);
|
||||
|
||||
if (fade > 0.0) {
|
||||
vec3 spec = probe_evaluate_planar(float(i), pd, worldPosition, N, V, rand.r, roughness, fade);
|
||||
vec3 spec = probe_evaluate_planar(float(i), pd, worldPosition, N, V, roughness, fade);
|
||||
accumulate_light(spec, fade, spec_accum);
|
||||
}
|
||||
}
|
||||
|
||||
/* Specular probes */
|
||||
vec3 spec_dir = get_specular_dominant_dir(N, V, roughnessSquared);
|
||||
vec3 spec_dir = get_specular_reflection_dominant_dir(N, V, roughnessSquared);
|
||||
|
||||
/* Starts at 1 because 0 is world probe */
|
||||
for (int i = 1; i < MAX_PROBE && i < probe_count && spec_accum.a < 0.999; ++i) {
|
||||
|
@ -489,6 +529,8 @@ vec3 eevee_surface_glossy_lit(vec3 N, vec3 f0, float roughness, float ao, int ss
|
|||
}
|
||||
}
|
||||
|
||||
vec4 rand = texture(utilTex, vec3(gl_FragCoord.xy / LUT_SIZE, 2.0));
|
||||
|
||||
/* Ambient Occlusion */
|
||||
vec3 bent_normal;
|
||||
float final_ao = occlusion_compute(N, viewPosition, ao, rand.rg, bent_normal);
|
||||
|
|
Loading…
Reference in New Issue