Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

RDPipelineColorBlendStateAttachment

继承: RefCounted < Object

管线颜色混合状态附件(由 RenderingDevice 使用)。

描述

控制使用 RenderingDevice 时如何在来源和目标片段之间进行混合。

以下是常见面向用户的混合模式在 Godot 的 2D 渲染器中的实现方法,仅供参考:

混合:

var attachment = RDPipelineColorBlendStateAttachment.new()
attachment.enable_blend = true
attachment.color_blend_op = RenderingDevice.BLEND_OP_ADD
attachment.src_color_blend_factor = RenderingDevice.BLEND_FACTOR_SRC_ALPHA
attachment.dst_color_blend_factor = RenderingDevice.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
attachment.alpha_blend_op = RenderingDevice.BLEND_OP_ADD
attachment.src_alpha_blend_factor = RenderingDevice.BLEND_FACTOR_ONE
attachment.dst_alpha_blend_factor = RenderingDevice.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA

加:

var attachment = RDPipelineColorBlendStateAttachment.new()
attachment.enable_blend = true
attachment.alpha_blend_op = RenderingDevice.BLEND_OP_ADD
attachment.color_blend_op = RenderingDevice.BLEND_OP_ADD
attachment.src_color_blend_factor = RenderingDevice.BLEND_FACTOR_SRC_ALPHA
attachment.dst_color_blend_factor = RenderingDevice.BLEND_FACTOR_ONE
attachment.src_alpha_blend_factor = RenderingDevice.BLEND_FACTOR_SRC_ALPHA
attachment.dst_alpha_blend_factor = RenderingDevice.BLEND_FACTOR_ONE

减:

var attachment = RDPipelineColorBlendStateAttachment.new()
attachment.enable_blend = true
attachment.alpha_blend_op = RenderingDevice.BLEND_OP_REVERSE_SUBTRACT
attachment.color_blend_op = RenderingDevice.BLEND_OP_REVERSE_SUBTRACT
attachment.src_color_blend_factor = RenderingDevice.BLEND_FACTOR_SRC_ALPHA
attachment.dst_color_blend_factor = RenderingDevice.BLEND_FACTOR_ONE
attachment.src_alpha_blend_factor = RenderingDevice.BLEND_FACTOR_SRC_ALPHA
attachment.dst_alpha_blend_factor = RenderingDevice.BLEND_FACTOR_ONE

乘:

var attachment = RDPipelineColorBlendStateAttachment.new()
attachment.enable_blend = true
attachment.alpha_blend_op = RenderingDevice.BLEND_OP_ADD
attachment.color_blend_op = RenderingDevice.BLEND_OP_ADD
attachment.src_color_blend_factor = RenderingDevice.BLEND_FACTOR_DST_COLOR
attachment.dst_color_blend_factor = RenderingDevice.BLEND_FACTOR_ZERO
attachment.src_alpha_blend_factor = RenderingDevice.BLEND_FACTOR_DST_ALPHA
attachment.dst_alpha_blend_factor = RenderingDevice.BLEND_FACTOR_ZERO

预乘 Alpha:

var attachment = RDPipelineColorBlendStateAttachment.new()
attachment.enable_blend = true
attachment.alpha_blend_op = RenderingDevice.BLEND_OP_ADD
attachment.color_blend_op = RenderingDevice.BLEND_OP_ADD
attachment.src_color_blend_factor = RenderingDevice.BLEND_FACTOR_ONE
attachment.dst_color_blend_factor = RenderingDevice.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
attachment.src_alpha_blend_factor = RenderingDevice.BLEND_FACTOR_ONE
attachment.dst_alpha_blend_factor = RenderingDevice.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA

属性

BlendOperation

alpha_blend_op

0

BlendOperation

color_blend_op

0

BlendFactor

dst_alpha_blend_factor

0

BlendFactor

dst_color_blend_factor

0

bool

enable_blend

false

BlendFactor

src_alpha_blend_factor

0

BlendFactor

src_color_blend_factor

0

bool

write_a

true

bool

write_b

true

bool

write_g

true

bool

write_r

true

方法

void

set_as_mix ( )


属性说明

BlendOperation alpha_blend_op = 0

Alpha 通道使用的混合模式。


BlendOperation color_blend_op = 0

红、绿、蓝通道使用的混合模式。


BlendFactor dst_alpha_blend_factor = 0

控制如何根据目标片段确定 Alpha 通道的混合系数。


BlendFactor dst_color_blend_factor = 0

控制如何根据目标片段确定颜色通道的混合系数。


bool enable_blend = false

  • void set_enable_blend ( bool value )

  • bool get_enable_blend ( )

如果为 true,则会根据 src_color_blend_factordst_color_blend_factorsrc_alpha_blend_factordst_alpha_blend_factor 中定义的系数对来源和目标进行混合。同时也会考虑 color_blend_opalpha_blend_op 混合模式,write_rwrite_gwrite_bwrite_a 则控制的是输出。


BlendFactor src_alpha_blend_factor = 0

控制如何根据来源片段确定 Alpha 通道的混合系数。


BlendFactor src_color_blend_factor = 0

控制如何根据来源片段确定颜色通道的混合系数。


bool write_a = true

  • void set_write_a ( bool value )

  • bool get_write_a ( )

如果为 true,则将新的 Alpha 通道写入最终结果。


bool write_b = true

  • void set_write_b ( bool value )

  • bool get_write_b ( )

如果为 true,则将新的蓝色通道写入最终结果。


bool write_g = true

  • void set_write_g ( bool value )

  • bool get_write_g ( )

如果为 true,则将新的绿色通道写入最终结果。


bool write_r = true

  • void set_write_r ( bool value )

  • bool get_write_r ( )

如果为 true,则将新的红色通道写入最终结果。


方法说明

void set_as_mix ( )

使用普通(非预乘)Alpha 进行标准混合混合(mix blending)的简便方法。这个方法会将 enable_blend 设为 true,将 src_color_blend_factor 设为 RenderingDevice.BLEND_FACTOR_SRC_ALPHA,将 dst_color_blend_factor 设为 RenderingDevice.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,将 src_alpha_blend_factor 设为 RenderingDevice.BLEND_FACTOR_SRC_ALPHA,将 dst_alpha_blend_factor 设为 RenderingDevice.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA