开发者

Direct3D 9 Shadow Mapping Blend Mode

I am currently trying to draw shadows over a scene in direct3d 9. I am trying to do some multi pass rendering and am having trouble understanding how to use/set the blend mode.

I have done a depth pass w开发者_开发知识库hich fills the depth buffer and I then have a loop which loops through all the lights in the scene. Within that loop I have 2 loops which both loop through all the shapes in the scene

I have this sort of set up

for(number of shapes)
{
  //render from camera position and fill depth buffer
}
for(number of lights)
{
  for(number of shapes)
  {
    //render to shadow map
  }
  for(number of shapes)
  {
    //render to screen
  }
}

In pix I can see that it loops through each light but when I run it only the last light in the light array is displayed. I think it is something to do with the blend mode.

I have looked into the blend mode and found information about source and destination blend. Is this what I need/could someone help explain it please?

Thanks in advance,

Mark

[EDIT] I got both lights visible using the following code

hr = device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
hr = device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
hr = device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

The shadows do not look correct but I am getting closer to the desired result.

Any more advice would be great,

Thanks,

Mark


I also think that you have wrong alpha blend states set. I assume that you do a SRC blend and replacing your old image with the new one and not doing any alpha blending. You need to think about what you want. I assume that you want a SRC_OVER blending.
The Porter Duff rules can give you a hint and they are very easy to implement in directX. For an example look here.
[Edit] I should read more carefully.

Alpha blending and pixel shaders are independent. So you can of course use the pixel shader to change the color value of your source. Maybe to add some special effect or what ever you want to try. But as soon as you want to blend your source over a destination and you don't want to replace all the pixels with new ones, you need to enable alpha blending. E.g. like this

hr = device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
hr = device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
hr = device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

This code will multiply all source pixels with their alpha value and all destination pixels with 1-source_alpha. And combine them to the new destination.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜