CompositorEffect

Experimental: The implementation may change as more of the rendering internals are exposed over time.

Inherits:Resource<RefCounted<Object

This resource allows for creating a custom rendering effect.

Description

This resource defines a custom rendering effect that can be applied toViewports 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.

Tutorials

Properties

bool

access_resolved_color

bool

access_resolved_depth

EffectCallbackType

effect_callback_type

bool

enabled

bool

needs_motion_vectors

bool

needs_normal_roughness

bool

needs_separate_specular

Methods

void

_render_callback(effect_callback_type:int, render_data:RenderData)virtual


Enumerations

enumEffectCallbackType:🔗

EffectCallbackTypeEFFECT_CALLBACK_TYPE_PRE_OPAQUE =0

The callback is called before our opaque rendering pass, but after depth prepass (if applicable).

EffectCallbackTypeEFFECT_CALLBACK_TYPE_POST_OPAQUE =1

The callback is called after our opaque rendering pass, but before our sky is rendered.

EffectCallbackTypeEFFECT_CALLBACK_TYPE_POST_SKY =2

The callback is called after our sky is rendered, but before our back buffers are created (and if enabled, before subsurface scattering and/or screen space reflections).

EffectCallbackTypeEFFECT_CALLBACK_TYPE_PRE_TRANSPARENT =3

The callback is called before our transparent rendering pass, but after our sky is rendered and we've created our back buffers.

EffectCallbackTypeEFFECT_CALLBACK_TYPE_POST_TRANSPARENT =4

The callback is called after our transparent rendering pass, but before any built-in post-processing effects and output to our render target.

EffectCallbackTypeEFFECT_CALLBACK_TYPE_MAX =5

Represents the size of theEffectCallbackType enum.


Property Descriptions

boolaccess_resolved_color🔗

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

Note: In_render_callback(), to access the resolved buffer use:

varrender_scene_buffers=render_data.get_render_scene_buffers()varcolor_buffer=render_scene_buffers.get_texture("render_buffers","color")

boolaccess_resolved_depth🔗

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

Note: In_render_callback(), to access the resolved buffer use:

varrender_scene_buffers=render_data.get_render_scene_buffers()vardepth_buffer=render_scene_buffers.get_texture("render_buffers","depth")

EffectCallbackTypeeffect_callback_type🔗

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


boolenabled🔗

Iftrue this rendering effect is applied to any viewport it is added to.


boolneeds_motion_vectors🔗

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

Note: In_render_callback(), to access the motion vector buffer use:

varrender_scene_buffers=render_data.get_render_scene_buffers()varmotion_buffer=render_scene_buffers.get_velocity_texture()

boolneeds_normal_roughness🔗

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

Note: In_render_callback(), to access the roughness buffer use:

varrender_scene_buffers=render_data.get_render_scene_buffers()varroughness_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 fromhere:

vec4normal_roughness_compatibility(vec4p_normal_roughness){floatroughness=p_normal_roughness.w;if(roughness>0.5){roughness=1.0-roughness;}roughness/=(127.0/255.0);returnvec4(normalize(p_normal_roughness.xyz*2.0-1.0)*0.5+0.5,roughness);}

boolneeds_separate_specular🔗

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


Method Descriptions

void_render_callback(effect_callback_type:int, render_data:RenderData)virtual🔗

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


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.