Reputation: 1436
I am writing a PixelShader (HLSL, SM40) and try to skip the output completely in some cases. My current code looks like this:
float4 PS( PS_INPUT input) : SV_Target
{
float4 result=float4(1,1,1,0);
if(input.Col.r >= 0.999998f)
result=float4(0,0,0,0);
return result;
}
But this will just write black pixels not seen (as black is backgroundcolor here). But in some cases were the pixel was colored previously, pixels become obviously black. My Intention is to skip writing to the rendertarget then. Is there a way to skip this, for example code could look like this non working one:
float4 PS( PS_INPUT input) : SV_Target
{
float4 result=float4(1,1,1,0);
if(input.Col.r >= 0.999998f)
return; //or 'return null;'
return result;
}
Edit - now we have a working (unoptimized to keep it comparable, clip instead of discard may be faster) sample:
float4 PS( PS_INPUT input) : SV_Target
{
float4 result=float4(1,1,1,0);
if(input.Col.r >= 0.999998f)
discard;
return result;
}
Upvotes: 3
Views: 3629
Reputation: 3180
This can be achieved with the intrinsic function clip
(doc) or with the flow control statemant discard
(doc). In your case clip
should be best suited :)
Upvotes: 6