" //! Weight of coat specular/glossy BRDF.\n"
" vec4 Kc;\n"
"\n"
- " //! Weight of base diffuse BRDF.\n"
+ " //! Weight of base diffuse BRDF + base color texture index in W.\n"
" vec4 Kd;\n"
"\n"
" //! Weight of base specular/glossy BRDF.\n"
" vec4 Ks;\n"
"\n"
- " //! Weight of base specular/glossy BTDF.\n"
- " vec3 Kt;\n"
+ " //! Weight of base specular/glossy BTDF + metallic-roughness texture index in W.\n"
+ " vec4 Kt;\n"
"\n"
" //! Fresnel coefficients of coat layer.\n"
" vec3 FresnelCoat;\n"
" aBSDF.Kc = texelFetch (uRaytraceMaterialTexture, MATERIAL_KC (aTriIndex.w));\n"
" aBSDF.Kd = texelFetch (uRaytraceMaterialTexture, MATERIAL_KD (aTriIndex.w));\n"
" aBSDF.Ks = texelFetch (uRaytraceMaterialTexture, MATERIAL_KS (aTriIndex.w));\n"
- " aBSDF.Kt = texelFetch (uRaytraceMaterialTexture, MATERIAL_KT (aTriIndex.w)).rgb;\n"
+ " aBSDF.Kt = texelFetch (uRaytraceMaterialTexture, MATERIAL_KT (aTriIndex.w));\n"
+ "\n"
+ " // fetch Fresnel reflectance for both layers\n"
+ " aBSDF.FresnelCoat = texelFetch (uRaytraceMaterialTexture, MATERIAL_FRESNEL_COAT (aTriIndex.w)).xyz;\n"
+ " aBSDF.FresnelBase = texelFetch (uRaytraceMaterialTexture, MATERIAL_FRESNEL_BASE (aTriIndex.w)).xyz;\n"
+ "\n"
+ " vec4 anLE = texelFetch (uRaytraceMaterialTexture, MATERIAL_LE (aTriIndex.w));\n"
"\n"
" // compute smooth normal (in parallel with fetch)\n"
" vec3 aNormal = SmoothNormal (aHit.UV, aTriIndex);\n"
- "\n"
" aNormal = normalize (vec3 (dot (aInvTransf0, aNormal),\n"
" dot (aInvTransf1, aNormal),\n"
" dot (aInvTransf2, aNormal)));\n"
" SLocalSpace aSpace = buildLocalSpace (aNormal);\n"
"\n"
"#ifdef USE_TEXTURES\n"
- " if (aBSDF.Kd.w >= 0.f)\n"
+ " if (aBSDF.Kd.w >= 0.0 || aBSDF.Kt.w >= 0.0 || anLE.w >= 0.0)\n"
" {\n"
" vec4 aTexCoord = vec4 (SmoothUV (aHit.UV, aTriIndex), 0.f, 1.f);\n"
" vec4 aTrsfRow1 = texelFetch (uRaytraceMaterialTexture, MATERIAL_TRS1 (aTriIndex.w));\n"
" aTexCoord.st = vec2 (dot (aTrsfRow1, aTexCoord),\n"
" dot (aTrsfRow2, aTexCoord));\n"
"\n"
- " vec4 aTexColor = textureLod (sampler2D (uTextureSamplers[int (aBSDF.Kd.w)]), aTexCoord.st, 0.f);\n"
- " aBSDF.Kd.rgb *= aTexColor.rgb * aTexColor.w;\n"
- " if (aTexColor.w != 1.0f)\n"
+ " if (anLE.w >= 0.0)\n"
+ " {\n"
+ " anLE.rgb *= textureLod (sampler2D (uTextureSamplers[int (anLE.w)]), aTexCoord.st, 0.0).rgb;\n"
+ " }\n"
+ " if (aBSDF.Kt.w >= 0.0)\n"
" {\n"
- " // mix transparency BTDF with texture alpha-channel\n"
- " aBSDF.Kt = (UNIT - aTexColor.www) + aTexColor.w * aBSDF.Kt;\n"
+ " vec2 aTexMetRough = textureLod (sampler2D (uTextureSamplers[int (aBSDF.Kt.w)]), aTexCoord.st, 0.0).bg;\n"
+ " float aPbrMetal = aTexMetRough.x;\n"
+ " float aPbrRough2 = aTexMetRough.y * aTexMetRough.y;\n"
+ " aBSDF.Ks.a *= aPbrRough2;\n"
+ " // when using metal-roughness texture, global metalness of material (encoded in FresnelBase) is expected to be 1.0 so that Kd will be 0.0\n"
+ " aBSDF.Kd.rgb = aBSDF.FresnelBase * (1.0 - aPbrMetal);\n"
+ " aBSDF.FresnelBase *= aPbrMetal;\n"
+ " }\n"
+ " if (aBSDF.Kd.w >= 0.0)\n"
+ " {\n"
+ " vec4 aTexColor = textureLod (sampler2D (uTextureSamplers[int (aBSDF.Kd.w)]), aTexCoord.st, 0.0);\n"
+ " vec3 aDiff = aTexColor.rgb * aTexColor.a;\n"
+ " aBSDF.Kd.rgb *= aDiff;\n"
+ " aBSDF.FresnelBase *= aDiff;\n"
+ " if (aTexColor.a != 1.0)\n"
+ " {\n"
+ " // mix transparency BTDF with texture alpha-channel\n"
+ " aBSDF.Ks.rgb *= aTexColor.a;\n"
+ " aBSDF.Kt.rgb = (UNIT - aTexColor.aaa) + aTexColor.a * aBSDF.Kt.rgb;\n"
+ " }\n"
" }\n"
" }\n"
"#endif\n"
"\n"
- " // fetch Fresnel reflectance for both layers\n"
- " aBSDF.FresnelCoat = texelFetch (uRaytraceMaterialTexture, MATERIAL_FRESNEL_COAT (aTriIndex.w)).xyz;\n"
- " aBSDF.FresnelBase = texelFetch (uRaytraceMaterialTexture, MATERIAL_FRESNEL_BASE (aTriIndex.w)).xyz;\n"
- "\n"
" if (uLightCount > 0 && IsNotZero (aBSDF, aThroughput))\n"
" {\n"
" aExpPDF = 1.f / uLightCount;\n"
" }\n"
"\n"
" // account for self-emission\n"
- " aRadiance += aThroughput * texelFetch (uRaytraceMaterialTexture, MATERIAL_LE (aTriIndex.w)).rgb;\n"
+ " aRadiance += aThroughput * anLE.rgb;\n"
"\n"
" if (aInMedium) // handle attenuation\n"
" {\n"