Table of Contents

Class CompositorEffect

This resource allows for creating a custom rendering effect.

Inheritance
CompositorEffect

Remarks

This resource defines a custom rendering effect that can be applied to Viewports through the viewports' Environment. You can implement a callback that is called during rendering at a given stage of the rendering pipeline and allows you to insert additional passes. Note that this callback happens on the rendering thread. CompositorEffect is an abstract base class and must be extended to implement specific rendering logic.

See Also

Properties

access_resolved_color

If true and MSAA is enabled, this will trigger a color buffer resolve before the effect is run.

Note: In CompositorEffect._render_callback, to access the resolved buffer use:

var render_scene_buffers = render_data.get_render_scene_buffers()
var color_buffer = render_scene_buffers.get_texture("render_buffers", "color")

var access_resolved_color : bool

Property Value

bool

Remarks

  • void set_access_resolved_color(bool value)
  • bool get_access_resolved_color

access_resolved_depth

If true and MSAA is enabled, this will trigger a depth buffer resolve before the effect is run.

Note: In CompositorEffect._render_callback, to access the resolved buffer use:

var render_scene_buffers = render_data.get_render_scene_buffers()
var depth_buffer = render_scene_buffers.get_texture("render_buffers", "depth")

var access_resolved_depth : bool

Property Value

bool

Remarks

  • void set_access_resolved_depth(bool value)
  • bool get_access_resolved_depth

effect_callback_type

The type of effect that is implemented, determines at what stage of rendering the callback is called.

var effect_callback_type : int

Property Value

int

Remarks

  • void set_effect_callback_type(int value)
  • int get_effect_callback_type

enabled

If true this rendering effect is applied to any viewport it is added to.

var enabled : bool

Property Value

bool

Remarks

  • void set_enabled(bool value)
  • bool get_enabled

needs_motion_vectors

If true this triggers motion vectors being calculated during the opaque render state.

Note: In CompositorEffect._render_callback, to access the motion vector buffer use:

var render_scene_buffers = render_data.get_render_scene_buffers()
var motion_buffer = render_scene_buffers.get_velocity_texture()

var needs_motion_vectors : bool

Property Value

bool

Remarks

  • void set_needs_motion_vectors(bool value)
  • bool get_needs_motion_vectors

needs_normal_roughness

If true this triggers normal and roughness data to be output during our depth pre-pass, only applicable for the Forward+ renderer.

Note: In CompositorEffect._render_callback, to access the roughness buffer use:

var render_scene_buffers = render_data.get_render_scene_buffers()
var roughness_buffer = render_scene_buffers.get_texture("forward_clustered", "normal_roughness")

The raw normal and roughness buffer is stored in an optimized format, different than the one available in Spatial shaders. When sampling the buffer, a conversion function must be applied. Use this function, copied from here:

vec4 normal_roughness_compatibility(vec4 p_normal_roughness) {
    float roughness = p_normal_roughness.w;
    if (roughness > 0.5) {
        roughness = 1.0 - roughness;
    }
    roughness /= (127.0 / 255.0);
    return vec4(normalize(p_normal_roughness.xyz * 2.0 - 1.0) * 0.5 + 0.5, roughness);

}

var needs_normal_roughness : bool

Property Value

bool

Remarks

  • void set_needs_normal_roughness(bool value)
  • bool get_needs_normal_roughness

needs_separate_specular

If true this triggers specular data being rendered to a separate buffer and combined after effects have been applied, only applicable for the Forward+ renderer.

var needs_separate_specular : bool

Property Value

bool

Remarks

  • void set_needs_separate_specular(bool value)
  • bool get_needs_separate_specular

Methods

_render_callback(int, RenderData)

Qualifiers: virtual

Implement this function with your custom rendering code. effect_callback_type should always match the effect callback type you've specified in effect_callback_type. render_data provides access to the rendering state, it is only valid during rendering and should not be stored.

void _render_callback(int effect_callback_type, RenderData render_data)

Parameters

effect_callback_type int
render_data RenderData