基于unity自己写光追。

12 篇文章 0 订阅
4 篇文章 0 订阅

前几天写的博客好像访问量多了不少。

最近听到裁员的消息挺多的。但是貌似搞unity的找工作还行。

毕竟从事这个的相对少一点。前些年互联网大热,大家都一窝蜂的去学java,后台,前端这个那个的。你看现在人才冗余了吧,所以还是搞点冷门的专业比较好,不要凑热闹。

曾国藩说过,众驶之地勿往。

---------------------------------------------------------------------------------

闲聊到此结束。

最近工作关系,需要用unity实现光追效果。

调研了一下,有3种方案。

第一种:参考shadertoy那种raymarching。场景模型通过sdf来描述。一般的mesh模型,需要转换为sdf的方式来描述,就比较麻烦了。还要单独写转换算法。从shadertoy上可以搬运很多酷炫的效果移植到unity里。不过webgl的shader是glsl语法,需要转换为hlsl。有很多注意的地方。最好用宏定义来解决。执行效率好像不太高,尤其是分辨率较高,且sdf函数复杂的模型,会掉帧比较严重。

第二种:通过computeshader来实现光追算法。这个一般也是参数化矢量模型可以用。也就是通过函数描述的比如球体,立方体之类的,可以直接用公式求取解析解,不需要递归搜索。而任意模型的渲染还需要自己编写BVH加速结构,做线碰撞计算。这个方法好处是不一定非得要支持RTX的显卡,通用性比较高,但是得需要computeshader的支持。

第三种:通过DX12的DXR,也就是unity里的HDRP自带的Raytracing shader。硬加速的,执行效率比较高。编写代码也比较简单。BVH加速结构也可以调用api搞定,相当好用。缺点是需要RTX显卡的支持。通用性不够。

所以针对不同场景,你得斟酌考虑用哪种方案。

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 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.
要在Unity中实现,可以使用Unity的Shader Graph工具来创建自定义着色器,从而实现线跟踪效果。以下是一个简单的步骤指南: 1. 创建一个空的项目,并导入所需的资源。 2. 在Assets窗口中右键单击并选择Create->Shader->PBR Graph,创建一个新的PBR着色器图。 3. 在着色器图中添加一个Custom Function节点,并将其设置为Surface Output的输入。 4. 在Custom Function节点中,使用HLSL编写光代码。例如,您可以使用以下代码来跟踪从相机位置到像素位置的线: ``` float3 rayDirection = normalize(IN.worldPos - _WorldSpaceCameraPos); ``` 5. 将代码输出到Surface节点的Albedo输入。 6. 调整代码的参数以获得所需的效果。例如,您可以使用更高的最大反弹数来增加线跟踪质量,或者使用更低的最大反弹数来提高性能。 7. 将新着色器应用于场景中的物体。 对于实现体积,您可以使用Unity的Volumetric Lighting组件。该组件允许您将线跟踪效果与体积合并,从而创建具有更真实外观的场景。以下是一个简单的步骤指南: 1. 在Assets窗口中右键单击并选择Create->Light->Volumetric Light,创建一个新的体积对象。 2. 将体积对象放置在场景中,并调整其大小和位置以适应所需的效果。 3. 在体积对象的属性面板中,启用Volumetric Fog选项,并选择所需的材质。 4. 如果需要,您可以通过调整体积的密度和噪声来进一步自定义外观。 5. 将适当的灯添加到场景中,并将其设置为影响体积。 6. 在相机对象的属性面板中启用HDR选项,以确保体积效果正确呈现。 7. 调整场景中的灯和相机位置,以获得所需的效果。 注意:实现和体积都需要高性能计算和显卡支持,因此在较低端的计算机上可能会出现性能问题。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值