0

NOTE: This question was originally made as a way to get graph shaders and the Fresnel Effect to work with cubes, however, I only really wanted a glow effect and I thought that graph shaders were the best solution. For me, they were not, I have left a link to what worked for me (to make a glow effect). If you are using graph shaders like I was, use @Kalle Halvarsson as it is a great answer for that. Thanks, cheers!

I was following a Brackey's tutorial on graph shaders (so that I could make a glow effect); https://www.youtube.com/watch?v=Ar9eIn4z6XE&t=604s, and came across a problem where the glow doesn't affect the cube from the front of the camera angle.

Here is a screenshot (im using the same shader as him at the timestamp it links to in the video):

Screenshot

I tried looking around but there doesn't seem to be much at all about this. So simply, is there a way to allow the graph shaders to have a better effect on sharp-edged objects?

To do this we need to somehow make the Fresnel Effect more compatible for front angles, as it is to be meant for reflections, not as much front on glow; https://docs.unity3d.com/Manual/StandardShaderFresnel.html. Or, maybe there is an alternative I mean, I really only need this for 2D so I don’t know.

I don't want to pay for something like MK Glow. Thanks for the help, cheers!

ThatComputerGuy
  • 175
  • 1
  • 3
  • 11
  • Straight Fresnel math will do this, unfortunately. Becuase the triangles are either "perfectly towards the camera" or "invisible" when you hit a corner, there's no faces in between where the Frensel math can operate, except when they're like that top face. The top and bottom of the cylinder work the same way. – Draco18s no longer trusts SE Nov 13 '19 at 14:40

2 Answers2

1

I can think of two methods off the top of my head:

Either, you bake a normal map of the object with smoothed corners. For this, you can use a regular Bevel/Chamfer modifier in a 3D tool like Blender (with a edge angle limit) and bake from the beveled mesh to the non-beveled one (tutorial). Then, you sample the normal map into a world-space normal and use that instead of the vertex normal for the fresnel effect. This is the only way to get a true fresnel effect for these objects. The downside of this of course is that you will have to create these maps for all the models you want to add the glow effect to, and they will need to have UVs.

The other option is to use a Sobel or Robert's Cross post effect for edge detection. There are multiple open source solutions for this on GitHub, like this or this. the larger the sample distance, the softer the edges become. These would have to be ported to Post Processing Stack however, there are instructions on how to write custom effects here. This solution seems to be already ported. The downside of this approach is that it can be hard to isolate the effect to only certain objects - you might have to go with a dual camera or render texture approach for this.

Kalle Halvarsson
  • 1,240
  • 1
  • 7
  • 15
0

I'm going to leave a link to a video that solves all glow problems, it doesn't use shader graphs at all.

https://www.youtube.com/watch?v=5B-JoycbeSg Hope this helps someone!

ThatComputerGuy
  • 175
  • 1
  • 3
  • 11