RenderEnableEmissiveBuffer - ApertureViewer/Aperture-Viewer GitHub Wiki

Technical Deep Dive: RenderEnableEmissiveBuffer

1. Setting Definition

  • Setting Name: RenderEnableEmissiveBuffer
  • Controlled By: This setting is typically controlled indirectly via the master setting RenderDisableVintageMode. When RenderDisableVintageMode is true (default), RenderEnableEmissiveBuffer is set to true. When RenderDisableVintageMode is false, RenderEnableEmissiveBuffer is set to false.
  • Assumed XML Definition (if directly controlled):
      <key>RenderEnableEmissiveBuffer</key>
      <map>
        <key>Comment</key>
        <string>Enables a dedicated buffer for PBR emissive material properties, affecting probe lighting and glow.</string>
        <key>Persist</key>
        <integer>1</integer> <!-- Likely persistent if controlled directly -->
        <key>Type</key>
        <string>Boolean</string>
        <key>Value</key>
        <integer>1</integer> <!-- Default Value (true) when modern pipeline is active -->
      </map>
  • Data Type: Boolean (Stored as integer 0/1, used as bool in C++)
  • Default Value: true (when RenderDisableVintageMode is true).

2. Function and Purpose

The primary function of RenderEnableEmissiveBuffer is to control the allocation and use of a dedicated render target (G-Buffer attachment) specifically for storing information about Physically Based Rendering (PBR) emissive materials.

This setting acts as a crucial enabler for two distinct PBR-specific effects:

  1. PBR Indirect Lighting via Reflection Probes: When enabled, it allows PBR materials with an emissive component (texture or color tint with Luminance > 0) to contribute accurately colored indirect light within the bounds of Reflection Probes. This light affects the appearance of nearby non-emissive surfaces captured by the probe.
  2. Accurate PBR Glow Effect: When enabled (and RenderGlow is also active), it allows the Glow post-processing effect to correctly read the intended color and intensity from PBR emissive materials, resulting in a visually correct and often significantly brighter glow contribution compared to when the buffer is disabled.

Critically, this setting has NO direct effect on traditional Blinn-Phong (BP) materials. BP materials use the "Fullbright" flag and their tint color for probe lighting contributions, and their Glow (f32) value and the RenderGlowNoise setting primarily influence their glow appearance.

3. Code Usage Analysis

  • File: llcommon/llviewercontrol.cpp
    • Function: handleDisableVintageMode(const LLSD& newvalue)
      • Logic: Directly sets RenderEnableEmissiveBuffer based on the RenderDisableVintageMode value. gSavedSettings.setBOOL("RenderEnableEmissiveBuffer", newvalue.asBoolean());
  • File: llcommon/pipeline.cpp
    • Function: LLPipeline::addDeferredAttachments(...)
      • Logic: Checks this setting (via cached has_emissive). If true, allocates the 3rd color attachment for the main G-Buffer (mRT->deferredScreen, attachment index 3). The format (GL_RGB16F or GL_RGB) depends on RenderHDREnabled. This is where the buffer itself is created.
      static LLCachedControl<bool> has_emissive(gSavedSettings, "RenderEnableEmissiveBuffer", false);
      // ... (check RenderHDREnabled for format) ...
      if (has_emissive)
      {
          valid = valid && target.addColorAttachment(emissive); // frag_data[3] PBR emissive
      }
    • Function: LLPipeline::generateLuminance(...)
      • Logic: The gLuminanceProgram shader reads from the emissive buffer (texture unit bound to LLShaderMgr::DEFERRED_EMISSIVE, sampling attachment index 3 of deferredScreen) if available. This contribution is added to the luminance calculated from diffuse surfaces, affecting the input to the auto-exposure system.
      channel = gLuminanceProgram.enableTexture(LLShaderMgr::DEFERRED_EMISSIVE);
      if (channel > -1)
      {
          // mGlow[1] is bound here in the provided code snippet, which seems potentially incorrect
          // if it's meant to read the main emissive G-buffer.
          // Assumed intent/correct implementation: Read from mRT->deferredScreen attachment 3.
           mRT->deferredScreen.bindTexture(3, channel, LLTexUnit::TFO_POINT); // Hypothetical correct binding
           // mGlow[1].bindTexture(0, channel); // Actual code - reads intermediate glow buffer? Needs verification.
      }
      (Note: The code snippet binding mGlow[1] here is suspicious and might be an error or relate to a later stage. The logical place to read the main emissive G-Buffer is mRT->deferredScreen attachment 3).
    • Function: LLPipeline::generateGlow(...)
      • Logic: The gGlowExtractProgram likely implicitly or explicitly uses the emissive buffer data when extracting initial glow information from the scene, contributing to the final bloom effect if the buffer is enabled.
  • File: llcommon/llviewershadermgr.cpp
    • Function: add_common_permutations(LLGLSLShader* shader)
      • Logic: If RenderEnableEmissiveBuffer is true, adds the preprocessor definition #define HAS_EMISSIVE 1 when compiling many shaders. Shaders using PBR materials rely on this define to include code paths that write to or read from the emissive buffer.

4. Performance Impact Analysis

  • Enabling (true):

    • Memory: Increases GPU VRAM usage by adding another full-screen render target to the G-Buffer. The size increase depends on screen resolution and whether HDR is enabled (e.g., GL_RGB16F uses more VRAM than GL_RGB8).
    • GPU Load:
      • Adds a minor cost during the G-Buffer pass for shaders (PBR opaque, PBR alpha mask) writing to the emissive buffer.
      • Adds a minor cost for shaders reading from the buffer (e.g., generateLuminance, potentially gGlowExtractProgram, reflection probe rendering).
    • Overall: A moderate increase in VRAM usage and a small increase in GPU processing load. Usually negligible on modern GPUs unless severely VRAM limited.
  • Disabling (false):

    • Memory: Saves the VRAM required for the emissive G-Buffer attachment.
    • GPU Load: Reduces GPU load slightly by eliminating writes/reads associated with the emissive buffer.
    • Overall: Provides a small performance optimization, primarily in VRAM savings.

Conclusion: Enabling the emissive buffer has a performance cost, mainly in VRAM. Disabling it saves resources but breaks PBR emissive functionality.

5. Visual Impact Analysis

The visual impact depends heavily on whether PBR or Blinn-Phong materials are used.

  • PBR Materials:

    • Reflection Probe Lighting:
      • Enabled (true): PBR materials with Emissive Tint (L>0) correctly contribute colored indirect light within reflection probes. This adds realism to reflections on nearby surfaces.
      • Disabled (false): PBR materials do not contribute any light to reflection probes based on their emissive properties.
    • Glow Effect (Requires RenderGlow=true):
      • Enabled (true): PBR materials with Emissive Tint (L>0) contribute their intended color and intensity to the glow effect. The glow appears correct, often bright, and accurately colored. If RenderGlowNoise=true, this combines with the noise effect.
      • Disabled (false): The PBR material's specific emissive contribution to glow is lost. If RenderGlowNoise=true and Emissive Tint (L>0), a glow effect may still appear but seems driven primarily by the noise map (potentially desaturated, speckled, weaker). If RenderGlowNoise=false, PBR glow is likely absent or minimal.
  • Blinn-Phong (BP) Materials:

    • Reflection Probe Lighting:
      • Enabled/Disabled (true/false): NO EFFECT. BP materials contribute light to probes based on the Fullbright flag and Tint color (L>0), independent of this setting.
    • Glow Effect (Requires RenderGlow=true):
      • Enabled/Disabled (true/false): NO EFFECT. BP glow depends on the material's Glow value (f32), the Fullbright flag, and RenderGlowNoise. If Fullbright is OFF and RenderGlowNoise is ON, glow seems driven by the noise map. If Fullbright is ON and RenderGlowNoise is ON, the fullbright appearance enhances/combines with the noise-driven glow. If RenderGlowNoise is OFF and Fullbright is OFF, BP materials typically show no glow regardless of their Glow value or this setting.

Summary of Visual Impact: Enabling is essential for correct PBR emissive lighting in probes and visually correct PBR glow. Disabling breaks these PBR features but saves minor resources and has no impact on Blinn-Phong materials.

6. Default Value Assessment

  • Defined Default: true (implicitly set by RenderDisableVintageMode being true).

This is the correct and intended default for the modern PBR rendering pipeline. Disabling it fundamentally breaks key visual features of PBR emissive materials.

7. Recommended Value (High-End Hardware)

  • For Correct PBR Rendering: true (Enabled). This is mandatory for PBR emissive materials to function as intended, both for probe lighting and for glow effects. The minor performance cost is generally worth the visual fidelity on capable hardware.
  • When to Disable: Only if deliberately using the "Vintage" rendering mode (via RenderDisableVintageMode), or possibly in extreme VRAM-limited scenarios where every buffer counts (though disabling HDR via RenderHDREnabled is usually far more impactful). Disabling this breaks PBR emissive rendering.

8. Testing Procedures

8.1 User Testing

Objective: To observe the conditional effects on PBR probe lighting and PBR/BP glow.

Prerequisites: Access to toggle RenderDisableVintageMode (or directly RenderEnableEmissiveBuffer if decoupled). Access to PBR and BP materials with emissive/fullbright/glow properties. A scene with reflection probes active (RenderReflectionProbeLevel > 0) and optionally Glow enabled (RenderGlow).

Procedure:

  1. PBR Probe Lighting Test:
    • Place a PBR object with a bright emissive color (Tint L>0) near a non-emissive, reflective surface, ensuring both are within a probe's influence.
    • Enable HDR (RenderDisableVintageMode=true).
    • Set RenderEnableEmissiveBuffer to true (default). Observe the reflection: colored light from the PBR object should illuminate the reflective surface within the probe's capture.
    • Set RenderEnableEmissiveBuffer to false (by setting RenderDisableVintageMode=false and back to true, or directly if possible). Observe the reflection again.
    • Expected Observation: The colored indirect light from the PBR object on the reflective surface should disappear when the buffer is disabled.
  2. PBR Glow Test:
    • View a PBR object with Emissive Tint (L>0).
    • Enable RenderGlow and RenderHDREnabled. Optionally toggle RenderGlowNoise.
    • Set RenderEnableEmissiveBuffer to true. Observe glow intensity and color.
    • Set RenderEnableEmissiveBuffer to false. Observe glow again.
    • Expected Observation: Glow should be significantly brighter and/or more accurately colored when the buffer is enabled. When disabled (especially if Noise is ON), glow might appear weaker, desaturated, or dominated by noise speckle.
  3. BP Control Test:
    • Repeat steps 1 & 2 using a BP object with Fullbright=true and/or a non-zero Glow value.
    • Toggle RenderEnableEmissiveBuffer ON and OFF.
    • Expected Observation: Toggling RenderEnableEmissiveBuffer should have no noticeable effect on the BP object's probe lighting contribution or its glow appearance.

8.2 Developer Testing

Objective: To verify conditional buffer allocation, shader compilation defines, and buffer usage.

Prerequisites: Debug build, graphics debugger, ability to modify settings (likely via RenderDisableVintageMode).

Procedure:

  1. Verify Buffer Allocation:
    • Use the graphics debugger. Enable HDR and Emissive Buffer (RenderDisableVintageMode=true). Capture frame. Inspect G-Buffer attachments (mRT->deferredScreen). Verify attachment 3 exists and has an appropriate format (e.g., GL_RGB16F).
    • Disable Emissive Buffer (RenderDisableVintageMode=false). Reload/restart. Capture frame. Verify G-Buffer attachment 3 is absent or unused.
  2. Verify Shader Defines:
    • Enable Emissive Buffer. Capture frame. Select a draw call using a PBR shader (e.g., gDeferredPBROpaqueProgram). Inspect the compiled shader source or definition. Verify #define HAS_EMISSIVE 1 is present.
    • Disable Emissive Buffer. Capture frame. Inspect the same shader. Verify #define HAS_EMISSIVE 1 is absent.
  3. Verify Buffer Reads:
    • Enable Emissive Buffer. Capture frame. Step into LLPipeline::generateLuminance. Verify that the code path attempting to bind/read LLShaderMgr::DEFERRED_EMISSIVE is active and binds the correct texture/attachment (likely G-Buffer attachment 3).
    • Disable Emissive Buffer. Capture frame. Verify the same code path is inactive or the texture binding for emissive is skipped/uses a dummy texture.

9. Summary

Feature Detail
Setting Name RenderEnableEmissiveBuffer
Controlled Via RenderDisableVintageMode
Purpose Enables dedicated render target for PBR Emissive data.
PBR Effect (Lighting) Enables PBR emissive materials to contribute colored indirect light within Reflection Probes.
PBR Effect (Glow) Enables correct color/intensity contribution of PBR emissive materials to the Glow effect.
Blinn-Phong Effect None. BP uses Fullbright/Glow value/Noise for its lighting/glow.
Default Value true (when modern pipeline active)
Code Locations pipeline (allocation, usage), llviewershadermgr (compilation define), llviewercontrol (setter)
Performance Moderate VRAM increase, minor GPU load increase when enabled.
Visual Impact Essential for correct PBR emissive visuals (probe lighting & glow). No impact on BP.
Recommended true for PBR pipeline. Disabling breaks PBR emissive.
⚠️ **GitHub.com Fallback** ⚠️