Home Unreal Engine

"Rounded Corners" shader - shader authors help!

polycounter lvl 8
Offline / Send Message
Rooster128 polycounter lvl 8
This is yet another shader I've been in the process if trying to figure out. Essentially what it does is average the normals on the edges of two adjacent faces to make it appear beveled or 'rounded'.

There is a patent for it that goes into more detail on how it works, here:
https://web.archive.org/web/20130304090841/http://www.patentgenius.com/patent/8049753.html

Which may or may not make this shader subject to IP rights- but I've seen similar lighting techniques used in many other packages, including mental ray's mia shader for Maya and Max, and a similar setup in Blender. What I'm interested in doing is figuring out how to make this render in Unreal in real time.

The shader works (as I understand it) by creating two vectors at the center of each face- one vector you translate along the face normal upwards just slightly, and one you translate along it downwards (negative) just slightly. From there, you cast N number of rays perpendicular to the face normal.

Depending on if the traces are occurring on either the inwards or outwards vector, the returned collision traces will give you the adjacent concave or convex faces, respectively.

Note: I have no delusions that this can be done in a material itself- it'd have to be code that would pipe parameters into a material)

From here, the application is fuzzy for me. You need to find the edge that both faces share, and then find the distance from any pixel on your face to that edge and weight the normal blending procedure by how close it is to the edge.

I ideally want to have a 'bevel width' attribute to the material, which would effect how much of a very small percentile would be weighted.

So from here, I have a few questions...

1. Is there a way to get an edge list out of a model or BSP? It appears it's possible to get a vertex list ( Rama has been able to do it with his vertex snap plugin found here: https://wiki.unrealengine.com/Rama%27s_Vertex_Snap_Editor_Plugin )

2. Once you can get edges, is it possible to return the closest edge to a trace call and feed that edge into a shader for each face?

From there I think I could figure out how to make this work... It is a bit ambitious, I'm not going to lie. And it could possibly be a HUGE resource hog (two verts and multiple traces from those verts for each face? Ouch.) But the benefit would be having rounded corners without baking, and drastically reducing creation time and poly count on hard surface assets.

An example of rounded corners at play:
8.png

Any help would be appreciated! Thanks dudes!

Replies

  • Der Hollander
    Options
    Offline / Send Message
    Just based on the shot you provided in the image, I can't really see the benefit of this approach. The resulting shader looks like a really bad normal map bake, and it seems like you could accomplish rounded corners with less R&D, bug fixes, and other jiggery-pokery, and having a better looking result just by taking your asset and adding a rounded chamfer to it in the geometry if you're worried about asset creation time.

    Plus, it seems like once you add this material to anything in real-time, as long as the lighting for each model is computed at the same time in your render pass, any and every asset that overlaps in your rendered frame would attempt to interpolate that lighting, even if they're supposed to be separate objects.

    It's an interesting concept, and interpolating across pixels to create roundness is something that gets done for rendering fluids. But, based upon the purpose of their original patent and the image provided, in order to get a decent result you'd still need a lot of geometry, and additional ray calculations piled on top of the lighting pass.
  • Vailias
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    Yeah its a neat idea to save chamfers, but I think it would be much less efficient in a game scenario than just adding in the bevel and baking a decent normal map.
  • Rooster128
    Options
    Offline / Send Message
    Rooster128 polycounter lvl 8
    I was thinking of using something like this for a stylized papercraft look- very angular but with round corners, I saw this as a great opportunity to try it out. Plus, I think it could just save a bunch of time and frustration when making modular pieces with round corners and baked normals- when you want to make one change, it can get ugly pretty quick unless you have a system devised.

    Also tangent-based normal maps will often break when objects are rotated to extremes- I'm thinking this shader might help with that.

    Of course, there are a lot of obvious disadvantages too...
Sign In or Register to comment.