用反射探头实现镜面反射
之前看到过一个日本人写的文章,关于如何使用Unity的反射探头来实现地板的镜面反射效果。
文章地址:http://nn-hokuson.hatenablog.com/entry/2016/10/17/202135。
核心代码很短,主要是根据下图所示实时更新反射探头的位置:
先贴一下位置计算的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ProbeReflection : MonoBehaviour
{
public GameObject reflectionPlane;
private ReflectionProbe probe;
void Start()
{
this.probe = GetComponent<ReflectionProbe>();
}
void Update()
{
if(reflectionPlane == null)
{
return;
}
Camera camera = Camera.main;
if(camera == nu