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) 4.75 kB
import{Z as e,$ as t,a0 as l,ay as r}from"./index-DFZFpUG-.esm.min.js";const a=1<<26,c=e=>`(vec2<f32>(dot(material.${e}m.xy, input.uv), dot(material.${e}m.zw, input.uv)) + material.${e}t.xy)`;function n(e,t,l,r){const a=t.get(`${l}m`),c=t.get(`${l}t`);if(void 0===a||void 0===c)return;const n=r?.uScale??1,i=r?.vScale??1,m=r?.uAng??0,o=a/4;if(0===m)e[o]=n,e[o+1]=0,e[o+2]=0,e[o+3]=i;else{const t=Math.cos(m),l=Math.sin(m);e[o]=t*n,e[o+1]=l*i,e[o+2]=-l*n,e[o+3]=t*i}const s=c/4;e[s]=r?.uOffset??0,e[s+1]=r?.vOffset??0}function i(e,t,l){if(!l.has("occlusionStrength"))return;const r=l.get("occlusionStrength")/4;e[r]=t.occlusionStrength??1,e[r+1]=t.metallicF0Factor??1,e[r+2]=t.specularWeight??t.metallicF0Factor??1;const a=t.metallicReflectanceColor;e[r+4]=a?a[0]:1,e[r+5]=a?a[1]:1,e[r+6]=a?a[2]:1,n(e,l,"reflUV",t.reflectanceTexture),n(e,l,"mrReflUV",t.metallicReflectanceTexture)}function m(e,t,l,r=!1,a=!1){const n=[];e&&n.push({_name:"metallicReflectanceMap",_type:{_kind:"texture",_textureType:"texture_2d<f32>"},_visibility:2},{_name:"metallicReflectanceMapSampler",_type:{_kind:"sampler",_samplerType:"sampler"},_visibility:2}),t&&n.push({_name:"reflectanceMap",_type:{_kind:"texture",_textureType:"texture_2d<f32>"},_visibility:2},{_name:"reflectanceMapSampler",_type:{_kind:"sampler",_samplerType:"sampler"},_visibility:2});const i=a?c("reflUV"):"input.uv",m=a?c("mrReflUV"):"input.uv";let o="var mrFactors = vec4<f32>(material.metallicReflectanceColor, material.metallicF0Factor);\nvar specularWeight = material.specularWeight;";t&&(o+=`\n{ let rSample = textureSample(reflectanceMap, reflectanceMapSampler, ${i});\n let rLinear = pow(rSample.rgb, vec3<f32>(2.2));\n mrFactors = vec4<f32>(mrFactors.rgb * rLinear, mrFactors.a); }`),e&&(o+=l?`\n{ let mrSample = textureSample(metallicReflectanceMap, metallicReflectanceMapSampler, ${m});\n mrFactors = vec4<f32>(mrFactors.rgb, mrFactors.a * mrSample.a);\n specularWeight *= mrSample.a; }`:`\n{ let mrSample = textureSample(metallicReflectanceMap, metallicReflectanceMapSampler, ${m});\n let mrLinear = pow(mrSample.rgb, vec3<f32>(2.2));\n mrFactors = vec4<f32>(mrFactors.rgb * mrLinear, mrFactors.a * mrSample.a);\n specularWeight *= mrSample.a; }`),o+="\nlet dielectricF0 = material.reflectance * mrFactors.a;\nlet surfaceReflectivityColor = mrFactors.rgb;\nlet dielectricColorF0 = vec3<f32>(dielectricF0) * surfaceReflectivityColor;\nlet metallicColorF0 = baseColor;\nvar colorF0 = mix(dielectricColorF0, metallicColorF0, metallic);\nlet colorF90 = vec3<f32>(mix(specularWeight, 1.0, metallic));\nlet surfaceAlbedo = baseColor * (vec3<f32>(1.0) - vec3<f32>(dielectricF0) * surfaceReflectivityColor) * (1.0 - metallic);";const s=[{_name:"occlusionStrength",_type:"f32"},{_name:"metallicF0Factor",_type:"f32"},{_name:"specularWeight",_type:"f32"},{_name:"_mrPad1",_type:"f32"},{_name:"metallicReflectanceColor",_type:"vec3<f32>"},{_name:"_mrPad2",_type:"f32"}];return a&&(t&&s.push({_name:"reflUVm",_type:"vec4<f32>"},{_name:"reflUVt",_type:"vec4<f32>"}),e&&s.push({_name:"mrReflUVm",_type:"vec4<f32>"},{_name:"mrReflUVt",_type:"vec4<f32>"})),{_id:a?"reflectance-U":"reflectance",_uboFields:s,_bindings:n,_fragmentSlots:{MF:o,AT:r?"let occlusion = mix(1.0, textureSample(occlusionTexture, occlusionSampler_, input.uv2).r, material.occlusionStrength);":"let occlusion = mix(1.0, orm.r, material.occlusionStrength);"}}}const o={id:"reflectance",phase:"fragment",detect(c){const n=c;let i=0,m=0;if(n.metallicReflectanceTexture&&(i|=e),n.reflectanceTexture&&(i|=t),0===i){const e=null!=n.metallicF0Factor&&Math.abs(n.metallicF0Factor-1)>1e-6,t=n.metallicReflectanceColor,r=null!=t&&(1!==t[0]||1!==t[1]||1!==t[2]);(e||r||n._occlStrengthAnimated)&&(m|=l)}(0!==i||m&l)&&n.useOnlyMetallicFromMetallicReflectanceTexture&&(i|=r);const o=e=>!!e?._hasTx;return 0!==i&&(o(n.reflectanceTexture)||o(n.metallicReflectanceTexture))&&(m|=a),{f:i,f2:m}},frag(c){const n=0!==(c._features&e),i=0!==(c._features&t),o=0!==(c._features2&l);return n||i||o?m(n,i,0!==(c._features&r),!!(32&(c._uv2Mask??0)),0!==(c._features2&a)):null},writeUbo:i,bind(l,r,a){if(0===(l._features&(e|t)))return a;const c=l._material;return c.metallicReflectanceTexture&&(r.push({binding:a++,resource:c.metallicReflectanceTexture.view}),r.push({binding:a++,resource:c.metallicReflectanceTexture.sampler})),c.reflectanceTexture&&(r.push({binding:a++,resource:c.reflectanceTexture.view}),r.push({binding:a++,resource:c.reflectanceTexture.sampler})),a},textures(e,t){const l=e;l.metallicReflectanceTexture&&t.push(l.metallicReflectanceTexture),l.reflectanceTexture&&t.push(l.reflectanceTexture)}};export{m as createReflectanceFragment,o as pbrExt,i as writeReflectanceUBO}; //# sourceMappingURL=reflectance-fragment-iNNnhxnj.esm.min.js.map