# Problem lighting quad with point/spotlights

This topic is 4941 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey, I'm having difficulty uisng Point and Spotlights to light a simple quad I've created in a vertex buffer. Basically, the quad will light up correctly if I use a Directional light, however when I switch to point or spot, it will not get lit at all. I know this because I've loaded a *.x mesh and placed it directly ontop of my quad. The mesh will be lit completely with the point/spotlight, but the quad will be solid black. I can move the quad up halfway through the mesh, and the mesh gets cut in half by darkness -- the quad simply isn't getting lit. Here is my vertex structure:
struct Vertex
{
Vertex(){}
Vertex( float x, float y, float z, float nx, float ny, float nz, float u, float v )
{
fx = x; fy = y; fz = z;
fnx = nx; fny = ny; fnz = nz;
tu = u; tv = v;
}
float fx, fy, fz;
float fnx, fny, fnz;
float tu, tv;
static const DWORD FVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1;
};


And here is how I'm creating the quad:
pd3dDevice->CreateVertexBuffer( 4 * sizeof(Vertex), D3DUSAGE_WRITEONLY, Vertex::FVF,
D3DPOOL_MANAGED, &m_VB, 0 );

Vertex* vertices;
m_VB->Lock( 0, 0, (void**)&vertices, 0 );

D3DXVECTOR3 n;
n = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
D3DXVec3Normalize( &n, &n );

// Position          // Normal       // Tex coord
vertices[0] = Vertex( -1.0f, 0.0f, -1.0f,  n.x, n.y, n.z,  0.0f, 1.0f );
vertices[1] = Vertex( -1.0f, 0.0f,  1.0f,  n.x, n.y, n.z,  0.0f, 0.0f );
vertices[2] = Vertex(  1.0f, 0.0f, -1.0f,  n.x, n.y, n.z,  1.0f, 1.0f );
vertices[3] = Vertex(  1.0f, 0.0f,  1.0f,  n.x, n.y, n.z,  1.0f, 0.0f );

m_VB->Unlock();


I then set the material, set the texture, and render using a tranglestrip. What's odd about this is that everything works perfectly when I render using a directional light. However, no matter what I change my normal to, I can't get it to -not- be lit by the directional light. Likewise, whenever I use point/spot, no matter what I set my normal to, it will not get lit at all. Am I missing something obvious here? P.S. My quad is aligned with the X-Z axis and the light is located 5 units up on the Y axis, pointing straight down.

##### Share on other sites
If you are using DirectX lighting then it is done per-vertex. Since your quad only has vertices for its corners the light value is set for these four vertices. The directional light will work simply because it is everywhere, the spotlight would only have an effect if the destination spot covered the entire quad or a particular vertex. The solution to this is for you to build a mesh panel made up of hundreds of quads.

ace

##### Share on other sites
Ah I see where I went wrong.. I scaled the quad out quite a bit to make it a plane, so naturally the vertices were out of range of the lights :)

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633769
• Total Posts
3013754
×