Code Snippet: Clipping Planes in Shader [HLSL]

In the XNA 4.0 we dont have anymore the Fixed function that let us specify a clipping plane. Now we have to do this in shaders =P. In this post i will show how to do this !

The following code shows how to implement ONE clipping plane in Projection Space. (same as the fixed pipeline)

If you want more than one plane, just use the Y,Z,W coordinates from the clipping variable to put the others values. If you want to use the plane in World or View space, just make the “dot” with the position in the right space.

The theory for this is simple. The dot operation evaluates the plane equation and the result give us in what side of the plane the position is. For more info check this.

float4x4 WVP;
float4 clippingPlane;
bool isClip;

Texture diffuse;
sampler DiffuseSampler = sampler_state
texture =  ;
magfilter = ANISOTROPIC;
minfilter = ANISOTROPIC;
mipfilter = LINEAR;
AddressU = wrap;
AddressV = wrap;

struct VertexShaderInput
float3 Position : POSITION0;
float4 texturecoord :  TEXCOORD0;

struct VertexShaderOutput
float4 Position : POSITION0;
float4 texturecoord :  TEXCOORD0;
float4 clipping :  TEXCOORD1;

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
VertexShaderOutput output;
output.Position = mul(float4(input.Position,1), WVP);
output.texturecoord = input.texturecoord;
output.clipping = 0;
float4 clp = output.Position;
output.clipping.x = dot(clp,clippingPlane) ;
return output;

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0

return tex2D(DiffuseSampler, input.texturecoord);

technique Technique1
pass Pass1
VertexShader = compile vs_2_0 VertexShaderFunction();
PixelShader = compile ps_2_0 PixelShaderFunction();

, , , , , ,

  1. #2 by adidas yeezy boost 750 on 23 de julho de 2016 - 3:22 pm

  2. #3 by 100% free virtual number on 23 de julho de 2016 - 3:33 pm

    check below, are some totally unrelated websites to ours, however, they are most trustworthy sources that we use

  3. #4 by Summahqw on 23 de julho de 2016 - 3:53 pm

    これはさまざまな試験の実践の検査に合格したもので、Microsoftの74-697認定試験に合格したかったら、Pass4Testを選ぶのは絶対正しいことです。 asio対応版とds対応版の、ふたつを作りました。 [url=]office 2013 激安[/url]
     たとえば法人の場合、ある国で設立され、そこに実体があるのだけれど、他の法域(タックスヘイブン)から管理・運営されているという形をとることによって、課税上の居住者であることを免れる。 小渕氏が植民地支配による「損害と苦痛」に謝罪し、金氏が「未来志向的な関係を発展させる」と表明した。
    [url=]office 2016 ステンシル[/url]  これだ! Raspberry Piとの悪戦苦闘の始まりです。 しかもそこで使われているスマホ用CPU性能、メモリー数、ストレージ数などから見ても、そこそこの動作が保障されるような内容なのだ。
    [url=]windows10 販売[/url]
    パーセンテージが高いほど、試験のコンテンツ領域に見られる可能性の高い質問が増えます。  XPのウイルス感染率は最新OSである「ウィンドウズ8」の21倍とされる。 [url=]office 2013 エディション[/url]
    Pass4TestのMicrosoftの70-460試験問題の問題と解答は本物の試験の挑戦で、あなたのいつもの考え方を変換しなければなりません。 そうなるとそのソフトと私のPCの相性が悪いか、他のソフトとの相性が悪い為に起きた可能性があります。
    [url=]office 2016 認証[/url] 明日から新しい勤務が始まり、トレード時間も制限されます。 スペイン語版の Microsoft Insider で紹介されたこの機能は、ブルースクリーンに追加される要素としてはへの字口の絵文字につづいて二つめと言えるかもしれません。
    [url=]office 2016 通販[/url]

  4. #5 by on 23 de julho de 2016 - 3:59 pm

    I paid for it searching for a very good gifts for the mom. The headphone arrived in a striking purple tied up container. This was the best searching present less than your christmas tree!! The headphone always seemed stunning, though my personal mom is actually gigantic boned and headphone are a little tight, but its a great present! I prefer that it.

  5. #6 by on 23 de julho de 2016 - 4:00 pm

    I paid for your looking for a very good present concerning my mom. That headphone emerged within a pretty purple tied up package. This is a looking present under on christmas tree!! Some sort of headphone even looked striking, though my personal mama is actually gigantic boned and the headphone is actually somewhat tight, however it is outstanding gift! I prefer it.

  6. #7 by on 23 de julho de 2016 - 6:02 pm

    I had gotten our gifts of my personal mother to Xmas as she is your jewelry freak. That the one thing she cannot don far of was, bracelets. I purchased the lady that charm bracelet and/or whenever she opened information technology yesterday she absolutley enjoyed information technology! Now the problem was, this girl acquiring information technology concerning and/or off through herself. Haha… overall awesome device, this sent and appeared completely early plus my personal mom is enjoying it. Thank we.

  7. #8 by on 23 de julho de 2016 - 6:02 pm

    I got our gifts to the mother of Xmas as she is letter precious jewelry freak. That the one thing she does not put on much to are, bracelets. I purchased the lady the appeal bracelet and/or when she opened it yesterday she absolutley enjoyed that! Today the issue is actually, this girl getting things on top of as well as down by herself. Haha… on the whole awesome product, that it delivered furthermore came massively early and our mother was enjoying they. Thank shoppers.

  8. #9 by on 23 de julho de 2016 - 6:03 pm

    I have your present to the mother for Holiday due she was one precious jewelry freak. Your something she does not don a lot concerning is actually, bracelets. I purchased the lady your appeal bracelet to whenever she started things yesterday she absolutley liked this! Today the issue is actually, her obtaining things on top of to down with herself. Haha… total very good supplement, that shipped and/or arrived extremely very early then my mother was enjoying that. Thank you.

  9. #10 by on 23 de julho de 2016 - 6:22 pm

    book jake a great situation nicely as. which will be up to (inform Randy Carlyle) when you can see so what so he desires do. we’re feeling there are other people who can satisfy where act actually together with Dion. there’re therapies just can’t produce indicates using the in-class. most of us read and learn the following fragmentary realizing drop by drop simply by Bannister’s “super physical, they knowledges generally knowledgeable with an outstanding from attempts, and thus, they are often considerably more dazzling and even unforgetable.

  10. #11 by amil baba on 23 de julho de 2016 - 6:36 pm

    hello!,I like your writing so much! share we communicate more about your post on AOL? I require an expert on this area to solve my problem. May be that’s you! Looking forward to see you.

  11. #12 by amil baba on 23 de julho de 2016 - 7:32 pm

    Keep functioning ,impressive job!

  12. #14 by on 23 de julho de 2016 - 8:14 pm

    likewise, We need straight into basketball game musicians who? re in the setting sun of the jobs. that is lebron james, Dwayne sort, Kevin Garnett and the list goes on. They’re not getting any one younger so when human straightforward, As we grow up, our bodies is very hard retain not to mention feeling in perfect shape might require higher undertaking.

  13. #15 by vcc mastercard and visa card buy on 23 de julho de 2016 - 8:14 pm

    one of our guests lately proposed the following website

  14. #16 by Jenni Kesselman on 23 de julho de 2016 - 8:28 pm

    coenzyme q10 cream in india

  15. #17 by Marion Humbard on 23 de julho de 2016 - 8:29 pm

    best fat burner supplement for men

  16. #18 by on 23 de julho de 2016 - 9:29 pm

    contest on the other hand develops creating the simple plays, proclaimed McQuaid. together, You can convincingly play excessively simplified. residence witness something, I trying to make the toy. Sandro attached to QPR is without a doubt pushed and also Ashley Westwood accommodation Aston. take pictures of: Ian Walton/Getty ImagesBrazil arena Sandro must have been picked concerning one-of-a-kind positive reviews by- broker Harry Redknapp just after a queen theme park ranger leapfrogged Burnley using the foot together with great category stand on thursday.EPL: Mourinho, Van Gaal take an argument apieceEPL: western pig stun gatwick hometown; manchester put up with undesirable lossThe start Tottenham Hotspur midfielder, what person and additionally caused Redknapp at only caucasian Hart isle to acquire tap out, enjoys fought to increase full well being as of progressing up from north to to the west london, uk on sept. 1,that is the first 90 moments Sandro needs dabbled in.john bowden criticizes pudge rodriguez matter

  17. #19 by Gerald Jandreau on 23 de julho de 2016 - 10:13 pm

    There is noticeably a bunch to realize about this. I believe you made certain nice points in features also.

  18. #20 by visit on 23 de julho de 2016 - 11:31 pm

    Do you have a spam issue on this blog; I also am a blogger, and I was curious about your situation; many of us have created some nice practices and we are looking to exchange strategies with others, please shoot me an e-mail if interested.

  19. #22 by IVC Filter lawsuit on 24 de julho de 2016 - 12:31 am

    Loving the info on this site, you have done outstanding job on the posts.

  20. #23 by Merlene Oslund on 24 de julho de 2016 - 3:56 am

    Many thanks picking the correct to go about this in turn, Personally i think really measurements along with really enjoy researching a little more about the idea market. Assuming feasible, since realise mastery, on earth would you intellect adding to ones own blogging site by way of additional information? This is very useful for us.

  21. #24 by on 24 de julho de 2016 - 5:03 am

    Hiya, I am really glad I’ve found this information. Nowadays bloggers publish only about gossips and internet and this is really annoying. A good web site with interesting content, that is what I need. Thank you for keeping this web site, I will be visiting it. Do you do newsletters? Cant find it.

  22. #25 by on 24 de julho de 2016 - 6:14 am

    great post, very informative. I wonder why the other specialists of this sector don’t notice this. You must continue your writing. I’m confident, you’ve a great readers’ base already!

  23. #26 by tee shirts on 24 de julho de 2016 - 7:21 am

    Great, thanks for sharing this blog.Much thanks again. Want more.

  24. #27 by Chu Bester on 24 de julho de 2016 - 7:23 am

    F*ckin’ remarkable issues here. I am very glad to peer your article. Thank you a lot and i am looking ahead to touch you. Will you please drop me a mail?

  25. #28 by Kris Wheetley on 24 de julho de 2016 - 8:44 am

    Just wish to say your article is as astounding. The clarity in your post is simply cool and i can assume you are an expert on this subject. Fine with your permission let me to grab your RSS feed to keep updated with forthcoming post. Thanks a million and please continue the rewarding work.

  26. #29 by satta matka on 24 de julho de 2016 - 2:32 pm

    usually posts some extremely interesting stuff like this. If youre new to this site

  27. #30 by coremdk on 24 de julho de 2016 - 3:49 pm

    (^^;ブログ エスマック2015/6/30(火) 午後 1:50なんだかんだと利益にしますたね。 それからというもの、診断ツールのファイルは真っ白くなって開けなくなるし、ドキュメントやピクチャーのファイルを開くと、同じような白くて開けないファイルがポコポコ出てきました。 [url=]windows10 販売[/url]
    その前に勤務先のITサポートに相談してコンピュータ全体のスキャンやオフィスのアンインストールとオンライン修復などにトライしましたが、上記の対策法にて今朝、ようやく正常に戻りました。  ちなみに、米戦争屋は配下にNSAをもっており、ネットのサイバー攻撃技術に長けています。
    [url=]office2016[/url]  世界経済は、新興国経済の減速に加え、原油価格の変動の影響は無視できないでしょう。 あなたはPass4Testの学習教材を購入した後、私たちは一年間で無料更新サービスを提供することができます。
    [url=]windows10 os[/url]
    やはり、日頃の運動不足がたたりましたなあ~。 子供五人ずつ産んだ祖父母は四人とも百歳まで生きませんでした。 [url=]office2010[/url]
    安井さん、マイナビ出版さん、ありがとうございます。 幸せな結婚をし、妊娠したばかりの妹が反政府分子として抹殺され、イーオンは政府に対する復讐を誓う。
    [url=]Office pro[/url] 試験番号:70-533Microsoft Azure インフラストラクチャ ソリューションの実装試験概要この試験は、Microsoft Azure でインフラストラクチャ ソリューションの実装経験がある方を対象としています。 JAL123守には戮に≈稍企舶家墓∽や≈ハウス咯墒家墓∽、铜叹参缄の≈轰塑跺∽らも烹捐していた。
    [url=]Office 2016 最安値[/url]

  28. #31 by emogemni on 24 de julho de 2016 - 3:53 pm

    あなたは遠隔測定を有効にし、すぐにデータ収集をトリガする必要があります。 弊社のMicrosoftの070-332日本語受験料ソフトを購入するのを決めるとき、我々は各方面であなたに保障を提供します。 [url=]office 2016 通販[/url]
    ( 各正解は完全なソリューションを提供します。 と、思っていたところに、タブレットだけどWindows搭載のAser Aspire Switch 10 E SW3-013-N12D/WFが登場しました。
    [url=]windows10 ライセンス認証[/url] カーソルをキーボードで好きなところに持って行き、shift+→とかshift+↓で好きなだけエリア選択ができる。 優秀な学歴を持っていても、様々な能力を求められる社会に出た後に対応出来ずに病気になるような若者もいる。
    [url=]windows10 プロダクトキー[/url]
    映画を観ていたので、原著はどうか知っておきたかったのと真実との違いを知りたかったこと。 発端となったのは、ある男性が綴ったブログだ。 [url=]windows10 認証[/url]
    The size of the room will determine how many people can come.部屋の大きさが何人来ることができるかを決める。 「なんちゃってデスクトップPC」からは近々番組再生ソフトの一切をアンインストールすることにします。
    [url=]office 2016 ステンシル[/url] また、このことにより議会事務局の効率化も図られると思います。 それは危険だけど、別の世界があることに気付かないということのほうが危険なこともある。
    [url=]windows7 格安[/url]

  29. #32 by clear skin on 24 de julho de 2016 - 4:42 pm

    Hands down, Apple’s app store wins by a mile. It’s a huge selection of all sorts of apps vs a rather sad selection of a handful for Zune. Microsoft has plans, especially in the realm of games, but I’m not sure I’d want to bet on the future if this aspect is important to you. The iPod is a much better choice in that case.

1 74 75 76
(não será publicado)