CompositorEffect

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

继承: Resource < RefCounted < Object

This resource allows for creating a custom rendering effect.

描述

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

属性

方法

void_render_callback ( effect_callback_type: int, render_data: RenderData ) virtual1

枚举

enum EffectCallbackType:

EffectCallbackType EFFECT_CALLBACK_TYPE_PRE_OPAQUE = 0

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

EffectCallbackType EFFECT_CALLBACK_TYPE_POST_OPAQUE = 1

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

EffectCallbackType EFFECT_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).

EffectCallbackType EFFECT_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.

EffectCallbackType EFFECT_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.

EffectCallbackType EFFECT_CALLBACK_TYPE_MAX = 5

Represents the size of the EffectCallbackType enum.


属性说明

bool access_resolved_color

  • void set_access_resolved_color ( value: bool )
  • bool get_access_resolved_color ( )

If true 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:


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

bool access_resolved_depth

  • void set_access_resolved_depth ( value: bool )
  • bool get_access_resolved_depth ( )

If true 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:


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

EffectCallbackType effect_callback_type

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


bool enabled

  • void set_enabled ( value: bool )
  • bool get_enabled ( )

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


bool needs_motion_vectors

  • void set_needs_motion_vectors ( value: bool )
  • bool get_needs_motion_vectors ( )

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

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


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

bool needs_normal_roughness

  • void set_needs_normal_roughness ( value: bool )
  • bool get_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 _render_callback, to access the roughness buffer use:


    var render_scene_buffers : RenderSceneBuffersRD = 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);
    }

bool needs_separate_specular

  • void set_needs_separate_specular ( value: bool )
  • bool get_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.


方法说明

void _render_callback ( effect_callback_type: int, render_data: RenderData ) virtual1

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.

1

本方法通常需要用户覆盖才能生效。

2

本方法无副作用,不会修改该实例的任何成员变量。

3

本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。

4

本方法用于构造某个类型。

5

调用本方法无需实例,可直接使用类名进行调用。

6

本方法描述的是使用本类型作为左操作数的有效运算符。

7

这个值是由下列位标志构成位掩码的整数。

8

无返回值。