Sign in to follow this  
kosmon_x

Problem lighting quad with point/spotlights

Recommended Posts

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


Link to post
Share on other sites
dave    2187
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 this post


Link to post
Share on other sites
kosmon_x    205
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this