1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-03 14:10:33 +03:00

0031096: Visualization, TKOpenGl - support metallic-roughness texture mapping

OpenGl_ShaderManager - metallic-roughness, emissive, occlusion
and normal texture maps are now supported by PBR.
Emissive, occlusion and normal texture maps are now supported by Phong shading model.
Path-Tracing now handles metallic-roughness and emissive texture maps.

Graphic3d_TextureUnit enumeration has been extended by
new values corresponding to supported texture maps.

OpenGl_TextureSet and OpenGl_ShaderProgram have been extended with
bitmask Graphic3d_TextureSetBits identifying texture slots read from GLSL Program
and slots defined within Texture Set to avoid undefined behavior by binding mock textures.

OpenGl_TextureSet now duplicates texture unit information to handle
textures shared across multiple slots (like Occlusion [R] + Metallic-Roughness [GB]).

OpenGl_Context::BindTextures() has been extended with active GLSL program paramter
to set mock textures to texture units used by program but undefined by texture set.
OpenGl_Workspace::ApplyAspects() has been extended with parameter to avoid bining texture set.
This commit is contained in:
iko
2019-11-07 16:52:53 +03:00
committed by bugmaster
parent f051908edc
commit 72f6dc612c
35 changed files with 856 additions and 405 deletions

View File

@@ -175,49 +175,76 @@ uniform THE_PREC_ENUM int occLightSourcesCount; //!< Total number of light sour
#endif
#endif
// Converts roughness value from range [0, 1] to real value for calculations
#if defined(THE_IS_PBR)
//! Converts roughness value from range [0, 1] to real value for calculations
float occRoughness (in float theNormalizedRoughness);
// Front material properties accessors
#if !defined(THE_IS_PBR)
vec4 occFrontMaterial_Emission(void); //!< Emission color
vec4 occFrontMaterial_Ambient(void); //!< Ambient reflection
vec4 occFrontMaterial_Diffuse(void); //!< Diffuse reflection
vec4 occFrontMaterial_Specular(void); //!< Specular reflection
float occFrontMaterial_Shininess(void); //!< Specular exponent
float occFrontMaterial_Transparency(void); //!< Transparency coefficient
// Front/back material properties accessors
vec4 occPBRMaterial_Color(in bool theIsFront); //!< Base color of PBR material
float occPBRMaterial_Metallic(in bool theIsFront); //!< Metallic coefficient
float occPBRMaterial_NormalizedRoughness(in bool theIsFront); //!< Normalized roughness coefficient
vec3 occPBRMaterial_Emission(in bool theIsFront); //!< Light intensity emitted by material
float occPBRMaterial_IOR(in bool theIsFront); //!< Index of refraction
#else
vec4 occPBRFrontMaterial_Color(void); //!< Base color of PBR material
float occPBRFrontMaterial_Metallic(void); //!< Metallic coefficient
float occPBRFrontMaterial_Roughness(void); //!< Roughness coefficient
float occPBRFrontMaterial_NormalizedRoughness(void); //!< Normalized roughness coefficient
vec3 occPBRFrontMaterial_Emission(void); //!< Light intensity emitted by material
float occPBRFrontMaterial_IOR(void); //!< Index of refraction
#endif
// Front material properties accessors
vec4 occFrontMaterial_Emission(void); //!< Emission color
vec4 occFrontMaterial_Ambient(void); //!< Ambient reflection
vec4 occFrontMaterial_Diffuse(void); //!< Diffuse reflection
vec4 occFrontMaterial_Specular(void); //!< Specular reflection
float occFrontMaterial_Shininess(void); //!< Specular exponent
float occFrontMaterial_Transparency(void); //!< Transparency coefficient
// Back material properties accessors
#if !defined(THE_IS_PBR)
vec4 occBackMaterial_Emission(void); //!< Emission color
vec4 occBackMaterial_Ambient(void); //!< Ambient reflection
vec4 occBackMaterial_Diffuse(void); //!< Diffuse reflection
vec4 occBackMaterial_Specular(void); //!< Specular reflection
float occBackMaterial_Shininess(void); //!< Specular exponent
float occBackMaterial_Transparency(void); //!< Transparency coefficient
#else
vec4 occPBRBackMaterial_Color(void); //!< Base color of PBR material
float occPBRBackMaterial_Metallic(void); //!< Metallic coefficient
float occPBRBackMaterial_Roughness(void); //!< Roughness coefficient
float occPBRBackMaterial_NormalizedRoughness(void); //!< Normalized roughness coefficient
vec3 occPBRBackMaterial_Emission(void); //!< Light intensity emitted by material
float occPBRBackMaterial_IOR(void); //!< Index of refraction
#endif
#ifdef THE_HAS_DEFAULT_SAMPLER
#define occActiveSampler occSampler0 //!< alias for backward compatibility
#define occSamplerBaseColor occSampler0 //!< alias to a base color texture
uniform sampler2D occSampler0; //!< current active sampler;
#define occActiveSampler occSampler0 //!< alias for backward compatibility
#define occSamplerBaseColor occSampler0 //!< alias to a base color texture
uniform sampler2D occSampler0; //!< current active sampler;
#endif //! occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing
#if defined(THE_HAS_TEXTURE_COLOR)
#define occTextureColor(theMatColor, theTexCoord) (theMatColor * occTexture2D(occSamplerBaseColor, theTexCoord))
#else
#define occTextureColor(theMatColor, theTexCoord) theMatColor
#endif
//! occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing
#if defined(THE_HAS_TEXTURE_OCCLUSION) && defined(FRAGMENT_SHADER)
uniform sampler2D occSamplerOcclusion; //!< R occlusion texture sampler
#define occTextureOcclusion(theColor, theTexCoord) theColor *= occTexture2D(occSamplerOcclusion, theTexCoord).r;
#else
#define occTextureOcclusion(theColor, theTexCoord)
#endif
#if defined(THE_HAS_TEXTURE_EMISSIVE) && defined(FRAGMENT_SHADER)
uniform sampler2D occSamplerEmissive; //!< RGB emissive texture sampler
#define occTextureEmissive(theMatEmis, theTexCoord) (theMatEmis * occTexture2D(occSamplerEmissive, theTexCoord).rgb)
#else
#define occTextureEmissive(theMatEmis, theTexCoord) theMatEmis
#endif
#if defined(THE_HAS_TEXTURE_NORMAL) && defined(FRAGMENT_SHADER)
uniform sampler2D occSamplerNormal; //!< XYZ normal texture sampler with W==0 indicating no texture
#define occTextureNormal(theTexCoord) occTexture2D(occSamplerNormal, theTexCoord)
#else
#define occTextureNormal(theTexCoord) vec4(0.0) // no normal map
#endif
#if defined(THE_HAS_TEXTURE_METALROUGHNESS) && defined(FRAGMENT_SHADER)
uniform sampler2D occSamplerMetallicRoughness; //!< BG metallic-roughness texture sampler
#define occTextureRoughness(theRoug, theTexCoord) (theRoug * occTexture2D(occSamplerMetallicRoughness, theTexCoord).g)
#define occTextureMetallic(theMet, theTexCoord) (theMet * occTexture2D(occSamplerMetallicRoughness, theTexCoord).b)
#else
#define occTextureRoughness(theRoug, theTexCoord) theRoug
#define occTextureMetallic(theMet, theTexCoord) theMet
#endif
uniform vec4 occColor; //!< color value (in case of disabled lighting)
uniform THE_PREC_ENUM int occDistinguishingMode; //!< Are front and back faces distinguished?
uniform THE_PREC_ENUM int occTextureEnable; //!< Is texture enabled?

View File

@@ -52,22 +52,12 @@ uniform vec4 occPbrFrontMaterial[3];
uniform vec4 occPbrBackMaterial[3];
#define MIN_ROUGHNESS 0.01
// Converts roughness value from range [0, 1] to real value for calculations
float occRoughness (in float theNormalizedRoughness) { return theNormalizedRoughness * (1.0 - MIN_ROUGHNESS) + MIN_ROUGHNESS; }
vec4 occPBRFrontMaterial_Color(void) { return occPbrFrontMaterial[0]; }
vec3 occPBRFrontMaterial_Emission(void) { return occPbrFrontMaterial[1].rgb; }
float occPBRFrontMaterial_IOR(void) { return occPbrFrontMaterial[1].w; }
float occPBRFrontMaterial_Metallic(void) { return occPbrFrontMaterial[2].b; }
float occPBRFrontMaterial_Roughness(void) { return occRoughness (occPbrFrontMaterial[2].g); }
float occPBRFrontMaterial_NormalizedRoughness(void) { return occPbrFrontMaterial[2].g; }
vec4 occPBRBackMaterial_Color(void) { return occPbrBackMaterial[0]; }
vec3 occPBRBackMaterial_Emission(void) { return occPbrBackMaterial[1].rgb; }
float occPBRBackMaterial_IOR(void) { return occPbrBackMaterial[1].w; }
float occPBRBackMaterial_Metallic(void) { return occPbrBackMaterial[2].b; }
float occPBRBackMaterial_Roughness(void) { return occRoughness (occPbrBackMaterial[2].g); }
float occPBRBackMaterial_NormalizedRoughness(void) { return occPbrBackMaterial[2].g; }
vec4 occPBRMaterial_Color(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[0] : occPbrBackMaterial[0]; }
vec3 occPBRMaterial_Emission(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[1].rgb : occPbrBackMaterial[1].rgb; }
float occPBRMaterial_IOR(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[1].w : occPbrBackMaterial[1].w; }
float occPBRMaterial_Metallic(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[2].b : occPbrBackMaterial[2].b; }
float occPBRMaterial_NormalizedRoughness(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[2].g : occPbrBackMaterial[2].g; }
#else
uniform vec4 occFrontMaterial[5];
uniform vec4 occBackMaterial[5];

View File

@@ -34,14 +34,14 @@ struct SBSDF
//! Weight of coat specular/glossy BRDF.
vec4 Kc;
//! Weight of base diffuse BRDF.
//! Weight of base diffuse BRDF + base color texture index in W.
vec4 Kd;
//! Weight of base specular/glossy BRDF.
vec4 Ks;
//! Weight of base specular/glossy BTDF.
vec3 Kt;
//! Weight of base specular/glossy BTDF + metallic-roughness texture index in W.
vec4 Kt;
//! Fresnel coefficients of coat layer.
vec3 FresnelCoat;
@@ -816,11 +816,16 @@ vec4 PathTrace (in SRay theRay, in vec3 theInverse, in int theNbSamples)
aBSDF.Kc = texelFetch (uRaytraceMaterialTexture, MATERIAL_KC (aTriIndex.w));
aBSDF.Kd = texelFetch (uRaytraceMaterialTexture, MATERIAL_KD (aTriIndex.w));
aBSDF.Ks = texelFetch (uRaytraceMaterialTexture, MATERIAL_KS (aTriIndex.w));
aBSDF.Kt = texelFetch (uRaytraceMaterialTexture, MATERIAL_KT (aTriIndex.w)).rgb;
aBSDF.Kt = texelFetch (uRaytraceMaterialTexture, MATERIAL_KT (aTriIndex.w));
// fetch Fresnel reflectance for both layers
aBSDF.FresnelCoat = texelFetch (uRaytraceMaterialTexture, MATERIAL_FRESNEL_COAT (aTriIndex.w)).xyz;
aBSDF.FresnelBase = texelFetch (uRaytraceMaterialTexture, MATERIAL_FRESNEL_BASE (aTriIndex.w)).xyz;
vec4 anLE = texelFetch (uRaytraceMaterialTexture, MATERIAL_LE (aTriIndex.w));
// compute smooth normal (in parallel with fetch)
vec3 aNormal = SmoothNormal (aHit.UV, aTriIndex);
aNormal = normalize (vec3 (dot (aInvTransf0, aNormal),
dot (aInvTransf1, aNormal),
dot (aInvTransf2, aNormal)));
@@ -828,7 +833,7 @@ vec4 PathTrace (in SRay theRay, in vec3 theInverse, in int theNbSamples)
SLocalSpace aSpace = buildLocalSpace (aNormal);
#ifdef USE_TEXTURES
if (aBSDF.Kd.w >= 0.f)
if (aBSDF.Kd.w >= 0.0 || aBSDF.Kt.w >= 0.0 || anLE.w >= 0.0)
{
vec4 aTexCoord = vec4 (SmoothUV (aHit.UV, aTriIndex), 0.f, 1.f);
vec4 aTrsfRow1 = texelFetch (uRaytraceMaterialTexture, MATERIAL_TRS1 (aTriIndex.w));
@@ -836,20 +841,36 @@ vec4 PathTrace (in SRay theRay, in vec3 theInverse, in int theNbSamples)
aTexCoord.st = vec2 (dot (aTrsfRow1, aTexCoord),
dot (aTrsfRow2, aTexCoord));
vec4 aTexColor = textureLod (sampler2D (uTextureSamplers[int (aBSDF.Kd.w)]), aTexCoord.st, 0.f);
aBSDF.Kd.rgb *= aTexColor.rgb * aTexColor.w;
if (aTexColor.w != 1.0f)
if (anLE.w >= 0.0)
{
// mix transparency BTDF with texture alpha-channel
aBSDF.Kt = (UNIT - aTexColor.www) + aTexColor.w * aBSDF.Kt;
anLE.rgb *= textureLod (sampler2D (uTextureSamplers[int (anLE.w)]), aTexCoord.st, 0.0).rgb;
}
if (aBSDF.Kt.w >= 0.0)
{
vec2 aTexMetRough = textureLod (sampler2D (uTextureSamplers[int (aBSDF.Kt.w)]), aTexCoord.st, 0.0).bg;
float aPbrMetal = aTexMetRough.x;
float aPbrRough2 = aTexMetRough.y * aTexMetRough.y;
aBSDF.Ks.a *= aPbrRough2;
// 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
aBSDF.Kd.rgb = aBSDF.FresnelBase * (1.0 - aPbrMetal);
aBSDF.FresnelBase *= aPbrMetal;
}
if (aBSDF.Kd.w >= 0.0)
{
vec4 aTexColor = textureLod (sampler2D (uTextureSamplers[int (aBSDF.Kd.w)]), aTexCoord.st, 0.0);
vec3 aDiff = aTexColor.rgb * aTexColor.a;
aBSDF.Kd.rgb *= aDiff;
aBSDF.FresnelBase *= aDiff;
if (aTexColor.a != 1.0)
{
// mix transparency BTDF with texture alpha-channel
aBSDF.Ks.rgb *= aTexColor.a;
aBSDF.Kt.rgb = (UNIT - aTexColor.aaa) + aTexColor.a * aBSDF.Kt.rgb;
}
}
}
#endif
// fetch Fresnel reflectance for both layers
aBSDF.FresnelCoat = texelFetch (uRaytraceMaterialTexture, MATERIAL_FRESNEL_COAT (aTriIndex.w)).xyz;
aBSDF.FresnelBase = texelFetch (uRaytraceMaterialTexture, MATERIAL_FRESNEL_BASE (aTriIndex.w)).xyz;
if (uLightCount > 0 && IsNotZero (aBSDF, aThroughput))
{
aExpPDF = 1.f / uLightCount;
@@ -893,7 +914,7 @@ vec4 PathTrace (in SRay theRay, in vec3 theInverse, in int theNbSamples)
}
// account for self-emission
aRadiance += aThroughput * texelFetch (uRaytraceMaterialTexture, MATERIAL_LE (aTriIndex.w)).rgb;
aRadiance += aThroughput * anLE.rgb;
if (aInMedium) // handle attenuation
{

View File

@@ -55,22 +55,12 @@ static const char Shaders_DeclarationsImpl_glsl[] =
"uniform vec4 occPbrBackMaterial[3];\n"
"\n"
"#define MIN_ROUGHNESS 0.01\n"
"// Converts roughness value from range [0, 1] to real value for calculations\n"
"float occRoughness (in float theNormalizedRoughness) { return theNormalizedRoughness * (1.0 - MIN_ROUGHNESS) + MIN_ROUGHNESS; }\n"
"\n"
"vec4 occPBRFrontMaterial_Color(void) { return occPbrFrontMaterial[0]; }\n"
"vec3 occPBRFrontMaterial_Emission(void) { return occPbrFrontMaterial[1].rgb; }\n"
"float occPBRFrontMaterial_IOR(void) { return occPbrFrontMaterial[1].w; }\n"
"float occPBRFrontMaterial_Metallic(void) { return occPbrFrontMaterial[2].b; }\n"
"float occPBRFrontMaterial_Roughness(void) { return occRoughness (occPbrFrontMaterial[2].g); }\n"
"float occPBRFrontMaterial_NormalizedRoughness(void) { return occPbrFrontMaterial[2].g; }\n"
"\n"
"vec4 occPBRBackMaterial_Color(void) { return occPbrBackMaterial[0]; }\n"
"vec3 occPBRBackMaterial_Emission(void) { return occPbrBackMaterial[1].rgb; }\n"
"float occPBRBackMaterial_IOR(void) { return occPbrBackMaterial[1].w; }\n"
"float occPBRBackMaterial_Metallic(void) { return occPbrBackMaterial[2].b; }\n"
"float occPBRBackMaterial_Roughness(void) { return occRoughness (occPbrBackMaterial[2].g); }\n"
"float occPBRBackMaterial_NormalizedRoughness(void) { return occPbrBackMaterial[2].g; }\n"
"vec4 occPBRMaterial_Color(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[0] : occPbrBackMaterial[0]; }\n"
"vec3 occPBRMaterial_Emission(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[1].rgb : occPbrBackMaterial[1].rgb; }\n"
"float occPBRMaterial_IOR(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[1].w : occPbrBackMaterial[1].w; }\n"
"float occPBRMaterial_Metallic(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[2].b : occPbrBackMaterial[2].b; }\n"
"float occPBRMaterial_NormalizedRoughness(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[2].g : occPbrBackMaterial[2].g; }\n"
"#else\n"
"uniform vec4 occFrontMaterial[5];\n"
"uniform vec4 occBackMaterial[5];\n"

View File

@@ -178,49 +178,76 @@ static const char Shaders_Declarations_glsl[] =
"#endif\n"
"#endif\n"
"\n"
"// Converts roughness value from range [0, 1] to real value for calculations\n"
"#if defined(THE_IS_PBR)\n"
"//! Converts roughness value from range [0, 1] to real value for calculations\n"
"float occRoughness (in float theNormalizedRoughness);\n"
"\n"
"// Front material properties accessors\n"
"#if !defined(THE_IS_PBR)\n"
"vec4 occFrontMaterial_Emission(void); //!< Emission color\n"
"vec4 occFrontMaterial_Ambient(void); //!< Ambient reflection\n"
"vec4 occFrontMaterial_Diffuse(void); //!< Diffuse reflection\n"
"vec4 occFrontMaterial_Specular(void); //!< Specular reflection\n"
"float occFrontMaterial_Shininess(void); //!< Specular exponent\n"
"float occFrontMaterial_Transparency(void); //!< Transparency coefficient\n"
"// Front/back material properties accessors\n"
"vec4 occPBRMaterial_Color(in bool theIsFront); //!< Base color of PBR material\n"
"float occPBRMaterial_Metallic(in bool theIsFront); //!< Metallic coefficient\n"
"float occPBRMaterial_NormalizedRoughness(in bool theIsFront); //!< Normalized roughness coefficient\n"
"vec3 occPBRMaterial_Emission(in bool theIsFront); //!< Light intensity emitted by material\n"
"float occPBRMaterial_IOR(in bool theIsFront); //!< Index of refraction\n"
"#else\n"
"vec4 occPBRFrontMaterial_Color(void); //!< Base color of PBR material\n"
"float occPBRFrontMaterial_Metallic(void); //!< Metallic coefficient\n"
"float occPBRFrontMaterial_Roughness(void); //!< Roughness coefficient\n"
"float occPBRFrontMaterial_NormalizedRoughness(void); //!< Normalized roughness coefficient\n"
"vec3 occPBRFrontMaterial_Emission(void); //!< Light intensity emitted by material\n"
"float occPBRFrontMaterial_IOR(void); //!< Index of refraction\n"
"#endif\n"
"// Front material properties accessors\n"
"vec4 occFrontMaterial_Emission(void); //!< Emission color\n"
"vec4 occFrontMaterial_Ambient(void); //!< Ambient reflection\n"
"vec4 occFrontMaterial_Diffuse(void); //!< Diffuse reflection\n"
"vec4 occFrontMaterial_Specular(void); //!< Specular reflection\n"
"float occFrontMaterial_Shininess(void); //!< Specular exponent\n"
"float occFrontMaterial_Transparency(void); //!< Transparency coefficient\n"
"\n"
"// Back material properties accessors\n"
"#if !defined(THE_IS_PBR)\n"
"vec4 occBackMaterial_Emission(void); //!< Emission color\n"
"vec4 occBackMaterial_Ambient(void); //!< Ambient reflection\n"
"vec4 occBackMaterial_Diffuse(void); //!< Diffuse reflection\n"
"vec4 occBackMaterial_Specular(void); //!< Specular reflection\n"
"float occBackMaterial_Shininess(void); //!< Specular exponent\n"
"float occBackMaterial_Transparency(void); //!< Transparency coefficient\n"
"#else\n"
"vec4 occPBRBackMaterial_Color(void); //!< Base color of PBR material\n"
"float occPBRBackMaterial_Metallic(void); //!< Metallic coefficient\n"
"float occPBRBackMaterial_Roughness(void); //!< Roughness coefficient\n"
"float occPBRBackMaterial_NormalizedRoughness(void); //!< Normalized roughness coefficient\n"
"vec3 occPBRBackMaterial_Emission(void); //!< Light intensity emitted by material\n"
"float occPBRBackMaterial_IOR(void); //!< Index of refraction\n"
"#endif\n"
"\n"
"#ifdef THE_HAS_DEFAULT_SAMPLER\n"
"#define occActiveSampler occSampler0 //!< alias for backward compatibility\n"
"#define occSamplerBaseColor occSampler0 //!< alias to a base color texture\n"
"uniform sampler2D occSampler0; //!< current active sampler;\n"
"#define occActiveSampler occSampler0 //!< alias for backward compatibility\n"
"#define occSamplerBaseColor occSampler0 //!< alias to a base color texture\n"
"uniform sampler2D occSampler0; //!< current active sampler;\n"
"#endif //! occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing\n"
"\n"
"#if defined(THE_HAS_TEXTURE_COLOR)\n"
"#define occTextureColor(theMatColor, theTexCoord) (theMatColor * occTexture2D(occSamplerBaseColor, theTexCoord))\n"
"#else\n"
"#define occTextureColor(theMatColor, theTexCoord) theMatColor\n"
"#endif\n"
" //! occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing\n"
"\n"
"#if defined(THE_HAS_TEXTURE_OCCLUSION) && defined(FRAGMENT_SHADER)\n"
"uniform sampler2D occSamplerOcclusion; //!< R occlusion texture sampler\n"
"#define occTextureOcclusion(theColor, theTexCoord) theColor *= occTexture2D(occSamplerOcclusion, theTexCoord).r;\n"
"#else\n"
"#define occTextureOcclusion(theColor, theTexCoord)\n"
"#endif\n"
"\n"
"#if defined(THE_HAS_TEXTURE_EMISSIVE) && defined(FRAGMENT_SHADER)\n"
"uniform sampler2D occSamplerEmissive; //!< RGB emissive texture sampler\n"
"#define occTextureEmissive(theMatEmis, theTexCoord) (theMatEmis * occTexture2D(occSamplerEmissive, theTexCoord).rgb)\n"
"#else\n"
"#define occTextureEmissive(theMatEmis, theTexCoord) theMatEmis\n"
"#endif\n"
"\n"
"#if defined(THE_HAS_TEXTURE_NORMAL) && defined(FRAGMENT_SHADER)\n"
"uniform sampler2D occSamplerNormal; //!< XYZ normal texture sampler with W==0 indicating no texture\n"
"#define occTextureNormal(theTexCoord) occTexture2D(occSamplerNormal, theTexCoord)\n"
"#else\n"
"#define occTextureNormal(theTexCoord) vec4(0.0) // no normal map\n"
"#endif\n"
"\n"
"#if defined(THE_HAS_TEXTURE_METALROUGHNESS) && defined(FRAGMENT_SHADER)\n"
"uniform sampler2D occSamplerMetallicRoughness; //!< BG metallic-roughness texture sampler\n"
"#define occTextureRoughness(theRoug, theTexCoord) (theRoug * occTexture2D(occSamplerMetallicRoughness, theTexCoord).g)\n"
"#define occTextureMetallic(theMet, theTexCoord) (theMet * occTexture2D(occSamplerMetallicRoughness, theTexCoord).b)\n"
"#else\n"
"#define occTextureRoughness(theRoug, theTexCoord) theRoug\n"
"#define occTextureMetallic(theMet, theTexCoord) theMet\n"
"#endif\n"
"\n"
"uniform vec4 occColor; //!< color value (in case of disabled lighting)\n"
"uniform THE_PREC_ENUM int occDistinguishingMode; //!< Are front and back faces distinguished?\n"
"uniform THE_PREC_ENUM int occTextureEnable; //!< Is texture enabled?\n"

View File

@@ -37,14 +37,14 @@ static const char Shaders_PathtraceBase_fs[] =
" //! 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"
@@ -819,11 +819,16 @@ static const char Shaders_PathtraceBase_fs[] =
" 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"
@@ -831,7 +836,7 @@ static const char Shaders_PathtraceBase_fs[] =
" 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"
@@ -839,20 +844,36 @@ static const char Shaders_PathtraceBase_fs[] =
" 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"
" // mix transparency BTDF with texture alpha-channel\n"
" aBSDF.Kt = (UNIT - aTexColor.www) + aTexColor.w * aBSDF.Kt;\n"
" anLE.rgb *= textureLod (sampler2D (uTextureSamplers[int (anLE.w)]), aTexCoord.st, 0.0).rgb;\n"
" }\n"
" if (aBSDF.Kt.w >= 0.0)\n"
" {\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"
@@ -896,7 +917,7 @@ static const char Shaders_PathtraceBase_fs[] =
" }\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"