- Home /
Rotation of a camera viewport
I want to have the top half of a level have a white background and grey objects, and the bottom half is inverted with a grey background and white objects. This is merely a visual effect.
I made a small example with some rigidbodies to clarify what I mean:
It is the same objects, but created using 2 cameras and 2 layers.
The top camera cannot see the layer "Grey", and the bottom camera cannot see the layer "White". There are some problems with this method though:
I want this effect to be rotated freely, but I haven't been capable of finding a way to rotate a viewport - fx, instead of having the border between the two colors being a horizontal line, it could be rotated to 45 degrees, making some of the upper half grey and some of the bottom half white.
For every visual object in the game, there has to be created a duplicate - one white and one grey (mildly annoying, but I can live with it).
Does anyone have an idea of how this effect can be done? Or is it just impossible to rotate a viewport? If it is possible, how big of an performance impact would it have?
Unfortunately, it appears target textures are Pro only.
I have, however, been pretty successful by using an inversion shader on the top half - http://forum.unity3d.com/threads/invert-colors-shader.205244/
Another possibility if you work with shader would be to modify your shader at runtime by creating a new temporary shader with a string... but I have no idea how bad on performance it could be.
Look at the clipping or crosssection shaders here: http://forum.unity3d.com/threads/simple-cross-section-shader.34508/ and just for the given global space coordinates apply inversion in similar way like clipping is applied here. Then expose the boundary plane in the shader parameters and manipulate with them over time.
Shader "Diffuse/HalfInvert" {
Properties {
_Color ("$$anonymous$$ain Color", Color) = (1,1,1,1)
_$$anonymous$$ainTex ("Texture", 2D) = "white" {}
_BoundaryPlane ("BoundaryPlane (x, y, z)", vector) = (0,1,0)
_CentrePoint ("CentrePoint (x, y, z)", vector) = (0,0,0)
_BoundaryOffset ("BoundaryOffset",float) = 0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Cull Back
CGPROGRA$$anonymous$$
#pragma surface surf BlinnPhong
#pragma debug
fixed4 _LowerColor;
fixed4 _Color;
fixed3 _BoundaryPlane;
fixed3 _CentrePoint;
float _BoundaryOffset;
struct Input {
float2 uv_$$anonymous$$ainTex;
float3 worldPos;
};
sampler2D _$$anonymous$$ainTex;
void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D(_$$anonymous$$ainTex, IN.uv_$$anonymous$$ainTex);
if (_BoundaryOffset -dot((IN.worldPos - _CentrePoint),_BoundaryPlane)>0){
//fixed4 tex = tex2D(_$$anonymous$$ainTex, IN.uv_$$anonymous$$ainTex);
o.Albedo = tex.rgb * _Color.rgb;
o.Alpha = tex.a * _Color.a;
}else{
o.Albedo = (1,1,1) - tex.rgb * _Color.rgb;
o.Alpha = tex.a * _Color.a;
}
}
ENDCG
}
Fallback "Diffuse"
}