UNPKG

@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) 5.52 kB
import{aA as e,aB as n,aC as s}from"./index-DFZFpUG-.esm.min.js";const t=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=!1,s=!1,t=!1,h=!1){let r="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;";if(e){r+=`\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))"};${h?"":"\nsheenRoughnessAdjusted *= sheenMapData.a;"}\n}`}h&&(r+="\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:r,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}),h&&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>"}),h&&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}}function r(e,n,s){const t=n.sheen;if(!t?.isEnabled||!s.has("sheenParams"))return;const a=s.get("sheenParams")/4,h=t.color??[1,1,1];e[a]=h[0],e[a+1]=h[1],e[a+2]=h[2],e[a+3]=t.intensity??1,e[a+4]=t.roughness??0,e[a+5]=t.texture?1:0,i(e,s,"sheenUVm","sheenUVt",t.texture),i(e,s,"sheenRoughUVm","sheenRoughUVt",t.roughnessTexture)}function i(e,n,s,t,a){const h=n.get(s),r=n.get(t);if(void 0===h||void 0===r)return;const i=a?.uScale??1,l=a?.vScale??1,o=a?.uAng??0,u=h/4,c=r/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[c]=a?.uOffset??0,e[c+1]=a?.vOffset??0,e[c+2]=0,e[c+3]=0}const l={id:"sheen",phase:"base-tex",detect(a){const h=a.sheen;if(!h?.isEnabled)return{f:0,f2:0};let r=n,i=0;return h.texture&&(r|=e,h.texture._hasTx&&(i|=8192)),h.roughnessTexture&&(i|=t),h.albedoScaling&&(r|=s),{f:r,f2:i}},frag:a=>a._features&n?h(0!==(a._features&e),a._hasIbl,0!==(a._features&s),!!(8192&a._features2),0!==(a._features2&t)):null,writeUbo:r,bind(n,s,a){const h=n._material.sheen;return 0!==(n._features&e)&&h?.texture&&(s.push({binding:a++,resource:h.texture.view}),s.push({binding:a++,resource:h.texture.sampler})),0!==(n._features2&t)&&h?.roughnessTexture&&(s.push({binding:a++,resource:h.roughnessTexture.view}),s.push({binding:a++,resource:h.roughnessTexture.sampler})),a},textures(e,n){const s=e.sheen;s?.texture&&n.push(s.texture),s?.roughnessTexture&&n.push(s.roughnessTexture)}};export{h as createSheenFragment,l as pbrExt,r as writeSheenUBO}; //# sourceMappingURL=sheen-fragment-vqD4XsSh.esm.min.js.map