+ Reply to Thread
Results 1 to 18 of 18

Thread: Really Crappy Lighting

  1. #1
    Senior Member
    Join Date
    Jul 2004
    Posts
    799

    Default Really Crappy Lighting

    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?

  2. #2
    Junior Member
    Join Date
    Sep 2004
    Location
    Vancouver, BC
    Posts
    18

    Default

    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;
    Last edited by Nutter; 10-09-2004 at 12:31 PM.
    Richard Sim

  3. #3
    Senior Member
    Join Date
    Jul 2004
    Posts
    799

    Default

    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.

  4. #4
    Junior Member
    Join Date
    Sep 2004
    Location
    Vancouver, BC
    Posts
    18

    Default

    Well you do have the range set to 500.. how big is the plane?
    Richard Sim

  5. #5
    Member
    Join Date
    Jul 2004
    Location
    UK
    Posts
    94

    Default Your Light Might be too Close to the Floor

    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.
    Last edited by Wayward; 10-10-2004 at 06:00 AM.

  6. #6
    Senior Member
    Join Date
    Jul 2004
    Posts
    799

    Default

    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.

  7. #7
    Member
    Join Date
    Aug 2004
    Location
    Poland
    Posts
    66

    Default

    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.

  8. #8
    Senior Member
    Join Date
    Jul 2004
    Location
    Isle of Wight, UK
    Posts
    3,773

    Default

    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.
    Regards,
    Paul Johnson

    [Great BIG War Game: iOS | Android] [Great Little War Game: iOS | Android] [Fruit Blitz: iOS | Android] [Yachty Deluxe: iOS | Android]

  9. #9
    Member
    Join Date
    Aug 2004
    Location
    Argentina
    Posts
    75

    Default

    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.)
    Mariano Ruggiero
    www.oniricgames.com

  10. #10
    Senior Member
    Join Date
    Aug 2004
    Posts
    173

    Default

    OMG It's another hampster ball game!!

  11. #11
    Senior Member
    Join Date
    Jul 2004
    Posts
    624

    Default

    Look closer.

  12. #12
    Senior Member
    Join Date
    Jul 2004
    Posts
    295

    Default

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

  13. #13
    Senior Member
    Join Date
    Aug 2004
    Location
    Utah, USA
    Posts
    844

    Default

    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.

  14. #14
    Junior Member
    Join Date
    Sep 2004
    Location
    Los Angeles
    Posts
    15

    Default

    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.

  15. #15
    Senior Member
    Join Date
    Aug 2004
    Location
    Portland, Oregon, USA
    Posts
    146

    Default Check your normals too

    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

  16. #16
    Senior Member
    Join Date
    Jul 2004
    Posts
    799

    Default

    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.

  17. #17
    Senior Member
    Join Date
    Jul 2004
    Posts
    295

    Default

    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.

  18. #18
    Senior Member
    Join Date
    Jul 2004
    Posts
    799

    Default

    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.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts