@babylonjs/viewer
Version:
The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.
3 lines (2 loc) • 6.83 kB
JavaScript
import{aX as e,aY as t,a8 as s}from"./index-B8IgtevW.esm.min.js";const n=1<<22,r=1<<23,a=1<<24;function c(e,t,s,n,r){let a="",c="input.uv",i="input.uv";r&&s&&(a+="let ssColorUV = vec2<f32>(dot(material.translucencyColorUVm.xy, input.uv), dot(material.translucencyColorUVm.zw, input.uv)) + material.translucencyColorUVt.xy;\n",c="ssColorUV"),r&&n&&(a+="let ssIntUV = vec2<f32>(dot(material.translucencyIntensityUVm.xy, input.uv), dot(material.translucencyIntensityUVm.zw, input.uv)) + material.translucencyIntensityUVt.xy;\n",i="ssIntUV");return`${a}${e?`let thicknessSample = textureSample(thicknessTexture_, thicknessSampler_, input.uv).${t?"g":"r"};`:"let thicknessSample = 1.0;"}\nlet ssThickness = max(material.subsurfaceParams.y + thicknessSample * material.subsurfaceParams.z, 0.000001);\nlet ssTranslucencyColor = material.subsurfaceParams3.rgb${s?` * textureSample(translucencyColorTexture_, translucencyColorSampler_, ${c}).rgb`:""};\nlet ssDiffDist = material.subsurfaceParams2.rgb;\nssIntensity = material.subsurfaceParams.x${n?` * textureSample(translucencyIntensityTexture_, translucencyIntensitySampler_, ${i}).a`:""};\nssTransmittance = transmittanceBRDF_Burley(ssTranslucencyColor, ssDiffDist, ssThickness) * ssIntensity;`}function i(e,t,s,n){const r=t.get(`${s}m`),a=t.get(`${s}t`);if(void 0===r||void 0===a)return;const c=n?.uScale??1,i=n?.vScale??1,u=n?.uAng??0,l=r/4;if(0===u)e[l]=c,e[l+1]=0,e[l+2]=0,e[l+3]=i;else{const t=Math.cos(u),s=Math.sin(u);e[l]=t*c,e[l+1]=s*i,e[l+2]=-s*c,e[l+3]=t*i}const o=a/4;e[o]=n?.uOffset??0,e[o+1]=n?.vOffset??0}const u={id:"subsurface",phase:"fragment",detect(s){const c=s,i=c._subsurface?.translucency;if(!i)return{f:0,f2:0};let u=t,l=0;return c._subsurface.thickness?.texture&&(u|=e),c._subsurface.thickness?.useGlTFChannel&&(l|=128),i.colorTexture&&(l|=n),i.intensityTexture&&(l|=r),(i.colorTexture?._hasTx||i.intensityTexture?._hasTx)&&(l|=a),{f:u,f2:l}},frag:s=>s._features&t?function(e,t,s,n,r,a){const i={_kind:"texture",_textureType:"texture_2d<f32>"},u={_kind:"sampler",_samplerType:"sampler"},l=[];e&&l.push({_name:"thicknessTexture_",_type:i,_visibility:2},{_name:"thicknessSampler_",_type:u,_visibility:2}),n&&l.push({_name:"translucencyColorTexture_",_type:i,_visibility:2},{_name:"translucencyColorSampler_",_type:u,_visibility:2}),r&&l.push({_name:"translucencyIntensityTexture_",_type:i,_visibility:2},{_name:"translucencyIntensitySampler_",_type:u,_visibility:2});const o=[{_name:"subsurfaceParams",_type:"vec4<f32>"},{_name:"subsurfaceParams2",_type:"vec4<f32>"},{_name:"subsurfaceParams3",_type:"vec4<f32>"}];a&&n&&o.push({_name:"translucencyColorUVm",_type:"vec4<f32>"},{_name:"translucencyColorUVt",_type:"vec4<f32>"}),a&&r&&o.push({_name:"translucencyIntensityUVm",_type:"vec4<f32>"},{_name:"translucencyIntensityUVt",_type:"vec4<f32>"});const f={SV:"var translucencyDirect = vec3<f32>(0.0);\nvar ssTransmittance = vec3<f32>(0.0);\nvar ssIntensity = 0.0;",AT:c(e,s,n,r,a),AD:"{\nlet NdotLU = dot(N, L);\nif (NdotLU < 0.0) {\nlet wrapNdotL = computeWrappedDiffuseNdotL(abs(NdotLU), 0.02);\ntranslucencyDirect += (1.0 / PI) * wrapNdotL * ssTransmittance * lightAtten * lightColor * material.directIntensity;\n}\n}"};t?f.AI="{\nlet N_back = -N_env;\nlet envIrrBack = (scene.vSphericalL00.rgb\n + scene.vSphericalL1_1.rgb * N_back.y + scene.vSphericalL10.rgb * N_back.z + scene.vSphericalL11.rgb * N_back.x\n + scene.vSphericalL2_2.rgb * (N_back.y * N_back.x) + scene.vSphericalL2_1.rgb * (N_back.y * N_back.z)\n + scene.vSphericalL20.rgb * (3.0 * N_back.z * N_back.z - 1.0) + scene.vSphericalL21.rgb * (N_back.z * N_back.x)\n + scene.vSphericalL22.rgb * (N_back.x * N_back.x - N_back.y * N_back.y)) * material.environmentIntensity;\nlet refractionIrradiance = envIrrBack * ssTransmittance;\ncolor -= finalIrradiance * ssIntensity;\ncolor += refractionIrradiance * occlusion;\ncolor -= directDiffuse * ssIntensity;\ncolor += translucencyDirect * occlusion;\n}":f.NI="color -= directDiffuse * ssIntensity;\ncolor += translucencyDirect;";const _=[];return t&&_.push("ibl"),{_id:"subsurface",_dependencies:_.length>0?_:void 0,_bindings:l.length>0?l:void 0,_uboFields:o,_helperFunctions:"\nfn transmittanceBRDF_Burley(tintColor: vec3<f32>, diffusionDistance: vec3<f32>, thickness: f32) -> vec3<f32> {\nlet S = 1.0 / max(vec3<f32>(0.000001), diffusionDistance);\nlet temp = exp((-0.333333333 * thickness) * S);\nreturn tintColor * 0.25 * (temp * temp * temp + 3.0 * temp);\n}\nfn computeWrappedDiffuseNdotL(NdotL: f32, w: f32) -> f32 {\nlet t = 1.0 + w;\nlet invt2 = 1.0 / (t * t);\nreturn saturate((NdotL + w) * invt2);\n}\n",_fragmentSlots:f}}(0!==(s._features&e),s._hasIbl,!!(128&s._features2),0!==(s._features2&n),0!==(s._features2&r),0!==(s._features2&a)):null,writeUbo(e,t,s){const n=t;n._subsurface?.translucency&&s.has("subsurfaceParams")&&function(e,t,s){const n=t.translucency,r=t.thickness,a=s.get("subsurfaceParams")/4;e[a]=n.intensity??1;const c=r?.min??0,u=r?.max??1;e[a+1]=c,e[a+2]=u-c;const l=s.get("subsurfaceParams2")/4,o=n.diffusionDistance??[1,1,1];e[l]=o[0],e[l+1]=o[1],e[l+2]=o[2];const f=s.get("subsurfaceParams3")/4,_=n.color??[1,1,1];e[f]=_[0],e[f+1]=_[1],e[f+2]=_[2],i(e,s,"translucencyColorUV",n.colorTexture),i(e,s,"translucencyIntensityUV",n.intensityTexture)}(e,n._subsurface,s)},bind(t,s,a){const c=t._material._subsurface;if(0!==(t._features&e)){const e=c?.thickness?.texture;e&&(s.push({binding:a++,resource:e.view}),s.push({binding:a++,resource:e.sampler}))}if(0!==(t._features2&n)){const e=c?.translucency?.colorTexture;e&&(s.push({binding:a++,resource:e.view}),s.push({binding:a++,resource:e.sampler}))}if(0!==(t._features2&r)){const e=c?.translucency?.intensityTexture;e&&(s.push({binding:a++,resource:e.view}),s.push({binding:a++,resource:e.sampler}))}return a},textures(e,t){const s=e._subsurface;s?.thickness?.texture&&t.push(s.thickness.texture),s?.translucency?.colorTexture&&t.push(s.translucency.colorTexture),s?.translucency?.intensityTexture&&t.push(s.translucency.intensityTexture)}};const l={id:"KHR_materials_diffuse_transmission",async applyMaterial(e,t){const n=e._rawMatDef?.extensions?.KHR_materials_diffuse_transmission;if(!n)return null;const r="number"==typeof n.diffuseTransmissionFactor?n.diffuseTransmissionFactor:0,[a,c]=await Promise.all([t._texture(n.diffuseTransmissionColorTexture,!0),t._texture(n.diffuseTransmissionTexture,!1)]);if(r<=0&&!a&&!c)return null;const i=Array.isArray(n.diffuseTransmissionColorFactor)&&3===n.diffuseTransmissionColorFactor.length?n.diffuseTransmissionColorFactor:[1,1,1],l={};return function(e,t){e._subsurface=t,s(u)}(l,{translucency:{intensity:r,color:[i[0],i[1],i[2]],...a?{colorTexture:a}:void 0,...c?{intensityTexture:c}:void 0},thickness:{min:0,max:0}}),l}};export{l as default};
//# sourceMappingURL=gltf-ext-diffuse-transmission-aUVtlaE8.esm.min.js.map