Lighting Spotlights

Started by
14 comments, last by EnigmaX 21 years, 2 months ago
Hello, I''m trying to make a spotlight show up on a simple triangle on the screen (black in a blue background). I''m trying to make a white spotlight show on the triangle, not light the whole thing. Here is the triangle: pVertices[0].position = D3DXVECTOR3 (-1.0f, -1.0f, 0.0f); pVertices[0].normal = D3DXVECTOR3 (-1.0f, 0.0f, 0.0f); pVertices[1].position = D3DXVECTOR3 (1.0f, -1.0f, 0.0f); pVertices[1].normal = D3DXVECTOR3 (1.0f, 0.0f, 0.0f); pVertices[2].position = D3DXVECTOR3 (0.0f, 1.0f, 0.0f); pVertices[2].normal = D3DXVECTOR3 (0.0f, 0.0f, 0.0f); Here''s the struct for it: struct SpotlightTriangle { D3DXVECTOR3 position; D3DXVECTOR3 normal; }; I tried going though the Direct3D tutorials and it didn''t explain it like I wanted. =/ I''m not entirely sure the normals are right either. Any small little code to just light the triangle with a SPOTLIGHT light would be appriciated. Thanks alot
Advertisement
You can''t get a spot light on a polygon. D3D lights vertices only, not the individual pixels on the polygon. You can get the spotlight''s brightness at each of the three points, but that''s it.

And yes, your normals are wrong. Very wrong. I''m not going to get into the details...
quote:Original post by Namethatnobodyelsetook
You can''t get a spot light on a polygon. D3D lights vertices only, not the individual pixels on the polygon. You can get the spotlight''s brightness at each of the three points, but that''s it.

And yes, your normals are wrong. Very wrong. I''m not going to get into the details...


Where can I find tutorial about normals ?
Could you explain ?
Yes, please explain.
Here''s how you calculate the normal:
vector a = vertices[2] - vertices[0];
vector b = vertices[1] - vertices[0];
normal = crossproduct(a, b);

Search google for vector math tutorials if you want to learn more.

Proceeding on a brutal rampage is the obvious choice.
___________________________________________________________Where to find the intensity (Updated Dec 28, 2004)Member of UBAAG (Unban aftermath Association of Gamedev)
Ok, here goes the basics.Normals are used in 3D solely for lighting calculations.  Theyare always a unit vector, ie:  They all have a length of 1.0For example (1,0,0), (0,1,0), (0.7071, 0, 0.7071) are allvectors of length 1... sqrt(x*x+y*y+z*z) = 1.0When DirectX renders a polygon, the normal at each vertex isused to calculate lighting.  The 3 light values are theninterpolated across the polygon as each pixel is drawn.Normals point outward from the object.  Ignoring the front andback sides, the normals on the top, bottom, left and right wouldbe as follows: +-X    |     (0,1,0) (0,1,0)         Y        |       |(-1,0,0)--+-------+--(1,0,0)          |       |          |       |          |       |(-1,0,0)--+-------+--(1,0,0)          |       |       (0,-1,0)(0,-1,0)    The front face would be pointing towards you, so (0,0,-1), andthe back face would be pointing away from you, so (0,0,1).  Notethat in order to get a cube lit correctly, you'll need 3 copiesof each corner vertex to hold the correct normals.  For examplein the top, right, back corner, you'll need one with a normal tolight the top correctly, one to light the right side correctly,and one to light the back side correctly.  These vertices willall have the same position, but different normals.Now, most meshes aren't as hard edged as cubes, and as such youwon't have to duplicate vertices to get new normals.  You'llwant the normals shared between faces on a curve.  For example,take this arc.  Imagine it's a top down view of a wall, so youcan't see the polygons making it up... but you can see thenormals, as they poke outwards.  You want the object to appearlike a smooth curve, even though it's just a bunch of triangles. +-X            |             (0,0,1) Z                |  (-.5, 0, .87) __+__ (.5, 0, .87)            +-~~     ~~-+           /             -          /               -         +                 +     (-.7,0,.7)            (.7,0,.7)When DX draws the polygons with normals like these, the lightingvalues at each vertex will be calculated as though it was a flatsurface pointing in the direction of the normal.  Then theselighting values are interpolated across the polygon giving it asmooth light change, rather than an abrupt change at eachpolygon.



[edited by - Namethatnobodyelsetook on January 21, 2003 10:09:12 PM]
So...

D3DXVec3Normalize() just basically scales it down to 1 unit?
quote:Original post by Anonymous Poster
So...

D3DXVec3Normalize() just basically scales it down to 1 unit?

yes
To add one more thing: if you really want a spotlight on an individual triangle, you must tesselate the triangle. Tesselation means that you break one big triangle into many little triangles. In this way, D3D''s per-vertex lighting will show the spotlight correctly, as it will calculate the lighting for many different points on the large triangle.

Firebird Entertainment
“[The clergy] believe that any portion of power confided to me, will be exerted in opposition to their schemes. And they believe rightly: for I have sworn upon the altar of God, eternal hostility against every form of tyranny over the mind of man” - Thomas Jefferson
a good way to immitate spotlights over a lot of geometry is a projected texture, it will show on everything that you render with the projected texture stage on (provided its within the projection matrix of the texture) and it can be pretty fast if you can multitexture it well.

This topic is closed to new replies.

Advertisement