Is it possible to do a fun house mirror effect in unity? something like this:
This can be done by remapping the UVs on a mesh. The code below use an AnimationCurve that you can set for the remapping. To use:
- Get the CreatePlane editor script from the Unity Wiki.
- Create a plane. My plane with 254 width segments, 254 height segments, width of 4, height of 6, Orientation was vertical, Anchor was center.
- Create a material. I used Unlit/Texture and with an image with an aspect ratio of 4 x 6.
- Add the following script
- Modify the AnimationCurves for horizontal and vertical
- Run the app
using UnityEngine;
using System.Collections;
public class FunHouseMirror : MonoBehaviour {
public AnimationCurve acHorizontal;
public AnimationCurve acVertical;
void Start () {
MeshFilter mf = GetComponent<MeshFilter>();
if (mf == null) {
Debug.Log ("No MeshFilter componenht");
return;
}
Mesh mesh = Instantiate(mf.mesh) as Mesh;
mf.mesh = mesh;
Vector2[] uvs = mesh.uv;
for (int i = 0; i < uvs.Length; i++) {
uvs_.x = acHorizontal.Evaluate (uvs*.x);*_
uvs_.y = acVertical.Evaluate (uvs*.y);
}
mesh.uv = uvs;
}
}
Here is an example of the two animation curves (produces the lower right image below):
[31714-funhousecurves.png*|31714]*
And here are the results applied to a public domain image:
[31715-funhouse2.jpg|31715]*_
*
*