Jump to content
  • Advertisement
Sign in to follow this  
RobMaddison

Mulitpass rendering - noob question

This topic is 3319 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm investigating multi-pass rendering using DX9/HLSL. I'd like to render a simple object using two different materials. Each material has its own index buffer meaning there will be one DIP call per material - the materials will blend with each other if they share vertices. After a bit of research on the subject I'm a bit confused about the second pass: I have a brand new blank back buffer. In the first pass, I render the first part of the object in a DIP call using material A. At the edges of the shape, I blend the material out to zero. What then happens with the second/third DIP call for material B/C, etc? Do I need to render each part/material to a render target and pass that on to the next DIP call? or In a pixel shader, can I get at what is currently in the back buffer in order to blend the second material with the first? Is this done with some kind of alpha blending pass state? I know you can draw subsets in meshes but this is a little different because of the blending between materials - plus I'm not using meshes, just a straight forward vertex buffer and two (or more) index buffers. Thanks

Share this post


Link to post
Share on other sites
Advertisement
Generally you do this by setting the blending render states. When AlphaBlendEnable is set to true, your blending equation works like this:


final.rgb = (output.rgb * SrcBlend) [BlendOp] (backbuffer.rgb * DestBlend);
final.a = (output.a * AlphaSrcBlend) [AlphaBlendOp] (backbuffer.a * AlphaDestBlend);


So how it works is the output (the value returned by your pixel shader) is multipled by some value, the current backbuffer value is multiplied by some value, and then some mathematical operation is used to combine these two products. The default for BlendOp and AlphaBlendOp is "ADD", which ill add the two products.

For your case, what you probably want is this:


final.rgb = (output.rgb * 1) + (backbuffer.rgb * 1);
final.a = (output.a * 1) + (backbuffer.a * 1);


This is because with multipass lighting, what you're doing is accumulating the contribution from multiple light sources. Therefore you want to sum the contributions. To get that that blending equation, you'd use the following effect states:


AlphaBlendEnable = true;
SrcBlend = ONE;
DestBlend = ONE;
BlendOp = ADD;
AlphaSrcBlend = ONE;
AlphaDestBlend = ONE;
AlphaBlendOp = ADD;


You can also do other things for you want... for instance with transparencies it's common to set SrcBlend to "SRCALPHA", and DestBlend to "INVSRCALPHA". This allows the alpha channel of your pixel shader output to control the opacity of what you're rendering.

Share this post


Link to post
Share on other sites
Thanks, Matt, that explains it perfectly.

I'm probably going to be using deferred shading/lighting, so I think the backBuffer in this case will actually be a texture after all which will serve as the diffuse buffer. I'll then store the normals in another buffer and so on, so the lighting will be done at a later stage.

Out of curiousity, what does the ONE enumeration actually mean on the xBlend states?

Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by RobMaddison

Out of curiousity, what does the ONE enumeration actually mean on the xBlend states?


It means "multiply the value by 1". So since you just want to add the incoming value and the framebuffer value, you multiply them by one so that they stay the same.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!