playcanvas
Version:
PlayCanvas WebGL game engine
44 lines (34 loc) • 1.32 kB
JavaScript
var aoSpecOccPS = /* wgsl */ `
uniform material_occludeSpecularIntensity: f32;
fn occludeSpecular(gloss: f32, ao: f32, worldNormal: vec3f, viewDir: vec3f) {
var specOcc: f32 = mix(1.0, ao, uniform.material_occludeSpecularIntensity);
var specOcc: f32 = ao;
// approximated specular occlusion from AO
// http://research.tri-ace.com/Data/cedec2011_RealtimePBR_Implementation_e.pptx
var specPow: f32 = exp2(gloss * 11.0);
var specOcc: f32 = saturate(pow(dot(worldNormal, viewDir) + ao, 0.01 * specPow) - 1.0 + ao);
specOcc = mix(1.0, specOcc, uniform.material_occludeSpecularIntensity);
dSpecularLight = dSpecularLight * specOcc;
dReflection = dReflection * specOcc;
sSpecularLight = sSpecularLight * specOcc;
sReflection = sReflection * specOcc;
}
`;
export { aoSpecOccPS as default };