PBR Terrain splatting MaterialDefinition

Hello all,

here is a basic contribution for using the TerrainLighting with PBR, it supports the following:

  • Roughness value for each DiffuseMap
  • Metallic value for each DiffuseMap
  • Separate Roughness Map
  • Separate Metallic Map
  • Classic Parallax Offset

Additionally, i’m using the parallax height to be stored in the alpha channel of the normal map. By comparing how the lighting shader is doing the other stuff one should be able to change it.

I know the Makro for blending is not really beautiful, but it helps to keep this massive texture blending more compact. The DiffuseMap should be renamed to AlbedoMap, but i was to lazy…

vertex shader:

#import "Common/ShaderLib/GLSLCompat.glsllib"
#import "Common/ShaderLib/Instancing.glsllib"

attribute vec3 inPosition;
attribute vec3 inNormal;
attribute vec2 inTexCoord;

varying vec2 texCoord;
varying vec3 wPosition;
varying vec3 wNormal;
#if defined(NORMALMAP_0) || defined(NORMALMAP_1) || defined(NORMALMAP_2) || defined(NORMALMAP_3) || defined(NORMALMAP_4) || defined(NORMALMAP_5) || defined(NORMALMAP_6) || defined(NORMALMAP_7)
    attribute vec4 inTangent;
    varying vec4 wTangent;
#endif

void main(){
    vec4 modelSpacePos = vec4(inPosition, 1.0);

    gl_Position = TransformWorldViewProjection(modelSpacePos);

    texCoord = inTexCoord;

    wPosition = TransformWorld(modelSpacePos).xyz;
    wNormal  = normalize(TransformWorldNormal(inNormal));
    #if  defined(NORMALMAP_0) || defined(NORMALMAP_1) || defined(NORMALMAP_2) || defined(NORMALMAP_3) || defined(NORMALMAP_4) || defined(NORMALMAP_5) || defined(NORMALMAP_6) || defined(NORMALMAP_7)
        wTangent = vec4(TransformWorldNormal(inTangent.xyz),inTangent.w);
    #endif
}

Fragment:

#import "Common/ShaderLib/GLSLCompat.glsllib"
#import "Common/ShaderLib/PBR.glsllib"
#import "Common/ShaderLib/Lighting.glsllib"

uniform vec4 g_LightData[NB_LIGHTS];

varying vec3 wPosition;

#ifdef INDIRECT_LIGHTING
//  uniform sampler2D m_IntegrateBRDF;
  uniform samplerCube g_PrefEnvMap;
  uniform samplerCube g_IrradianceMap;
  uniform vec4 g_LightProbeData;
#endif

#ifdef METALLICMAP
    uniform sampler2D m_MetallicMap;
#else
    uniform float m_Metallic_0;
    uniform float m_Metallic_1;
    uniform float m_Metallic_2;
    uniform float m_Metallic_3;
    uniform float m_Metallic_4;
    uniform float m_Metallic_5;
    uniform float m_Metallic_6;
    uniform float m_Metallic_7;
    uniform float m_Metallic_8;
    uniform float m_Metallic_9;
    uniform float m_Metallic_10;
    uniform float m_Metallic_11;
#endif
#ifdef ROUGHNESSMAP
    uniform sampler2D m_RoughnessMap;
#endif
uniform float m_Roughness_0;
uniform float m_Roughness_1;
uniform float m_Roughness_2;
uniform float m_Roughness_3;
uniform float m_Roughness_4;
uniform float m_Roughness_5;
uniform float m_Roughness_6;
uniform float m_Roughness_7;
uniform float m_Roughness_8;
uniform float m_Roughness_9;
uniform float m_Roughness_10;
uniform float m_Roughness_11;

#ifdef EMISSIVE
    uniform vec4 m_Emissive;
#endif
#ifdef EMISSIVEMAP
    uniform sampler2D m_EmissiveMap;
#endif
#if defined(EMISSIVE) || defined(EMISSIVEMAP)
    uniform float m_EmissivePower;
    uniform float m_EmissiveIntensity;
#endif 

#ifdef SPECGLOSSPIPELINE
  uniform sampler2D m_SpecularMap;
  uniform sampler2D m_GlossMap;
#endif

#ifdef LIGHTMAP
  uniform sampler2D m_LightMap;
#endif

varying vec3 wNormal;
#if defined(NORMALMAP_0) || defined(NORMALMAP_1) || defined(NORMALMAP_2) || defined(NORMALMAP_3) || defined(NORMALMAP_4) || defined(NORMALMAP_5) || defined(NORMALMAP_6) || defined(NORMALMAP_7)
    varying vec4 wTangent;
#endif

varying vec2 texCoord;
#ifdef DIFFUSEMAP_0
  uniform sampler2D m_DiffuseMap_0;
#endif
#ifdef DIFFUSEMAP_1
  uniform sampler2D m_DiffuseMap_1;
#endif
#ifdef DIFFUSEMAP_2
  uniform sampler2D m_DiffuseMap_2;
#endif
#ifdef DIFFUSEMAP_3
  uniform sampler2D m_DiffuseMap_3;
#endif
#ifdef DIFFUSEMAP_4
  uniform sampler2D m_DiffuseMap_4;
#endif
#ifdef DIFFUSEMAP_5
  uniform sampler2D m_DiffuseMap_5;
#endif
#ifdef DIFFUSEMAP_6
  uniform sampler2D m_DiffuseMap_6;
#endif
#ifdef DIFFUSEMAP_7
  uniform sampler2D m_DiffuseMap_7;
#endif
#ifdef DIFFUSEMAP_8
  uniform sampler2D m_DiffuseMap_8;
#endif
#ifdef DIFFUSEMAP_9
  uniform sampler2D m_DiffuseMap_9;
#endif
#ifdef DIFFUSEMAP_10
  uniform sampler2D m_DiffuseMap_10;
#endif
#ifdef DIFFUSEMAP_11
  uniform sampler2D m_DiffuseMap_11;
#endif

#ifdef DIFFUSEMAP_0_SCALE
  uniform float m_DiffuseMap_0_scale;
#endif
#ifdef DIFFUSEMAP_1_SCALE
  uniform float m_DiffuseMap_1_scale;
#endif
#ifdef DIFFUSEMAP_2_SCALE
  uniform float m_DiffuseMap_2_scale;
#endif
#ifdef DIFFUSEMAP_3_SCALE
  uniform float m_DiffuseMap_3_scale;
#endif
#ifdef DIFFUSEMAP_4_SCALE
  uniform float m_DiffuseMap_4_scale;
#endif
#ifdef DIFFUSEMAP_5_SCALE
  uniform float m_DiffuseMap_5_scale;
#endif
#ifdef DIFFUSEMAP_6_SCALE
  uniform float m_DiffuseMap_6_scale;
#endif
#ifdef DIFFUSEMAP_7_SCALE
  uniform float m_DiffuseMap_7_scale;
#endif
#ifdef DIFFUSEMAP_8_SCALE
  uniform float m_DiffuseMap_8_scale;
#endif
#ifdef DIFFUSEMAP_9_SCALE
  uniform float m_DiffuseMap_9_scale;
#endif
#ifdef DIFFUSEMAP_10_SCALE
  uniform float m_DiffuseMap_10_scale;
#endif
#ifdef DIFFUSEMAP_11_SCALE
  uniform float m_DiffuseMap_11_scale;
#endif

#ifdef ALPHAMAP
    uniform sampler2D m_AlphaMap;
#endif
#ifdef ALPHAMAP_1
  uniform sampler2D m_AlphaMap_1;
#endif
#ifdef ALPHAMAP_2
  uniform sampler2D m_AlphaMap_2;
#endif

#ifdef NORMALMAP_0
  #define NORMALMAP
  uniform sampler2D m_NormalMap_0;
#endif
#ifdef NORMALMAP_1
  uniform sampler2D m_NormalMap_1;
#endif
#ifdef NORMALMAP_2
  uniform sampler2D m_NormalMap_2;
#endif
#ifdef NORMALMAP_3
  uniform sampler2D m_NormalMap_3;
#endif
#ifdef NORMALMAP_4
  uniform sampler2D m_NormalMap_4;
#endif
#ifdef NORMALMAP_5
  uniform sampler2D m_NormalMap_5;
#endif
#ifdef NORMALMAP_6
  uniform sampler2D m_NormalMap_6;
#endif
#ifdef NORMALMAP_7
  uniform sampler2D m_NormalMap_7;
#endif


#ifdef PARALLAXMAPPING
    uniform float m_ParallaxHeight;
    vec2 classicOffset;

    void applyParallax(inout vec2 coord, in sampler2D normalMap){
        coord = coord + (texture2D(normalMap,coord).a - 0.6) *  classicOffset;
    }
#else
    void applyParallax(inout vec2 coord, in sampler2D normalMap){}
#endif

#define DEFINE_COORD(index) vec2 coord##index = texCoord * m_DiffuseMap##index##_scale;

#define BLEND(index, ab)\
    DEFINE_COORD(index)\
    diffuseColor.rgb = mix( diffuseColor.rgb,  texture2D(m_DiffuseMap##index, coord##index).rgb ,ab );\
    Metallic = mix(Metallic, m_Metallic##index; ab);\
    Roughness = mix(Roughness, m_Roughness##index, ab);

#define BLEND_NORMAL(index, ab)\
    DEFINE_COORD(index)\
    applyParallax(coord##index, m_NormalMap##index);\
    normal = mix(normal,texture2D(m_NormalMap##index, coord##index).xyz, ab);\
    diffuseColor.rgb = mix( diffuseColor.rgb,  texture2D(m_DiffuseMap##index, coord##index).rgb ,ab );\
    Metallic = mix(Metallic, m_Metallic##index, ab);\
    Roughness = mix(Roughness, m_Roughness##index, ab);

uniform vec3 g_CameraPosition;
void main(){
    vec3 viewDir = normalize(g_CameraPosition - wPosition);
    #if defined(NORMALMAP_0) || defined(NORMALMAP_1) || defined(NORMALMAP_2) || defined(NORMALMAP_3) || defined(NORMALMAP_4) || defined(NORMALMAP_5) || defined(NORMALMAP_6) || defined(NORMALMAP_7)
        mat3 tbnMat = mat3(wTangent.xyz, wTangent.w * cross( (wNormal), (wTangent.xyz)), wNormal.xyz);
    #endif

    #ifdef PARALLAXMAPPING
        vec3 vViewDir =  normalize(viewDir * tbnMat);  
        classicOffset = m_ParallaxHeight * vViewDir.xy * vViewDir.z;
    #endif

    #ifdef ALPHAMAP
        vec4 alphaBlend = texture2D( m_AlphaMap, texCoord);
    #elif defined(DIFFUSEMAP_0) || defined(DIFFUSEMAP_1) || defined(DIFFUSEMAP_2) || defined(DIFFUSEMAP_3) 
        vec4 alphaBlend = vec4(0.5);
    #endif
    #ifdef DIFFUSEMAP_0
        DEFINE_COORD(_0)
        #ifdef NORMALMAP_0       
            applyParallax(coord_0, m_NormalMap_0);
            vec3 normal = texture2D(m_NormalMap_0, coord_0).xyz * alphaBlend.r;
         #else   
            vec3 normal = vec3(0.5,0.5,1);
         #endif  
        vec4 diffuseColor =  vec4(texture2D(m_DiffuseMap_0, coord_0).rgb * alphaBlend.r, 1.0);
        float Metallic =  m_Metallic_0;
        float Roughness =  m_Roughness_0;
    #endif

    #ifdef DIFFUSEMAP_1
        #ifdef NORMALMAP_1
            BLEND_NORMAL(_1, alphaBlend.g)
        #else
            BLEND(_1,  alphaBlend.g)
        #endif
    #endif
    #ifdef DIFFUSEMAP_2
        #ifdef NORMALMAP_2
            BLEND_NORMAL(_2, alphaBlend.b)
        #else
            BLEND(_2,  alphaBlend.b)
        #endif
    #endif
    #ifdef DIFFUSEMAP_3
        #ifdef NORMALMAP_3
            BLEND_NORMAL(_3, alphaBlend.a)
        #else
            BLEND(_3,  alphaBlend.a)
        #endif
    #endif

    #ifdef ALPHAMAP_1
        vec4 alphaBlend1 = texture2D( m_AlphaMap_1, texCoord);  
    #elif defined(DIFFUSEMAP_4) || defined(DIFFUSEMAP_5) || defined(DIFFUSEMAP_6) || defined(DIFFUSEMAP_7) 
        vec4 alphaBlend1 = vec4(0.5);
    #endif
    #ifdef DIFFUSEMAP_4  
        #ifdef NORMALMAP_4
            BLEND_NORMAL(_4, alphaBlend1.r)
        #else
            BLEND(_4, alphaBlend1.r)
        #endif
    #endif
    #ifdef DIFFUSEMAP_5
        #ifdef NORMALMAP_5
            BLEND_NORMAL(_5, alphaBlend1.g)
        #else
            BLEND(_5,  alphaBlend1.g)
        #endif
    #endif  
    #ifdef DIFFUSEMAP_6
        #ifdef NORMALMAP_6
            BLEND_NORMAL(_6, alphaBlend1.b)
        #else
            BLEND(_6,  alphaBlend1.b)
        #endif
    #endif
    #ifdef DIFFUSEMAP_7
        #ifdef NORMALMAP_7
            BLEND_NORMAL(_7, alphaBlend1.a)
        #else
            BLEND(_7,  alphaBlend1.a)
        #endif
    #endif
    #ifdef ALPHAMAP_2
        vec4 alphaBlend2 = texture2D( m_AlphaMap_2, texCoord);  
    #elif defined(DIFFUSEMAP_8) || defined(DIFFUSEMAP_9) || defined(DIFFUSEMAP_10) || defined(DIFFUSEMAP_11) 
        vec4 alphaBlend2 = vec4(0.5);
    #endif
    #ifdef DIFFUSEMAP_8
        BLEND(_8,  alphaBlend2.r)
    #endif                   
    #ifdef DIFFUSEMAP_9
        BLEND(_9,  alphaBlend2.g)
    #endif
    #ifdef DIFFUSEMAP_10
        BLEND(_10,  alphaBlend2.b)
    #endif                   
    #ifdef DIFFUSEMAP_11
        BLEND(_11,  alphaBlend2.a)
    #endif          

    float specular = 0.5;
    Roughness =  max(Roughness, 1e-8);
    #ifdef ROUGHNESSMAP
        Roughness = texture2D(m_RoughnessMap, texCoord).r * Roughness;
    #endif
    #ifdef METALLICMAP   
        Metallic = texture2D(m_MetallicMap, texCoord).r;
    #endif
 
    #if defined(NORMALMAP_0) || defined(NORMALMAP_1) || defined(NORMALMAP_2) || defined(NORMALMAP_3) || defined(NORMALMAP_4) || defined(NORMALMAP_5) || defined(NORMALMAP_6) || defined(NORMALMAP_7)
      normal = normalize(tbnMat * normalize(normal * vec3(2.0) - vec3(1.0)));
    #else
      normal = normalize(wNormal);            
    #endif

    #ifdef SPECGLOSSPIPELINE
          vec4 specularColor = texture2D(m_SpecularMap, texCoord);
          Roughness = 1.0 - texture2D(m_GlossMap, texCoord).r;          
    #else      
        float nonMetalSpec = 0.08 * specular;
        vec4 specularColor = (nonMetalSpec - nonMetalSpec * Metallic) + diffuseColor * Metallic;
        diffuseColor = diffuseColor - diffuseColor * Metallic;
    #endif

    #ifdef LIGHTMAP
       vec3 lightMapColor;
       #ifdef SEPARATE_TEXCOORD
          lightMapColor = texture2D(m_LightMap, texCoord2).rgb;
       #else
          lightMapColor = texture2D(m_LightMap, texCoord).rgb;
       #endif
       specularColor.rgb *= lightMapColor;
       diffuseColor.rgb  *= lightMapColor;
    #endif


    gl_FragColor.rgb = vec3(0.0);
    float ndotv = max( dot( normal, viewDir ),0.0);
    for( int i = 0;i < NB_LIGHTS; i+=3){
        vec4 lightColor = g_LightData[i];
        vec4 lightDir;
        vec3 lightVec;            
        lightComputeDir(wPosition, lightColor.w, g_LightData[i+1], lightDir, lightVec);

        float spotFallOff = 1.0;
        if(lightColor.w > 1.0){
            spotFallOff = computeSpotFalloff(g_LightData[i+2], lightVec);
        }
        //point light attenuation
        spotFallOff *= lightDir.w;
        lightDir.xyz = normalize(lightDir.xyz);
        vec3 directDiffuse;
        vec3 directSpecular;
        
        PBR_ComputeDirectLight(normal, lightDir.xyz, viewDir,
                            lightColor.rgb,specular, Roughness, ndotv,
                            directDiffuse,  directSpecular);
        vec3 directLighting = diffuseColor.rgb *directDiffuse + directSpecular * specularColor.rgb;
        
        gl_FragColor.rgb += directLighting * spotFallOff;

    }

    #ifdef INDIRECT_LIGHTING
        vec3 rv = reflect(-viewDir.xyz, normal.xyz);
        //prallax fix for spherical bounds from https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
        // g_LightProbeData.w is 1/probe radius, g_LightProbeData.xyz is the position of the lightProbe.
        rv = g_LightProbeData.w * (wPosition - g_LightProbeData.xyz) +rv;

         //horizon fade from http://marmosetco.tumblr.com/post/81245981087
        float horiz = dot(rv, wNormal.xyz);
        float horizFadePower= 1.0 - Roughness;
        horiz = clamp( 1.0 + horizFadePower * horiz, 0.0, 1.0 );
        horiz *= horiz;

        vec3 indirectDiffuse = vec3(0.0);
        vec3 indirectSpecular = vec3(0.0);
        indirectDiffuse = textureCube(g_IrradianceMap, normal.xyz).rgb * diffuseColor.rgb;

        indirectSpecular = ApproximateSpecularIBLPolynomial(g_PrefEnvMap, specularColor.rgb, Roughness, ndotv, rv.xyz);
        indirectSpecular *= vec3(horiz);

        vec3 indirectLighting =  indirectDiffuse + indirectSpecular;

        gl_FragColor.rgb = gl_FragColor.rgb + indirectLighting * step( 0.0, g_LightProbeData.w);
    #endif

    #if defined(EMISSIVE) || defined (EMISSIVEMAP)
        #ifdef EMISSIVEMAP
            vec4 emissive = texture2D(m_EmissiveMap, texCoord);
        #else
            vec4 emissive = m_Emissive;
        #endif
        gl_FragColor += emissive * pow(emissive.a, m_EmissivePower) * m_EmissiveIntensity;
    #endif

    gl_FragColor.a = 1.0;
}

MaterialDefinition:

MaterialDef Terrain Lighting {

    MaterialParameters {
        // Use alpha channel of normal texture for parallax mapping;
        Boolean parallaxMapping

        Float ParallaxHeight : 0.005

        // The emissive color of the object
        Color Emissive        
        // the emissive power
        Float EmissivePower : 3.0        
        // the emissive intensity
        Float EmissiveIntensity : 1.0

        // Specular/gloss map
        Texture2D MetallicMap -LINEAR
        
        // For Spec gloss pipeline
        Texture2D SpecularMap
        Texture2D GlossMap

        // Roughness Map
        Texture2D RoughnessMap -LINEAR
        
        // Texture of the emissive parts of the material
        Texture2D EmissiveMap

        Vector4 ProbeData

        // Prefiltered Env Map for indirect specular lighting
        TextureCubeMap PrefEnvMap -LINEAR
        
        // Irradiance map for indirect diffuse lighting
        TextureCubeMap IrradianceMap -LINEAR

        //integrate BRDF map for indirect Lighting
        Texture2D IntegrateBRDF -LINEAR


        // Set to Use Lightmap
        Texture2D LightMap


        // Texture map #0
        Texture2D DiffuseMap_0
        Float DiffuseMap_0_scale
        Texture2D NormalMap_0 -LINEAR       
        //metalness of the material
        Float Metallic_0 : 0.0
        //Roughness of the material
        Float Roughness_0 : 1.0        

        // Texture map #1
        Texture2D DiffuseMap_1
        Float DiffuseMap_1_scale
        Texture2D NormalMap_1 -LINEAR   
        //metalness of the material
        Float Metallic_1 : 0.0
        //Roughness of the material
        Float Roughness_1 : 1.0        

        // Texture map #2
        Texture2D DiffuseMap_2
        Float DiffuseMap_2_scale
        Texture2D NormalMap_2 -LINEAR
        //metalness of the material
        Float Metallic_2 : 0.0
        //Roughness of the material
        Float Roughness_2 : 1.0        

        // Texture map #3
        Texture2D DiffuseMap_3
        Float DiffuseMap_3_scale
        Texture2D NormalMap_3 -LINEAR   
        //metalness of the material
        Float Metallic_3 : 0.0
        //Roughness of the material
        Float Roughness_3 : 1.0        

        // Texture map #4
        Texture2D DiffuseMap_4
        Float DiffuseMap_4_scale
        Texture2D NormalMap_4 -LINEAR   
        //metalness of the material
        Float Metallic_4 : 0.0
        //Roughness of the material
        Float Roughness_4 : 1.0        

        // Texture map #5
        Texture2D DiffuseMap_5
        Float DiffuseMap_5_scale
        Texture2D NormalMap_5 -LINEAR   
        //metalness of the material
        Float Metallic_5 : 0.0
        //Roughness of the material
        Float Roughness_5 : 1.0        

        // Texture map #6
        Texture2D DiffuseMap_6
        Float DiffuseMap_6_scale
        Texture2D NormalMap_6 -LINEAR   
        //metalness of the material
        Float Metallic_6 : 0.0
        //Roughness of the material
        Float Roughness_6 : 1.0        

        // Texture map #7
        Texture2D DiffuseMap_7
        Float DiffuseMap_7_scale
        Texture2D NormalMap_7 -LINEAR   
        //metalness of the material
        Float Metallic_7 : 0.0
        //Roughness of the material
        Float Roughness_8 : 1.0        

        // Texture map #8
        Texture2D DiffuseMap_8
        Float DiffuseMap_8_scale   
        //metalness of the material
        Float Metallic_8 : 0.0
        //Roughness of the material
        Float Roughness_8 : 1.0        

        // Texture map #9
        Texture2D DiffuseMap_9
        Float DiffuseMap_9_scale
          //metalness of the material
        Float Metallic_9 : 0.0
        //Roughness of the material
        Float Roughness_9 : 1.0        

        // Texture map #10
        Texture2D DiffuseMap_10
        Float DiffuseMap_10_scale   
        //metalness of the material
        Float Metallic_10 : 0.0
        //Roughness of the material
        Float Roughness_10 : 1.0        

        // Texture map #11
        Texture2D DiffuseMap_11
        Float DiffuseMap_11_scale   
        //metalness of the material
        Float Metallic_11 : 0.0
        //Roughness of the material
        Float Roughness_11 : 1.0        

        // Texture that specifies alpha values
        Texture2D AlphaMap -LINEAR
        Texture2D AlphaMap_1 -LINEAR
        Texture2D AlphaMap_2 -LINEAR

        //shadows
        Int FilterMode
        Boolean HardwareShadows

        Texture2D ShadowMap0
        Texture2D ShadowMap1
        Texture2D ShadowMap2
        Texture2D ShadowMap3
        //pointLights
        Texture2D ShadowMap4
        Texture2D ShadowMap5

        Float ShadowIntensity
        Vector4 Splits
        Vector2 FadeInfo

        Matrix4 LightViewProjectionMatrix0
        Matrix4 LightViewProjectionMatrix1
        Matrix4 LightViewProjectionMatrix2
        Matrix4 LightViewProjectionMatrix3
        //pointLight
        Matrix4 LightViewProjectionMatrix4
        Matrix4 LightViewProjectionMatrix5   
        Vector3 LightPos
        Vector3 LightDir

        Float PCFEdge
        Float ShadowMapSize

        // Texture of the glowing parts of the material
        Texture2D GlowMap

        // The glow color of the object
        Color GlowColor

        Boolean BackfaceShadows : false
    }

   
Technique {

        LightMode SinglePassAndImageBased

        VertexShader GLSL150:   MatDefs/Terrain/SinglePassImageBased/TerrainLighting.vert
        FragmentShader GLSL150: MatDefs/Terrain/SinglePassImageBased/TerrainLighting.frag

        WorldParameters {
            WorldViewProjectionMatrix
            CameraPosition
            WorldMatrix
        }

        Defines {
            PARALLAXMAPPING : parallaxMapping
            PARALLAX_HEIGHT : ParallaxHeight 
            METALLICMAP : MetallicMap
            ROUGHNESSMAP : RoughnessMap
            EMISSIVEMAP : EmissiveMap
            EMISSIVE : Emissive
            SPECGLOSSPIPELINE : SpecularMap
            LIGHTMAP : LightMap

            DIFFUSEMAP_0 : DiffuseMap_0
            DIFFUSEMAP_1 : DiffuseMap_1
            DIFFUSEMAP_2 : DiffuseMap_2
            DIFFUSEMAP_3 : DiffuseMap_3
            DIFFUSEMAP_4 : DiffuseMap_4
            DIFFUSEMAP_5 : DiffuseMap_5
            DIFFUSEMAP_6 : DiffuseMap_6
            DIFFUSEMAP_7 : DiffuseMap_7
            DIFFUSEMAP_8 : DiffuseMap_8
            DIFFUSEMAP_9 : DiffuseMap_9
            DIFFUSEMAP_10 : DiffuseMap_10
            DIFFUSEMAP_11 : DiffuseMap_11
            NORMALMAP_0 : NormalMap_0
            NORMALMAP_1 : NormalMap_1
            NORMALMAP_2 : NormalMap_2
            NORMALMAP_3 : NormalMap_3
            NORMALMAP_4 : NormalMap_4
            NORMALMAP_5 : NormalMap_5
            NORMALMAP_6 : NormalMap_6
            NORMALMAP_7 : NormalMap_7
            ALPHAMAP : AlphaMap
            ALPHAMAP_1 : AlphaMap_1
            ALPHAMAP_2 : AlphaMap_2
            DIFFUSEMAP_0_SCALE : DiffuseMap_0_scale
            DIFFUSEMAP_1_SCALE : DiffuseMap_1_scale
            DIFFUSEMAP_2_SCALE : DiffuseMap_2_scale
            DIFFUSEMAP_3_SCALE : DiffuseMap_3_scale
            DIFFUSEMAP_4_SCALE : DiffuseMap_4_scale
            DIFFUSEMAP_5_SCALE : DiffuseMap_5_scale
            DIFFUSEMAP_6_SCALE : DiffuseMap_6_scale
            DIFFUSEMAP_7_SCALE : DiffuseMap_7_scale
            DIFFUSEMAP_8_SCALE : DiffuseMap_8_scale
            DIFFUSEMAP_9_SCALE : DiffuseMap_9_scale
            DIFFUSEMAP_10_SCALE : DiffuseMap_10_scale
            DIFFUSEMAP_11_SCALE : DiffuseMap_11_scale
        }
    }
}

Edit:
A screenshot :).

And one concrete splatted:

edit: removed -linear on diffuse samplers

15 Likes

Can we have any demo screenshots? :stuck_out_tongue:

1 Like

sure ;). I will attach it.

1 Like

Thank you for the contribution :wink:

Hi @b00n

It seems your matdef does not support tri-planar mapping which was in TerrainLighting material

Any reason why you not included it ?
I am a shader noob! Curious if it will work fine if I add it from TerrainLighting material to this one ?

Regards

Seems your shader is not compatible with current master branch ?

I also tried with a modified version shared by @tsr

The model is rendered in black. I already added a light probe to scene and my other model which is using PBRLighting material renders just fine.

Anybody has a modified version which works fine with jme current master branch ?

i had a lot of issues when i tried to port it, so i decided to skip it.

oh that is bad… actually i’m currently only using a version with textur arrays. Ah i know the problem it has to do with the shader change from nehon… At the moment i cannot effort much time for this, but if you diff the pbrlighting shader in the master branch you should see the changes nehon made and you can do the same change to this contribution.

Updated it to work with current master branch

#import "Common/ShaderLib/GLSLCompat.glsllib"
#import "Common/ShaderLib/PBR.glsllib"
#import "Common/ShaderLib/Parallax.glsllib"
#import "Common/ShaderLib/Lighting.glsllib"

uniform vec4 g_LightData[NB_LIGHTS];

varying vec3 wPosition;

#if NB_PROBES >= 1
  uniform samplerCube g_PrefEnvMap;
  uniform vec3 g_ShCoeffs[9];
  uniform mat4 g_LightProbeData;
#endif
#if NB_PROBES >= 2
  uniform samplerCube g_PrefEnvMap2;
  uniform vec3 g_ShCoeffs2[9];
  uniform mat4 g_LightProbeData2;
#endif
#if NB_PROBES == 3
  uniform samplerCube g_PrefEnvMap3;
  uniform vec3 g_ShCoeffs3[9];
  uniform mat4 g_LightProbeData3;
#endif

#ifdef INDIRECT_LIGHTING
//  uniform sampler2D m_IntegrateBRDF;
  uniform samplerCube g_PrefEnvMap;
  uniform vec3 g_ShCoeffs[9];
  uniform vec4 g_LightProbeData;
#endif

#ifdef METALLICMAP
    uniform sampler2D m_MetallicMap;
#else
    uniform float m_Metallic_0;
    uniform float m_Metallic_1;
    uniform float m_Metallic_2;
    uniform float m_Metallic_3;
    uniform float m_Metallic_4;
    uniform float m_Metallic_5;
    uniform float m_Metallic_6;
    uniform float m_Metallic_7;
    uniform float m_Metallic_8;
    uniform float m_Metallic_9;
    uniform float m_Metallic_10;
    uniform float m_Metallic_11;
#endif
#ifdef ROUGHNESSMAP
    uniform sampler2D m_RoughnessMap;
#endif
uniform float m_Roughness_0;
uniform float m_Roughness_1;
uniform float m_Roughness_2;
uniform float m_Roughness_3;
uniform float m_Roughness_4;
uniform float m_Roughness_5;
uniform float m_Roughness_6;
uniform float m_Roughness_7;
uniform float m_Roughness_8;
uniform float m_Roughness_9;
uniform float m_Roughness_10;
uniform float m_Roughness_11;

#ifdef EMISSIVE
    uniform vec4 m_Emissive;
#endif
#ifdef EMISSIVEMAP
    uniform sampler2D m_EmissiveMap;
#endif
#if defined(EMISSIVE) || defined(EMISSIVEMAP)
    uniform float m_EmissivePower;
    uniform float m_EmissiveIntensity;
#endif 

#ifdef SPECGLOSSPIPELINE
  uniform sampler2D m_SpecularMap;
  uniform sampler2D m_GlossMap;
#endif

#ifdef LIGHTMAP
  uniform sampler2D m_LightMap;
#endif

varying vec3 wNormal;
#if defined(NORMALMAP_0) || defined(NORMALMAP_1) || defined(NORMALMAP_2) || defined(NORMALMAP_3) || defined(NORMALMAP_4) || defined(NORMALMAP_5) || defined(NORMALMAP_6) || defined(NORMALMAP_7)
    varying vec4 wTangent;
#endif

varying vec2 texCoord;
#ifdef DIFFUSEMAP_0
  uniform sampler2D m_DiffuseMap_0;
#endif
#ifdef DIFFUSEMAP_1
  uniform sampler2D m_DiffuseMap_1;
#endif
#ifdef DIFFUSEMAP_2
  uniform sampler2D m_DiffuseMap_2;
#endif
#ifdef DIFFUSEMAP_3
  uniform sampler2D m_DiffuseMap_3;
#endif
#ifdef DIFFUSEMAP_4
  uniform sampler2D m_DiffuseMap_4;
#endif
#ifdef DIFFUSEMAP_5
  uniform sampler2D m_DiffuseMap_5;
#endif
#ifdef DIFFUSEMAP_6
  uniform sampler2D m_DiffuseMap_6;
#endif
#ifdef DIFFUSEMAP_7
  uniform sampler2D m_DiffuseMap_7;
#endif
#ifdef DIFFUSEMAP_8
  uniform sampler2D m_DiffuseMap_8;
#endif
#ifdef DIFFUSEMAP_9
  uniform sampler2D m_DiffuseMap_9;
#endif
#ifdef DIFFUSEMAP_10
  uniform sampler2D m_DiffuseMap_10;
#endif
#ifdef DIFFUSEMAP_11
  uniform sampler2D m_DiffuseMap_11;
#endif

#ifdef DIFFUSEMAP_0_SCALE
  uniform float m_DiffuseMap_0_scale;
#endif
#ifdef DIFFUSEMAP_1_SCALE
  uniform float m_DiffuseMap_1_scale;
#endif
#ifdef DIFFUSEMAP_2_SCALE
  uniform float m_DiffuseMap_2_scale;
#endif
#ifdef DIFFUSEMAP_3_SCALE
  uniform float m_DiffuseMap_3_scale;
#endif
#ifdef DIFFUSEMAP_4_SCALE
  uniform float m_DiffuseMap_4_scale;
#endif
#ifdef DIFFUSEMAP_5_SCALE
  uniform float m_DiffuseMap_5_scale;
#endif
#ifdef DIFFUSEMAP_6_SCALE
  uniform float m_DiffuseMap_6_scale;
#endif
#ifdef DIFFUSEMAP_7_SCALE
  uniform float m_DiffuseMap_7_scale;
#endif
#ifdef DIFFUSEMAP_8_SCALE
  uniform float m_DiffuseMap_8_scale;
#endif
#ifdef DIFFUSEMAP_9_SCALE
  uniform float m_DiffuseMap_9_scale;
#endif
#ifdef DIFFUSEMAP_10_SCALE
  uniform float m_DiffuseMap_10_scale;
#endif
#ifdef DIFFUSEMAP_11_SCALE
  uniform float m_DiffuseMap_11_scale;
#endif

#ifdef ALPHAMAP
    uniform sampler2D m_AlphaMap;
#endif
#ifdef ALPHAMAP_1
  uniform sampler2D m_AlphaMap_1;
#endif
#ifdef ALPHAMAP_2
  uniform sampler2D m_AlphaMap_2;
#endif

#ifdef NORMALMAP_0
  #define NORMALMAP
  uniform sampler2D m_NormalMap_0;
#endif
#ifdef NORMALMAP_1
  uniform sampler2D m_NormalMap_1;
#endif
#ifdef NORMALMAP_2
  uniform sampler2D m_NormalMap_2;
#endif
#ifdef NORMALMAP_3
  uniform sampler2D m_NormalMap_3;
#endif
#ifdef NORMALMAP_4
  uniform sampler2D m_NormalMap_4;
#endif
#ifdef NORMALMAP_5
  uniform sampler2D m_NormalMap_5;
#endif
#ifdef NORMALMAP_6
  uniform sampler2D m_NormalMap_6;
#endif
#ifdef NORMALMAP_7
  uniform sampler2D m_NormalMap_7;
#endif


#ifdef PARALLAXMAPPING
    uniform float m_ParallaxHeight;
    vec2 classicOffset;

    void applyParallax(inout vec2 coord, in sampler2D normalMap){
        coord = coord + (texture2D(normalMap,coord).a - 0.6) *  classicOffset;
    }
#else
    void applyParallax(inout vec2 coord, in sampler2D normalMap){}
#endif

#define DEFINE_COORD(index) vec2 coord##index = texCoord * m_DiffuseMap##index##_scale;

#define BLEND(index, ab)\
    DEFINE_COORD(index)\
    diffuseColor.rgb = mix( diffuseColor.rgb,  texture2D(m_DiffuseMap##index, coord##index).rgb ,ab );\
    Metallic = mix(Metallic, m_Metallic##index; ab);\
    Roughness = mix(Roughness, m_Roughness##index, ab);

#define BLEND_NORMAL(index, ab)\
    DEFINE_COORD(index)\
    applyParallax(coord##index, m_NormalMap##index);\
    normal = mix(normal,texture2D(m_NormalMap##index, coord##index).xyz, ab);\
    diffuseColor.rgb = mix( diffuseColor.rgb,  texture2D(m_DiffuseMap##index, coord##index).rgb ,ab );\
    Metallic = mix(Metallic, m_Metallic##index, ab);\
    Roughness = mix(Roughness, m_Roughness##index, ab);

uniform vec3 g_CameraPosition;
void main(){
    vec3 viewDir = normalize(g_CameraPosition - wPosition);
    vec3 norm = normalize(wNormal);

    #if defined(NORMALMAP_0) || defined(NORMALMAP_1) || defined(NORMALMAP_2) || defined(NORMALMAP_3) || defined(NORMALMAP_4) || defined(NORMALMAP_5) || defined(NORMALMAP_6) || defined(NORMALMAP_7)
        mat3 tbnMat = mat3(wTangent.xyz, wTangent.w * cross( (wNormal), (wTangent.xyz)), wNormal.xyz);
    #endif

    #ifdef PARALLAXMAPPING
        vec3 vViewDir =  normalize(viewDir * tbnMat);  
        classicOffset = m_ParallaxHeight * vViewDir.xy * vViewDir.z;
    #endif

    #ifdef ALPHAMAP
        vec4 alphaBlend = texture2D( m_AlphaMap, texCoord);
    #elif defined(DIFFUSEMAP_0) || defined(DIFFUSEMAP_1) || defined(DIFFUSEMAP_2) || defined(DIFFUSEMAP_3) 
        vec4 alphaBlend = vec4(0.5);
    #endif
    #ifdef DIFFUSEMAP_0
        DEFINE_COORD(_0)
        #ifdef NORMALMAP_0       
            applyParallax(coord_0, m_NormalMap_0);
            vec3 normal = texture2D(m_NormalMap_0, coord_0).xyz * alphaBlend.r;
         #else   
            vec3 normal = vec3(0.5,0.5,1);
         #endif  
        vec4 diffuseColor =  vec4(texture2D(m_DiffuseMap_0, coord_0).rgb * alphaBlend.r, 1.0);
        float Metallic =  m_Metallic_0;
        float Roughness =  m_Roughness_0;
    #endif

    #ifdef DIFFUSEMAP_1
        #ifdef NORMALMAP_1
            BLEND_NORMAL(_1, alphaBlend.g)
        #else
            BLEND(_1,  alphaBlend.g)
        #endif
    #endif
    #ifdef DIFFUSEMAP_2
        #ifdef NORMALMAP_2
            BLEND_NORMAL(_2, alphaBlend.b)
        #else
            BLEND(_2,  alphaBlend.b)
        #endif
    #endif
    #ifdef DIFFUSEMAP_3
        #ifdef NORMALMAP_3
            BLEND_NORMAL(_3, alphaBlend.a)
        #else
            BLEND(_3,  alphaBlend.a)
        #endif
    #endif

    #ifdef ALPHAMAP_1
        vec4 alphaBlend1 = texture2D( m_AlphaMap_1, texCoord);  
    #elif defined(DIFFUSEMAP_4) || defined(DIFFUSEMAP_5) || defined(DIFFUSEMAP_6) || defined(DIFFUSEMAP_7) 
        vec4 alphaBlend1 = vec4(0.5);
    #endif
    #ifdef DIFFUSEMAP_4  
        #ifdef NORMALMAP_4
            BLEND_NORMAL(_4, alphaBlend1.r)
        #else
            BLEND(_4, alphaBlend1.r)
        #endif
    #endif
    #ifdef DIFFUSEMAP_5
        #ifdef NORMALMAP_5
            BLEND_NORMAL(_5, alphaBlend1.g)
        #else
            BLEND(_5,  alphaBlend1.g)
        #endif
    #endif  
    #ifdef DIFFUSEMAP_6
        #ifdef NORMALMAP_6
            BLEND_NORMAL(_6, alphaBlend1.b)
        #else
            BLEND(_6,  alphaBlend1.b)
        #endif
    #endif
    #ifdef DIFFUSEMAP_7
        #ifdef NORMALMAP_7
            BLEND_NORMAL(_7, alphaBlend1.a)
        #else
            BLEND(_7,  alphaBlend1.a)
        #endif
    #endif
    #ifdef ALPHAMAP_2
        vec4 alphaBlend2 = texture2D( m_AlphaMap_2, texCoord);  
    #elif defined(DIFFUSEMAP_8) || defined(DIFFUSEMAP_9) || defined(DIFFUSEMAP_10) || defined(DIFFUSEMAP_11) 
        vec4 alphaBlend2 = vec4(0.5);
    #endif
    #ifdef DIFFUSEMAP_8
        BLEND(_8,  alphaBlend2.r)
    #endif                   
    #ifdef DIFFUSEMAP_9
        BLEND(_9,  alphaBlend2.g)
    #endif
    #ifdef DIFFUSEMAP_10
        BLEND(_10,  alphaBlend2.b)
    #endif                   
    #ifdef DIFFUSEMAP_11
        BLEND(_11,  alphaBlend2.a)
    #endif          

    float specular = 0.5;
    Roughness =  max(Roughness, 1e-8);
    #ifdef ROUGHNESSMAP
        Roughness = texture2D(m_RoughnessMap, texCoord).r * Roughness;
    #endif
    #ifdef METALLICMAP   
        Metallic = texture2D(m_MetallicMap, texCoord).r;
    #endif
 
    #if defined(NORMALMAP_0) || defined(NORMALMAP_1) || defined(NORMALMAP_2) || defined(NORMALMAP_3) || defined(NORMALMAP_4) || defined(NORMALMAP_5) || defined(NORMALMAP_6) || defined(NORMALMAP_7)
      normal = normalize(tbnMat * normalize(normal * vec3(2.0) - vec3(1.0)));
    #else
      normal = normalize(wNormal);            
    #endif

    #ifdef SPECGLOSSPIPELINE
          vec4 specularColor = texture2D(m_SpecularMap, texCoord);
          Roughness = 1.0 - texture2D(m_GlossMap, texCoord).r;          
          vec3 fZero = specularColor.xyz;
    #else      
        float nonMetalSpec = 0.08 * specular;
        vec4 specularColor = (nonMetalSpec - nonMetalSpec * Metallic) + diffuseColor * Metallic;
        diffuseColor = diffuseColor - diffuseColor * Metallic;
        vec3 fZero = vec3(specular);
    #endif

    #ifdef LIGHTMAP
       vec3 lightMapColor;
       #ifdef SEPARATE_TEXCOORD
          lightMapColor = texture2D(m_LightMap, texCoord2).rgb;
       #else
          lightMapColor = texture2D(m_LightMap, texCoord).rgb;
       #endif
       specularColor.rgb *= lightMapColor;
       diffuseColor.rgb  *= lightMapColor;
    #endif


    gl_FragColor.rgb = vec3(0.0); 
    vec3 ao = vec3(1.0);
    float ndotv = max( dot( normal, viewDir ),0.0);
    for( int i = 0;i < NB_LIGHTS; i+=3){
        vec4 lightColor = g_LightData[i];
        vec4 lightData1 = g_LightData[i+1];                
        vec4 lightDir;
        vec3 lightVec;            
        lightComputeDir(wPosition, lightColor.w, lightData1, lightDir, lightVec);

        float fallOff = 1.0;
        #if __VERSION__ >= 110
            // allow use of control flow
        if(lightColor.w > 1.0){
        #endif
            fallOff =  computeSpotFalloff(g_LightData[i+2], lightVec);
        #if __VERSION__ >= 110
        }
        #endif
        //point light attenuation
        fallOff *= lightDir.w;

        lightDir.xyz = normalize(lightDir.xyz);            
        vec3 directDiffuse;
        vec3 directSpecular;
        
        float hdotv = PBR_ComputeDirectLight(normal, lightDir.xyz, viewDir,
                            lightColor.rgb, fZero, Roughness, ndotv,
                            directDiffuse,  directSpecular);

        vec3 directLighting = diffuseColor.rgb *directDiffuse + directSpecular;
        
        gl_FragColor.rgb += directLighting * fallOff;        
    }

    
    #if NB_PROBES >= 1
        vec3 color1 = vec3(0.0);
        vec3 color2 = vec3(0.0);
        vec3 color3 = vec3(0.0);
        float weight1 = 1.0;
        float weight2 = 0.0;
        float weight3 = 0.0;

        float ndf = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData, g_ShCoeffs, g_PrefEnvMap, color1);
        #if NB_PROBES >= 2
            float ndf2 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData2, g_ShCoeffs2, g_PrefEnvMap2, color2);
        #endif
        #if NB_PROBES == 3
            float ndf3 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData3, g_ShCoeffs3, g_PrefEnvMap3, color3);
        #endif

         #if NB_PROBES >= 2
            float invNdf =  max(1.0 - ndf,0.0);
            float invNdf2 =  max(1.0 - ndf2,0.0);
            float sumNdf = ndf + ndf2;
            float sumInvNdf = invNdf + invNdf2;
            #if NB_PROBES == 3
                float invNdf3 = max(1.0 - ndf3,0.0);
                sumNdf += ndf3;
                sumInvNdf += invNdf3;
                weight3 =  ((1.0 - (ndf3 / sumNdf)) / (NB_PROBES - 1)) *  (invNdf3 / sumInvNdf);
            #endif

            weight1 = ((1.0 - (ndf / sumNdf)) / (NB_PROBES - 1)) *  (invNdf / sumInvNdf);
            weight2 = ((1.0 - (ndf2 / sumNdf)) / (NB_PROBES - 1)) *  (invNdf2 / sumInvNdf);

            float weightSum = weight1 + weight2 + weight3;

            weight1 /= weightSum;
            weight2 /= weightSum;
            weight3 /= weightSum;
        #endif
        gl_FragColor.rgb += color1 * clamp(weight1,0.0,1.0) + color2 * clamp(weight2,0.0,1.0) + color3 * clamp(weight3,0.0,1.0);

    #endif

    #ifdef INDIRECT_LIGHTING
        vec3 rv = reflect(-viewDir.xyz, normal.xyz);
        //prallax fix for spherical bounds from https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
        // g_LightProbeData.w is 1/probe radius + nbMipMaps, g_LightProbeData.xyz is the position of the lightProbe.
        float invRadius = fract( g_LightProbeData.w);
        float nbMipMaps = g_LightProbeData.w - invRadius;
        rv = invRadius * (wPosition - g_LightProbeData.xyz) +rv;

         //horizon fade from http://marmosetco.tumblr.com/post/81245981087
        float horiz = dot(rv, norm);
        float horizFadePower = 1.0 - Roughness;
        horiz = clamp( 1.0 + horizFadePower * horiz, 0.0, 1.0 );
        horiz *= horiz;

        vec3 indirectDiffuse = vec3(0.0);
        vec3 indirectSpecular = vec3(0.0);
        indirectDiffuse = sphericalHarmonics(normal.xyz, g_ShCoeffs) * diffuseColor.rgb;
        vec3 dominantR = getSpecularDominantDir( normal, rv.xyz, Roughness*Roughness );
        indirectSpecular = ApproximateSpecularIBLPolynomial(g_PrefEnvMap, specularColor.rgb, Roughness, ndotv, dominantR, nbMipMaps);
        indirectSpecular *= vec3(horiz);

        vec3 indirectLighting = indirectDiffuse + indirectSpecular;

        gl_FragColor.rgb = gl_FragColor.rgb + indirectLighting * step( 0.0, g_LightProbeData.w);
    #endif

    #if defined(EMISSIVE) || defined (EMISSIVEMAP)
        #ifdef EMISSIVEMAP
            vec4 emissive = texture2D(m_EmissiveMap, texCoord);
        #else
            vec4 emissive = m_Emissive;
        #endif
        gl_FragColor += emissive * pow(emissive.a, m_EmissivePower) * m_EmissiveIntensity;
    #endif

    gl_FragColor.a = 1.0;
}

Will give it a try soon, in case I was successful, going to share it here.

i use almost same shader, but i think there is some issue in blending normalMaps.

see image and videos:

video show no normals or broken normals between textures - on blend areas.

here is color between green and red:

image:

hope someone will help solve this.

will try solve this somehow. if i will success, i will post fix.

Also @Ali_RS ambientLight code

    #if USE_AMBIENT_LIGHT
        color1.rgb *= g_AmbientLightColor.rgb;
        color2.rgb *= g_AmbientLightColor.rgb;
        color3.rgb *= g_AmbientLightColor.rgb;
    #endif

should be added

You may try the one updated by @yaRnMcDonuts

this one also supports TRIPLANAR mapping.
there is also a test included
https://github.com/yaRnMcDonuts/AfflictedPbrTerrainConverter/blob/master/PBRTerrain/TestPBRTerrain.java

Edit:
@yaRnMcDonuts it seems you forgot to upload the light probe to the repo

I yet have them in my google drive in case:

1 Like

I also just updated the 3.3 compatible version of the PBR Terrain shader to support @Ali_RS’s most recent PR for that supports AmbientLight

Also, @oxplay2 I remember you tried to use my PBR shader in the past, before I cleaned it up and had @Ali_RS help me test a 3.3 compatible version - when you tried it last there were actually lots of errors, as it was my first time putting libraries on github to share, but it should be working now - if you try it out again and have any trouble, let me know

2 Likes

yes, thanks for that time, now i just copied PBR again and i had some of this errors, but only in IDE, where i had different version. once i just copy all ShaderLibs i had no errors even in IDE.

Probably some simple issues created crazy shader errors i did not understand before.

Anyway i copied all PBR and started replacing things, and now i test normals and something is wrong there.

I also already have @Ali_RS AmbientLight change, since i copied Master PBR Lighting shader.

Generally my shader is very similar to this one in this topic, everything works fine, but in texture blend areas, the normalmap is blending somehow not fully correctly.

noticed some issue i created myself by NormalIntensity, but anyway blending work ugly.

also noticed a very nice page where are several blend options and i try them all.

https://blog.selfshadow.com/publications/blending-in-detail/

Also now i look again at your converter.

Have you tried looking at normalmap between textures? i mean in blend area.

you use

newNormal = texture2D(m_NormalMap##index, coord##index).xyz;\
normal = mix(normal, newNormal, ab);

that is kind of the same as this topic one:

normal = mix(normal,texture2D(m_NormalMap##index, coord##index).xyz, ab);\

just in TRI and basic blend i see something odd.

normal.rgb = mix(normal.xyz, wNormal.xyz, ab);\

but try yours BLEND_NORMAL, i think it might have issues too, because its same as here.