Sunday, 2nd November, 2008

Custom pixel clipping in HLSL

Filed under: GPU Shader, Games, Virtools, Virtools Tutorials, Tips and Tricks — dominique @ 11:26

Friday I was composing some object shaders and integrated them into the project. At some point we realized that under-water objects where reflected as they were above the water although I was using clipping panes. I thought I screwed up something but an idea made me check everything without the shaders and I found the trouble maker: the default shader of virtools is setting ClipPlaneEnable to zero! 

:-(

After the initial shock, I thought: interesting, can it entirely be setup and used inside the HLSL technique definitions? Soon I dropped that idea, because I would have to do technique-switching and that requires manual bookkeeping as Virtools offers no help with that. So how could I get back my correct reflections?

I thought about an old workaround I did somewhen in end 2006 or early 2007 but for this scenario it wouldn't work. This time I really would need some kind of "texkill" instruction that I did not found back then. And you know what? The HLSL counterpart is

Clip(x)

Probably you all already know about that, but for me it's my new best "HLSL  friend"! :)

All fine now 8)

(Btw. in regards to the default shader, it might be a better idea to omit that state overwrite. Don't know how this is helpful in the way it is right now. )

Bookmark and Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • Digg
  • Reddit
  • Google Bookmarks
  • YahooMyWeb
  • Live-MSN
  • Facebook

3 Comments »

  1. Hey Dom :) Thanks for the info, someday i'll get around to digging into hlsl enough to actually understand what it was you just typed out lol.

    Comment by vsai — Sunday, 2nd November, 2008 @ 11:52

  2. Yes, Clip() is cool ! I used it for exactly the same purpose. The only drawback is that all the objects you want clipped, need to be rendered with a shader that performs the clip. In the end I only used it in a scene that already used an image-based lighting shader (by Oliver). How do you distribute the shader across all scene objects ? Just wondering how a pipeline-minded guy like you tackles that.

    Comment by Patrick — Monday, 3rd November, 2008 @ 12:37

  3. We do automatic imports and processing on our assets. Shaders are assigned in this process using rules.

    Comment by dominique — Monday, 3rd November, 2008 @ 01:42

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .

Bookmark and Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • Digg
  • Reddit
  • Google Bookmarks
  • YahooMyWeb
  • Live-MSN
  • Facebook