Home Coding, Scripting, Shaders

[Unity Shader Graph] Net Diagram

interpolator
Offline / Send Message
SnowInChina interpolator
i would like to create a diagram shader in unity shader graph, but i cannot find anything on how its made
it should like something like the red line going from point to point

any pointers ?
i could propably do this with c# and the line renderer, but i would like to have it as a shader

Replies

  • Eric Chadwick
    What decides the position of the red vertex along the edge?
  • SnowInChina
    Offline / Send Message
    SnowInChina interpolator
    input value 0-1, the vertex itself doesnt have to get displayed, the graph would suffice
    zero is the middle of the graph, so they have a radial arrangement

  • SnowInChina
    Offline / Send Message
    SnowInChina interpolator
    okay, someone told me a neat trick
    if i create a 7sided polygon and unwrap that in the 2nd uv channel into a rectangle, i can create 7 evenly spaced stripes which i can fade from black to white through the inputs and displace the vertices on their normal direction.
    and then either create an outline shader or something along the line. genius
    gonna try that
  • poopipe
    Offline / Send Message
    poopipe grand marshal polycounter

    The code in the Combining Powers section on this page shows you how to generate the distance field for an ngon
    https://thebookofshaders.com/07/

    At the end he smoothsteps the distance field to get a nice antialiased mask  - if you subtract from the distance (offsetting the zero point) and abs() the distance field you will get a line :
    eg.
       d = abs(cos(floor(.5+a/r)*r-a)*length(st) - 0.5);
       color = vec3(1.0-smoothstep(.0,.01,d));

    this next bit is speculative (as in I haven't tried it)
    To get the wobble you would offset the distance by adding/subtracting from the distance field prior to calculating d  
    The rectangular stripes/texture you have now but converted to polar coordinates  would probably be quite good for that 


    should add that atan is a lot less good than atan2 so if you have the option, always use atan2
  • SnowInChina
    Offline / Send Message
    SnowInChina interpolator
    thanks, but thats too deep into scripting for me
    i can do some c# and have a beginner understanding of scripting, but thats a little bit too much (for now at least)

  • poopipe
    Offline / Send Message
    poopipe grand marshal polycounter
    It's basically doing what you did with the UVs anyway really so probably not a big difference 😁
Sign In or Register to comment.