UNPKG

gpu-curtains

Version:

gpu-curtains is a 3D WebGPU rendering engine. It can be used as a standalone 3D engine, but also includes extra classes focused on mapping 3d objects to DOM elements; It allows users to synchronize values such as position, sizing, or scale between them.

43 lines (42 loc) 2.08 kB
import { getTextureSample } from "./get-texture-sample.mjs"; //#region src/core/shaders/chunks/fragment/body/get-sheen.ts /** * Set the `sheenRoughness` (`f32`) and `sheenColor` (`vec3f`) values from the material sheen variables and eventual sheen textures. * @param parameters - Parameters used to set the `sheenRoughness` (`f32`) and `sheenColor` (`vec3f`) values. * @param parameters.extensionsUsed - {@link PBRFragmentShaderInputParams.extensionsUsed | extensionsUsed} to check if sheen is enabled. * @param parameters.sheenTexture - {@link ShaderTextureDescriptor | Sheen texture descriptor} (mixing both sheen color in the `RGB` channels and sheen roughness in the `A` channel) to use if any. * @param parameters.sheenColorTexture - {@link ShaderTextureDescriptor | Sheen color texture descriptor} (using the `RGB` channels) to use if any. * @param parameters.sheenRoughnessTexture - {@link ShaderTextureDescriptor | Sheen roughness texture descriptor} (using the `A` channel) to use if any. * @returns - String with the `sheenRoughness` (`f32`) and `sheenColor` (`vec3f`) values set. */ const getSheen = ({ extensionsUsed = [], sheenTexture = null, sheenColorTexture = null, sheenRoughnessTexture = null } = {}) => { let sheen = ` var sheenSpecularDirect: vec3f = vec3(0.0); var sheenSpecularIndirect: vec3f = vec3(0.0);`; if (!extensionsUsed.includes("KHR_materials_sheen")) return sheen; if (sheenTexture) { sheen += getTextureSample(sheenTexture, "sheen"); sheen += ` sheenColor = sheenColor * sheenSample.rgb; sheenRoughness = sheenRoughness * sheenSample.a; `; } else { if (sheenColorTexture) { sheen += getTextureSample(sheenColorTexture, "sheenColor"); sheen += ` sheenColor = sheenColor * sheenColorSample.rgb; `; } if (sheenRoughnessTexture) { sheen += getTextureSample(sheenRoughnessTexture, "sheenRoughness"); sheen += ` sheenRoughness = sheenRoughness * sheenRoughnessSample.a; `; } } sheen += ` sheenRoughness = clamp(sheenRoughness, 0.0001, 1.0);`; return sheen; }; //#endregion export { getSheen };