Files
filament/shaders/src/surface_shading_model_cloth.fs
T
Sungun Park 87bdf96449 Refactor: Rename shader snippets w/ new naming convention (see README.md) (#8402)
This commit renames all shader snippet files to conform to the newly
introduced naming convention outlined in README.md.

The new naming convention uses a `prefix_name.suffix` format to clearly
indicate the purpose and target shader stage of each snippet. This
improves the overall organization and readability of the shader code,
making it easier to understand how each snippet contributes to the
shader generation process.

No functional changes were made to the shader code itself or source
code. This is purely a refactoring for clarity and maintainability.
2025-01-31 00:02:53 +00:00

51 lines
2.1 KiB
GLSL

/**
* Evaluates lit materials with the cloth shading model. Similar to the standard
* model, the cloth shading model is based on a Cook-Torrance microfacet model.
* Its distribution and visibility terms are however very different to take into
* account the softer apperance of many types of cloth. Some highly reflecting
* fabrics like satin or leather should use the standard model instead.
*
* This shading model optionally models subsurface scattering events. The
* computation of these events is not physically based but can add necessary
* details to a material.
*/
vec3 surfaceShading(const PixelParams pixel, const Light light, float occlusion) {
vec3 h = normalize(shading_view + light.l);
float NoL = light.NoL;
float NoH = saturate(dot(shading_normal, h));
float LoH = saturate(dot(light.l, h));
// specular BRDF
float D = distributionCloth(pixel.roughness, NoH);
float V = visibilityCloth(shading_NoV, NoL);
vec3 F = pixel.f0;
// Ignore pixel.energyCompensation since we use a different BRDF here
vec3 Fr = (D * V) * F;
// diffuse BRDF
float diffuse = diffuse(pixel.roughness, shading_NoV, NoL, LoH);
#if defined(MATERIAL_HAS_SUBSURFACE_COLOR)
// Energy conservative wrap diffuse to simulate subsurface scattering
diffuse *= Fd_Wrap(dot(shading_normal, light.l), 0.5);
#endif
// We do not multiply the diffuse term by the Fresnel term as discussed in
// Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886"
// The effect is fairly subtle and not deemed worth the cost for mobile
vec3 Fd = diffuse * pixel.diffuseColor;
#if defined(MATERIAL_HAS_SUBSURFACE_COLOR)
// Cheap subsurface scatter
Fd *= saturate(pixel.subsurfaceColor + NoL);
// We need to apply NoL separately to the specular lobe since we already took
// it into account in the diffuse lobe
vec3 color = Fd + Fr * NoL;
color *= light.colorIntensity.rgb * (light.colorIntensity.w * light.attenuation * occlusion);
#else
vec3 color = Fd + Fr;
color *= light.colorIntensity.rgb * (light.colorIntensity.w * light.attenuation * NoL * occlusion);
#endif
return color;
}