Stencil buffer and a texture with transparency

Started by
24 comments, last by pindrought 5 years, 1 month ago
1 hour ago, JohnnyCode said:

That is strange if you have proper value in your transparent texture. Try discarding pixels manualy when you render it upon its alpha comparison then? Just as a fast test to bypass around your alpha settings that you should publish.

It works fine if I go back to using my pixel shader where i'm discarding the pixels but that seems to defeat the purpose of setting up a blend state and masking over the alpha values.

 

Edited to add: Actually, just ran some tests and it seems like if I use the discard method combined the masking over the alpha values that it is a slight performance increase. Interesting.

Advertisement

Not sure what blending should do. All blending operations are done after the stencil buffer is written for a pixel, so it won't affect the stencil buffer at all.

You can have a pixel shader with no output (return type "void"), just discard the pixels you don't need. That should be the fastest way.

10 hours ago, Magogan said:

Not sure what blending should do. All blending operations are done after the stencil buffer is written for a pixel, so it won't affect the stencil buffer at all.

You can have a pixel shader with no output (return type "void"), just discard the pixels you don't need. That should be the fastest way.

That's what I was doing before I needed to take the transparency into account for the texture.

However, that wont work when I need to take the transparency into account because that will just use the whole quad for the stencil.

 

2 minutes ago, pindrought said:

However, that wont work when I need to take the transparency into account because that will just use the whole quad for the stencil.


Texture2DArray<float4> Texture;
SamplerState SampleType;

struct PixelInputType{
    float4 position : SV_POSITION;
	float3 tex: TEXCOORDS;	
};

void main(PixelInputType input){
	if(Texture.Sample(SampleType, input.tex).a < 0.8f) discard;	
}

I use this pixel shader for a similar problem - I don't want to write depth (for the shadow), but it should work the same way for the stencil.

5 minutes ago, Magogan said:


Texture2DArray<float4> Texture;
SamplerState SampleType;

struct PixelInputType{
    float4 position : SV_POSITION;
	float3 tex: TEXCOORDS;	
};

void main(PixelInputType input){
	if(Texture.Sample(SampleType, input.tex).a < 0.8f) discard;	
}

I use this pixel shader for a similar problem - I don't want to write depth (for the shadow), but it should work the same way for the stencil.

Sorry I misread your post. I was thinking you were saying to use a null pixel shader. Thanks for the example. I didn't know you could actually have it return void.

 

Edited to add: Just tested and this seems to be much better performance doing it this way. Thanks again!

This topic is closed to new replies.

Advertisement