Eevee: Hair: Make SSR works with hairs.
This commit is contained in:
parent
119423b252
commit
98e4d548a1
|
@ -896,7 +896,7 @@ static struct DRWShadingGroup *EEVEE_default_shading_group_get(
|
|||
DRWShadingGroup *shgrp = DRW_shgroup_hair_create(ob, psys, md,
|
||||
vedata->psl->default_pass[options], vedata->psl->hair_tf_pass,
|
||||
e_data.default_lit[options]);
|
||||
add_standard_uniforms(shgrp, sldata, vedata, NULL, NULL, false, false);
|
||||
add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL, false, false);
|
||||
return shgrp;
|
||||
}
|
||||
else {
|
||||
|
@ -1584,6 +1584,8 @@ void EEVEE_hair_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sldata,
|
|||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
Scene *scene = draw_ctx->scene;
|
||||
|
||||
bool use_ssr = ((stl->effects->enabled_effects & EFFECT_SSR) != 0);
|
||||
|
||||
if (ob->type == OB_MESH) {
|
||||
if (ob != draw_ctx->object_edit) {
|
||||
for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
|
||||
|
@ -1628,6 +1630,8 @@ void EEVEE_hair_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sldata,
|
|||
|
||||
shgrp = NULL;
|
||||
if (ma->use_nodes && ma->nodetree) {
|
||||
static int ssr_id;
|
||||
ssr_id = (use_ssr) ? 1 : -1;
|
||||
static float half = 0.5f;
|
||||
static float error_col[3] = {1.0f, 0.0f, 1.0f};
|
||||
static float compile_col[3] = {0.5f, 0.5f, 0.5f};
|
||||
|
@ -1640,7 +1644,7 @@ void EEVEE_hair_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sldata,
|
|||
ob, psys, md,
|
||||
psl->material_pass, psl->hair_tf_pass,
|
||||
gpumat);
|
||||
add_standard_uniforms(shgrp, sldata, vedata, NULL, NULL, false, false);
|
||||
add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL, false, false);
|
||||
break;
|
||||
}
|
||||
case GPU_MAT_QUEUED:
|
||||
|
@ -1660,7 +1664,6 @@ void EEVEE_hair_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sldata,
|
|||
|
||||
/* Fallback to default shader */
|
||||
if (shgrp == NULL) {
|
||||
bool use_ssr = ((stl->effects->enabled_effects & EFFECT_SSR) != 0);
|
||||
shgrp = EEVEE_default_shading_group_get(sldata, vedata,
|
||||
ob, psys, md,
|
||||
true, false, use_ssr,
|
||||
|
|
|
@ -6,14 +6,38 @@ uniform float roughness;
|
|||
|
||||
Closure nodetree_exec(void)
|
||||
{
|
||||
#ifdef HAIR_SHADER
|
||||
vec3 B = normalize(cross(worldNormal, hairTangent));
|
||||
float cos_theta;
|
||||
if (hairThicknessRes == 1) {
|
||||
vec4 rand = texelFetch(utilTex, ivec3(ivec2(gl_FragCoord.xy) % LUT_SIZE, 2.0), 0);
|
||||
/* Random cosine normal distribution on the hair surface. */
|
||||
cos_theta = rand.x * 2.0 - 1.0;
|
||||
}
|
||||
else {
|
||||
/* Shade as a cylinder. */
|
||||
cos_theta = hairThickTime / hairThickness;
|
||||
}
|
||||
float sin_theta = sqrt(max(0.0, 1.0f - cos_theta*cos_theta));;
|
||||
vec3 N = normalize(worldNormal * sin_theta + B * cos_theta);
|
||||
vec3 vN = mat3(ViewMatrix) * N;
|
||||
#else
|
||||
vec3 N = normalize(gl_FrontFacing ? worldNormal : -worldNormal);
|
||||
vec3 vN = normalize(gl_FrontFacing ? viewNormal : -viewNormal);
|
||||
#endif
|
||||
|
||||
vec3 dielectric = vec3(0.034) * specular * 2.0;
|
||||
vec3 albedo = mix(basecol, vec3(0.0), metallic);
|
||||
vec3 f0 = mix(dielectric, basecol, metallic);
|
||||
vec3 N = (gl_FrontFacing) ? worldNormal : -worldNormal;
|
||||
vec3 out_diff, out_spec, ssr_spec;
|
||||
eevee_closure_default(N, albedo, f0, 1, roughness, 1.0, out_diff, out_spec, ssr_spec);
|
||||
|
||||
Closure result = Closure(out_spec + out_diff * albedo, 1.0, vec4(ssr_spec, roughness), normal_encode(normalize(viewNormal), viewCameraVec), 0);
|
||||
Closure result = Closure(
|
||||
out_spec + out_diff * albedo,
|
||||
1.0,
|
||||
vec4(ssr_spec, roughness),
|
||||
normal_encode(vN, viewCameraVec),
|
||||
0);
|
||||
|
||||
#ifdef LOOKDEV
|
||||
gl_FragDepth = 0.0;
|
||||
|
|
|
@ -178,21 +178,6 @@ void CLOSURE_NAME(
|
|||
|
||||
vec4 rand = texelFetch(utilTex, ivec3(ivec2(gl_FragCoord.xy) % LUT_SIZE, 2.0), 0);
|
||||
|
||||
#ifdef HAIR_SHADER
|
||||
vec3 B = normalize(cross(worldNormal, hairTangent));
|
||||
float cos_theta;
|
||||
if (hairThicknessRes == 1) {
|
||||
/* Random cosine normal distribution on the hair surface. */
|
||||
cos_theta = rand.x * 2.0 - 1.0;
|
||||
}
|
||||
else {
|
||||
/* Shade as a cylinder. */
|
||||
cos_theta = hairThickTime / hairThickness;
|
||||
}
|
||||
float sin_theta = sqrt(max(0.0, 1.0f - cos_theta*cos_theta));;
|
||||
N = normalize(N * sin_theta + B * cos_theta);
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* -------------------- SCENE LAMPS LIGHTING ---------------------- */
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
@ -399,12 +384,6 @@ void CLOSURE_NAME(
|
|||
}
|
||||
|
||||
out_spec += spec_accum.rgb * ssr_spec * spec_occlu * float(specToggle);
|
||||
|
||||
# ifdef HAIR_SHADER
|
||||
/* Hack: Overide spec color so that ssr will not be computed
|
||||
* even if ssr_id match the active ssr. */
|
||||
ssr_spec = vec3(0.0);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef CLOSURE_REFRACTION
|
||||
|
|
|
@ -2558,7 +2558,23 @@ void node_output_world(Closure surface, Closure volume, out Closure result)
|
|||
/* EEVEE output */
|
||||
void world_normals_get(out vec3 N)
|
||||
{
|
||||
#ifdef HAIR_SHADER
|
||||
vec3 B = normalize(cross(worldNormal, hairTangent));
|
||||
float cos_theta;
|
||||
if (hairThicknessRes == 1) {
|
||||
vec4 rand = texelFetch(utilTex, ivec3(ivec2(gl_FragCoord.xy) % LUT_SIZE, 2.0), 0);
|
||||
/* Random cosine normal distribution on the hair surface. */
|
||||
cos_theta = rand.x * 2.0 - 1.0;
|
||||
}
|
||||
else {
|
||||
/* Shade as a cylinder. */
|
||||
cos_theta = hairThickTime / hairThickness;
|
||||
}
|
||||
float sin_theta = sqrt(max(0.0, 1.0f - cos_theta*cos_theta));;
|
||||
N = normalize(worldNormal * sin_theta + B * cos_theta);
|
||||
#else
|
||||
N = gl_FrontFacing ? worldNormal : -worldNormal;
|
||||
#endif
|
||||
}
|
||||
|
||||
void node_eevee_specular(
|
||||
|
|
Loading…
Reference in New Issue