Search Unity

Question How do I build a Tron-like shader?

Discussion in 'Shader Graph' started by Palimon, Dec 13, 2019.

  1. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    Hey all, I'm trying to build a simple asset creation pipeline using extremely low poly meshes and some simple mono-color materials, and then add some neon highlighting on various edges. A simple example would be the Tron carrier:


    The goal is to select which edges have this highlighting, and what color it would be. My thought is that I could add vertex color to a mesh, and, where the vertex color is non-black, a shader will draw the highlighting. After a bunch of playing between Blender and Shader Graph, I've come up with this.


    I mean...it's getting there, right? At this point, I have no idea how to continue. I'm brand new to shaders, and I'm not sure how to get the color to only run along the edge between like-colored vertices. Any help would be greatly appreciated!
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    You might need to add a multipler vector 1 if you want to have glow that you can set above 1.
    The vertex colors are only in 0-1 area but for glowing you most likely need values above 1.
    I hope this will work for your art-style.
     
  3. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    I would use an edge detection shader, will give you less control over which edges have the glow effect though.
     
  4. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    Thanks for the responses. To reiterate, I have no idea to keep the edge highlighting to just along the edge, and not bleed into the rest of the poly. In my image, you can see how the 4 red vertices make the entire top face red? I just want the red on the poly edges. No idea what shader mechanics (or Shader Graph nodes) to pursue towards that goal, and Google isn't being my friend right now.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Shaders don’t really have a way of detecting geometry edges, especially if you only want specific edges. You have to either build the lines into the geometry or use a texture to mark where the lines should be.
     
  6. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    400
    Further to the post from bgolus: maybe try using an external tool to generate a curvature map and use that to drive emission output? There is probably code out there to do that. I would use substance painter as i happen to have that to hand.
     
  7. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    Can't you just render your highlighted parts as another mesh ?

    I assume you don't want to use any textures.
     
    bgolus likes this.
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    You can use one mesh with multiple materials, or use vertex colors to denote the areas that glow. I’ve used vertex colors + vertex alpha to mark areas that I want to be emissive (I.e. glow).
     
  9. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    Can you elaborate on 'don't really have a way of detecting geometry edges'?

    the 'only specific edges' part I get, but there are ways to detect geometry edges right? (depth, normals, color,...)
     
  10. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Not with Shader Graph, or any shader that runs on an object itself.

    Most edge detection shaders are post process effects, which means they run after all objects in the scene have already been rendered, which means the edge detection shader is working on a texture that's basically a screenshot of the camera view. Shader Graph is for writing shaders that run on an object itself. Those shaders only ever have information about a single vertex, or a single pixel at a time and not any information about geometry edges. Technically you can get information about a neighboring pixel in the fragment shader stage using ddx & ddy, but this can't be used for doing edge effects because ... well, it's complicated. If you try to get information about a pixel outside of the single triangle your current pixel is rendering, you don't get information about other triangles, but over-interpolated data from the same triangle.
     
  11. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    In shader graph I manage to get a depthnormals texture, and then sample that and draw an outline on the object itself.

    What am I missing here?
     
  12. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    That’s making things work as a post process of sorts. I also didn’t realize the depth normal texture worked with the SRPs. I didn’t remember it working last I checked (but it’s been a long time).

    It also requires rendering the entire scene an extra time to generate the _CameraDepthNormalsTexture for the LWRP / URP, and probably only works on transparent objects for the HDRP since the later is a deferred renderer and that texture won’t exist until after opaque objects are rendered.
     
  13. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    I only tested it in URP (so yeah forward renderer) and the _CameraDepthNormalsTexture had to be generated by me since it was not provided by the SRP. Thanks for the insight!
     
  14. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    Can you elaborate on what you did here? It sounds similar to what I'm looking to do.

    Currently, I'm leaning towards just beveling the edges and going the one-mesh, multiple materials route. But it'd still be nice to remove any steps possible from the asset creation pipeline.
     
  15. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    I mean, I kind of described the entirety of the process. Use vertex coloring, any place you want to be emissive instead of diffuse set the vertex color alpha to 0%. In the shader multiply the vertex color by it’s alpha for the diffuse, and by one minus the alpha for the emissive, multiplied by some arbitrary factor either hard coded in the shader or set in the material.

    As far as the mesh setup is concerned, could do bevel edges, or inset, or manually cut, whatever you’re comfortable with or like the look of. The main thing is to make sure you’re setting an entire faces to a solid color rather than individual vertices. You need hard edges between the vertex coloring otherwise you won’t get hard edges in Unity either.
     
  16. Palimon

    Palimon

    Joined:
    Apr 18, 2013
    Posts:
    225
    Thanks! Like I said, I'm new to the area, so that's a description I can follow :).