- Home /
Border overlapping shader
Hi!
I'm using Vectrosity to draw circles as borders around units but there's a small issue. I want the borders to be invisible where they overlap (as shown on the image). I'm thinking i need to add a material with a special shader to vectrosity, i'm just not good with shaders, so is there already a shader that does this or do i have to work something out? Is there any other/better way to do this?
I can't just create the borders "overlapped" because the units are moving so at one time they should cover each other, other times the whole circle needs to be rendered.
Answer by Pangamini · Dec 15, 2016 at 10:06 AM
There are many ways how to achieve what you want, but the question is, why do you need to use Vectrosity for it? With just drawing circles you have no information about the inside of the filled circle, so you can't really do much there. Also you didn't give many details on the specific usage inside your project, so it's hard to tell what would be the best approach
Quick sketches for 2 different solutions that crossed my mind now:
Render each inner circle to a stencil; use the stencil in line renderer to get the insides discarded (should work with Vectrosity, if you have a way how to render the inside - filled circle)
If you are aiming for a glow like effect (like in Left4Dead), you could render objects (circles, spheres whatever) into a separate buffer, blur it, subtract by the original non-blurred value (keep it in alpha or somewhere) and then just blend with the main RT
Vectrosity seemed the cleanest way to draw different sized circles (like radar ranges that can change the radius) with the same border width. The circles are actually not filled, i just need to draw lines. See Endless space solar system borders but without the fill.
First sketch sounds somewhat like what i need, i just don't know how to render to a stencil.
Ok i looked into the stencil and i should be able to figure something out. Looking at the pictures here seem to answer something similar.
Thanks for letting me know about this.
Also, there are better ways how to render a circle with uniform width than doing it with complex geometry. For example, I use a shader that can render a circle on a quad. There are no input textures, the shader simply takes the UV, calculates the distance from center (squared, sqrt is expensive :) ) And renders the circle based on that value. Then you can use advanced techniques utilizing ddx and ddy to make the edges of the circle smooth independently from the geometry size - meaning that the smooth edge may always be 2 pixels wide on your screen - making it a superb solution for antialiasing of these circles. Also, no geometry is required, so the circle will be as perfect as it can be, no matter how big the circle and your screen is. Just a food for thought.
Interesting thoughts... I'll have to learn more about shader coding before i start messing with this.
Your answer
Follow this Question
Related Questions
Are there any 'ghost-like'/smokey shaders for a line material? 0 Answers
How do you write a flexible wireframe shader with backface culling? 1 Answer
How to force the compilation of a shader in Unity? 5 Answers
Add Light To Shader 1 Answer
Is it possible to pass SubShader tag as a parameter? 2 Answers