Let's talk about image convolution
Convolution in image processing is transforming an image by applying a kernel to each pixel. A kernel is a convolution matrix or a rectangular array of numbers or functions. each pixel is assigned a value that is multiplied by the corresponding kernel, then the sum of the neighboring pixels determines the new value of the pixel. this is the process used for almost every basic photo editing (blur, sharpen, emboss, outline, Sobel etc.)
Convolution exists in UE as a way to control bloom in post-process volumes. it has also been turned into material by YouTube Martin Baadsgaard. his convolution material set is free to download so I did just that. upon inspecting the material I've learned that it's a 2D material powered by a custom node. because this is set up for a 2d material, I need to find a way to make it compatible with a screenspace so that it can be used as a post-process volume.
the issue here comes from the two texture nodes at the bottom of the main material, as they are 2D, when making a post-process material you need to use a scene texture node, so it can reference whats in front of the camera. a scene texture is not a float4, not compatible with 2D nodes. so I thought that I'd have to change some things in the custom nodes.
It's hard to see but everything that's yellow/gold is a constant2. One "fix" I found for this is to replace every constant2 with a constant, however, constant2 uses x and y values, and constant4 is RGBA, so I don't think that (while its technically compatible with scene texture) this would apply the kernels to the screenspace correctly.
SO! We're making another material from scratch, lets go.
My goal with adding convolution processing to the scene is Edge detection, this was supposed to be taken care of by the Sobel function when we made the Kuwahara filter, but one of three things happened, 1. it's not working
2. I didn't do it right
3. it works perfectly I just don't like how it looks.
Overall I just don't think the Sobel function made a visual difference so why use it. I also tried to fix edge preservation using a cel shader, which made the edges more noticeable, but overall darkened the scene. It's also more expensive, what I came up with was a lot of "if/then" statements which is fine but your computer would have to "if/then" 10 times for every pixel. I made another shader I called toon with a more node tree
 |
| toon nodes |
 |
no effect
|
 |
| toon shader |
 |
cel shader
Comparatively, the toon shader does a better job of preserving edges but has some weird aliasing in flat surfaces. It also has the darkening issue.
Anyway, convolution. I found a tutorial for a post process edge detection that is based on/uses kernals.
to start, set up another post process material and make sure your scene is using custom depth stencil, with enable with stencil turned on, then add scene texture nodes with vector masks to create the basis that with determine the center pixel.
|
 |
| on their own, these nodes with break the meshes down into 3 colors |
The kernel values for the effect created in the tutorial are
so basically the next step is we multiply the uvs by each other these values then add them back up. side note, the Sobel function is a type of convolution, and the settings for it are as listed
So, hypothetically i should be able to duplicate this shader and adjust the values to get a working sobel function
The kernel values go into the B input of the multiply, the A input is the scenedepth inverse, then the muliplys become the a input for another set of multiply nodes, and the B input is connected to a constant parameter with a value of 1. those multiply nodes then feed into the be input of add nodes, the a input is connected to texture coordinates.
Next is a lot of duplicating, for read add node you need to duplicate the screen depth and normals. connect the add to the uvs for ever scene texture.
Once you have multiple scene depths set up, add them together, then multiply the center pixel function by 4, and divide the final add node. then you can connect this to the final material (the sensitivity and distance thing isn't needed, it just makes it render out more realistically, with less detail in the distance.). to finish create a standard post-process scene texture and connect it to a lerp with the final subtract value.
 |
the final outcome looks like this!
this is what the edge detection looks like with the other shaders.
SO! it looks better, but I'm thinking maybe I need a way to sort these filters. create some sort of hierarchy that way they aren't getting lost within each other. So my goals now are - add color variance
- mask player from filters
- create filter hierarchy?
- combine all volumes into one huge filter
|
Sources
Comments
Post a Comment