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.

57 lines (48 loc) 1.45 kB
import { lambertUtils } from './lambert-shading.mjs'; import { REIndirectSpecular } from '../fragment/head/RE-indirect-specular.mjs'; import { getIBLTransmission } from '../fragment/head/get-IBL-transmission.mjs'; import { getPBRDirect } from '../fragment/head/get-PBR-direct.mjs'; import { getPBRShading } from '../fragment/body/get-PBR-shading.mjs'; import { applyToneMapping } from '../fragment/body/apply-tone-mapping.mjs'; const getPBR = ({ addUtils = true, receiveShadows = false, toneMapping, useOcclusion = false, environmentMap = null, transmissionBackgroundTexture = null, extensionsUsed = [] } = {}) => ( /* wgsl */ ` ${addUtils ? lambertUtils : ""} ${REIndirectSpecular} ${getIBLTransmission} ${getPBRDirect} fn getPBR( normal: vec3f, worldPosition: vec3f, color: vec4f, viewDirection: vec3f, metallic: f32, roughness: f32, specularIntensity: f32, specularColor: vec3f, ior: f32, transmission: f32, dispersion: f32, thickness: f32, attenuationDistance: f32, attenuationColor: vec3f, ${useOcclusion ? "occlusion: f32," : ""} ) -> vec4f { ${!useOcclusion ? "let occlusion: f32 = 1.0;" : ""} var outputColor: vec4f = color; ${getPBRShading({ receiveShadows, environmentMap, transmissionBackgroundTexture, extensionsUsed })} outputColor = vec4(outgoingLight, outputColor.a); ${applyToneMapping({ toneMapping })} return outputColor; } ` ); export { getPBR };