PDA

View Full Version : Really Crappy Lighting



Raptisoft
10-09-2004, 12:14 PM
Hi all,

I've having some crappy lighting problems... consider this screenshot:
http://www.raptisoft.com/FYI/reallycrappy.jpg

Now, I'm using D3D, and here's the code I'm using to set up the light:

mData.Type=D3DLIGHT_POINT;
mData.Diffuse=1.0f;
mData.Specular=1.0f;
mData.Ambient=1.0f;
mData.Falloff=1.0f;
mData.Position=D3DXVECTOR3(x,y,z);
mData.Attenuation0=mData.Attenuation1=mData.Attenu ation2=0.0f;
mData.Attenuation0=1.0f;
mData.Range=500;
mData.Theta=0.0f; // Umbra
mData.Phi=0.0f; // Penumbra

mDevice->SetLight(mLightNumber,&mData);


...no matter how I twiddle these numbers, I can't get a more gradual falloff. Does anything see anything that I'm doing obviously wrong?

Nutter
10-09-2004, 12:20 PM
You're using vertex lighting - that's just how it works/looks. :) The most practical ways around it would be to either use a much finer resolution mesh (more vertices), or use shaders for per-pixel lighting. I'm guessing that the former would suit you better, since the later requires a much higher min-spec and would limit your potential market.

*edit: Ah, re-reading your question I see what you're asking now - falloff, not how coarse the lighting is.
Change:
mData.Attenuation0=1.0f;
To:
mData.Attenuation1=1.0f;

Raptisoft
10-09-2004, 02:19 PM
Thanks for replying, Nutter.

I did try that... but when I do that, I get no lighting at all. It seems that my light doesn't fall off at all, but simply ends on the edge.

Nutter
10-09-2004, 05:49 PM
Well you do have the range set to 500.. how big is the plane?

Wayward
10-10-2004, 01:15 AM
Is your light positioned inside or very close to the ball?

It looks to me like the close proximity of your light to the floor is causing the problem. With a light source that close to a surface you'll get a very bright spot in the centre which falls off rapidly due to the changing angle of the surface to the light.

If your design allows, position your light somewhere higher above the ball and you should get a smoother, more-linear attenuation that is much easier to control.

Raptisoft
10-10-2004, 06:42 AM
Thanks Wayward, that did help somewhat.

Ideally, I *do* want a bright and large fully-lit circle in the center. But then I want a smoother fall-off from outside that. No twiddling of numbers seems to do anything effective.

The surface is 1000 units across-- the light's range is 300. I sort of need the light to be close to the ball because I don't want to light things that the ball goes under, from above.

MirekCz
10-10-2004, 09:49 AM
Depending on your scene, you can change the lighting model.

Just take a texture that represents light fallout and cast it over your surface... if your surface is simple (plane like now or a dyna-blaster like map) then you can easily calculate texture coordinades on this lightmap and cast it on objects as additional texture. Fast and you get nice smooth edges.

Applewood
10-10-2004, 12:16 PM
If all you want to do is light the ball, don't use any sort of dynamic lighting at all.

Draw a texture that represents your fall-off (a disc with bright center radiating out to blackness). Stick this texture on as a second layer (additive blend or mod2x maybe) and make sure it's always aligned properly by using a texture transform matrix at render time.

Night Elf
10-10-2004, 07:23 PM
I'm not an expert in D3D lighting and I've had my problems with it too, but I'll try to help anyway.

The fixed function pipeline in Direct3D calculates attenuation like follows:

A = 1 / (A0 + A1 * D + A2 * D^2)

whrere A0, A1 and A2 are the attenuation constants and D is the distance from the light source to the vertex. This number gets multiplied by the light color before it's applied to the vertex.

As far as I understand, there's no standard set of attenuation values because their effect depends on the light range, which is related to the units you're using in your game (for example, in a game using 1 unit = 1 metre, a 500 units range will be much larger that in one using 100 units = 1 metre.) In your case, when you use (0,1,0) constants, as suggested, the problem is that the attenuation factor gets too small too fast, that's why you seem to get no lighting. I expect a smaller value for A1 would provide better results.

But, if you're looking for a smoother transition, you should give a non-zero value to the A2 constant. For example, A2 = 0.001. You can also combine A1 and A2 values for different effects (more or less abrupt falloff curves.)

Sunshine
10-10-2004, 07:48 PM
OMG :eek: It's another hampster ball game!!

EpicBoy
10-11-2004, 05:20 AM
Look closer.

simonh
10-11-2004, 05:24 AM
What about using a spotlight instead of a point light? Then you could maybe adjust the inner and outer cones to alter the falloff.

Greg Squire
10-11-2004, 01:26 PM
Sorry off topic, but I just wanted to say congratulations to Raptisoft on your FlexArcade deal. (See here (http://www.flexarcade.com/games/game_packs.html)) I noticed it on the flyers at indiegamescon. I’m looking forward to see Hampsterball in an arcade near me. :)

Chigley
10-11-2004, 06:06 PM
Here's a hacky solution .. You could just use 2 lights. A spot a little above the ball, and a point light in or just above the ball. You can tweak the properties of both lights to get the desired effect.

Chaster
10-11-2004, 08:26 PM
Having worked with D3D for waaaay too long, one thing I ALWAYS check is my normals (make sure they are pointed in the right direction and unit length). If they are screwy, they will mess up the vertex lighting giving you very odd results (sometimes like your screenshot)..

Chaster

Raptisoft
10-12-2004, 03:06 AM
Sorry off topic, but I just wanted to say congratulations to Raptisoft on your FlexArcade deal. (See here) I noticed it on the flyers at indiegamescon. I’m looking forward to see Hampsterball in an arcade near me.

Thanks... we're excited about that too. No feedback yet on how it's doing, but we actually have some hope that it will make more money in the arcades than it does on downloads.


Here's a hacky solution .. You could just use 2 lights. A spot a little above the ball, and a point light in or just above the ball. You can tweak the properties of both lights to get the desired effect.

Ye-ees, I thought about this. My concern would be that it would be somewhat slow. HB runs even on a 500mhz machine, and this level (which is going to be a dark one) needs to be very tesselated. I'm concerned about the extra computation necessary.


What about using a spotlight instead of a point light? Then you could maybe adjust the inner and outer cones to alter the falloff.

Same issue as above; I'm concerned about speed at this point.

simonh
10-12-2004, 03:19 AM
A spotlight wouldn't be any slower than a point light would it? As far as I know it's all done in hardware, and speed differences between directional/point/spotlights are negligible.

Even having multiple lights shouldn't cause much of a speed hit.

Raptisoft
10-12-2004, 06:56 AM
Well, Hamsterball avoids hardware T&L whenever possible-- we found that a *lot* of NVidia cards were returning bs stats about whether they could do clip planes, or not. So HB runs almost totally software, except for the actual drawing.

We've sort of come up with a solution that works... makes for a better light circle by using .4 in Attentuation0. However, I fully expect to find that some machine out there interprets this as total darkness, or whatnot. :)

An exciting preview for them that cares: http://www.raptisoft.com/FYI/neon.jpg

What's all this for? Shockwave talked us into-- we're total money whores on this-- addings more content for the Shockwave version of Hamsterball. So if you liked Hamsterball, the Shockwave version will have some new and 'citing races.