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.
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
}
}
}