- Home /
CG: How to NOT write the pixel
Hi Guys,
This is really a CG question. I'm adding a clipping rectangle to an existing Cg shader. If the coordinates of the pixel are outside of the clipping rectangle I want nothing written to the screen or z-buffer.
Question: How can I tell a fragment shader to abort writing a pixel? Is there some kind of special Color I can return or a method I can call within the frag shader to end processing of that pixel?
I suppose I could force the depth to be outside of the clip range, but is there a cleaner way?
Answer by Jeff-Kesselman · Apr 27, 2014 at 08:04 PM
Ah... it appears there is a discard command.
Trying it now...
Yes, saying the command discard; in the frag shear prevents the pixel from being drawn.
Your answer
![](https://koobas.hobune.stream/wayback/20220613143724im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
CG Shader: Setting output alpha changes RGB too 0 Answers
Refraction Shader. Strange Artifacts 0 Answers
How to get color of a fragment in CG after it's lit? 0 Answers
Where Is UNITY_POSITION(pos) Defined? 1 Answer
Best way to make an unlit Cg shader 2 Answers