Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Making unity player / scene background transparent

Discussion in 'Windows' started by DanglingNeuron, Jun 17, 2015.

  1. DanglingNeuron

    DanglingNeuron

    Joined:
    Dec 4, 2012
    Posts:
    37
    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 :) but I have some good use for it.
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    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:

    Code (csharp):
    1.  
    2. // Skybox shader that just draws flat texture in the background
    3. Shader "Skybox/Background Texture"
    4. {
    5.    Properties
    6.    {
    7.      _MainTex ("Texture", 2D) = "white" {}
    8.    }
    9.    SubShader
    10.    {
    11.      Tags { "Queue"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
    12.      Cull Off ZWrite Off
    13.  
    14.      Pass
    15.      {
    16.        CGPROGRAM
    17.        #pragma vertex vert
    18.        #pragma fragment frag
    19.        #include "UnityCG.cginc"
    20.  
    21.        void vert (float4 pos : POSITION, out float4 ouv : TEXCOORD0, out float4 opos : SV_POSITION)
    22.        {        
    23.          opos = mul(UNITY_MATRIX_MVP, pos);
    24.          ouv = ComputeScreenPos(opos);
    25.        }
    26.  
    27.        sampler2D _MainTex;
    28.      
    29.        fixed4 frag (float4 uv : TEXCOORD0) : SV_Target
    30.        {
    31.          fixed4 col = tex2Dproj(_MainTex, uv);
    32.          return col;
    33.        }
    34.        ENDCG
    35.      }
    36.    }
    37. }
    38.  
     
    MRCalderon3D likes this.
  3. micla

    micla

    Joined:
    Aug 25, 2015
    Posts:
    1
    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?
     
  4. cchacon

    cchacon

    Joined:
    Sep 20, 2015
    Posts:
    18
    hi guys did you get more details on how to do this?
     
  5. MRCalderon3D

    MRCalderon3D

    Joined:
    Jan 22, 2013
    Posts:
    7
    Tautvydas Zilys I tried it but can't make it works :( any advise or sample?
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    What exactly did you do and what didn't work?