Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

EnigmaX

Lighting Spotlights

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

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

Share this post


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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 ?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Yes, please explain.

Share this post


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

Share this post


Link to post
Share on other sites

Ok, here goes the basics.

Normals are used in 3D solely for lighting calculations. They
are always a unit vector, ie: They all have a length of 1.0

For example (1,0,0), (0,1,0), (0.7071, 0, 0.7071) are all
vectors of length 1... sqrt(x*x+y*y+z*z) = 1.0

When DirectX renders a polygon, the normal at each vertex is
used to calculate lighting. The 3 light values are then
interpolated across the polygon as each pixel is drawn.

Normals point outward from the object. Ignoring the front and
back sides, the normals on the top, bottom, left and right would
be 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), and
the back face would be pointing away from you, so (0,0,1). Note
that in order to get a cube lit correctly, you'll need 3 copies
of each corner vertex to hold the correct normals. For example
in the top, right, back corner, you'll need one with a normal to
light the top correctly, one to light the right side correctly,
and one to light the back side correctly. These vertices will
all have the same position, but different normals.

Now, most meshes aren't as hard edged as cubes, and as such you
won't have to duplicate vertices to get new normals. You'll
want the normals shared between faces on a curve. For example,
take this arc. Imagine it's a top down view of a wall, so you
can't see the polygons making it up... but you can see the
normals, as they poke outwards. You want the object to appear
like 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 lighting
values at each vertex will be calculated as though it was a flat
surface pointing in the direction of the normal. Then these
lighting values are interpolated across the polygon giving it a
smooth light change, rather than an abrupt change at each
polygon.
[/CODE]


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
So...

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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!