Force No Reflections On PBRMaterial

Yo @sebavan or @Deltakosh

How can force no specular reflections on a material in a scene that has scene.environmentTexture.
I was under the impression if you set the material.reflectionTexture = null it would fallback and use the scene.environmentTexture instead.

I need it to not use ANY reflectionTexture and I cannot just set material.environmentIntensity = 0.

I need the diffuse ibl, but I need to disable the specular reflections ?

Maybe something like that will work for you? Just use NodeMaterial and combine PBR outputs to fragment in a way you want to. Upload some IBL to see results

https://playground.babylonjs.com/#50477C

Not quite what i was looking for… I way so that NEITHER material.reflectionTexture or scene.environmentTexture contribute specular reflections.. for a BABYLON.PBRMaterial

There’s no switch to disable the reflection texture in PBR materials.

What you can do:

  • override _getReflectionTexture():
pbrMaterial._getReflectionTexture = () => null;
  • set MaterialFlags.ReflectionTextureEnabled = false. This one will also disable the reflection texture for standard materials, though.

I am actually trying to do the SPLIT IBL trick @sebavan talks about… except i am doing in in a shader plugin:

    public getCustomCode(shaderType: string, shaderLanguage: BABYLON.ShaderLanguage): any {
      if (!this.isEnabled) return null;
      const wgsl = shaderLanguage === BABYLON.ShaderLanguage.WGSL;
      if (shaderType === "fragment") {
        const iblScalingCode = wgsl
          ? `
            // Unity-Style IBL split scaling (WGSL)
            reflectionOut.environmentIrradiance *= uniforms.tkIblDiffuseScale;
            reflectionOut.environmentRadiance *= uniforms.tkIblSpecularScale; // adjust .rgb if it's a vec4
            `
          : `
            // Unity-Style IBL split scaling (GLSL)
            reflectionOut.environmentIrradiance *= tkIblDiffuseScale;
            reflectionOut.environmentRadiance.rgb *= tkIblSpecularScale;
            `;
        return {
          "CUSTOM_FRAGMENT_DEFINITIONS": this.fragmentDefinitions,
          "CUSTOM_FRAGMENT_BEFORE_LIGHTS": iblScalingCode
        };
      }

      return null;
    }

I dont want to have HACK the shader with regex for finalIrradiance and finalRadiance but i dont know how to get to FINALIRRADIANCE and FINALRADIANCE.

The shader code snippet above is where i left off and cant get to work…

So setting Specular IBL Slipt to ZERO should KILL the specular reflections with out HACKING the pbr._getReflectionTexture

Any ideal how to do that ? @Evgeni_Popov

I think your code above should work? If you can setup a simple repro, we should be able to find why it doesn’t.

Also, you can access finalRadianceScaled (which is the very final radiance value that will be added to the pixel color) in the CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION point, if that can help.

Yeah, i figured that one out as well. My UnityStyleLightingPlugin does the IBL split for me. Now diffuseIBL wont contribute to my lightmapped textures, but Specular Reflections can contribute full (or even scaled up or down reflections… including passing 0 to the Specular IBL split to turn off reflections no matter if it has a reflectionTexture or getting reflections from the environment)

Works Beautiful:

    public getCustomCode(shaderType: string, shaderLanguage: BABYLON.ShaderLanguage): any {
      const wgsl = shaderLanguage === BABYLON.ShaderLanguage.WGSL;
      if (shaderType === "fragment") {
        const iblScalingCode = wgsl
          ? `
            // Unity-Style IBL split scaling (WGSL)
            #if defined(REFLECTION) && defined(UNITYSTYLELIGHTINGPLUGIN)
                finalIrradiance = finalIrradiance * uniforms.tkIblDiffuseScale;
                finalRadiance = finalRadiance * uniforms.tkIblSpecularScale;
                finalRadianceScaled = finalRadianceScaled * uniforms.tkIblSpecularScale;
            #endif
            `
          : `
            // Unity-Style IBL split scaling (GLSL)
            #if defined(REFLECTION) && defined(UNITYSTYLELIGHTINGPLUGIN)
                finalIrradiance = finalIrradiance * tkIblDiffuseScale;
                finalRadiance = finalRadiance * tkIblSpecularScale;
                finalRadianceScaled = finalRadianceScaled * tkIblSpecularScale;
            #endif
            `;
        return {
          CUSTOM_FRAGMENT_DEFINITIONS: this.fragmentDefinitions,
          CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION: iblScalingCode
        };
      }
      return null;
    }