# How to get D3DLight spotlight working properly?..eg settings

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

## Recommended Posts

Hi, i'm attempting to use the d3dlight9 spotlight. Except when I do it the light just seems to draw in one spot across my surface. eg See how the arrow is pointing into the darkened part, the triangle is where the pos is, and the point is where the direction pos is of the spotlight I've never used spot lights before, so what settings would i use, if say i have: the surface 300 by 300 points, light at pos (140,140,100) and dir(80,80,0). My current settings are: range=200.0f phi = 6.3f theta = 6.3f falloff = 1.0f pos = (140,140,100) dir = (80,80,0) type = d3dlight_spot diffuse r,g,b,a = 1,1,1,0 thanks

##### Share on other sites
From the docs for D3DLIGHT9:

Quote:
 ThetaAngle, in radians, of a spotlight's inner cone—that is, the fully illuminated spotlight cone. This value must be in the range from 0 through the value specified by Phi.PhiAngle, in radians, defining the outer edge of the spotlight's outer cone. Points outside this cone are not lit by the spotlight. This value must be between 0 and pi.

Could be something to look into...

##### Share on other sites
Theta and phi are specified in radians. So 6.3 radians is about 2 pi. Phi must be between 0 and pi, theta must be between 0 and phi. So use D3DXToRadian(6.3f) if you want 6.3 degrees.

*edit*
Ahh! Beat me to it.

##### Share on other sites
In addition to the cone angle...

Direction I'd expect to be a normalized direction vector, not a point in space. ie: normalize(LookAtPos-LightPos).

I'd also expect that all the colors need initializing, though maybe that's magically occuring if you use C# or something. In C++ you'll want to set EVERYTHING.

You'll need attenuation values, like a point light. Try setting att0 to 1, and att1 (4/range) or so, and att2 to 0.

##### Share on other sites
ive tried normalising the direction vector and everything else that has been suggested.

What else could i be missing?

btw, with the phi and theta, where could i find some info that could actually teach me on how to know to use these values properly, right now im not sure how they work

thx

##### Share on other sites
They are in inner and outer spot light cone angles, in radians.... Theta is the inner cone, and phi is the outer cone. (ie: phi must be >= theta)

A circle has 360 degrees, or 2*D3DX_PI radians. To convert, just rescale. To convert 90 degrees for example:

90.0f * (2*D3DX_PI/360.0f)
or
90.0f * (D3DX_PI/180.0f)

The spot light is at full brightness in the inner cone, and drops to 0 at the outer cone. The curve it follows to drop to 0 depends on falloff.

Open the D3D help, click the index tab, and type "spotlight model". The page there shows graphs of how the falloff values affects things.

• 21
• 13
• 9
• 17
• 13