Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: [D3D] smooth lightning

  1. #1

    [D3D] smooth lightning

    Hi all.

    Today i started to build some lightning-support in my engine, the only problem is that the edges of the litted area are quiet sharp (see picture).



    When i try some Attenuation values, the light seems to dissapear (sometimes only a small litted dot is visible).

    Vertex density should be OK, its a 32x24 segment plane. each segment is 20x20.

    Does anyone know how to make the lightning smoother :?

    P.S: This is my first picture of my engine in action, maybe i'll post some more later. :razz:
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  2. #2

    [D3D] smooth lightning

    I don't think you can make lighting smoother by any means if you want to use vertex lighting. I would personally go with perpixel lighting but i have no idea how to implement that in d3d
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #3

    [D3D] smooth lightning

    I don't know anything about D3D, but if this is simple vertex lighting, you could use a DotProduct. Depending on the angle of the vertex to the light, it will receive the appropriate lighting shade. ie, smother blend from light to shadow .

    If you need a bit of code, I'll see what I can do.

  4. #4

    [D3D] smooth lightning

    First you should understand these docs/presentations:
    one
    two
    three

    And after reading them - come back and ask questions about implementation
    It would be great if you specify on what kind of hardware you would like to implement per-pixel lighting: DX7; DX8/9 ps.1.1/ps.1.4/ps.2.0; assembler pixel shaders or HLSL?
    There are only 10 types of people in this world; those who understand binary and those who don't.

  5. #5

    [D3D] smooth lightning

    dang it! K4Z is completely right! it should ofcourse look much better than that by the way you are doing it..

    Do you remember to set the normals?
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  6. #6

    [D3D] smooth lightning

    I think this should be possible without perpixel-lightning. You can get quiet good results with per-vertex-lightning when vertex density is high enough (and i think it is in this case )

    but this is even stranger:



    This supposed to be a point light but it looks like some sort of spotlight pointing to the bottom-right corner.but despite its weird shape, it IS smooth
    Here is the code i used:

    [pascal]
    ZeroMemory(@light,SizeOf(TD3DLight);
    light._Type := D3DLIGHT_POINT;
    light.Diffuse.r := 3.0;
    light.Diffuse.g := 3.0;
    light.Diffuse.b := 3.0;
    light.Position := D3DXVector3(0,0,20);
    light.Range:= 500.0;
    light.Attenuation0 := 0;
    Light.Attenuation1 := 0.2;
    Light.Attenuation2 := 0;
    Graphic.D3D.SetLight(0, light);
    Graphic.D3D.LightEnable(0, True);
    [/pascal]

    This just doesn't make any sense, can someone tell me what's goin on?? :?

    First you should understand these docs/presentations:
    one
    two
    three
    Wow.. that's a whole lot of math for a teenager. Do i realy need to understand it all to use per-pixel lightning (i'll try PP lightning if PV lightning doesn't seem to work out ).

    I don't know anything about D3D, but if this is simple vertex lighting, you could use a DotProduct. Depending on the angle of the vertex to the light, it will receive the appropriate lighting shade. ie, smother blend from light to shadow Wink.
    Hmmm :think: this can be a good option, but i rather let the video-hardware do the job (not my CPU)

    Does someone have an example wich demonstrates a point light or can someone explain the picture above??

    EDIT// the previous picture i posted shows a circle like it should be, unfortunatly i dont know how to reproduce it anymore :cry:
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  7. #7

    [D3D] smooth lightning

    do you remember to set normals? and are those per-vertex normals and are they normalized?
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  8. #8

    [D3D] smooth lightning

    You can find fixed-function lighting example named "Lighting" here in big archive with all DirectX SDK samples for DX 8.1. On page you can find some small description. Basically example allows you to change light types, turn on/off wireframe rendering, etc.
    There are only 10 types of people in this world; those who understand binary and those who don't.

  9. #9

    [D3D] smooth lightning

    Per-Pixel Lighting would probably be over-kill for your needs.
    From what I've seen, D3D lighting model is pretty restrictive, and to gain complete control you should just override it.
    Depending on your scene, software lighting shouldn't be too bad, though look into 'Vertex Programs' (I think D3D calls them that also) for pretty much no frame loss.

    Hmm, but anyway, if your happy to stick with D3D lighting...That second picture looks familar to a problem I had. Will need to see some more code to be sure, but from an OpenGL view (D3D is pretty much the same), make sure you are in fact using a point light instead of a spotlight.

    And most importantly, make sure you are (re)setting the light position every frame, ei, if you rotate or translate the entire scene, the light might not be exactly were you think it is.

    and third, as Jsoftware said, make sure you set your normals correctly, and they are in fact 'Normalised'.

    That's all I can think of at the moment

  10. #10
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    [D3D] smooth lightning

    Maybe it could be your vertex normals. I had sort of the same problem with my engine.
    NecroSOFT - End of line -

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

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