Jump to content
  • Advertisement
Sign in to follow this  

Confusion Moving to Shaders from FFP

This topic is 4885 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

Hey, I am shifting to using shaders from using the Fixed Function Pipeline and I have some confusion on which renderstates are related to using the Fixed Function Pipeline and which ones are necessary hardware setting even when using custom shaders. Specifically, if I am doing alpha testing and blending using the alpha value of the texture pixels it seems that this is handled outside of the shader by setting the following render states: SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); SetRenderState(D3DRS_ALPHAREF, 50); SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); However, how do I do alpha blending if I want to use vertex or material alpha values? Is this done in the shader or through render states? Also, can I do alpha testing using the pixel alpha and alpha blending using the material (I think this has to be handled by the shader). Thanks Todd

Share this post


Link to post
Share on other sites
Advertisement
The color/alpha output from the vertex shader can be used in the pixel shader, or the fixed pipe. The result will be in D3DTA_DIFFUSE for fixed pipe, v0 for pixel shader assembly 1.1, or whatever variable you bind to color0 in your HLSL/CG interface.

The resulting color/alpha from the pixel shader (written to HLSL/CG OUTput value, or in register r0 in asm ps.1.1) is much like the color at the end of the TextureStageState chain. It is this final color/alpha that you'll be doing blending and testing with.

Assuming you're going for standard per-vertex lighting, choosing vertex or material colors is up to your vertex shader. There is no specific "material color" register or constant. You are responsible for programming constants for materials, lights, transformations, etc. yourself. Choosing material color or vertex color is a matter of changing from multiplying the l.n lighting result by either a vertex register or a constant register.

If you're not familar with how lighting works at a "do it yourself" level, you're going to have to learn before shaders are useful to you.

Share this post


Link to post
Share on other sites
Thanks for the help with this.

So, if I understand you properly, to use the material for semi-transparency while still assuming that a texture alpha value of 0 is fully transparent I would do the following in the shaders:

Pass the material values to the vertex shader.
Pass the material alpha from the vertex shader to the pixel shader.
In the pixel shader multiply the texel alpha by the material alpha
Set this value to the alpha component of the output color

And all of the renderstates that I mentioned would still have to be set because that is how the pixel output from the shader will be blended with the final buffer.

Thanks again for the help.
(I understand how to do simple phong lighting in software but am still working on understanding shaders, the D3D API, and their interaction with the graphics card .)

Share this post


Link to post
Share on other sites
Yup, that's exactly how you'd do it.

You can experiment with one shader type at a time to avoid confusion or learning overload. You can do fixed pipe vertex processing and a pixel shader or a vertex shader and fixed pipe pixel processing. This allows you to experiment in one area at a time. You don't have to completely switch to all shaders. On an older machine without shaders this can be an advantage, as you can use software processing to emulate whatever vertex shader you want while still using the fixed pipe for pixel processing.

You might find this other recent post useful

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!