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.

52 lines (43 loc) 1.47 kB
import { BRDF_GGX } from '../../utils/BRDF_GGX.mjs'; const getPBRDirect = ( /* wgsl */ ` ${BRDF_GGX} fn EnvironmentBRDF( normal: vec3<f32>, viewDir: vec3<f32>, specularColor: vec3<f32>, specularF90: f32, roughness: f32 ) -> vec3<f32> { let fab = DFGApprox(normal, viewDir, roughness); return specularColor * fab.x + specularF90 * fab.y; } fn computeSpecularOcclusion( NdotV: f32, occlusion: f32, roughness: f32 ) -> f32 { return saturate(pow(NdotV + occlusion, exp2(- 16.0 * roughness - 1.0)) - 1.0 + occlusion); } fn getPBRDirect( normal: vec3f, diffuseColor: vec3f, viewDirection: vec3f, specularFactor: f32, specularColor: vec3f, metallic: f32, roughness: f32, directLight: DirectLight, ptr_reflectedLight: ptr<function, ReflectedLight> ) { let H: vec3f = normalize(viewDirection + directLight.direction); let NdotV: f32 = saturate(dot(normal, viewDirection)); let NdotL: f32 = saturate(dot(normal, directLight.direction)); let NdotH: f32 = saturate(dot(normal, H)); let VdotH: f32 = saturate(dot(viewDirection, H)); let irradiance: vec3f = NdotL * directLight.color; let ggx: vec3f = BRDF_GGX(NdotV, NdotL, NdotH, VdotH, roughness, specularFactor, specularColor); let diffuseContribution: vec3f = BRDF_Lambert(diffuseColor); (*ptr_reflectedLight).directDiffuse += irradiance * diffuseContribution; (*ptr_reflectedLight).directSpecular += irradiance * ggx; } ` ); export { getPBRDirect };