Archived

This topic is now archived and is closed to further replies.

Wintermute01

Alpha Blending using Pixel Shader

Recommended Posts

Hi! I am using Pixel Shader in my current project. I''m still learning all the stuff, so forgive me this stupid question! I''m trying to implement Alpha Blending, but actually I don''t know how to do it... The following Shader should render a 50% transparent green: ''begin shader'' ps_2_0 def c0, 0.0f, 1.0f, 0.0f, 0.5f mov oC0, c0 ''shader end'' But pixels become completely opaque instead! What am I doing wrong? Thanks Christoph

Share this post


Link to post
Share on other sites
Add
SetRenderState(D3DRS_ALPHABLENDENABLE,true);
SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);

Share this post


Link to post
Share on other sites
But doing this he is using the fixed pipeline (T&L), not the pixel shader. This is just as fine, but he should remove the shader - it''s not in use any more.

Sorry if this is obvious



Real programmers don''t comment their code, it was hard to write, it should be hard to understand

Share this post


Link to post
Share on other sites
quote:
Original post by Qpeg
But doing this he is using the fixed pipeline (T&L), not the pixel shader. This is just as fine, but he should remove the shader - it''s not in use any more.

Sorry if this is obvious



I think you may be mistaking SetRenderState for SetTextureStageState here...

I''d suggest taking another look at the D3D pipeline DirectX SDK documentation, in particular the diagram located at (assuming DX9):

DirectX C++ ->
DirectX Graphics ->
Programming Guide ->
Getting Started with Direct3D ->
Direct3D Architecture ->
Architectural Overview for Direct3D

AND

DirectX C++ ->
DirectX Graphics ->
Programming Guide ->
Programmable Pipeline ->
Integration of Pixel Shaders into the Graphics Pipeline

You''ll notice that alpha blending with the frame buffer along with things such as stencil test, depth test and alpha test happen *AFTER* any pixel shader or fixed function texture blending involvement and are *separate* from pixel shaders.

4x500

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Not shure who you are talking to, S1CA, but if its me I need to clear up my previous statement.

What I meant was that the original post got an answer that, I believe, does not fix the transparency problem in the shader program itself. The result may look similar, ofcourse, because (again, I believe) he would be using the T&L to do the alpha blending.
What I wanted to point out, was that the pixel shader was still broken, and that if the T&L blending was satisfactory, he should disable the ps.

Now, I may be very wrong here, but I can not see how
SetRenderState(D3DRS_ALPHABLENDENABLE,true);
SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
can affect the pixel shaders blending attempt! (this is at least how _I_ enable alpha blending in my programs, and I am not using any ps/vs (not yet, at least))

Any comments are welcome, have I misunderstood something here?




Real programmers don''t comment their code, it was hard to write, it should be hard to understand

Share this post


Link to post
Share on other sites