mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-29 17:55:45 +01:00
Adds the direct-light BRDF, the split-sum environment BRDF and the default studio environment of EffectCraft's adv/shade.rs and adv/scene.rs to craft-pbr, with EffectCraft's tests on the new API. - Material::try_new and try_with_weights check base color, metallic, roughness and the specular and diffuse weights; NaN, infinity and values out of range give PbrError::BadMaterial. try_direct checks and normalizes its directions (PbrError::BadDirection). - The BRDF is the final form of glTF 2.0 section B.3.5 with Schlick's Fresnel and the GGX distribution of ggx_distribution, evaluated in f64. The geometry term stays the Smith-Schlick term with k = (roughness + 1)^2 / 8 for analytic lights; it equals glTF's separable Smith term at roughness 1. - Roughness is shaded as at least 0.032 instead of 0.03, above the alpha floor of ggx_distribution. A view straight opposite the light gives 0. - try_environment_brdf keeps scale and bias at least 0 with a sum of at most 1. The fit gave a scale of -0.044 and a bias of 1.044 at n.v = 0 and roughness 0, and a bias of -0.0024 at n.v = 0 and roughness 1. - default_environment returns the 8 x 4 studio gradient in this crate's frame; its pixels match EffectCraft's within 1e-6. New tests: a white metal reflects at most the light it receives at every roughness and view angle, the BRDF is reciprocal, roughness is clamped at MIN_DIRECT_ROUGHNESS, metallic 0 and 1 match glTF's dielectric and metal BRDFs, the geometry term against glTF's Smith form, invalid values are refused, and the direct light, environment BRDF and default environment match a copy of EffectCraft's code.