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. #1 by guexexw on 21 de outubro de 2016 - 9:38 pm

    台湾Taiwan、中国同胞Chyugugu doshi、ippe-nife-de-bilu!/私はあまりにも嬉しくて言葉が見つからない。 ただし、スポーツスタイルの販売拠点は、3月末時点で、直営店を含む約50店に限られる。 [url=]PING ピンg25アイアン[/url]
    おまけに使えるWi-Fiの回線が無いので、結局スマホのテザリング接続してて、ネカフェに入った意味が全然無かったりしてね・・・・・・。 イメージ的にはドローで打ちたいと思ってはいるのだけれど、なかなか定まらない。
    [url=][/url] しかるべき会員限定のBLOG、ML(メーリングリスト)にご案内します。 ⑤切削荷重は比切削抵抗と切込みと送りの積で求められるが、実際に は被削材と工具切れ刃の接触面の大小で大きく左右される。
    [url=]714 AP2 価格[/url]
    (*^▽^*)ノハーイめちゃくちゃ  楽しかったんですもんこれからも  もっと、もっと    ゴルフ ( ・・)_/ゞ ~゜ (「゜ー゜) オッ! ノッタ!! ( ・ P 楽しんじゃいます~=^_^= 《《《《♪♪(*´▽`*)ノ゛うふふ~。 さらに、森喜朗会長の ❝極めて残念だ。 [url=]タイトリスト スコッティキャメロン セレクト ニューポート2 パター[/url]
    最近の左手伸ばしボディターンスイングの練習に励みます。 LinkedInはブランドとプロダクトと維持し、Micorosoftのプロダクティビティとビジンスプロセス部門の一部となる。
    [url=]PING ピンg25アイアン[/url] LinkedInは200以上の国で利用でき、月間アクティブユーザーは1億500万人だ。 スイングとFWで打っていたシャフトからチョイスされたのがクロカゲXTとスピーダーエボ2でした。
    [url=]ニューポート2 パター[/url]

  2. #2 by Hoverboard Electrique on 21 de outubro de 2016 - 10:00 pm

    fransisco} towards coast city of Eureka found in 1918.

  3. #3 by sell your house fast videos on 21 de outubro de 2016 - 10:22 pm

    I have been reading out some of your posts and i can state pretty clever stuff. I will definitely bookmark your website.

  4. #4 by sell your house fast with pros on 21 de outubro de 2016 - 10:43 pm

    Your place is valueble for me. Thanks!…

  5. #5 by SEO in Oxted on 21 de outubro de 2016 - 11:14 pm

    WONDERFUL Post.thanks for share..more wait .. …

  6. #6 by health in usa on 21 de outubro de 2016 - 11:59 pm

    Hands down, Apple’s application retail store wins by means of a mile. It is really a large variety of all styles of purposes vs a as an alternative not happy final decision of a handful for Zune. Microsoft includes Ideas, specially in just the realm of games, but I am not certainly I would need to have in direction of guess upon the upcoming if this feature is significant in direction of oneself. The iPod is a much much better conclusion inside that situation.

  7. #7 by cash advance montel williams on 22 de outubro de 2016 - 12:16 am

    hello there and thank you for your information – I have definitely picked up anything new from right here. I did however expertise a few technical issues using this web site, since I experienced to reload the website a lot of times previous to I could get it to load properly. I had been wondering if your web hosting is OK? Not that I am complaining, but sluggish loading instances times will very frequently affect your placement in google and can damage your quality score if ads and marketing with Adwords. Anyway I’m adding this RSS to my email and can look out for a lot more of your respective fascinating content. Ensure that you update this again soon..

  8. #8 by SEO in Oxted on 22 de outubro de 2016 - 2:53 am

    I just couldn’t depart your site prior to suggesting that I actually enjoyed the standard info a person provide for your visitors? Is gonna be back often in order to check up on new posts

  9. #9 by The Ranch at Prescott on 22 de outubro de 2016 - 6:35 am

    Very nice post. I just stumbled upon your weblog and wanted to say that I’ve really enjoyed browsing your blog posts. After all I will be subscribing to your feed and I hope you write again very soon!

1 150 151 152
(não será publicado)