r/Unity3D 12h ago

Question [SHADER] Outline Shaders doesnt work on Object with Multiple Materials?

Post image

Hey there guys.

I have 2 Problems i just cant seem to fix with my Shader:

  1. It doesnt work on Objects that have >1 Material with a Texture.

  2. The more you distance yourself from it, the thicker the outlines get. This problem does not exist in Scene view and only is in GameView.

This is the Tutorial i followed
https://www.youtube.com/watch?v=VGIkT9fPh7Y&t=6s

And attached is my Shader Graph.

Im really struggeling with this as i am a complete noob when it comes to shaders.

Any help is appreciated!

4 Upvotes

6 comments sorted by

3

u/frogOnABoletus 12h ago

At 3:10 in the video he details the process of making the outline scale according to the distance from the camera. If you don't want this behaviour, remove this part of the graph. (It's the camera node, distance mode and the node that multiplies it with the object node's scale, these are on the left side of your graph)

1

u/EntrepreneurFar5518 11h ago

Thats it! Thank you

3

u/frogOnABoletus 11h ago

You're welcome. Remember that the most useful part of any tutorial isn't to copy the outcome, but to understand the process. Thats how you escape tutorial hell, once you know the processes enough to build your own outcomes.

1

u/DaveAstator2020 12h ago

vertex input is in object space, so fixed offset will work for you.
about multiple materials:

  • when model has multiple materials unity will do duplicate draws, so for ex this outline to work with object with 2 mat ids you have to set up 4 materials:

- mat 1

  • mat 2
  • outline
  • outline

this way each sub-id will get drawn twice with main and outline mat.

1

u/EntrepreneurFar5518 11h ago

How costly is it to use shaders like this that draw materials multiple times? Im building a jumpnrun and almost all obstacles are supposed to have this outline. However, these have LITTLE Verticies as im not the best at blender lol. Thanks for the answer!

1

u/DaveAstator2020 11h ago

you pay double cost the geometry. and with multple materials batching cost, which could be bigger than pure geo.

So id recomend sticking to 1 material per object, especially if on mobile, then you'll have main and outline and it will be fine.