I’m using this script from the Manual to set my vanishing point away from the center.
It work’s great, except that the skybox dosn’t respect the change in the projection matrix. Can this be fixed in the skybox shader? How?
I’m using this script from the Manual to set my vanishing point away from the center.
It work’s great, except that the skybox dosn’t respect the change in the projection matrix. Can this be fixed in the skybox shader? How?
I know this question is from a while ago, but I just encountered this problem recently and found a solution today.
From what I can tell, Unity passes a different projection matrix when rendering skyboxes, one that omits the obliqueness parameters.
I made a copy of the built-in skybox cubed shader and applied the obliqueness manually:
Shader "Custom/Skybox Oblique" {
Properties {
_Tint ("Tint Color", Color) = (.5, .5, .5, .5)
_Tex ("Cubemap", Cube) = "white" {}
_Obliqueness ("Obliqueness", Vector) = (0, 0, 0, 0)
}
SubShader {
Tags { "Queue"="Background" "RenderType"="Background" }
Cull Off ZWrite Off Fog { Mode Off }
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
samplerCUBE _Tex;
fixed4 _Tint;
float4 _Obliqueness;
struct appdata_t {
float4 vertex : POSITION;
float3 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : POSITION;
float3 texcoord : TEXCOORD0;
};
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.vertex.xy += _Obliqueness.xy * o.vertex.w;
o.texcoord = v.texcoord;
return o;
}
fixed4 frag (v2f i) : COLOR
{
fixed4 tex = texCUBE (_Tex, i.texcoord);
fixed4 col;
col.rgb = tex.rgb + _Tint.rgb - unity_ColorSpaceGrey;
col.a = tex.a * _Tint.a;
return col;
}
ENDCG
}
}
Fallback Off
}
Your code that sets the obliqueness on the camera projection matrix should then also provide the values to the RenderSettings.skybox material using SetVector (remember to cache a local copy of the material so you don’t inadvertently modify assets on-disc), and both the skybox and camera should then stay in sync.