Eevee: fix some glsl for low quality lamps.
This commit is contained in:
parent
e053fade99
commit
c28a4eb8cb
|
@ -5,6 +5,8 @@
|
|||
#define M_1_2PI 0.159154943091895335768 /* 1/(2*pi) */
|
||||
#define M_1_PI2 0.101321183642337771443 /* 1/(pi^2) */
|
||||
|
||||
#define LUT_SIZE 64
|
||||
|
||||
/* ------- Structures -------- */
|
||||
|
||||
struct LightData {
|
||||
|
@ -127,6 +129,16 @@ vec3 line_aligned_plane_intersect(vec3 lineorigin, vec3 linedirection, vec3 plan
|
|||
return lineorigin + linedirection * dist;
|
||||
}
|
||||
|
||||
/* Return texture coordinates to sample Surface LUT */
|
||||
vec2 lut_coords(float cosTheta, float roughness)
|
||||
{
|
||||
float theta = acos(cosTheta);
|
||||
vec2 coords = vec2(roughness, theta / M_PI_2);
|
||||
|
||||
/* scale and bias coordinates, for correct filtered lookup */
|
||||
return coords * (LUT_SIZE - 1.0) / LUT_SIZE + 0.5 / LUT_SIZE;
|
||||
}
|
||||
|
||||
/* -- Tangent Space conversion -- */
|
||||
vec3 tangent_to_world(vec3 vector, vec3 N, vec3 T, vec3 B)
|
||||
{
|
||||
|
|
|
@ -96,13 +96,13 @@ vec3 direct_ggx_point(ShadingData sd, float roughness, vec3 f0)
|
|||
vec3 direct_ggx_sphere(LightData ld, ShadingData sd, float roughness, vec3 f0)
|
||||
{
|
||||
#ifdef USE_LTC
|
||||
float NV = max(dot(sd.N, sd.V), 1e-8);
|
||||
vec3 P = line_aligned_plane_intersect(vec3(0.0), sd.spec_dominant_dir, sd.l_vector);
|
||||
|
||||
vec3 Px = normalize(P - sd.l_vector) * ld.l_radius;
|
||||
vec3 Py = cross(Px, sd.L);
|
||||
|
||||
float NV = max(dot(sd.N, sd.V), 1e-8);
|
||||
vec2 uv = ltc_coords(NV, sqrt(roughness));
|
||||
vec2 uv = lut_coords(NV, sqrt(roughness));
|
||||
mat3 ltcmat = ltc_matrix(uv);
|
||||
|
||||
// #define HIGHEST_QUALITY
|
||||
|
@ -148,7 +148,7 @@ vec3 direct_ggx_sphere(LightData ld, ShadingData sd, float roughness, vec3 f0)
|
|||
|
||||
/* Fresnel */
|
||||
float VH = max(dot(sd.V, normalize(sd.V + sd.L)), 0.0);
|
||||
vec3 spec = F_schlick(f0, NV) * bsdf;
|
||||
vec3 spec = F_schlick(f0, VH) * bsdf;
|
||||
#endif
|
||||
return spec;
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ vec3 direct_ggx_rectangle(LightData ld, ShadingData sd, float roughness, vec3 f0
|
|||
{
|
||||
#ifdef USE_LTC
|
||||
float NV = max(dot(sd.N, sd.V), 1e-8);
|
||||
vec2 uv = ltc_coords(NV, sqrt(roughness));
|
||||
vec2 uv = lut_coords(NV, sqrt(roughness));
|
||||
mat3 ltcmat = ltc_matrix(uv);
|
||||
|
||||
float bsdf = ltc_evaluate(sd.N, sd.V, ltcmat, sd.area_data.corner);
|
||||
|
@ -180,7 +180,7 @@ vec3 direct_ggx_rectangle(LightData ld, ShadingData sd, float roughness, vec3 f0
|
|||
|
||||
/* Fresnel */
|
||||
float VH = max(dot(sd.V, normalize(sd.V + sd.L)), 0.0);
|
||||
vec3 spec = F_schlick(f0, NV) * bsdf;
|
||||
vec3 spec = F_schlick(f0, VH) * bsdf;
|
||||
#endif
|
||||
return spec;
|
||||
}
|
||||
|
|
|
@ -264,7 +264,7 @@ vec3 eevee_surface_lit(vec3 world_normal, vec3 albedo, vec3 f0, float roughness,
|
|||
}
|
||||
|
||||
/* Envmaps */
|
||||
vec2 uv = ltc_coords(dot(sd.N, sd.V), sqrt(roughness));
|
||||
vec2 uv = lut_coords(dot(sd.N, sd.V), sqrt(roughness));
|
||||
vec2 brdf_lut = texture(brdfLut, uv).rg;
|
||||
vec3 Li = textureLod(probeFiltered, sd.spec_dominant_dir, roughness * lodMax).rgb;
|
||||
indirect_radiance += Li * brdf_lut.y + f0 * Li * brdf_lut.x;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* Mainly From https://eheitzresearch.wordpress.com/415-2/ */
|
||||
|
||||
#define USE_LTC
|
||||
#define LTC_LUT_SIZE 64
|
||||
|
||||
uniform sampler2D ltcMat;
|
||||
uniform sampler2D brdfLut;
|
||||
|
@ -146,15 +145,6 @@ int clip_quad_to_horizon(inout vec3 L[5])
|
|||
return n;
|
||||
}
|
||||
|
||||
vec2 ltc_coords(float cosTheta, float roughness)
|
||||
{
|
||||
float theta = acos(cosTheta);
|
||||
vec2 coords = vec2(roughness, theta/(0.5*3.14159));
|
||||
|
||||
/* scale and bias coordinates, for correct filtered lookup */
|
||||
return coords * (LTC_LUT_SIZE - 1.0) / LTC_LUT_SIZE + 0.5 / LTC_LUT_SIZE;
|
||||
}
|
||||
|
||||
mat3 ltc_matrix(vec2 coord)
|
||||
{
|
||||
/* load inverse matrix */
|
||||
|
|
Loading…
Reference in New Issue