0
\$\begingroup\$

I have this bit of shader code to orient SV_target writing depending on alpha value for SV_Target0 : color0 = (input.a == 1)? float4(some value) : float4(0,0,0,0); for SV_Target1 : color1 = (input.a < 1)? float4(some other value) : float4(0,0,0,0); works fine to orient drawing on the targets depending on input.alpha value

As in fact I don't need to write float4(0,0,0,0) I've tried this: if ( input.a == 1 ) color0 = float4(some value); else color1 = float4(some other value); but here the shader write all objects on the two targets. Any idea on how to better write this code or solve this problem thanks in advance PhilB

\$\endgroup\$
1
  • \$\begingroup\$ Can you clarify what it is you're using this code to accomplish? What visual effect are you seeking to achieve? This context can help us find solutions appropriate to your application (and can improve your post's search hits) \$\endgroup\$
    – DMGregory
    Feb 16, 2022 at 11:27

1 Answer 1

0
\$\begingroup\$

Thanks for your interest in this question. I've seen somewhere that deffered rendering is not fully suitable for alpha rendering. So I'm trying to separate opaque and transparent objects while using deffered shaders anyway. The two targets(opaque left and alpha right (3rd is depth)) are then blended for the final result (see picture). The blending is not perfect but you have the idea. So target0 need to receive only opaque and target1 alpha. but in fact target0 draw alpha with color 0,0,0, and the same for opaque in target1. As alphablending is enable in alpha pass nothing appear in target0. But for target1 the opaque objects aer drawn (I've checked by using white color instead of black). So with black colors you see only what you need to see. I really want to try avoiding drawing "black" objects to save some fps. I'was thinking of clip but I'm not sure you can put it in a if then statement and I'm not sure you can use it for a given target in multitarget purposes. PhilB

\$\endgroup\$
1
  • \$\begingroup\$ If this solved your problem, remember to click the checkmark at the top left to mark this answer as Accepted. If it doesn't, then it probably should have been an edit to your question, not posted as an Answer. \$\endgroup\$
    – DMGregory
    Mar 19, 2022 at 18:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .