Which shader can be used with cube texture shape?

Skybox/Cubemap shader can be used with cube texture shape which is visible from inside of the box correctly. In other words camera should be inside of the box for this shader.

Is there a shader, which can be used with cube texture shape which is visible from outside of the box correctly?
In other words camera should be outside of the box for this shader.

Are you asking if there’s a shader included with Unity?
No.

Can you write a shader that uses a cube map texture?
Yes.

The only difference between a cubemap texture and a 2D texture is a 2D texture uses a UV with two components which is a position, and a cubemap uses a UVW with three components which is a direction. Most of the time cubemaps are using a world space view direction (skybox) or reflected world space view direction (reflections), but you can just use a box’s local vertex position and it’ll work.

1 Like

Thank you for detailed answer, I tried to write custom shader today.
However, texture does not stay stable on the cube, if I rotate the cube or camera.
How can I use box’s local vertex position?

Shader "Custom/NewSurfaceShader"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        [NoScaleOffset] _MainTex("Cubemap", Cube) = "" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        samplerCUBE _MainTex;

        struct Input
        {
            float3 worldRefl;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 c = texCUBE (_MainTex, IN.worldRefl) * _Color;
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

You’ll need a custom vertex function to get the object space vertex position and pass it from the vertex shader stage to the fragment shader stage where the surf function runs.

See the section titled “Custom data computed per-vertex”:

But instead of abs(v.normal) you want v.vertex.xyz.

1 Like

It works. Thank you, bgolus, very much for detailed answers.