Archived

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

Direct X 9 lighting along with HLSL shaders

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

I''m curious if anyone knows if it is possible to continue to use Direct X''s software vertex lighting and a HLSL vertex shader at the same time? I want to to use the shader for various effects like environment mapping, different material textures, etc. and the standard DX9 per-vertex lighting calculations are good enough for me right now. I haven''t seen anyone talk about this before, so I''m not sure if it''s possible or not, or even desirable. I''m targeting 1.1 vertex shaders, so my choices are kinda limited for handling things like a large number of lights in the scene, etc. The idea situation would be the shader to receive transformed vertex properties AFTER the DX9 lighting engine has done it''s thing. --- http://www.gapingwolf.com

Share this post


Link to post
Share on other sites
No, they cannot be mixed. If you use a vertex shader, you must do lighting yourself. A workaround to this is to do multiple passes, some with shaders, some without (though the math ends up slightly different and the pixels aren''t necessarily at the same depth).

Having said that though, doing lights isn''t too hard. Directional lights are just a couple instructions, and a half dozen more if you want specular (vertex specular looks bad, so I''m assuming you don''t want it, especially since you want env maps, which can do the same thing, only nicer).

The next question is whether you really need shaders or not. Env Mapping can be done with setting the texcoordindex to one of the D3DTCI_* defines, such as CAMERASPACENORMAL. CameraSpace normal mixed with a transform matrix which just does a scale 0.5, and translate 0.5, is all env mapping is. In DX9 they have added D3DTCI_SPHERICALENVMAP (or something like that), which will do the scale/translate for you... I''m not sure if it works on all hardware, so stick with the normals.

And what do you mean by different material textures. You can use many textures, and blend them if a variety of ways with the fixed pipeline. If it doesn''t fit your needs (it''s rare to actually need the 1.1 pixel shader) you could make a pixel shader, but that''s independant of the vertex shader, and lighting will continue to work. SetTextureStageState is where to look to see how to use and mix a variety of textures.

Share this post


Link to post
Share on other sites
Looking over my intentions for the game''s graphics engine, I''ve come to realize you''re right. I can emulate most of this stuff using multi-texturing instead of relying upon vertex shaders.

Primarily, I am wanting to create certain specular effects using VS/PS, but I realize now that gloss maps could achieve the same effect. I''m just not sure how to use them. I understand that the gloss map should modulate the environment map, and then be added to the base texture -- but I haven''t figured out how to express that in texture stages yet.

---
http://www.gapingwolf.com

Share this post


Link to post
Share on other sites