Skip to content

Commit

Permalink
Fixed dual-source blending in the forward shading pass on Vulkan.
Browse files Browse the repository at this point in the history
  • Loading branch information
apanteleev committed Dec 3, 2024
1 parent abe5cb5 commit b52bc31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions include/donut/shaders/binding_helpers.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@
#define VK_BINDING(reg,dset) [[vk::binding(reg,dset)]]
#define VK_DESCRIPTOR_SET(dset) ,space##dset

// To use dual-source blending on Vulkan, a pixel shader must specify the same Location but different Index
// decorations for two outputs. In HLSL, that can only be achieved with explicit attributes.
// Use on the declarations of pixel shader outputs.
#define VK_LOCATION(loc) [[vk::location(loc)]]
#define VK_LOCATION_INDEX(loc,idx) [[vk::location(loc)]] [[vk::index(idx)]]

#else

#define VK_PUSH_CONSTANT
#define VK_BINDING(reg,dset)
#define VK_DESCRIPTOR_SET(dset)
#define VK_LOCATION(loc)
#define VK_LOCATION_INDEX(loc,idx)

#endif

Expand Down
4 changes: 2 additions & 2 deletions shaders/passes/forward_ps.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ void main(
in float4 i_position : SV_Position,
in SceneVertex i_vtx,
in bool i_isFrontFace : SV_IsFrontFace,
out float4 o_color : SV_Target0
VK_LOCATION_INDEX(0, 0) out float4 o_color : SV_Target0
#if TRANSMISSIVE_MATERIAL
, out float4 o_backgroundBlendFactor : SV_Target1
, VK_LOCATION_INDEX(0, 1) out float4 o_backgroundBlendFactor : SV_Target1
#endif
)
{
Expand Down

0 comments on commit b52bc31

Please sign in to comment.