Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The way that I create shadows is by the following technique:

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.


share|improve this question

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

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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