@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.09 kB
JavaScript
import{aU as e,aV as n,aW as s,a8 as t}from"./index-B8IgtevW.esm.min.js";const r=1<<29,a=e=>`\n{\nlet shIntensity = ${e};\nlet shColorScaled = sheenColorFinal * shIntensity;\nlet shRoughness_clamped = max(sheenRoughnessAdjusted, AA_factor_x);\nlet shAlphaG = shRoughness_clamped * shRoughness_clamped + 0.0005;\nlet shD = normalDistributionFunction_CharlieSheen(NdotH, shAlphaG);\nlet shV = visibility_Ashikhmin(NdotL, NdotV);\nsheenDirectTerm = shColorScaled * shD * shV * NdotL * lightColor * lightAtten * material.directIntensity;\n}\n`;function h(e,n,s,t,r){const a=n.get(s),h=n.get(t);if(void 0===a||void 0===h)return;const i=r?.uScale??1,l=r?.vScale??1,o=r?.uAng??0,u=a/4,_=h/4;if(0===o)e[u]=i,e[u+1]=0,e[u+2]=0,e[u+3]=l;else{const n=Math.cos(o),s=Math.sin(o);e[u]=n*i,e[u+1]=s*l,e[u+2]=-s*i,e[u+3]=n*l}e[_]=r?.uOffset??0,e[_+1]=r?.vOffset??0,e[_+2]=0,e[_+3]=0}const i={id:"sheen",phase:"base-tex",detect(t){const a=t._sheen;if(!a?.isEnabled)return{f:0,f2:0};let h=n,i=0;return a.texture&&(h|=e,a.texture._hasTx&&(i|=8192)),a.roughnessTexture&&(i|=r),a.albedoScaling&&(h|=s),{f:h,f2:i}},frag:t=>t._features&n?function(e,n=!1,s=!1,t=!1,r=!1){let h="var sheenDirectTerm = vec3<f32>(0.0);\nvar sheenIblTerm = vec3<f32>(0.0);\nvar sheenAlbedoScaling = 1.0;\nvar sheenColorFinal = material.sheenParams.rgb;\nvar sheenRoughnessAdjusted = material.sheenParams2.x;";e&&(h+=`\n{\n${t?"let sheenUV = vec2<f32>(dot(material.sheenUVm.xy, input.uv), dot(material.sheenUVm.zw, input.uv)) + material.sheenUVt.xy;":"let sheenUV = input.uv;"}\nlet sheenMapData = textureSample(sheenTexture_, sheenSampler_, sheenUV);\nsheenColorFinal *= ${s?"sheenMapData.rgb":"pow(sheenMapData.rgb, vec3<f32>(2.2))"};${r?"":"\nsheenRoughnessAdjusted *= sheenMapData.a;"}\n}`);r&&(h+="\n{\nlet sheenRoughUV = vec2<f32>(dot(material.sheenRoughUVm.xy, input.uv), dot(material.sheenRoughUVm.zw, input.uv)) + material.sheenRoughUVt.xy;\nsheenRoughnessAdjusted *= textureSample(sheenRoughTexture_, sheenRoughSampler_, sheenRoughUV).a;\n}");const i=s?"material.sheenParams.a":"material.sheenParams.a * (1.0 - dielectricF0)",l={SV:h,AD:a(i)};n?l.AI=((e,n)=>`\n{\nlet shIntensity_ibl = ${e};\nlet shColorScaled = sheenColorFinal * shIntensity_ibl;\nlet shRoughness_ibl = sheenRoughnessAdjusted;\nlet shAlphaG_ibl = shRoughness_ibl * shRoughness_ibl + 0.0005 + AA_factor_y;\nvar shSpecLod = log2(cubemapDim * shAlphaG_ibl) * scene.vImageInfos.z;\nlet shEnvRadiance = textureSampleLevel(iblTexture, iblSampler, R, clamp(shSpecLod, 0.0, maxLod)).rgb * material.environmentIntensity;\nlet shBrdf = textureSampleLevel(brdfLUT, brdfSampler_, vec2<f32>(NdotV, shRoughness_ibl), 0.0);\nlet shEnvReflectance = shColorScaled * shBrdf.b${n?" * seo * eho":""};\nsheenIblTerm = shEnvRadiance * shEnvReflectance;\n${n?"let shMax = max(shColorScaled.r, max(shColorScaled.g, shColorScaled.b));\nsheenAlbedoScaling = 1.0 - shMax * shBrdf.b;":""}\n}\n`)(i,s)+(s?"\n{\ncolor = (finalIrradiance\n + finalRadianceScaled\n + finalSpecularScaled\n + directDiffuse) * sheenAlbedoScaling\n + sheenDirectTerm\n + sheenIblTerm\n + emissive;\n}\n":"\n{\ncolor = finalIrradiance\n + finalRadianceScaled\n + finalSpecularScaled\n + directDiffuse\n + sheenDirectTerm\n + sheenIblTerm\n + emissive;\n}\n"):l.NI="\n{\ncolor = color + sheenDirectTerm;\n}\n";const o=[];e&&o.push({_name:"sheenTexture_",_type:{_kind:"texture",_textureType:"texture_2d<f32>"},_visibility:2},{_name:"sheenSampler_",_type:{_kind:"sampler",_samplerType:"sampler"},_visibility:2}),r&&o.push({_name:"sheenRoughTexture_",_type:{_kind:"texture",_textureType:"texture_2d<f32>"},_visibility:2},{_name:"sheenRoughSampler_",_type:{_kind:"sampler",_samplerType:"sampler"},_visibility:2});const u=[{_name:"sheenParams",_type:"vec4<f32>"},{_name:"sheenParams2",_type:"vec4<f32>"}];return t&&u.push({_name:"sheenUVm",_type:"vec4<f32>"},{_name:"sheenUVt",_type:"vec4<f32>"}),r&&u.push({_name:"sheenRoughUVm",_type:"vec4<f32>"},{_name:"sheenRoughUVt",_type:"vec4<f32>"}),{_id:"sheen",_dependencies:n?["ibl"]:void 0,_uboFields:u,_bindings:o,_helperFunctions:"\nfn normalDistributionFunction_CharlieSheen(NdotH_sh: f32, alphaG_sh: f32) -> f32 {\nlet invR = 1.0 / alphaG_sh;\nlet cos2h = NdotH_sh * NdotH_sh;\nlet sin2h = 1.0 - cos2h;\nreturn (2.0 + invR) * pow(sin2h, invR * 0.5) / (2.0 * 3.141592653589793);\n}\nfn visibility_Ashikhmin(NdotL_sh: f32, NdotV_sh: f32) -> f32 {\nreturn 1.0 / (4.0 * (NdotL_sh + NdotV_sh - NdotL_sh * NdotV_sh));\n}\n",_fragmentSlots:l}}(0!==(t._features&e),t._hasIbl,0!==(t._features&s),!!(8192&t._features2),0!==(t._features2&r)):null,writeUbo:function(e,n,s){const t=n._sheen;if(!t?.isEnabled||!s.has("sheenParams"))return;const r=s.get("sheenParams")/4,a=t.color??[1,1,1];e[r]=a[0],e[r+1]=a[1],e[r+2]=a[2],e[r+3]=t.intensity??1,e[r+4]=t.roughness??0,e[r+5]=t.texture?1:0,h(e,s,"sheenUVm","sheenUVt",t.texture),h(e,s,"sheenRoughUVm","sheenRoughUVt",t.roughnessTexture)},bind(n,s,t){const a=n._material._sheen;return 0!==(n._features&e)&&a?.texture&&(s.push({binding:t++,resource:a.texture.view}),s.push({binding:t++,resource:a.texture.sampler})),0!==(n._features2&r)&&a?.roughnessTexture&&(s.push({binding:t++,resource:a.roughnessTexture.view}),s.push({binding:t++,resource:a.roughnessTexture.sampler})),t},textures(e,n){const s=e._sheen;s?.texture&&n.push(s.texture),s?.roughnessTexture&&n.push(s.roughnessTexture)}};const l={id:"KHR_materials_sheen",async applyMaterial(e,n){const s=e._rawMatDef?.extensions?.KHR_materials_sheen;if(!s)return null;const r=await n._texture(s.sheenColorTexture,!0),a=s.sheenRoughnessTexture,h=a&&s.sheenColorTexture&&a.index===s.sheenColorTexture.index&&a.extensions?.KHR_texture_transform===s.sheenColorTexture.extensions?.KHR_texture_transform,l=a&&!h?await n._texture(a,!1):void 0,o={};return function(e,n){e._sheen=n,t(i)}(o,{isEnabled:!0,color:s.sheenColorFactor??[0,0,0],roughness:s.sheenRoughnessFactor??0,intensity:1,texture:r,...l?{roughnessTexture:l}:void 0,albedoScaling:!0}),o}};export{l as default};
//# sourceMappingURL=gltf-ext-sheen-CMNzFSvb.esm.min.js.map