Making unity player / scene background transparent

Is there any way to make the unity scene background transparent?

e.g.

Lets say I only have a cube in the center of my scene. I only want unity to display that and the rest of the player surface be transparent. So in my exported visual studio project, I can render whatever I need natively e.g. a background with text/image. I want to augment unity graphics cube on top of native stuff (background) I do in visual studio.

I know it may sound crazy :slight_smile: but I have some good use for it.

Are you targeting Windows Store?

There’s a couple of ways to achieve it, the easiest being render your stuff to a texture and use a custom shader that draws your texture instead of the skybox. You could use this one:

// Skybox shader that just draws flat texture in the background
Shader "Skybox/Background Texture"
{
   Properties
   {
     _MainTex ("Texture", 2D) = "white" {}
   }
   SubShader
   {
     Tags { "Queue"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
     Cull Off ZWrite Off

     Pass
     {
       CGPROGRAM
       #pragma vertex vert
       #pragma fragment frag
       #include "UnityCG.cginc"

       void vert (float4 pos : POSITION, out float4 ouv : TEXCOORD0, out float4 opos : SV_POSITION)
       {        
         opos = mul(UNITY_MATRIX_MVP, pos);
         ouv = ComputeScreenPos(opos);
       }

       sampler2D _MainTex;
      
       fixed4 frag (float4 uv : TEXCOORD0) : SV_Target
       {
         fixed4 col = tex2Dproj(_MainTex, uv);
         return col;
       }
       ENDCG
     }
   }
}
1 Like

great! Unfortunately I’m a novice and am stuck getting this properly wired up. Does anyone have a sample solution they’re willing to share?

hi guys did you get more details on how to do this?

Tautvydas Zilys I tried it but can’t make it works :frowning: any advise or sample?

What exactly did you do and what didn’t work?