3
\$\begingroup\$

I'm trying to set a GameObject(plane) to be positioned at my camera's farplane. I plan on using this billboard as a sort of dynamic skybox. How would I create a billboard that is fixed to my camera's farplane?

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

I'd do this in the shader:

Shader "Unlit/SkyplaneShader"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" "Queue"="Geometry+1"}
        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 = float4(v.uv * 2.0f - 1.0f, 0.9999f, 1.0f);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                // sample the texture
                fixed4 col = tex2D(_MainTex, i.uv);
                return col;
            }
            ENDCG
        }
    }
}

What this does is take a quad or and stretch it to fill the camera's viewport, at the furthest depth.

Note that this breaks Unity's expected bounds on the object - it's always in view, no matter whether Unity thinks the mesh is outside the camera frustum. I'd recommend either parenting it to the camera so they move together, or using a script to disable frustum culling on this object.

\$\endgroup\$
0
\$\begingroup\$

First of all Skybox is not that sort of thing you are trying to create. It is a set of 6 images representing up, down, left, right, top, bottom. To understand it, make it simple, consider your camera is in a cube and your cube has definitely all 6 faces. For more details see this link.

Second Plane is quite expensive as compare to Quad, so if you want to use it in this way (anyway) then use Quad instead.

Third is I'd would suggest to use Quad on different layer rendering with a different camera, camera having depth less than your Main Camera and only rendering that Quad. From this easy step you will get your desired effect as your question is pretending.

\$\endgroup\$
6
  • \$\begingroup\$ Wouldn't it be more fitting to describe the sky box as 6 inner sides of a cube: front, back, left, right, top and bottom ? \$\endgroup\$
    – zcabjro
    Mar 2, 2016 at 15:52
  • \$\begingroup\$ He wants in that way, so... :) \$\endgroup\$ Mar 2, 2016 at 15:58
  • \$\begingroup\$ Just thought I'd throw it out there for anyone learning about sky boxes. Point taken :) \$\endgroup\$
    – zcabjro
    Mar 2, 2016 at 17:30
  • \$\begingroup\$ Im brand new to unity and game design so sorry if this question seems stupid but if im constantly generating a texture on a plane at my cameras farplane will that mean I am avoiding the need for a skybox? \$\endgroup\$
    – MarsYeti
    Mar 2, 2016 at 20:57
  • \$\begingroup\$ As far as I can understand what you have in your mind is a simple matte painting. And for that, my suggestion will work super duperly \$\endgroup\$ Mar 2, 2016 at 21:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .