Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

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(value: bool)

  • 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(value: bool)

  • bool get_write_a()

如果為 true,則將新的 Alpha 通道寫入最終結果。


bool write_b = true 🔗

  • void set_write_b(value: bool)

  • bool get_write_b()

如果為 true,則將新的藍色通道寫入最終結果。


bool write_g = true 🔗

  • void set_write_g(value: bool)

  • bool get_write_g()

如果為 true,則將新的綠色通道寫入最終結果。


bool write_r = true 🔗

  • void set_write_r(value: bool)

  • 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