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
{
if(isClip)
clip(input.clipping.x);

return tex2D(DiffuseSampler, input.texturecoord);
}

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

, , , , , ,

  1. #1 by Earlie Ochsenbein on 27 de setembro de 2016 - 9:34 am

    I more or less share your opinion on this topic and look forward to additional posts and comments here at ploobs.com.br. Keep up the good work!

  2. #2 by katana on 27 de setembro de 2016 - 9:56 am

    Very fast shipping, which is always great!

  3. #3 by недвижими имоти on 27 de setembro de 2016 - 10:17 am

    Aw, this was a really nice post. In idea I would like to put in writing like this additionally – taking time and actual effort to make a very good article… but what can I say… I procrastinate alot and by no means seem to get something done.

  4. #4 by Malia on 27 de setembro de 2016 - 10:43 am

    Hello. fantastic job. I did not imagine this. This is a excellent story. Thanks!

  5. #5 by Booker on 27 de setembro de 2016 - 10:56 am

    Yesterday, while I was at work, my cousin stole my apple ipad and tested to see if it can survive a twenty five foot drop, just so she can be a youtube sensation. My iPad is now destroyed and she has 83 views. I know this is totally off topic but I had to share it with someone!

  6. #6 by japanese swords on 27 de setembro de 2016 - 11:06 am

    Really QUICK shipping! Thank you!!! A+++++

  7. #7 by concrete molds for sale on 27 de setembro de 2016 - 11:11 am

    Do you have a spam problem on this site; I also am a blogger, and I was wanting to know your situation; we have developed some nice methods and we are looking to trade solutions with others, be sure to shoot me an e-mail if interested.

  8. #8 by http://vonradio.com/lovebracelet.html on 27 de setembro de 2016 - 11:11 am

    Your headset ended up being because breathtaking like inside picture. That it arrived quickly. I’d suggest using a towel above each and every coating while you press they off w / any steam iron. It doesn’t vapor out among only a steamer. Their iron is important. It is very fragile, so if you don’t trust your self with the towel and/or steam iron, then need that to a certified. Awesome appear.

  9. #9 by Tsukas on 27 de setembro de 2016 - 1:06 pm

    Love it ! Juste comme décrit !

  10. #10 by jananese katana sword on 27 de setembro de 2016 - 1:06 pm

    J’ai été très heureux avec l’ article et l’expédition rapide … merci !

  11. #12 by Nike Air Max courtbAllistec on 27 de setembro de 2016 - 1:54 pm

    Lin Ruoxi put out his finger and held his forehead and smiled: you are you, the flowers are flowers, how could the same breath

  12. #13 by tag bagagli Louis Vuitton on 27 de setembro de 2016 - 2:24 pm

  13. #14 by erfahren on 27 de setembro de 2016 - 4:02 pm

    Als sie im Raum war, schlüpfte er wieder ins Bett.

  14. #15 by katana SAKABATO on 27 de setembro de 2016 - 4:02 pm

    Excellent Seller , expédition rapide , je recommande vivement aimeraient acheter à nouveau

  15. #16 by brazilian body wav on 27 de setembro de 2016 - 4:25 pm

    We really like this kind of brazilian body wav https://www.youtube.com/watch?v=T6hp4Ndf7vU!This does not have any a lot easier as opposed to which will! 😉

  16. #17 by http://www.oceanoverde.org/files/utilidades/foro/temp/689.html on 27 de setembro de 2016 - 5:34 pm

    Recieved this particular item before the time presented in a very good present package . That photo that is presented for bracelet is what you will definitely recieve. That is quite sensitive still a awesome piece to jewelry which will final as iof all toggle clasp which is very robust so that the bracelet eill maybe not come off.

  17. #18 by http://swsociety.se/wp-content/themes/responsive/core/code/246.html on 27 de setembro de 2016 - 5:35 pm

    This is an awesome present towards ones family. I’d strongly incourage people to buy this it will make a very good gift. The actual transmitter performs a great evening work at buying some sort of stuff on instant. I purchased my products everyday ago and I also reveived it certainly quickly.

  18. #19 by http://www.actulite.com/c-jewelry/c-bracelets on 27 de setembro de 2016 - 7:56 pm

    Your headset ended up being just as breathtaking just as in photo. They arrived promptly. I’d recommend utilizing a towel during every layer while you push that out w / your steam iron. It does not steam outside using merely a steamer. On iron is appropriate. It is very fragile, so if you do not trust your self aided by the towel and steam iron, well choose they up to a certified. Stunning seem.

  19. #20 by apply singapore pr on 27 de setembro de 2016 - 8:05 pm

    Great post!

  20. #21 by steven matz jersey on 27 de setembro de 2016 - 11:03 pm

    Sorts of write-up Think carefully about the sort of ship you usually get. In the event you tend to get hold of mainly regular bigger envelopes throughout the post then you don’t need to to decide on a huge and often dearer style. In the event you frequently receive opportunities throughout the place it can be a decent investment for you to opt for a safe and sound mailbox with a strong container on the other hand.

  21. #22 by Nike Air Max shopping on 27 de setembro de 2016 - 11:08 pm

    All these lonely North Mu blame themselves, that is their own trouble and make yourselves celadon celadon is the reason that man, she is not going to blame the Yin nine nights, but she will blame myself.

  22. #23 by visit on 28 de setembro de 2016 - 1:34 am

    Here is a great Weblog You may Obtain Intriguing that we Encourage You

  23. #24 by Kaka on 28 de setembro de 2016 - 3:08 am

    Great internet site you’ve gotten in here
    Kaka http://wiki.humansvszombies.org/index.php?title=User:AveryPettey435

  24. #25 by Philipp Lahm on 28 de setembro de 2016 - 3:08 am

    You’re an extremely valuable web site; couldn’t make it without ya!
    Philipp Lahm http://pakvillage.com/modules.php?name=Your_Account&op=userinfo&username=QXEHuey294

  25. #26 by Pele on 28 de setembro de 2016 - 3:08 am

    Wow cuz this is really excellentexcellent job! Congrats and keep it up
    Pele http://www.tzxdd.net/comment/html/index.php?page=1&id=224745

  26. #27 by such a good point on 28 de setembro de 2016 - 3:09 am

    marriage counselor yelp chicago

  27. #28 by Moupqla on 28 de setembro de 2016 - 3:30 am

    74-343試験の対象となる受験者は、Project Standard 2013、Project Professional 2013、Project Pro for Office 365 のデスクトップ機能 (Project Server 機能を除く) の使用者です。 最近のマクロウイルスの役割「ダウンローダ」復活したマクロウイルスの役割の1つは、外部ネットワークからWindows向け実行ファイル(拡張子 .exe)をダウンロードしてきて起動する ダウンローダ です。 [url=http://solidiphy.com/16922/office2013_1/index.html]office 2013 認証[/url]
    そのため今年上半期に《REAL》が金秀賢の全てだと言っても、少しも過言ではありません。 すると、非商用で個人ユースなら殆どの機能が使えるムービー編集ソフトの「VideoPad」が見つかりました。
    [url=http://gastrofreunde.de/16922/office2013_1/index.html]office 2013[/url] エアコンのツイートがちょっとしたことでスマホやPCに上がってくるのはうるさい。 他の人は自慢気に言わなかった所を見ると、トップだったみたいです。
    [url=http://solusiukm.com/16923/windows7_1/index.html]windows os[/url]
    1801年 – フランスの天文学者ジャン=ルイ・ポンが初めて彗星を発見。 #12時間の飛行機となり、まず間違いなくお通夜には出席できないです。 [url=http://optymex.ru/wp-content/16922/windows10_1/index.html]windows10 販売[/url]
    我が家のパソコンには、ろくなソフトが入っていないということかも。 PCの番組表が見づらいのでiPadで録画するの探した方が全然やりやすい。
    [url=http://solidiphy.com/16922/office2013_1/index.html]office 2013 アカデミック[/url] この辺、光害があるし、雲もあるし、水蒸気もあるので、こういうのって実は苦手な部類です。 サーフィンをしていれば、波高がたったの『60cm』程度でも、相当な力があることを実感します。
    [url=http://stcmi.org.sg/16923/windows10_1/index.html]windows 10 無料[/url]

  28. #31 by guexbif on 28 de setembro de 2016 - 5:42 am

    Office無し版にはOneDriveが100GB(2年間)付いていました。 新任研修の時、コンピュータやタブレットの映像を映す以前はOHPとか言うプロジェクタを使っていたと講師の先生が言ってました。 [url=http://www.somecco.biz/somegolf/somegolf_1/index.html]golfoffjp.com[/url]
    一方、日本のアシックスは2001年度と2015年度の売上高を比較すると3倍以上になっており、高い成長率を示していますが、現在のナイキの売上高はアシックスの約9倍というのには驚かされます。 AserのIconiaは、すでにツクモでは取り扱っていない。
    [url=http://www.rtcnet.co.jp/rtcnetgolf/rtcnetgolf_1/]mb 714[/url] もし不合格になる場合は、ご心配なく、私たちは資料の費用を全部返金します。  びっくりしたのは、一応査定してもらったSONYのPC「VAIO VGN-Y70P」のお値段。
    [url=http://wina-riva.pl/winagolf/winagolf_1/index.html]タイトリスト スコッティキャメロン セレクト ニューポート2 パター[/url]
    無料サポートは終了しているから、企業はwindowsにお金を払ってセキュリティの面倒を見てもらっている。  だからある程度金づちを釘から離すまで持ち上げる。 [url=http://voice-fan.net/voicegolf/voicegolf_1/index.html]テーラーメイドバーナー2.0アイアン の特徴[/url]
    今回は、簡単で便利なUSBメモリーに落とす手順です。 パソコン,ウェブ関連の不具合や故障は、いろいろ調べても結局原因がわからない場合が多い。
    [url=http://futava.com/sarugplf/sarugplf_1/index.html]g25アイアン[/url] チリパウダーは辛くはなくて、ココナッツミルクのまろやかな風味にシーフードの旨みがたっぷりで、これがすっごく美味しくて赤ビーツゼリー(ジェレイア・ジ・ベテハーバ)ブラジルではポピュラー野菜の赤ビーツ。 (笑)昨日は、少し雨が降りましたが、あっという間に真夏日に。
    [url=http://voice-fan.net/voicegolf/voicegolf_1/index.html]激安ゴルフクラブ[/url]

  29. #32 by book of ra casino on 28 de setembro de 2016 - 7:36 am

    the time to read or check out the subject material or sites we’ve linked to beneath the

1 131 132 133
(não será publicado)