Sign in to follow this  
David Clark

Rendering RGBA onto RGBA without pixel shaders?

Recommended Posts

Hi, I'm working on a project that involves rendering a quad (with a A8R8G8B8 texture) onto a render target texture A8R8G8B8, and then rendering that texture onto the main surface of Direct X. The only issue I'm having is I need a method of blending a RGBA texture onto another RGBA texture. Using render states I have come up with this method: display.d3dDevice->SetRenderState(D3DRS_SRCBLEND , D3DBLEND_SRCALPHA); display.d3dDevice->SetRenderState(D3DRS_DESTBLEND , D3DBLEND_INVSRCALPHA); display.d3dDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE); display.d3dDevice->SetRenderState(D3DRS_SRCBLENDALPHA, D3DBLEND_ONE); display.d3dDevice->SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_INVSRCALPHA); Which works brilliantly and is exactly the effect I'm after. The only problem is, it only works on my Radeon9800PRO....my poor little Geforce3 is too old and cant do it :( It simply performs the blend using src * srcA + dest*(1-srcA) which works for the colour channels but not the alpha channel...results in a kind of 'washed out' look. My Geforce3 supports pixel shader 1, so one idea I had was to get the pixel shader to perform the blend operation... Another idea I had was to have two textures, one being a R8G8B8 and the other being A8 ( representing the colour and the alpha channel data). When the R8G8B8 renders onto the R8G8B8A8 surface, the alpha channel becomes opaque. However, is it then possible to change the alpha channel of the surface by rendering the A8 texture such that it only modifies the alpha channel data of the A8R8G8B8 texture? Thanks

Share this post


Link to post
Share on other sites
Even without splitting up your textures you can do this:

pDev->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE);
// Set color blending mode
// Render
pDev->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA);
// Set alpha blending mode
// Render

Another simpler, and likely much faster, option would be to use blend mode ONE,INVSRCALPHA and make the last line of the pixel shader "Output.rgb *= Output.A;", effectively doing the SRCALPHA multiply of the color blend by yourself, making the color and alpha blend required on the frame buffer identical for both color and alpha.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this