New dev - How to dynamically grab neightboor/material color for outline post process

Hello everyone! I hope you’re doing ok.

I followed this great tutorial to create a outline post process material https://www.youtube.com/watch?v=9KvUfnrHcqM&list=TLPQMjkxMTIwMjTRafr2u88eyQ and it is working great but what I would like to do is change the hardcoded color I gave it to a group of node or a function that would be able to grab the color of the pixel next to it that is inside the outline and set the color to a darker version of it only for this pixel so tree leaves get a dark green outline, walls get a darker version of their colors etc. Hopefully something dyanamic that can work with multicolored characters/materials/environment instead of a fix of manually setting ONE outline color for each object even if they have more than 1 material and/or color.

While looking for something like this I stumble on that old post and that’s basically what I want. (I have no idea if we can private message others were aren’t friends with here though and couldn’t find the option so that’s why I’m asking here :)) https://forums.unrealengine.com/t/how-to-color-outlines-by-objects-material-color/2159080

Thanks for reading me, have a nice day!

I think you can try to do the following:

  • On the edge, you will choose a base color based on the depth. So the pixel closest to the camera will be used as the edge color.

That’s it. The material setup itself may seem terrifying, but in practice it does exactly what I wrote above.

So the material function I created looks like this:

There is one “thickness” input and an output which is an RGB color. The purple and blue are just named rerouting notes used to clean up messy connections.

Then you just use this function instead of the default colors. You can then divide the color by scalar parameter to darken it or do whatever you want.
This may not be a perfect solution, but I hope it will work for you.