Skip to main content
GameDev.net gamedev.net
🔒 Locked

Lighting textures

Started by peter86 Apr 26, 2004 at 2:37 AM 5 replies 1.5k views
Original Post
peter86
peter86
Is it possible to light textures with "normal" light? or do I have to use vertex shaders? If yes, the how? I''ve tried but it dosen''t seem to work.
peter86
peter86
*BUMP*

Someone must know!
Endurion
Endurion
There are samples in the DirectX SDK and the docs are quite good on that.

Basically you set up a D3DLIGHTx struct, set that light to your device, enable the light, enable general lighting, add normals to your meshes (no normals, no lighting!) and render away.

Start with a simple directional light. No shaders needed.

The general lights are maxed at 8, but you can set and unset lights all the time. They only affect the following rendering.

[edited by - Endurion on April 29, 2004 3:19:13 AM]
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
Nik02
Nik02
If I understand your question:
Enable the relevant texture stage states. The texture operation "Modulate" multiplies the stage arguments together to be passed to next stage or to the framebuffer.
Stage arguments 0 and 1 should be set to "Texture" and "Diffuse" or "Current" respectively. The "Diffuse" parameter is the color that the vertex pipe (the lighting engine, more specifically) has passed forward.

Note that this has nothing to do with vertex shaders, actually - the texture stage function is applied per-fragment (in the same way as pixel shaders).

-Nik

[edited by - Nik02 on April 29, 2004 3:31:34 AM]
Niko Suni
Namethatnobodyelsetook
Namethatnobodyelsetook
Also make sure you SetMaterial... without a material, lighting won't work.

So a summary...
SetLight(0, a filled in d3dlight9 struct)
EnableLight(0, true)
SetMaterial(a filled in d3dmaterial9 struct)
SetRenderState(D3DRS_LIGHTING, true)
SetTextureStage(0, D3DTSS_COLOROP, D3DTOP_MODULATE)
SetTextureStage(0, D3DTSS_COLORARG1, D3DTA_TEXTURE)
SetTextureStage(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE)
SetTextureStage(1, D3DTSS_COLOROP, D3DTOP_DISABLE)
SetTexture(0, pTexture)
Draw[Indexed]Primitive[UP](...)

edit - You've already got yours fixed, but just for the record I wanted to fixed a bug, in case anybody else can benefit... I put the disable in stage 0 too (oops!)

[edited by - namethatnobodyelsetook on April 29, 2004 10:50:50 AM]
peter86
peter86
Thanks alot guys, I''ve fixed it
I just didn''t know that I had to set the "Diffuse" parameter in the texture stages.
Nik02
Nik02
If i remember correctly, some drivers tend to put the Diffuse argument to stage 0 color parameter 2 as the default, even though the DX specification states that Current should be set when the device is created.
Best to explicitly set such parameters, so you don''t rely on dodgy drivers

Sorry about the mis-information; the relevant parameters are indeed 1 and 2 instead of 0 and 1. Parameter 0 is used only in the three-parameter operations, Lerp and Multiply-add as well as in temp reading.

-Nik
Niko Suni

Topic Locked

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

Sign in to reply to this topic.