Creating A Procedural Rust Shader In Unity?

Hi guys!

Long time no post.

I'm working on a little project that involves a dystopian aesthetic, lots of 3D low poly art and what not. I was wondering (seeing as I have absolutely no clue on how to write shaders or even use the shader graph properly) if there was a way to create a procedural RUST shader of sorts? My thinking is that it should be somewhat possible but I couldn't find anything really upon googling such things. I saw a Brackeys tutorial where he used vector normals and dot products to make a procedural "snow shader" that only targets specific normals and applied a custom texture to it.

Does anybody have any possible idea or even resources I could dive into to find out more about these types of things or even a hands on project file I could look at?

I have a general theory about how I would go about doing it, but have no clue where to start or what maths are involved in doing such a thing. So here is a very crude demonstration of how I see me needing to go about doing it in my mind.

A; you have a mesh
image

B: you target all of the edges and/or vertices within the mesh
image

C: you conjure up a way to expand the edges along the normals of the mesh or create a 'threshold' of sorts
image

D: you have a noise texture
image

E: You apply that texture only to those expanded/highlited edges that have magically expanded based on some sort of threshold
image

F: You add some sort of a colour input to change the colour of the outputed texture
image

So that's how my brain imagines it working. Not sure how accurate (or most probably INACCURATE) this sort of thinking is, but nonetheless this is an effect I'm looking for, rather than texturing each individual object with a rust texture.

Any and all help is greatly appreciated,
Thanks guys! :3
1.jpg
720 x 720 - 31K
2.jpg
720 x 720 - 37K
3.jpg
720 x 720 - 52K
4.jpg
720 x 720 - 72K
6.jpg
720 x 720 - 61K
7.jpg
720 x 720 - 66K

Comments

  • edited
    Yeah, that's about how you'd do it. :)

    Something you might want to ask yourself first is whether this needs to be real-time procedural. There are existing tools that add procedural detail to your textures and then bake them in. (The main ones that come to mind are Substance Painter and dDo, although I'm sure there are others). Unless there's some reason that the rust has to be calculated while the game's running, you most likely just want to go with this route.

    ----
    Now, assuming you really need this to be real-time:

    The "hard" part is knowing where your edges are -- and which the "correct" edges are. There are a few ways of getting this info, but they all have down-sides. The one that likely gives the best visual result is to bake another texture that marks where your edges are. A map that's particularly suited to this is the curvature map, which you can bake in free software like xNormal, or probably any generalist 3D package. It looks like this:
    image

    You can then use either the red or the green channels to mask out whether you want the exposed (convex) edges or the hidden (concave) edges. You can control the tightness of the mask by raising it to some power (although there are other mathematical ways of doing it too, depending on the visuals you're after). If you're certain you'll only be using the one or the other (in convex vs concave), you can save a texture that only has data in that one channel, freeing up your other colour channels for other data you might want to use (e.g. ambient occlusion, metallic, specular or whatever).

    The down-side to this method is that you'd have to bake out a curvature map for every asset that you want to apply this shader to.

    Otherwise, you'd have to find some other way to get that curvature. You could calculate it in a post-process effect (but then your rust is likely to get artifacts particularly when your camera moves around, like wiggling, or growing and shrinking, or appearing where it's not supposed to). Or you could bake the curvature into your vertex colours, but this then requires your geometry to be quite dense around your edges to hold up.

    Once you've got the curvature, the rest of the shader's pretty straight-forward I think.
    Thanked by 2Timothy pieter
  • Oh wow @elyaradine thanks so much for such a detailed and clear description! Well I guess the procedural way isn't really the best way for optimization purposes, guess I'll go with the substance painter route! :) thanks so much for the lesson on curvature maps and baking and what not, will definitely keep it in mind for future stuff. For now though, seeing as it is all just low poly stuff, I guess just throwing everything into substance painter would be the best and easiest route forward.

    Thanks again so much! <3
  • Wow. That curvature map approach is great. I did something similar in the past, but I was using barocentric coordinates to determine the distance to an edge.... there were a bunch of additional challenges in using that approach. I want to go back and try this curvature map approach instead... It makes a lot more sense.
    Thanked by 1Timothy
Sign In or Register to comment.