Per vertex pre-computated lighting in DirectX9 using fixed function rendering pipeline

感情迁移 提交于 2019-12-11 14:06:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!