• Advertisement
Sign in to follow this  

Problem lighting quad with point/spotlights

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

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( 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;

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 );

	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 );


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 this post

Link to post
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.


Share this post

Link to post
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 :)

Thanks for the reply!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement