#Angel Dome Skybox

1 messages · Page 1 of 1 (latest)

cosmic imp
#

So I gave it a shot by just creating an image effect shader, changing the parameter to Cube, giving it a cube map and using the following code: ```Shader "Hidden/NewImageEffectShader 1"
{
Properties
{
_MainTex ("Texture", Cube) = "white" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always

    Pass
    {
        CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag

        #include "UnityCG.cginc"
        #include "UnityShaderVariables.cginc"
        #include "UnityShaderUtilities.cginc"

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

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

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

        sampler2D _MainTex;

        fixed4 frag (v2f i) : SV_Target
        {
            fixed4 col = tex2D(_MainTex, i.uv);
            // just invert the colors
            col.rgb = 1 - col.rgb;
            return col;
        }
        ENDCG
    }
}

}

#

Basically all I changed was o.vertex = UnityObjectToClipPos(v.vertex - _WorldSpaceCameraPos);

#

The result is this:

#

I dunno what I'm doing with shaders, lmao.

#

Angel Dome Skybox

tardy lily
# cosmic imp So I gave it a shot by just creating an image effect shader, changing the parame...

I assume this is for built-in render pipeline?

You don't want an "image effect" shader, that's for full-screen effects. I'd use the Unlit Shader template instead.

Keep o.vertex = UnityObjectToClipPos(v.vertex); as is, you don't want to alter the vertex positions.

float3 viewDir : TEXCOORD1; would need to be added to the v2f struct, and in the vert function we set it. There's probably a function to calculate it, but I'm not too familiar with the built-in pipeline stuff. I think o.viewDir = normalize(v.vertex - _WorldSpaceCameraPos) would do.

A cubemap would be samplerCUBE, not sampler2D. To sample it you'd want to use fixed4 col = texCUBE (_MainTex, i.viewDir);

I think that might be everything you need.

cosmic imp
#

Okay, thanks. I'll give it another go later today.

cosmic imp
#

Wow, that worked a dream!

#

Thank you so much, that's exactly what I wanted.

cosmic imp
#

Alright, I hate to come back one more time to bother you, but is there a way to make it not curve around the vertices? Like, so that instead of drawing the dome, it would "look" through to the other skybox as if it was the real skybox?

tardy lily
#

I thought it would already do that when using the viewDir. Perhaps I calculated it wrong, could try inverting it? (-i.viewDir)
If that doesn't help might need to share the shader code

cosmic imp
#

That flips it upside down.

#
{
    Properties
    {
        _MainTex ("Texture", Cube) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        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;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
                float3 viewDir : TEXCOORD1; 
            };

            samplerCUBE _MainTex;
            float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                //o.viewDir = normalize(v.vertex - _WorldSpaceCameraPos);
                o.viewDir = normalize(v.vertex - _WorldSpaceCameraPos);
                o.viewDir = -1 * o.viewDir;
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                // sample the texture
                fixed4 col = texCUBE (_MainTex, i.viewDir);
                // apply fog
                UNITY_APPLY_FOG(i.fogCoord, col);
                return col;
            }
            ENDCG
        }
    }
}```
tardy lily
# cosmic imp ```Shader "Unlit/NewUnlitShader" { Properties { _MainTex ("Textu...
Shader "Unlit/RenderCubemap"
{
    Properties
    {
        _MainTex ("Texture", Cube) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        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;
                //UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
                float3 viewDir : TEXCOORD2;
            };

            samplerCUBE _MainTex;
            //float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                //o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                o.viewDir = mul(unity_ObjectToWorld, v.vertex) - _WorldSpaceCameraPos;
                //UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                // sample the texture
                fixed4 col = texCUBE (_MainTex, normalize(i.viewDir));
                // apply fog
                //UNITY_APPLY_FOG(i.fogCoord, col);
                return col;
            }
            ENDCG
        }
    }
}
#

Okay that should fix it, needed to transform v.vertex to world space for viewDir. And not normalize in vert, but in frag

#

Also noticed that viewDir was TEXCOORD1 but you also had UNITY_FOG_COORDS(1) which would use the same so I changed it to TEXCOORD2 instead. But I also commented out all the fog stuff while testing. If you need that can uncomment those lines.

cosmic imp
#

That works exactly as intended 😮