This change adds support for custom background images. Usage: - Background images are stored in "backgrounds" folder as with jpg or png. - Both 360 degree (equirectangular) and 6-side cubemap images are supported. This is automatically detected based on aspect ratio (with cubemap having 4:3 aspect ratio). - Select the background from Settings. Changes: - The selected background image is persisted in config in this format: "background": "backgrounds/my_background.jpg", - Image is decoded in a background thread (via Android plugin), as Texture2D.LoadImage can cause multi-second freeze on the UI thread. We then compensate for unity (re-ordering coordinate origin and also alpha channel). - Made ground smaller & semi-transparent
72 lines
2.1 KiB
Plaintext
72 lines
2.1 KiB
Plaintext
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
|
|
|
Shader "skybox/equirectangular" {
|
|
Properties {
|
|
_Tint ("Tint Color", Color) = (.5, .5, .5, .5)
|
|
[Gamma] _Exposure ("Exposure", Range(0, 8)) = 1.0
|
|
_Rotation ("Rotation", Range(0, 360)) = 0
|
|
[NoScaleOffset] _Tex ("Panorama (HDR)", 2D) = "grey" {}
|
|
}
|
|
|
|
SubShader {
|
|
Tags { "Queue"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
|
|
Cull Off ZWrite Off
|
|
|
|
Pass {
|
|
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
|
|
#include "UnityCG.cginc"
|
|
|
|
sampler2D _Tex;
|
|
half4 _Tex_HDR;
|
|
half4 _Tint;
|
|
half _Exposure;
|
|
float _Rotation;
|
|
|
|
float4 RotateAroundYInDegrees (float4 vertex, float degrees)
|
|
{
|
|
float alpha = degrees * UNITY_PI / 180.0;
|
|
float sina, cosa;
|
|
sincos(alpha, sina, cosa);
|
|
float2x2 m = float2x2(cosa, -sina, sina, cosa);
|
|
return float4(mul(m, vertex.xz), vertex.yw).xzyw;
|
|
}
|
|
|
|
struct appdata_t {
|
|
float4 vertex : POSITION;
|
|
};
|
|
|
|
struct v2f {
|
|
float4 vertex : SV_POSITION;
|
|
float3 texcoord : TEXCOORD0;
|
|
};
|
|
|
|
v2f vert (appdata_t v)
|
|
{
|
|
v2f o;
|
|
o.vertex = UnityObjectToClipPos(RotateAroundYInDegrees(v.vertex, _Rotation));
|
|
o.texcoord = v.vertex.xyz;
|
|
return o;
|
|
}
|
|
|
|
fixed4 frag (v2f i) : SV_Target
|
|
{
|
|
float3 dir = normalize(i.texcoord);
|
|
float2 longlat = float2(atan2(dir.x, dir.z) + UNITY_PI, acos(-dir.y));
|
|
float2 uv = longlat / float2(2.0 * UNITY_PI, UNITY_PI);
|
|
half4 tex = tex2D (_Tex, uv);
|
|
half3 c = DecodeHDR (tex, _Tex_HDR);
|
|
c = c * _Tint.rgb * unity_ColorSpaceDouble.rgb;
|
|
c *= _Exposure;
|
|
|
|
return half4(c, 1);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
|
|
Fallback Off
|
|
} |