着色器可以使立方体的边缘倾斜? [英] Shader to bevel the edges of a cube?

查看:90
本文介绍了着色器可以使立方体的边缘倾斜?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与使用着色器有关(可能是在Unity3D环境中,但是可以使用Metal或OpenGL),

This question relates to using shaders (probably in the Unity3D milieu, but Metal or OpenGL is fine),

在最小网格物体上获得圆角的边缘.

to achieve rounded edges on a mesh-minimal cube.

  • 我只想使用12个三角形的极简网格,

  • I wish to use only 12-triangle minimalist mesh cubes,

,然后通过着色器,

将每个块的边缘(/角)稍微倒角.

Achieve the edges (/corners) of each block being slightly bevelled.

实际上,可以使用着色器吗?

感谢着色大师!

推荐答案

我最近完成了此类着色器的创建.它唯一可行的方法是提供4个法向矢量,而不是为每个顶点提供一个(对于给定的顶点,平滑,锐利并且为三角形的每个边缘提供一个).您还需要一个float3来检测边缘.

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

要在网格中添加此类数据,我制作了一个自定义网格编辑器,它来自Unity Asset Store的Playtime Painter Asset.将在下一个更新中发布着色器.还将发布到公共GitHub.

To add such data in a mesh I made a custom mesh editor, comes with Playtime Painter Asset from Unity Asset Store. Will post the shader with the next update. Also will post to public GitHub.

您会看到一些黑线,这是因为它开始向背向光源的法线矢量进行插值,但是由于没有其他三角形,因此在面向相机的三角形上可以看到结果.

You can see some dark lines, it's because it starts to interpolate to a normal vector which facing away from light source, but since there are no additional triangles, the result is visible on a triangle which is facing the camera.

更新(2/12/2018) 通过裁剪最终以法线背离相机的像素来实现,可以平滑轮廓形状.它并未针对所有可能的情况进行测试,但适用于简单的形状:

Update (2/12/2018) Realised that by clipping pixels that end up having a normal facing away from the camera, it is possible to smooth the outline shape. It wasn't tested for all possible scenarios but works great for simple shapes:

根据请求添加了一个比较多维数据集:

As per request added a comparison cube:

当前, Playtime Painter 的简化版本为该着色器,可在2个法向矢量之间进行插值,并在某些边缘上给出确定的结果.

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

撰写文章.

这篇关于着色器可以使立方体的边缘倾斜?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆