Hi,
I want to implement a rectangular ground object that reflects like a mirror.
Is there a way to do that? I’m using Unity 3.5.6/4.0.0 Pro and want to deploy to iOS.
Thx ia,
Ekki
Hi,
I want to implement a rectangular ground object that reflects like a mirror.
Is there a way to do that? I’m using Unity 3.5.6/4.0.0 Pro and want to deploy to iOS.
Thx ia,
Ekki
Take a look at Unity Pro’s built in water system. Basically what you need to do is render the scene one more time with a different camera. Code excerpt from Unity’s water:
// Render reflection if needed
if( mode >= WaterMode.Reflective )
{
// Reflect camera around reflection plane
float d = -Vector3.Dot (normal, pos) - m_ClipPlaneOffset;
Vector4 reflectionPlane = new Vector4 (normal.x, normal.y, normal.z, d);
Matrix4x4 reflection = Matrix4x4.zero;
CalculateReflectionMatrix (ref reflection, reflectionPlane);
Vector3 oldpos = cam.transform.position;
Vector3 newpos = reflection.MultiplyPoint( oldpos );
reflectionCamera.worldToCameraMatrix = cam.worldToCameraMatrix * reflection;
// Setup oblique projection matrix so that near plane is our reflection
// plane. This way we clip everything below/above it for free.
Vector4 clipPlane = CameraSpacePlane( reflectionCamera, pos, normal, 1.0f );
Matrix4x4 projection = cam.projectionMatrix;
CalculateObliqueMatrix (ref projection, clipPlane);
reflectionCamera.projectionMatrix = projection;
reflectionCamera.cullingMask = ~(1<<4) m_ReflectLayers.value; // never render water layer
reflectionCamera.targetTexture = m_ReflectionTexture;
GL.SetRevertBackfacing (true);
reflectionCamera.transform.position = newpos;
Vector3 euler = cam.transform.eulerAngles;
reflectionCamera.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z);
reflectionCamera.Render();
reflectionCamera.transform.position = oldpos;
GL.SetRevertBackfacing (false);
renderer.sharedMaterial.SetTexture( "_ReflectionTex", m_ReflectionTexture );
}