νμ΄νλΌμΈ λΉλλ₯Ό μμ±ν λ, λΈλ λ© λ‘μ§μ μμ ν μλ΅νμμ΅λλ€. λΈλ λ©μ ν¬λͺ ν κ°μ²΄λ λͺλͺ κ·Έλν½ ν¨κ³Όμ νμμ μΌλ‘ μ¬μ©λκΈ° λλ¬Έμ μ€μν κΈ°λ₯μ λλ€. λ°λΌμ μ΄λ²μλ μ§λ κΈμμ λ λλ§ν μ¬κ°νμ ν¬λͺ νκ² λ§λ€κ² μ΅λλ€.
νμ΄νλΌμΈ λΈλ λ©
μ °μ΄λμμ λΈλ λ©μ μ μ΄ν μλ μμΌλ©°, μ΄λ νμ΄νλΌμΈμ μμ±μ λλ€. GPU νλμ¨μ΄ μμ²΄κ° λΈλ λ© μ°μ°μ μ²λ¦¬νλ©°, λ€μν μ΅μ μ μ 곡ν©λλ€. PipelineBuilderμ 2κ°μ§ μλ‘μ΄ λΈλ λ© λͺ¨λλ₯Ό μΆκ°ν΄ λ³΄κ² μ΅λλ€. νλλ λ¨μν μμμ λνλ addtive blending, λ€λ₯Έ νλλ μμκ³Ό μν κ°μ μλ alpha blending μ λλ€.
PipelineBuilderμ λ€μ λ ν¨μλ₯Ό μΆκ°ν©λλ€.
void PipelineBuilder::enable_blending_additive()
{
_colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
_colorBlendAttachment.blendEnable = VK_TRUE;
_colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
_colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
_colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
_colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
_colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
_colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
}
void PipelineBuilder::enable_blending_alphablend()
{
_colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
_colorBlendAttachment.blendEnable = VK_TRUE;
_colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
_colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
_colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
_colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
_colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
_colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
}
Vulkanμμ λΈλ λ© μ΅μ μ μ€μ ν λ μμκ³Ό μνκ°μ κ°κ°μ λν΄ λΈλ λ© μμ μ§μ ν΄μ£Όμ΄μΌ ν©λλ€. μμκ³Ό μνμ λ§€κ°λ³μλ λμΌνκ² λμνλ©°, λΈλ λ© μμ λ€μκ³Ό κ°μ λ°©μμΌλ‘ μλν©λλ€.
outColor = srcColor * srcColorBlendFactor <op> dstColor * dstColorBlendFactor;
λΈλ λ©μλ μ¬λ¬ μ°μ°μκ° μμ§λ§, λλΆλΆμ κ°μ₯ κΈ°λ³Έμ μ΄κ³ μμ μ μΌλ‘ μλνλ VK_BLEND_OP_ADD
λ₯Ό μ¬μ©ν©λλ€. κ·Έ μΈμλ λ€μν κ³ κΈ μ°μ°μλ€μ΄ μμ§λ§, λλΆλΆ νμ₯μ΄ νμνλ©° μ¬κΈ°μλ λ€λ£¨μ§ μκ² μ΅λλ€. Sourceλ νμ΄νλΌμΈμμ νμ¬ μ²λ¦¬μ€μΈ μμμ μλ―Ένκ³ , Destinationμ μ°λ¦¬κ° λ λλ§ μ€μΈ μ΄λ―Έμ§μ νμ¬ ν½μ
κ°μ
λλ€.
μμ μμ λ°νμΌλ‘ λ§μ λΈλ λ©μ΄ μ΄λ»κ² μλνλμ§ μ€λͺ νκ² μ΅λλ€.
VK_BLEND_FACTOR_ONE
μ blend factorλ₯Ό 1.0μΌλ‘ μ€μ νλ―λ‘, κ³±μ
μ°μ° μμ΄ κ·Έλλ‘ λν΄μ§κ² λ©λλ€. VK_BLEND_FACTOR_SRC_ALPHA
μ λ°λ©΄ Sourceμ alpha κ°μ κ³±ν©λλ€. μ΄ κ²½μ° μ°λ¦¬μ λΈλ λ© κ³΅μμ λ€μκ³Ό κ°μ ννκ° λ©λλ€.
outColor = srcColor.rgb * srcColor.a + dstColor.rgb * 1.0
μν λΈλ λ©μ μ¬μ©ν κ²½μ° λμ λ€μκ³Ό κ°μ λͺ¨μ΅μ΄ λ κ²μ λλ€.
outColor = srcColor.rgb * srcColor.a + dstColor.rgb * (1.0 - srcColor.a)
λ³Έμ§μ μΌλ‘ srcColorμ alphaκ°μ μν΄ μ μ΄λλ 보κ°μ μννλ μ μ΄λ©°, μ΄ alpha κ°μ μ °μ΄λμμ μ λ¬λ©λλ€.
μ΄κ±Έ μ¬μ©ν΄ μ΄λ€ κ²°κ³Όκ° λμ€λμ§ νμΈν΄ λ΄
μλ€. μ
°μ΄λμμλ μν κ°μ λ°λ‘ μ€μ νμ§ μμμΌλ, addtiveλ₯Ό μ¬μ©ν΄ λ΄
μλ€. init_mesh_pipeline()
ν¨μμμ λΈλ λ© μ€μ μ λ³κ²½ν΄ μ£ΌμΈμ.`
//pipelineBuilder.disable_blending();
pipelineBuilder.enable_blending_additive();
μ΄μ μμμ΄ λ©μκ° λ°ν¬λͺ ν΄μ§ κ²μ λ³Ό μ μμ΅λλ€. λ€μν λΈλ λ© λͺ¨λλ₯Ό μλν΄λ³΄λ©΄μ κ°κ°μ΄ μ΄λ€ ν¨κ³Όλ₯Ό μ£Όλμ§ νμΈν΄ 보μΈμ.
4μ₯μΌλ‘ λμ΄κ°κΈ° μ μ μ°½ ν¬κΈ° μ‘°μ κΈ°λ₯μ ꡬνν΄λ΄ μλ€.
Next: Window Resizing