ict.shenzhi/Assets/Evereal/VideoCapture/Resources/Shaders/CubemapToEquirect2.shader

65 lines
1.4 KiB
Plaintext

// Copyright (c) 2019-present Evereal. All rights reserved.
Shader "VideoCapture/CubemapToEquirect2"
{
Properties
{
}
SubShader
{
// No culling or depth
Cull Off
ZWrite Off
ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
samplerCUBE _CubeTex;
float2 _SphereScale;
float2 _SphereOffset;
float4x4 _CubeTransform;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = (v.uv *_SphereScale + _SphereOffset) * float2(UNITY_PI*2.0, UNITY_PI); // convert to angles
return o;
}
// convert spherical coordinates (azimuth, elevation angles) to Cartesian coordinates (x, y, z) on sphere
float3 sphericalToCartesian(float2 a)
{
return float3(cos(a.x)*sin(a.y), cos(a.y), sin(a.x)*sin(a.y));
}
fixed4 frag(v2f i) : SV_Target
{
float3 dir = sphericalToCartesian(i.uv);
dir = mul(_CubeTransform, float4(dir, 1)).xyz;
fixed4 col = texCUBE(_CubeTex, dir);
return col;
}
ENDCG
}
}
}