Last active
January 9, 2024 00:28
-
-
Save aras-p/3d8218ef5d96d5984019 to your computer and use it in GitHub Desktop.
Unity flat skybox picture shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 outUV : TEXCOORD0, out float4 outPos : SV_POSITION) | |
{ | |
outPos = mul(UNITY_MATRIX_MVP, pos); | |
outUV = ComputeScreenPos(outPos); | |
} | |
sampler2D _MainTex; | |
fixed4 frag (float4 uv : TEXCOORD0) : SV_Target | |
{ | |
fixed4 col = tex2Dproj(_MainTex, uv); | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a more advanced variant.
Needed if you want to toggle between envelope/fitInsideViewport.
Or if you want to ensure there is "empty" space when squeezing the image into viewport.
Notice, to make this variant work you need to feed it the size of your image. For example: