Home Unreal Engine

Detecting Edges in Normal maps in the Unreal material editor

polycounter lvl 13
Offline / Send Message
16bit polycounter lvl 13
I need to make an edge detector for normal maps in the material editor.
I’ve figured out how it would do it in theory. It would look at the Red channel and it will look at each pixel and then it’s neighboring 8 pixels. If one of them is significantly brighter or darker from a certain range that I can set, it will be turned black.
The same would be done for the Green and Blue.
All of this then would be added together and multiplied with the diffuse texture. Hopefully giving me a cartoonish look.
The problem being is that I don’t know how I could tell unreal to check pixels against one another and then to tell it to turn that specific pixel black if it’s true. Or if it’s even possible.

(Edit: don't know why the text was black for.)

Oh, just had an idea. What If I duplicate the texture node and use a uv node to tell it to move over 1 pixel. This would place each pixel over a sample pixel and compare those. I would have 8 copies though. One for each direction that it would have to move. But how would I tell unreal to compare the pixels? I think I would have to use an if statement, but I don’t know how I could tell the if statement how much above or below the pixels next to the sample pixel would need to be for it to tell the sample pixel to turn black.
I don’t know if I explained that well.
Oh wait, how can I tell the uv panner to only move 1 pixel?

Replies

  • JordanW
    Options
    Offline / Send Message
    JordanW polycounter lvl 19
    To check pixels against another you need to offset texture coordinates like you would do to blur an image.
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    And JordanW beat me to my edit. How can I tell it to offset 1 pixel then?
  • JordanW
    Options
    Offline / Send Message
    JordanW polycounter lvl 19
    texture coordinates are 0-1 so you'll have to divide that by the pixels in your image. So for a texture that is 16x16 to offset one pixel you would do 1/16 = 0.0625
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    I figured. But then I'd have to make sure all dimensions are the same.. or make it a parameter.
  • Oniram
    Options
    Offline / Send Message
    Oniram polycounter lvl 17
    if i may ask.. are you trying to do this per normal map so you can have an outline for specific objects? if you want everything to have an outline then there are many multiple ways to do that.
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    A bit of an update. I worked on it when I got him and it seems like it's working.. kinda.

    edge1.png

    It detects the edges.. but only on one side. I understand this is because of the normal map being a gradient and its only picking up on one side of the gradient.

    line1.png

    mat1.png

    Here is my material.
    The only problems that need fixing is that it doesn't really look like an ink line.
    The whole, only detecting one side problem.

    I only used 5 samples instead of 9 to save on memory. Would missing the diagonal sampling do this?

    And it's not to outline an object, just to make ink lines like you would see for muscles in comic books. What are the other ways if you don't mind telling me?
  • divi
    Options
    Offline / Send Message
    divi polycounter lvl 12
    i did something like that in the other direction - making a normal map inside the mat editor from a greyscale image. what makes you think that the red channel is enough for the outline?^try repeating the same thing for the green channel and see if it fixes your problem.
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    Both red and green are used.
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    It's working.. kind of.

    finished.png

    But now it's picking up too much detail. Since this is going to be for a cartoon. I don't know how to tell the editor to only get the bigger changes, and not the smaller details like cracks.

    fixedmat.png

    Also, how can I make it more smooth like a pen and less blocky.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    prolly would be better to just make a new texture map for it.

    take the normal into PS make a cavity map from it with NDO or the xnormal plugins and level it till it is black and white.
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    I have the xNormal plugin for photoshop. But what settings do I use? There are like 8 choices.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    make sure swizzle is set to the same settings you baked with and also check emit blue channel and play with it from there.

    i never used it for this purpose but i do use normal2cavity and the resulting cavity map a lot for for highlighting my edges in the spec map.
Sign In or Register to comment.