Unity3d 模拟视锥的实现

一个独立游戏 Teleglitch 使用了一种欺骗手法来模拟视锥,效果如下:

 

博主看了看了看提示

Actually, the line of sight shadows aren’t done with perspective. They are just black polygons extruded from the walls away from the player. The math is similar to black 3d walls extruding towards the camera, but if you really look at them, they aren’t.

原理和卡通渲染挤出边是一样的,

就是把物体沿着视线(玩家)向外挤出一定距离来产生阴影的感觉,

博主没调距离之前的实现效果:


关于距离的调法,不能单单只调整挤出的距离,那样的话阴影会脱离物体,博主根据视线到物体方向与法线进行角度比较,也就是点积,来线性改变这个距离,离得远的拉伸的长,近的基本不动,

最终效果:



另外注意,方向上的比较是世界空间的比较,需要把物体顶点位置变为世界空间的位置。

 

博主近期渲染:

近期渲染

 

                              ---- by wolf96

 

 

 

原文地址:https://www.cnblogs.com/zhanlang96/p/5398045.html