Skip to main content
gamedev.net
🔒 Locked

Fixed Function Functions

Started by RealMarkP Oct 8, 2008 at 1:28 PM 5 replies 1.4k views
Original Post
RealMarkP
RealMarkP
I come from a Fixed Function background. Everything I coded up to this point has used all the fixed function functions that DirectX has to offer to get the job done. What I'm trying to do is refactor my game engine to use nothing but Shaders but I don't know which of the functionality that DirectX offers is Fixed Function and which applies to Shaders. My Shader experience is limited so I don't quite know what shaders replace in the fixed function pipeline. Does anyone know what shaders replace in the FFP? Which functions are still used (ie. Texture, Blend states, render states etc...). Also, if anyone knows any free or open source engines that use only shaders, that would help me greatly. I could learn how its all done. EDIT: I stumbled upon a post that said D3DLIGHT9 is obsolete and is not included in DX10. I'm going to look through the DX10 headers to see what else was removed since DX10 no longer implements the FFP [Edited by - RealMarkP on October 8, 2008 2:27:09 PM]
------------Anything prior to 9am should be illegal.
MJP
MJP
Indeed, the lighting stuff is all fixed-function. So this includes IDirect3DDevice9::SetLight and the corresponding IDirect3DDevice9::SetMaterial. You'll have to do all your lighting and material stuff in the shader code.

Texture stage states are also all fixed function...you still use IDirect3DDevice9::SetTexture to indicate which textures are bound to the device before drawing, but IDirect3DDevice9::SetTextureStageState doesn't do anything when you use shaders. Instead, you'll typically just write your blending operations in straight-up HLSL as part of your pixel shader.

As far as render states, it depends on which state you're talking about. Anything pertaining to lighting and materials won't do anything (D3DRS_LIGHTING, D3DRS_DIFFUSEMATERIALSOURCE). However stuff like the blending mode, z-culling, stenciling, or backface culling will still affect what you do with shaders.


RealMarkP
RealMarkP
So,

- Lighting
- Materials
- Textures

are all mostly obsolete (texture binding excluded), Correct? Is there anything else that can be done in shaders? Fog? View/Projection/World matrix stuff? FVF?

I'm using OGRE, XEngine, and Nebula Device as my resources. But as I thumb through their code, it turns out they use the fixed function pipeline heavily, which is sort of cumbersome since you can do it all in shaders nowadays.
------------Anything prior to 9am should be illegal.
RealMarkP
RealMarkP
I did some more digging and I came across this poster that details out how the DirectX9 pipeline works. Its very informative but I still ahve one lingering question. The Vertex Processing stage has two portions: The Vertex Shader ALU and the Matrix manipuilation and geometry blending, etc. Does this mean that the Vertex Shader replaces all that matrix and geometry stuff to the right of the Vertex Shader ALU diagram?
------------Anything prior to 9am should be illegal.
MJP
MJP
-I believe you can still use pixel fog, since that's done during the fixed-function blending stage after your shaders have run. However vertex fog was part of the fixed-function lighting pipeline, so that's out.

-As far as matrices and transforms, you're on your own. Like you guessed, your vertex shader will completely replace everything on the right side of that diagram. Your vertex shader will basically be given whatever position values are stored in your vertex buffer, and it will then be responsible for outputting a position in clip space. Typically you'll probably just do things exactly as they were done in fixed-function (multiply the vertex position by a combined world-view-projection matrix) but for fancy techniques you could perform any number of transforms. If you'd like can still use IDirect3DDevice9::SetTransform, you'll just have to use semantics to bind your shader constants. They look like this in HLSL:
float4x4 worldMatrix : WORLD;float4x4 viewMatrix : VIEW;float4x4 projectionMatrix : PROJECTION:float4x4 worldViewProjMatrix : WORLDVIEWPROJECTION;

Otherwise you can just use the standard D3DX methods for binding matrices to shader constants.

-I'm not really sure what the design philosophies behind those engines are. If I had to guess, there's probably 2 good reasons I could come up with:
1. Legacy code that has yet to be replaced
2. For older GPU's and probably a lot of integrated chips, fixed-function is still the performance path.


RealMarkP
RealMarkP
Thanks for the detailed answer. I have a fairly good idea which functionality is replaced by shaders. I'm assuming that since the vertex shader portion replaces the Matrix stuff, similarly the Pixel shader also replaces all the texture stages, bump mapping, specular effects, etc.
------------Anything prior to 9am should be illegal.
MJP
MJP
Quote:
Original post by RealMarkP
Thanks for the detailed answer. I have a fairly good idea which functionality is replaced by shaders. I'm assuming that since the vertex shader portion replaces the Matrix stuff, similarly the Pixel shader also replaces all the texture stages, bump mapping, specular effects, etc.


Yup, that's correct. Your pixel shader code will control which texture you sample, where you sample them, and what you do with the texture data once it's sampled. Then once you're done you simply output a 4-component vector indicating the red, green, blue, and alpha values to be placed in the render target.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.