本节主要参考:
https://catlikecoding.com/unity/tutorials/custom-srp/baked-light/
这真实一个很好的unity教程网址。

本节主要重点讲解,两个知识点:
1、light probe的使用
2、light probe proxy volume的使用

这两个都是给gi使用的,所谓gi就是全局光照,为了弥补gi对动态物件的影响,unity为我们提供了light probe和light probe proxy volume的两个组件。

1、light probe的使用
如下图:

可以添加多个小球:

这准备好了LightProbe,下面是准备好灯光、和一个静态物件。
我们先不考虑灯光,只有一个静态物件。

然后进行烘焙了,烘焙了,烘焙的是啥呀?我记录的是光的信息呢?还是物体表面的自发光信息呢?还是物体表面漫反射的信息呢?
首先烘焙是记录的是光经过多次反射之后的结果。

烘焙使用的shader里我们之前试验过,必须使用light mode=meta的pass。
也说明过了,在片段着色器中的如何进行光照、自发光、物体表面漫反射的颜色。
所以,至于最后烘焙成啥,完全看这个meta pass的写法如何。这里我们不妨让这个静态物件的meta pass就返回一个颜色:

float4 frag(v2f input) : SV_TARGET
{return float4(1, 1, 0, 1);
}

这是返回的一个黄色。

ok,也行这时候,你看到的是一个漆黑的光照贴图。

没关系,who care这个贴图的颜色呢?我们继续。

下面是采样,这个光照贴图:

float3 SampleLightProbe(SurfaceProperty sp)
{#if defined LIGHTMAP_ONreturn 0.0f;#elsefloat4 coefficients[7];coefficients[0] = unity_SHAr;coefficients[1] = unity_SHAg;coefficients[2] = unity_SHAb;coefficients[3] = unity_SHBr;coefficients[4] = unity_SHBg;coefficients[5] = unity_SHBb;coefficients[6] = unity_SHC;return max(0.0, SampleSH9(coefficients, sp.normal));#endif
}

这里使用SampleSH9的方法。

当然,还需要物体表面的法线(世界法线)。

最后的结果,可以在片段着色器中直接返回LightProbe的颜色:

咦,这样就采样处理,light probe的颜色了。

2、light probe proxy volume的使用
上面是对小物件的使用light probe的信息,计算出颜色。然而对于大物件,这种方式不足了。因为大物件,很难通过一个位置,去计算收到哪几个球的影响,所以unity提供了Light probe proxy volume的组件,让其大物件能够收到多个球的影响。
如下:

如图所示,这物体挂了一个LightProbeProxyVolume组件,然后设置了

ok,这是第一步,如何采样呢?
如下所示:

float3 SampleLightProbe(SurfaceProperty sp){#if defined LIGHTMAP_ONreturn 0.0f;
#elseif (unity_ProbeVolumeParams.x)  //这个x分量为1,表示使用LPPV组件了,unity自动判断{//return float3(1, 1, 0);return SampleProbeVolumeSH4(TEXTURE3D_ARGS(unity_ProbeVolumeSH, samplerunity_ProbeVolumeSH),sp.position, sp.normal,unity_ProbeVolumeWorldToObject,unity_ProbeVolumeParams.y, unity_ProbeVolumeParams.z,unity_ProbeVolumeMin.xyz, unity_ProbeVolumeSizeInv.xyz);}else {//return float3(1, 0, 0);float4 coefficients[7];coefficients[0] = unity_SHAr;coefficients[1] = unity_SHAg;coefficients[2] = unity_SHAb;coefficients[3] = unity_SHBr;coefficients[4] = unity_SHBg;coefficients[5] = unity_SHBb;coefficients[6] = unity_SHC;return max(0.0, SampleSH9(coefficients, sp.normal));}
#endif}

函数:SampleProbeVolumeSH4需要诸多参数:
unity_ProbeVolumeSH——图,由unity自动提供(后面再看看,如何动态的设置)
samplerunity_ProbeVolumeSH——采样器
sp.position, sp.normal——物体世界坐标位置,世界法线
unity_ProbeVolumeWorldToObject,
unity_ProbeVolumeParams.y, unity_ProbeVolumeParams.z,
unity_ProbeVolumeMin.xyz, unity_ProbeVolumeSizeInv.xyz————————都是unity的内置变量

ok,最后效果:

如果不使用LPPV则是:

可见,不使用LPPV,颜色稍微单调了许多,好像就一个颜色,而使用了LPPV在颜色又明显的起伏效果。这大概就是LPPV的作用了。

注意点:
1、如何查看一个物体收到的light probe的影响呢?
第一要在srp中画gizmos:

private void RenderOneCamera(Camera camera)
{……DrawGizmos(camera);m_context.Submit();
}private void DrawGizmos(Camera camera)
{if(Handles.ShouldRenderGizmos() && camera.cameraType == CameraType.SceneView){m_context.DrawGizmos(camera, GizmoSubset.PreImageEffects);m_context.DrawGizmos(camera, GizmoSubset.PostImageEffects);}
}

2、如何正确采样lightprobe、LPPV、以及光照贴图呢?
要让画物体的时候,让其传递给shader数据:

DrawingSettings drawingSettings = new DrawingSettings(m_shaderTagId, sortingSettings);
drawingSettings.perObjectData = PerObjectData.Lightmaps | PerObjectData.LightProbe | PerObjectData.LightProbeProxyVolume;

3、如果scene下的选中的物体,受到的light probe影响的四面体线,有偏移了咋办呢?
这可能是你的shader,没有使用:
#pragma multi_compile_instancing
以及,顶点着色器要正确的设置:

v2f vert (appdata input)
{v2f output;UNITY_SETUP_INSTANCE_ID(input);UNITY_TRANSFER_INSTANCE_ID(input, output);

ok,讲到这里差不多了,后面有新的内容,继续再更新。
本文是在srp的基础上讲解,当然要正确的导入core rp的包,然后,#include对应的函数文件,才能使shader编译正常。

2.2 light map coordinates
to get the light map uv coordinates unity has to send them to the shader.
we have to instruct the pipeline to do this for each object that is lightmapped.
this is done by setting the per-object data peroperty of the drawing settings to PerObjectData.Lightmaps in CameraRenderer.DrawVisibleGeometry.

var drawingSettings = new DrawingSettings(unlitShaderTagId, sortingSettings) {enableDynamicBatching = useDynamicBatching,enableInstancing = useGPUInstancing,perObjectData = PerObjectData.Lightmaps};

unity will now render lightmapped objects with a shader variant that has the LIGHTMAP_ON keyword.
add a multi-compile directive for that to the CustomLit pass of our Lit shader.

#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile_instancing

Baked Light Light Maps and Probes——srp中使用lightprobe和light probe proxy volume(简称LPPV)相关推荐

  1. SRP中的shader

    SRP中的shader 在Unity中使用SRP时,我们需要使用HLSL来编写shader.HLSL语法与GLSL类似,在使用HLSL的地方我们需要用HLSLPROGRAM和ENDHLSL来包裹: S ...

  2. 哇哦,灵光乍现——srp中commandbuffer设置SetViewProjectionMatrices方法注意点,终于对了

    重点是这里: m_commandBuffer.SetViewProjectionMatrices(m_myCamera.m_lightCamera.worldToCameraMatrix, m_myC ...

  3. 爬虫中 Selenium-Requets-模拟登陆cookie-代理proxy 的简单总结

    爬虫项目的简单总结 上面两个文章主要展示了两个Selenium爬虫的具体程序,对于中间遇到的小的问题和具体内容的实现在这里进行简单的介绍和总结. 1.通过Cookie实现网站登陆 保存Cookie # ...

  4. c++ 写文件怎么让0x00不被识别成结束符_使用docker-copyedit工具删除镜像中不需要的环境变量和VOLUME...

    docker-copyedit使用样例 0x00 背景 在docker中,我们可以使用Dockerfile来从一个已有的镜像build出一个新镜像.在Dockerfile中,基本上可以对基础镜像的很多 ...

  5. Talib中文文档(三):Volume Indicators 成交量指标

    AD - Chaikin A/D Line 量价指标 函数名:AD 名称:Chaikin A/D Line 累积/派发线(Accumulation/Distribution Line) 简介:Marc ...

  6. talib 中文文档(九):Volume Indicators 成交量指标

    Volume Indicators 成交量指标 AD - Chaikin A/D Line 量价指标 函数名:AD 名称:Chaikin A/D Line 累积/派发线(Accumulation/Di ...

  7. vue2中使用mockjs出现报错proxy error: could not proxy request xxx from xxx to xxx 和404,500问题

    问题说明 出现proxy error: could not proxy request报错,应该是因为devServer代理的服务器未开启,或者地址错误,改正就好. 404 not found,找不到 ...

  8. asp.net 探针下载_光探针代理卷:5.4功能展示

    asp.net 探针下载 Unity 5.4已进入测试版,并且出色的功能是Light Probe Proxy Volume(LPPV). 我只是想与您分享所有内容,工作流程和一些小实验以展示其实际效果 ...

  9. 渲染18——实时GI

    https://catlikecoding.com/unity/tutorials/rendering/part-18/ 参考网址:https://docs.unity3d.com/Manual/GI ...

最新文章

  1. Python打印json文件,实现输出
  2. (0109)iOS开发之CocoaPods Mac App的安装和使用
  3. android案例一 电话拨号器
  4. @NotNull 、@NotBlank、@NotEmpty区别
  5. hive cli启动判断hadoop version的问题
  6. ztree 标准得json数据格式_Django+zTree构建组织架构树
  7. 造轮子:前端模板引擎
  8. GoF设计模式——适配器模式(C++实现)
  9. Pyflink系列之使用pyflink实现flink大数据引挚的经典案例wordcount
  10. 手游脚本_雷电模拟器
  11. 一段有趣的代码,喂仓鼠
  12. 星宸科技嵌入式CPU-SSD222D芯片在人脸门锁应用
  13. 2022.04.15【单细胞】|Seurat安装,C++ compiler supports the long long type... no解决方法
  14. TiDB 帮助万达网络科技集团实现高性能高质量的实时风控平台
  15. axios中的put和patch有什么区别
  16. 如何寻找软件外包公司?
  17. Java温故而知新-递归
  18. H5竞价单页网站源码带订单系统
  19. 搜狗搜索事业部总经理:从识图搜索谈未来大势
  20. MRO工业品采购如何降低成本?SCM供应链管理系统助力企业优化采购流程

热门文章

  1. 二进制老鼠毒药c语言,老鼠试药  二进制问题
  2. vue实现点击某个dom元素之外的方法
  3. 高压放大器在工作中的应用实例有哪些
  4. ubuntu找不到命令 add-apt-repository command not found
  5. Ubuntu软件管理、换源、驱动及部分软件安装操作(持续更新)
  6. 学生用计算机如何弄心形,电脑画图软件内如何绘制心形
  7. 让CS的头像支持GIF动画
  8. dll 库文件下载地址
  9. 怎么批量从NCBI上下载基因序列
  10. 二阶常系数线性微分方程的解法