Results 1 to 31 of 31

Thread: VB: Advanced Lighting and Shadowing (Tutorial)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    VB: Advanced Lighting and Shadowing (Tutorial)

    Source + Exe coming as soon as its done.


    All lights are realtime and the fps is good (50 fps uncompiled, 8 objects, 2 lights and I havent optimized yet). The lighting is perpixel lighting and the shadows are the only things slowing down the framerate, the perpixel lighting is actually very efficient.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    Exe is done, I just have to clean up the source a bit before I also post the source.
    Link to exe

  3. #3
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    In the first image the box near the centre should be illuminated on three sides but it appears to be only two on the image. Looks a bit odd. Also on some other boxes the shadows are actually cancelling out some lit regions. Or am I reading it wrong?
    I don't live here any more.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    In the first pic, there are only 2 lights. The shadows cancel out the lit areas where the lights meet, where the light is full intensity, the shadow wont cancel out.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Re: VB: Advanced Lighting and Shadowing (Tutorial)


  6. #6
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    The shadows shouldn't fall on the boxes? I mean... shadow should go on another box only if it is shorter than the box that makes the shadow. Though, I guess this is more of a 2D... but in that case a shadow should never go on top of another box afaik. It just looks weird and unrealistic.

    Of course other than that it is great, though I didn't take a look in the source

  7. #7
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    I think merri is right, the shadows dont look too good.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    Well I could modify the shadows so they are under all the boxes (that was my old method) but that doesnt look nice, even if it looks more realistic.

  9. #9
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    well lets see it like you said above

    No one is having a go, the work looks good and we are just trying to help you make it look better

    Pino

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    Er... I cant put it back without writing a whole new program(just tried), the shadows and lights are both drawn on the same buffer, the objects onto another and they are multiplied, with the output on the backbuffer.

  11. #11
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    Here you have a sample of what is somewhat should look like:



    You can clearly see what is the problem when you compare it to the screenshots: the more lights, the more shadows, but the more shadows, the lighter they are: except in the places where there are shadow on shadow. The light strength should also be taken into account, a stronger light surpasses a weaker one and makes shadow to the area of a weaker one.

    I'm not an expert in this area, but I've thought about lights and shadows in the dark nights when I've been walking from a light to another in the street
    Attached Images Attached Images  

  12. #12
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    Merri, what you get up to on the streets at night is your own business j/k.

    I don't think the problem lies with shadows being on top of boxes or not, the fact is that if the shadow engine was more realistic then that effect wouldn't occur at all...

    I think the first picture would look more like this... (the grey areas would be in light, the black areas in shadow, I haven't bothered with gradients)

    Since the middle square is being lit from 3 sides, then only the 4th side can be in shadow, and not as in the original pic. I omitted a couple of boxes for clarity.
    Attached Images Attached Images  
    I don't live here any more.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    If anyone could modify the code I did and show the updated code, that would be really nice. What I do is, for each light, all the shadows are subtracted from the light and then the light is added onto the lightbuffer.

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    By using 2 lights, 1 object and the same code I uploaded (only difference is number of lights & objects), I position the lights at 0,0 and 640,0 and the object at 320,240, I get the following

    Looks correct?

  15. #15
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    yea that looks good.

    Pino

  16. #16
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    Yeah, but you should make it take other objects into account At the moment it works somewhat correctly to one object (it seems), but the first screenshots up there were odd. What happens when you include another object near the other one??

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    It gets partly shadowed

  18. #18
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    Lets see another screen?

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Re: VB: Advanced Lighting and Shadowing (Tutorial)


  20. #20
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    Yup, it gets distorted. For example, it seems that it can make a shadow on a light source. There should be no shadow on a light source. The shadows should get weaker when close to light. And as stated already, the shadows should cut out when they go on another object (they do cut out now, but in the wrong edge).


    Humm... I played around with a flashlight. I think I got the real problem now: your lights are in the same level as the objects. When I placed a flashlight in the same (ground)level with the object, it didn't make any shadow. So, you should also know how high your lights are compared to the objects. This way you can do more accurate shadow and also calculate where the shadow ends (and where extra light should be made).
    Last edited by Merri; Jun 15th, 2005 at 07:54 PM.

  21. #21
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    259

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    What version of D3D and what VB version is this? you peeked my intrest.
    i may tap your brain later when i move on to lighting.

  22. #22

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    D3d 8.1, Vb6

  23. #23
    New Member First.Assassin's Avatar
    Join Date
    Jun 2005
    Location
    South Africa
    Posts
    4

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    The reason why it looks strange is because the shadows are extending too close to the light sources.

    The shadow generation seems perfect but after the shadows are generated they are not lit up enough by the light source. Look at the picture and see those shadows right close to the lights, they should be much fainter if not invisible.

    The red areas show where it is too dark too close to the light

    The blue rings show how far the light should extend where no shadows form and from then onwards shadows should get gradually darker.
    Attached Images Attached Images  
    Last edited by First.Assassin; Jul 17th, 2005 at 02:26 PM. Reason: addition

  24. #24
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    Anyone else get a automation error when you run it? Haven't had time to look into why its happening but think its not being initalised properly for all cards.


    As for the problem its seems from the pics that when you generate a shadow from one light you don't take into account any other lights at that time. Would probably mean taking a different approch, instead of using each light and applying it to each pixel then the next light ect. you could go through each pixel once each and calculate its light value. That sounds like it would be a rather big rewrite so i guess you could go back to how you've done it using each light at a time but when doing each pixel cross referance it with other lights. This might result in still a one pass situation but could be rather processor hungry too .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  25. #25
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    One way would be to use a midpoint, which would be the highest light. I'll explain this a bit better:

    values 0 - 127 = black to white
    value 128 - 255 = "too bright to see the brightness", are always considered to be white

    Now what does this give to use? You got it: the possibility to have too big values! But why? This would be a small "override" to the problem mentioned by First.Assasin. It would give you the power to control easier what would be the point where shadow turns out to be invisible. The lights would be stronger and not weak as they are now.

  26. #26

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    I tried it, it looks washed out. If someone could edit the code and post the results, that would be good.

  27. #27

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    Update: I am working on a new version with stencil shadow volumes (much more faster) and I am trying to make the light fade using a 1D .bmp (1x256), i'll post it as soon as im done.

  28. #28
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    Sorry I was meaning to post this but forgot about it ...

    I think I figured out why it was looking wrong, the way you are doing it is starting with white and then turning the pixels darker where the shadows are cast....if you go at it the other way by starting with black and lighten the pixels where the lights fall it will give the correct/natural effect .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  29. #29

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    That is what Im trying to do but it looks about the same so im trying to use a 1D texture as the light texture. Ill post more once I get it working.

  30. #30
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: VB: Advanced Lighting and Shadowing (Tutorial)

    Think about this: what happens when a light source goes up and down?

  31. #31

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Re: VB: Advanced Lighting and Shadowing (Tutorial)


Posting Permissions

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



Click Here to Expand Forum to Full Width