KITASENJU DESIGN BLOG

memo, html, javascript, unity

Cubemap shader for sphere

cubemap shader for sphere (without skybox)

Shader "Unlit/CubeMapForSphere"
{
    Properties
    {
        _Cube ("Cubemap", Cube) = "grey" {}        
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100
        cull front

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float3 pos : TEXCOORD1;
                float4 vertex : SV_POSITION;
            };

            samplerCUBE _Cube;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.pos = v.vertex;
                o.uv = v.uv;
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                half4 col = texCUBE (_Cube, i.pos);//pos = direction
                return col;
            }
            ENDCG
        }
    }
}
"FOOTER"