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.

31 lines (28 loc) 1.09 kB
const getMetallicRoughness = ({ metallicRoughnessTexture = null } = {}) => { let metallicRoughness = ""; if (metallicRoughnessTexture) { metallicRoughness += /* wgsl */ ` var metallicRoughnessUV: vec2f = ${metallicRoughnessTexture.texCoordAttributeName ?? "uv"};`; if ("useTransform" in metallicRoughnessTexture.texture.options && metallicRoughnessTexture.texture.options.useTransform) { metallicRoughness += /* wgsl */ ` metallicRoughnessUV = (${metallicRoughnessTexture.texture.options.name}Matrix * vec3(metallicRoughnessUV, 1.0)).xy;`; } metallicRoughness += /* wgsl */ ` let metallicRoughness = textureSample(${metallicRoughnessTexture.texture.options.name}, ${metallicRoughnessTexture.sampler?.name ?? "defaultSampler"}, metallicRoughnessUV); metallic = metallic * metallicRoughness.b; roughness = roughness * metallicRoughness.g; `; } metallicRoughness += /* wgsl */ ` metallic = saturate(metallic); roughness = clamp(roughness, 0.0525, 1.0); `; return metallicRoughness; }; export { getMetallicRoughness };