问题
I'm making a DirectX 9 C++ application using the fixed function pipeline, given pre-computated lighting for each vertex, (Regardless of normals/etc) how can I apply this to the final image?
I'm currently using textured primitives and I'm trying to change colour as a whole (over the entire primitive -- rather than using a gradient) and I have to precalculate lighting because of the the number of lights and the application being designed to get decent framerates even on low-end machines. (IE one pass per light is one too many)
My vertex struct looks like
struct Vertex
{
float x, y, z, u, v;
};
Basically I want to add a lighting value to that and apply it using the fixed function pipeline per vertex (without using actual "lights")
Any help would be greatly appreciated...
回答1:
I no longer work with fixed function pipeline, as I am using shaders like almost anyone else in the field, I have forgotten the details and I am therefore unable to provide a complete and ready to work answer, but this could hopefully give you a start:
Per-Vertex Color State (Direct3D 9).
You need to use FVF like this:
D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_DIFFUSE
and to enable using the vertex color by:
m_pDevice9->SetRenderState(D3DRS_COLORVERTEX, TRUE);
m_pDevice9->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1);
If you do not want to use any lighting, one option is to use a single directional light with diffuse component black and ambient component white. This way the lighting will be completely flat and only the material colors will be used.
That said, do you really need to be concerned about fixed function rendering? Using shaders it would be very easy to implement this and you can find a lot of people able to give you advice how to do that.
来源:https://stackoverflow.com/questions/4982929/per-vertex-pre-computated-lighting-in-directx9-using-fixed-function-rendering-pi