Jump to content
  • Advertisement
Sign in to follow this  
Darthmarshie

Passing SDF occluder data to shader from main game class

This topic is 610 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!

Using a Signed Distance Function shader to create 2D shadows, like this one: https://www.shadertoy.com/view/4dfXDn

What would be the best method to pass the occluders from the actual game to the shader so that the lights know when they're being occluded?

In that shader the occluders are defined like this:

float merge(float d1, float d2)
{
    return min(d1, d2);
}

float boxDist(vec2 p, vec2 size)
{
    vec2 d = abs(p) - size;
    return min(max(d.x, d.y), 0.0) + length(max(d, 0.0));
}

float sceneDist(vec2 p)
{
    //First box at position 100, 250 with size 80*80
    float b1 = boxDist(p - vec2(100, 250), vec2(80, 80));

    //Second box at position 200, 250 with size 40*40
    float b2 = boxDist(p - vec2(200, 250), vec2(40, 40);

    //Combine distances
    float m = merge(b1, b2);

    return m;
}

etc.

The SceneDist function is then called to get the distance from light to occluder and to define the box it just needs a position and size, which could be stored as a Vector4 if necessary. 

So they're defined directly in the shader and the distance from the light to occluder is just returned by calling a function. What's a practical and fast way to get occlusion data from the main game into the shader so that the lights behave correctly? I'm working in XNA, C# and shader model 3.0, but a general explanation would be great too. Obviously defining all the occluders in the shader is not a way to go about things.

 

I'd like it to work on a scale where I could define tiles that occlude light. Maybe I'm approaching this totally wrong?

 

 

Any help would be great. Thanks!

Edited by Darthmarshie

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!