主要参考Standard Asset 的水的镜面反射的思路
private static bool s_InsideWater = false;
private RenderTexture m_ReflectionTexture;
private Dictionary<Camera, Camera> m_ReflectionCameras = new Dictionary<Camera, Camera>(); // Camera -> Camera table
public float clipPlaneOffset = 0.07f;
public int textureSize = 256;
public LayerMask reflectLayers = -1;
public void OnWillRenderObject()
{
Camera currentCamera = Camera.current;
//Camera currentCamera = Camera.main;
if (!currentCamera)
{
return;
}
if (s_InsideWater)
{
return;
}
s_InsideWater = true;
if (!m_ReflectionTexture)
{
m_ReflectionTexture = new RenderTexture(textureSize, textureSize, 16);
m_ReflectionTexture.name = "__WaterReflection" + GetInstanceID();
m_ReflectionTexture.isPowerOfTwo = true;
m_ReflectionTexture.hideFlags = HideFlags.DontSave;
}
Camera reflectionCamera;
// Camera for reflection
m_ReflectionCameras.TryGetValue(currentCamera, out reflectionCamera);
if (!reflectionCamera) // catch both not-in-dictionary and in-dictionary-but-deleted-GO
{
//GameObject go = new GameObject("Water Refl Camera id" + GetInstanceID() + " for &