Shader to mow the edges of the cube?

This question is related to the use of shaders (perhaps in Unity3D, but Metal or OpenGL is fine),

to get rounded edges on a mesh minimal cube.

enter image description here

  • I want to use only 12-triangular minimalist mesh cubes,

  • and then through the shader,

  • Ensure that the edges (/ corners) of each block are slightly beveled.

Actually, can this be done using a shader ?

Thanks, shader gurus!

+8
source share
2 answers

I recently finished creating such a shader. The only way it can work is to provide 4 normal vectors instead of one for each vertex (smooth, sharp, and one for each edge of the triangle for a given vertex). You will also need one float3 to detect edges.

To add such data to the grid, I created a custom grid editor that comes with the Playtime Painter Asset from the Unity Asset Store. A shader will be published with the next update. Also will publish the publication of GitHub.

Sharp edge Smooth edge

You can see some dark lines because it begins to interpolate onto a regular vector that is facing away from the light source, but since there are no additional triangles, the result is displayed on the triangle that faces the camera.

Update (2/12/2018) I realized that by cutting off the pixels, which ultimately have a normal back side from the camera, you can smooth out the outline shape. It has not been tested for all possible scenarios, but works great for simple forms: Cropped edges

On request, a comparison cube was added: Cubes with bump mapping

Currently, Playtime Painter has a simplified version of this shader that interpolates between two normal vectors and gives ok results on some edges.

Wrote an article .

0
source

In general, a relief display can change the silhouette of an object, for example, on this . You will need to prepare a height map that falls at the borders and what it is. However, I think that using such a shader might be unnecessary for such a simple effect, so it might be better to just do it in your geometry.

+3
source

Source: https://habr.com/ru/post/973278/


All Articles