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.24 kB
import{a4 as e,a5 as t,a6 as l,y as r,bw as c,a8 as a}from"./index-B8IgtevW.esm.min.js";const n=1<<26,i=e=>`(vec2<f32>(dot(material.${e}m.xy, input.uv), dot(material.${e}m.zw, input.uv)) + material.${e}t.xy)`;function m(e,t,l,r){const c=t.get(`${l}m`),a=t.get(`${l}t`);if(void 0===c||void 0===a)return;const n=r?.uScale??1,i=r?.vScale??1,m=r?.uAng??0,o=c/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 u=a/4;e[u]=r?.uOffset??0,e[u+1]=r?.vOffset??0}const o={id:"reflectance",phase:"fragment",detect(r){const a=r;let i=0,m=0;if(a._metallicReflectanceTexture&&(i|=e),a._reflectanceTexture&&(i|=t),0===i){const e=null!=a._metallicF0Factor&&Math.abs(a._metallicF0Factor-1)>1e-6,t=a._metallicReflectanceColor,r=null!=t&&(1!==t[0]||1!==t[1]||1!==t[2]);(e||r||a._occlStrengthAnimated)&&(m|=l)}(0!==i||m&l)&&a._useOnlyMetallicFromMetallicReflectanceTexture&&(i|=c);const o=e=>!!e?._hasTx;return 0!==i&&(o(a._reflectanceTexture)||o(a._metallicReflectanceTexture))&&(m|=n),{f:i,f2:m}},frag(a){const m=0!==(a._features&e),o=0!==(a._features&t),u=0!==(a._features2&l);return m||o||u?function(e,t,l,r=!1,c=!1,a=!1){const n=r?"textureSample(occlusionTexture, occlusionSampler_, input.uv2).r":a?"textureSample(ormTexture,ormSampler,occlUV).r":"orm.r",m=[];e&&m.push({_name:"metallicReflectanceMap",_type:{_kind:"texture",_textureType:"texture_2d<f32>"},_visibility:2},{_name:"metallicReflectanceMapSampler",_type:{_kind:"sampler",_samplerType:"sampler"},_visibility:2}),t&&m.push({_name:"reflectanceMap",_type:{_kind:"texture",_textureType:"texture_2d<f32>"},_visibility:2},{_name:"reflectanceMapSampler",_type:{_kind:"sampler",_samplerType:"sampler"},_visibility:2});const o=c?i("reflUV"):"input.uv",u=c?i("mrReflUV"):"input.uv";let s="var mrFactors = vec4<f32>(material.metallicReflectanceColor, material.metallicF0Factor);\nvar specularWeight = material.specularWeight;";t&&(s+=`\n{ let rSample = textureSample(reflectanceMap, reflectanceMapSampler, ${o});\n let rLinear = pow(rSample.rgb, vec3<f32>(2.2));\n mrFactors = vec4<f32>(mrFactors.rgb * rLinear, mrFactors.a); }`),e&&(s+=l?`\n{ let mrSample = textureSample(metallicReflectanceMap, metallicReflectanceMapSampler, ${u});\n mrFactors = vec4<f32>(mrFactors.rgb, mrFactors.a * mrSample.a);\n specularWeight *= mrSample.a; }`:`\n{ let mrSample = textureSample(metallicReflectanceMap, metallicReflectanceMapSampler, ${u});\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; }`),s+="\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 f=[{_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 c&&(t&&f.push({_name:"reflUVm",_type:"vec4<f32>"},{_name:"reflUVt",_type:"vec4<f32>"}),e&&f.push({_name:"mrReflUVm",_type:"vec4<f32>"},{_name:"mrReflUVt",_type:"vec4<f32>"})),{_id:c?"reflectance-U":"reflectance",_uboFields:f,_bindings:m,_fragmentSlots:{MF:s,AT:`let occlusion = mix(1.0, ${n}, material.occlusionStrength);`}}}(m,o,0!==(a._features&c),!!(32&(a._uv2Mask??0)),0!==(a._features2&n),0!==(a._features2&r)&&!!(a._features2&1<<28)):null},writeUbo:function(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 c=t._metallicReflectanceColor;e[r+4]=c?c[0]:1,e[r+5]=c?c[1]:1,e[r+6]=c?c[2]:1,m(e,l,"reflUV",t._reflectanceTexture),m(e,l,"mrReflUV",t._metallicReflectanceTexture)},bind(l,r,c){if(0===(l._features&(e|t)))return c;const a=l._material;return a._metallicReflectanceTexture&&(r.push({binding:c++,resource:a._metallicReflectanceTexture.view}),r.push({binding:c++,resource:a._metallicReflectanceTexture.sampler})),a._reflectanceTexture&&(r.push({binding:c++,resource:a._reflectanceTexture.view}),r.push({binding:c++,resource:a._reflectanceTexture.sampler})),c},textures(e,t){const l=e;l._metallicReflectanceTexture&&t.push(l._metallicReflectanceTexture),l._reflectanceTexture&&t.push(l._reflectanceTexture)}};function u(e,t){t.color&&(e._metallicReflectanceColor=t.color),t.texture&&(e._metallicReflectanceTexture=t.texture),t.reflectanceTexture&&(e._reflectanceTexture=t.reflectanceTexture),void 0!==t.f0Factor&&(e._metallicF0Factor=t.f0Factor),void 0!==t.specularWeight&&(e._specularWeight=t.specularWeight),void 0!==t.useOnlyMetallicFromTexture&&(e._useOnlyMetallicFromMetallicReflectanceTexture=t.useOnlyMetallicFromTexture),a(o)}export{u as setPbrMetallicReflectance}; //# sourceMappingURL=set-metallic-reflectance-CdBVQVJt.esm.min.js.map