srp中使用Reflection Probe

Reflection Probe——反射探针
1、功能:用来反射天空盒或者反射某一个块的场景。
2、表现:
srp中使用Reflection Probe_第1张图片
在物体上加入了周围场景的颜色。

3、实现方式
在场景的某个位置创建一个Reflection Probe
srp中使用Reflection Probe_第2张图片
调整好位置,ok此时如果有天空盒的话:
srp中使用Reflection Probe_第3张图片
则可以进行bake了:
srp中使用Reflection Probe_第4张图片

srp中使用Reflection Probe_第5张图片

ok,这是bake天空盒。
那么场景的物价也是可以bake的,只要把要bake的物价设置为:
srp中使用Reflection Probe_第6张图片
即可,连同物价一起bake。

4、采样reflection probe

TEXTURECUBE(unity_SpecCube0); //环境贴图
SAMPLER(samplerunity_SpecCube0);
float4 unity_SpecCube0_HDR;


float3 SampleEnvironment(SurfaceProperty sp, BRDFProperty brdf)
{
	float3 uvw = reflect(-sp.viewDir, sp.normal);
	float4 environment = SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, uvw, 0.0); //这里的0.0为考虑mip
	return DecodeHDREnvironment(environment, unity_SpecCube0_HDR);
}

ok,下面就是C#要注意的地方:
在这里插入图片描述

 DrawingSettings drawingSettings = new DrawingSettings(m_shaderTagId, sortingSettings);
        drawingSettings.perObjectData = 
        PerObjectData.Lightmaps | 
        PerObjectData.LightProbe | 
        PerObjectData.LightProbeProxyVolume | 
        PerObjectData.ReflectionProbes; //这里要或一个标志位,让其能够将reflection probe的图传入shader中去

ok,最终效果:
srp中使用Reflection Probe_第7张图片

你可能感兴趣的:(Unity)