10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

(極座標変換)シェーダーでTheta 画像をリトルプラネットに変換

Last updated at Posted at 2016-01-16

スクリーンショット 2016-01-16 23.33.25.png

シェーダーで行うので、WebcamTextureに動画として表示したものをリトルプラネットとしてリアルタイムに変換することもできるんじゃないかと思います。

CircularPolar.shader
Shader "Unlit/CircularPolar"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
	}
	SubShader
	{
		Tags { "RenderType"="Opaque" }
		LOD 100

		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;
			};

			sampler2D _MainTex;
			float4 _MainTex_ST;
			
			v2f vert (appdata v)
			{
				v2f o;
				o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
				o.uv = TRANSFORM_TEX(v.uv, _MainTex);
				return o;
			}
			
			fixed4 frag (v2f i) : SV_Target
			{
				float2 huv = (i.uv-0.5)*2;
				float2 pl;
				pl.y = sqrt(huv.x*huv.x+huv.y*huv.y)*2+1;
				pl.x = atan2(huv.y,huv.x)/3.14159265;
				huv = pl;
				i.uv = (huv+1)*0.5;
				i.uv.x = clamp(i.uv.x,0.0,1);
				i.uv.y = clamp(i.uv.y,0,1.99);

				// sample the texture
				fixed4 col = tex2D(_MainTex, i.uv);
				return col;
			}
			ENDCG
		}
	}
}
10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?