unity3d软阴影和硬阴影的原理_Unity实现简易体积光/体积阴影

6b15028c851f5592403e68a8f6e8c1cd.png

有玩过《杀戮地带:暗影坠落》的小伙伴可能会对游戏里的体积光影有很深刻的印象,感觉开发人员在设计画面的时候非常想要突出体积光以及横向的高光,使得游戏画面很有特色。其使用的体积光影之多甚至让我产生了“光污染”的感觉,本文就来简单的实现一下这种朦胧的效果。

f4d12456bdb3d51033749c8ad1d854d3.png
99b25fd4343e1682dde7952099a07094.png

刚接触渲染时就被下面这些大佬的实现惊艳到,这里也用到了许多里面的技巧。

CSDN-专业IT技术社区-登录blog.csdn.net

MaxwellGeng:Unity3D实时体积光zhuanlan.zhihu.com37cc90909d45384ed39a9648b83cc6dc.png

介绍:

光线传播时照射到尘埃或者水汽会产生散射效果,产生雾蒙蒙的感觉。

本文介绍在前向渲染下简单的实现平行光的体积光效果,采用了后处理的方案。

丁达尔效应_百度百科baike.baidu.com3c2cf0a42502873f7a56b727af3035da.png

主要思路:

通过光线步进(ray marching)将点/坐标沿着视线前进,每次前进判断该点是否在阴影中,这样经过若干次的前进,我们就能知道当前像素点在看到最终位置时会经过怎样的光影信息,这样就可以对该像素的明暗进行操作,在光或者影上进行操作。

实现:

先预览下开启体积光影的效果,对比如下:

a9d2273cedcd61df54befd62b55daa56.png
原场景
19b9391302022823a2a3bd8206a43546.png
体积光
3427a6376944c91a7d36be13aec62dcc.png
体积阴影
ff81febaaf524c0edbff2b183b132c37.png
体积光+体积阴影

1.采样阴影信息

首先我们需要一个方法来知道某个点是否是处于阴影中,对于平行光的话如果了解unity自带shadowmap的实现就能知道可以通过对比灯光空间的shadowmapTexture深度和该点在灯光空间的深度作比较来获得阴影信息,可以参考以下资料:

Rendering 7catlikecoding.com5664eea5cd9f7dfd205c6b3c2b118713.png

需要注意这里阴影级联 (Shadow Cascade)选择了无,注意如果开启了多个的话采样阴影算法需要调整,大家可以自行修改。

d61226c09574b2ca54faf1b0f156356f.png

下图是输出的是当前像素对应的阴影信息,和直接看到默认的阴影信息一样。之后我们只需每个点都照这样获取阴影信息就行。

6659b9e79e3a670e51a36d1ea66a4892.png

2.进行步进

ray marching参考资料如下:

1. Why Ray Marchingwww.jianshu.com72ba2d890e4f82e36b46c4dccd385681.pngfractals, computer graphics, mathematics, sh

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
For those that do not know me: My name is Jacco Bikker, also known as 'Phantom'. I work as '3D tech guy' at Overloaded, a company that develops and distributes games for mobile phones. I specialize at 3D Symbian games, which require highly optimized fixed-point, non-HW-accelerated 3D engines, crammed into 250Kb installers. So basically I'm having fun. As software rendering used to be my spare time activity, I was looking for something else. I tried some AI, which was great fun, and recently I dove into a huge pile of research papers on raytracing and related topics; such as global illumination, image based lighting, photon maps and so on. One document especially grabbed my attention. It's titled: "State-of-the-Art in Interactive Ray Tracing", and was written by Wald & Slusallek. I highly recommend this paper. Basically, it summarizes recent efforts to improve the speed of raytracing, and adds a couple of tricks too. But it starts with a list of benefits of raytracing over rasterization-based algorithms. And one of those benefits is that when you go to extremes, raytracing is actually faster than rasterizing. And they prove it: Imagine a huge scene, consisting of, say, 50 million triangles. Toss it at a recent GeForce with enough memory to store all those triangles, and write down the frame rate. It will be in the vicinity of 2-5. If it isn't, double the triangle count. Now, raytrace the same scene. These guys report 8 frames per second on a dual PIII/800. Make that a quad PIII/800 and the speed doubles. Raytracing scales linearly with processing power, but only logarithmically with scene complexity. Now that I got your attention, I would like to move on to the intended contents of this crash course in raytracing.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值