Search Unity

How to "dim" transparent areas of the URP simple lit shader?

Discussion in 'General Graphics' started by DroidifyDevs, Apr 4, 2020.

  1. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    Hi!

    So here is what my model looks like from the side:
    upload_2020-4-4_15-38-34.png

    But when looking at it head on, it's quite confusing:
    upload_2020-4-4_15-39-46.png

    Therefore, what I'd like to do is have the area between the glowing blue lines much darker, instead of transparent. That way, when looking through multiple "folds" of the same mesh, the parts that are farther away are darkened, or almost invisible.

    These are my current shader settings:
    upload_2020-4-4_15-41-0.png


    Here you can see that while it is dimming the cube, it is NOT dimming itself. The blue lines, no matter how many times they're obscured by the mesh, are still just as bright when they're far away.

    With the emission map texture, I've tried making it in Gimp to make the space between the lines 50% opacity, however, it seems to have no effect.

    What should I do to make the transparent parts of this shader dark?

    Thank you!
     
    Last edited: Apr 4, 2020
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    My guess is if you view your mesh from the other end it'll work like you want.

    The order the triangles are listed in a mesh determines the order they're rendered in. For transparent surfaces, if objects are rendered "front to back" (closer objects before further objects) than the further objects won't appear to be affected by the closer objects because GPUs are just rendering transparent objects over whatever else has been rendered before. The same is true for single meshes. If you can make sure the triangles in the mesh are ordered furthest to nearest so that it renders "back to front" than the closer surfaces will render "over" the further ones, dulling them as you would expect.
     
    DroidifyDevs likes this.
  3. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    Wow that was bang on:
    upload_2020-4-7_15-12-44.png
    That's viewing from the other side - EXACTLY the effect I wanted. Thank you!!

    So now I need to figure out how to procedurally generate a mesh while making the triangles order backwards... interesting! :)

    EDIT: Turns out this was really simple. Just do vertices.Reverse() but keep the triangles in the original order.
     
    Last edited: Apr 13, 2020
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The other option you might want to look into is to use Shader Graph to fade the brightness by distance from the camera and just using an additive blend rather than alpha blend. That way the “tracks” can fade without darkening the rest of the scene.
     
  5. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    That's a great idea too... for now I'm trying to figure out wheel colliders for the game so I'm not sure what "vision" I have for it yet. I was initially planning to have the whole track visible but kind of transparent, I needed it to darken though so the glowing lines don't look so messy when looking at them head-on. I also am planning to add ramps and a lot more sideways tilting and curves so the procedurally generated levels are much more interesting and less "vertical" feeling. I think I want the player to be able to see the whole track ahead of them so they can plan accordingly and it looks cooler instead of fading it by distance, but again this might change!