UNPKG

@babylonjs/core

Version:

Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.

52 lines 3.09 kB
// Do not edit. import { ShaderStore } from "../../Engines/shaderStore.js"; import "./ltcHelperFunctions.js"; const name = "pbrDirectLightingSetupFunctions"; const shader = `struct preLightingInfo {lightOffset: vec3f, lightDistanceSquared: f32, lightDistance: f32, attenuation: f32, L: vec3f, H: vec3f, NdotV: f32, NdotLUnclamped: f32, NdotL: f32, VdotH: f32, LdotV: f32, roughness: f32, diffuseRoughness: f32, surfaceAlbedo: vec3f, #ifdef IRIDESCENCE iridescenceIntensity: f32 #endif #if defined(AREALIGHTUSED) && defined(AREALIGHTSUPPORTED) areaLightDiffuse: vec3f, #ifdef SPECULARTERM areaLightSpecular: vec3f, areaLightFresnel: vec4f #endif #endif };fn computePointAndSpotPreLightingInfo(lightData: vec4f,V: vec3f,N: vec3f,posW: vec3f)->preLightingInfo {var result: preLightingInfo;result.lightOffset=lightData.xyz-posW;result.lightDistanceSquared=dot(result.lightOffset,result.lightOffset);result.lightDistance=sqrt(result.lightDistanceSquared);result.L=normalize(result.lightOffset);result.H=normalize(V+result.L);result.VdotH=saturate(dot(V,result.H));result.NdotLUnclamped=dot(N,result.L);result.NdotL=saturateEps(result.NdotLUnclamped);return result;} fn computeDirectionalPreLightingInfo(lightData: vec4f,V: vec3f,N: vec3f)->preLightingInfo {var result: preLightingInfo;result.lightDistance=length(-lightData.xyz);result.L=normalize(-lightData.xyz);result.H=normalize(V+result.L);result.VdotH=saturate(dot(V,result.H));result.NdotLUnclamped=dot(N,result.L);result.NdotL=saturateEps(result.NdotLUnclamped);result.LdotV=dot(result.L,V);return result;} fn computeHemisphericPreLightingInfo(lightData: vec4f,V: vec3f,N: vec3f)->preLightingInfo {var result: preLightingInfo;result.NdotL=dot(N,lightData.xyz)*0.5+0.5;result.NdotL=saturateEps(result.NdotL);result.NdotLUnclamped=result.NdotL; #ifdef SPECULARTERM result.L=normalize(lightData.xyz);result.H=normalize(V+result.L);result.VdotH=saturate(dot(V,result.H)); #endif return result;} #if defined(AREALIGHTUSED) && defined(AREALIGHTSUPPORTED) #include<ltcHelperFunctions> var areaLightsLTC1SamplerSampler: sampler;var areaLightsLTC1Sampler: texture_2d<f32>;var areaLightsLTC2SamplerSampler: sampler;var areaLightsLTC2Sampler: texture_2d<f32>;fn computeAreaPreLightingInfo(ltc1: texture_2d<f32>,ltc1Sampler:sampler,ltc2:texture_2d<f32>,ltc2Sampler:sampler,viewDirectionW: vec3f,vNormal:vec3f,vPosition:vec3f,lightCenter:vec3f,halfWidth:vec3f, halfHeight:vec3f,roughness:f32)->preLightingInfo {var result: preLightingInfo;var data: areaLightData=computeAreaLightSpecularDiffuseFresnel(ltc1,ltc1Sampler,ltc2,ltc2Sampler,viewDirectionW,vNormal,vPosition,lightCenter,halfWidth,halfHeight,roughness); #ifdef SPECULARTERM result.areaLightFresnel=data.Fresnel;result.areaLightSpecular=data.Specular; #endif result.areaLightDiffuse+=data.Diffuse;return result;} #endif `; // Sideeffect if (!ShaderStore.IncludesShadersStoreWGSL[name]) { ShaderStore.IncludesShadersStoreWGSL[name] = shader; } /** @internal */ export const pbrDirectLightingSetupFunctionsWGSL = { name, shader }; //# sourceMappingURL=pbrDirectLightingSetupFunctions.js.map