Results 1 to 5 of 5

Thread: ClanLib 2.2 Shadow Example

  1. #1
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default ClanLib 2.2 Shadow Example

    I am taking a break from programming for a while

    Here is the work-in-progress in the shadow example.

    Feel free to fix it, to implement shadows.

    The grey scale image in the top right, is the RGBA representation of the depth buffer (rendered to a framebuffer)

    Known problems:
    1) The frame buffer also requires a "Color" buffer, this should not be required
    2) The depth screen should be rendered using an orthographic projection
    3) The real light source (used in the shaders rendering the scene) is not set to the light source object (although not required to get the example to work)
    4) The shaders need to use "sampler2dshadow" to render the shadow



  2. #2
    Serf
    Join Date
    Jan 2010
    Posts
    2

    Default

    I checked your example and it seems that despite the amount of redundant code there are only two things that stop it from working: a rather distant far clip plane and some errors with matrices. I did minimal changes to your code (rev 4197) and was able to get it working. Patch below. Screenshot here.
    Attached Files Attached Files

  3. #3
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Amazing!!!

    Many many thanks.

    It took myself the whole of last week to try to get it to work.

    Looking at the patch, I tried everything except the light far clip plane. I assumed the clip plane can be as large as you want without any side effects, obviously not

    ref the "amount of redundant code there", I had planned to extend the engine to be more generic:
    At the moment it can render a newtek lightwave ( http://en.wikipedia.org/wiki/LightWave_3D ) scene at 20KM radias. (Except it uses collada, instead of lightwave model loader, to make it more generic).
    This includes nesting objects within the scene and changing the camera / light position to become any object. For example, a spotlight can easily be added to become a headlamp on a car.
    Last edited by rombust; 01-09-2010 at 08:26 AM. Reason: extra info

  4. #4
    Serf
    Join Date
    Jan 2010
    Posts
    2

    Default

    Quote Originally Posted by rombust View Post
    I assumed the clip plane can be as large as you want without any side effects, obviously not
    Indeed, it can't. The reason for it is that when you render from the viewpoint of the light, all distances in the range [near_clip_plane; far_clip_plane] get scaled down to [-1; 1]. So in your case you had n=0.1 and f=10000 whereas most objects were approximately 25-50 units away from the light, this means they had a final depth value in the range [-0.995000; -0.990000].

    Now, while writing this, I realized that this range should be enough for shadow mapping to work. Turns out that if you make the z bias in the texture shader even smaller, then having a far clip plane of 10000 will work just fine.

    shader_texture.cpp line 91:
    Code:
    if(sc.x >= 0 && sc.x <= 1 && sc.y >= 0 && sc.y <= 1 && (shadow.z+0.00001) < sc.z)

  5. #5
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Yes, that makes sense. Thanks

Similar Threads

  1. Feature Request - Shadow Direction and Color
    By loken in forum Novashell Game Creation System
    Replies: 3
    Last Post: 01-12-2007, 08:10 PM

Bookmarks

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
  •