Help with thinking through a shader setup

If I was to try and do the following scenario:

Imagine 100 objects floating around the screen. When they intersect, the colour is intensified. Not overly interested in how to achieve the actual effect, but rather the setup.

Would a seperate shader be applied to each object? Would that be completely inefficient? Or would a shader be applied to a single background object that would render the final result?

How would the presence of many objects be able to contribute to the overall result in a shader on a single large object?

Really having trouble thinking this particular scenario through.

Comments

  • Well the setup relies heavily on the effect you want to achieve.
    In the case of having colors intensify with overdraw, using additive blending might be a good start.

    Other than that, having a shader per object will not help you much as all you'll have is the content of the object itself, not the content of the target surface. A full screen effect (usually called a postfx) would be the way to go.
    You can even combine additive blending and a postfx shader to remap the color range, for example.

    If you have a more precise effect you'd like to achieve, I'd be happy to try to give a better advice on it.

  • Thanks Iarwain. Ok, yes so additive blending (or a better one) is ultimately what I'd like to achieve.

    Based on the above, one large object as my render area for my result shader is the way to go.

    So the next step, how does the 100 similar objects floating around, and their textures influence what goes on it the shader? We have parameters for shaders in the orx config but I imagine I can't create a hundred parameters. That would be silly of course.

    But the shader needs to take the texture and position information of each object and use it within itself to make the calculations. That's the next step.

  • edited June 2019

    Well, actually what you want to do is probably something along the lines of:

    • Use a grey scale version of your image, let's start with just using a single component (Red) and take a simple image with a single color in it, your image would have a color of RGBA(0, 0, 0, 0) for background and RGBA(1, 0, 0, 0) where your object is defined
    • Render all your objects to a temp texture
    • Render that texture to your world (via an impostor object) using your shader, that shader will map red 0-255 to the scale of your choice (remember that values are normalized floats in a shader though, so the range 0-255 will become 0.0-1.0)

    And that's about it.
    Now if you simply want to have objects get brighter when they overlay on top of each other, a simple additive blend might do the trick. An example can be seen in the 2nd screenshot of the compositing tutorial:

Sign In or Register to comment.