The way that I create shadows is by the following technique: http://www.catalinzima.com/2010/07/my-technique-for-the-shader-based-dynamic-2d-shadows/

But I have questions to HLSL. The way that I currently do it is, I have a black and white image, where Black means 'object', and white means 'nothing'. I then distort the image like in the tutorial. I do this with a pixel shader, but instead of rendering to the screen, I render to a texture, back to my application. I then take this, and create the shadows, and then send it back to the graphics card to undo the distortion, after the shadow has been added - this comes back and I have a stencil of shadow. I can put this ontop of the original image and send them back to the graphics card, which then puts them on the screen.

To me this is alot of back and forth. Is there a way i can avoid this?

The problem that I am having is that I need to basically go through all positions in the texture 3 times, and use the new new texture every time instead of the orginal one. I tried to read up on Passes, but i don't think that i am heading in the right direction there.



I've studied Catalin's method for quite a while. The problem with this method is that it's pixel perfect. That requires a great deal of work in the pixel shader to function, although with great effect.

A much faster way of creating shadows is via the vertex shader. I tried Krypton and am thinking of adding shadow meshes to my content just to use it. Video


The best you'll be able to do is to have two lights.

You'll notice in one of the later steps, the distortion of horizontal position is stored in the red channel and vertical position is stored in the green channel. The blue and alpha channels are currently unused, meaning that you could essentially perform this shader on two light sources.

It's a really complicated and expensive shader, so I don't think you'll be able to cut out more than maybe one step.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.