Edge Detection in Unreal Engine 3

Since my internship in 2K Marin, I have been exposed to a lot of new things that are specific to Unreal Engine. To practice and recap with the edge detection shader I did in GLSL last semester, I made this basic edge detection shader in UDK on weekends. :D

Below is the result when no depth exclusion is applied. The sky dome is calculated too. But usually there’s no need to include the sky in the calculation, because it’s basically……a dome.

No Depth Exclusion

This is the result with depth exclusion. When the pixel depth is greater than a threshold, it will be rendered white.

As shown in the picture, sky’s gone. But there’s still a lot of black on the ground in front of the mountain. I think it’s because in this shader I’m using the same threshold for different pixel depth, and the fact that this specific scene is too big in size. That explains why there’s black pixels at strange places far from camera. The further the pixel depth is and the sharper the view angle is, the difference from the pixel and its neighbor pixels gets larger. If the mesh is really far, the distance could be really large where the shader would consider it as an edge pixel – thus rendering black. A better way to do it, would be using different thresholds for different pixel depth. To test and verify my thought, I used the foliage map that’s included in UDK. This is a much smaller map, and the result turns out good.

Composition with texture.

Material Editor’s a great tool to pull up some cool effects very quickly, but not so much when dealing with math problems. For example, to change the kernel in the shader, in programming language I’d only need to change a few values in the matrix, while in Material Editor I probably need to re-link the add/substract/multiply/divide nodes all over again, just to do the matrix computation.

Anyway, there’s a lot of exploration inside Unreal for me to do! Keep up the spirit! :D

Leave a Reply