Advertisement
noradninja

Stencil pass Skybox

Jun 20th, 2022
1,098
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.16 KB | None | 0 0
  1. // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
  2.  
  3. Shader "Vita/Skybox(Stencil)" {
  4. Properties {
  5.     _Tint ("Tint Color", Color) = (.5, .5, .5, .5)
  6.     [Gamma] _Exposure ("Exposure", Range(0, 8)) = 1.0
  7.     _Rotation ("Rotation", Range(0, 360)) = 0
  8.     [NoScaleOffset] _Tex ("Cubemap   (HDR)", Cube) = "grey" {}
  9.     [IntRange] _StencilRef ("Stencil Ref", Range(0,255)) = 0
  10. }
  11.  
  12. SubShader {
  13.     Tags { "Queue"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
  14.     Cull Off ZWrite Off
  15.     Stencil {
  16.         Ref [_StencilRef]
  17.         Comp NotEqual
  18.         Pass Replace
  19.     }
  20.     Pass {
  21.  
  22.         CGPROGRAM
  23.         #pragma vertex vert
  24.         #pragma fragment frag
  25.         #pragma target 2.0
  26.  
  27.         #include "UnityCG.cginc"
  28.  
  29.         samplerCUBE _Tex;
  30.         half4 _Tex_HDR;
  31.         half4 _Tint;
  32.         half _Exposure;
  33.         float _Rotation;
  34.  
  35.         float3 RotateAroundYInDegrees (float3 vertex, float degrees)
  36.         {
  37.             float alpha = degrees * UNITY_PI / 180.0;
  38.             float sina, cosa;
  39.             sincos(alpha, sina, cosa);
  40.             float2x2 m = float2x2(cosa, -sina, sina, cosa);
  41.             return float3(mul(m, vertex.xz), vertex.y).xzy;
  42.         }
  43.  
  44.         struct appdata_t {
  45.             float4 vertex : POSITION;
  46.             UNITY_VERTEX_INPUT_INSTANCE_ID
  47.         };
  48.  
  49.         struct v2f {
  50.             float4 vertex : SV_POSITION;
  51.             float3 texcoord : TEXCOORD0;
  52.             UNITY_VERTEX_OUTPUT_STEREO
  53.         };
  54.  
  55.         v2f vert (appdata_t v)
  56.         {
  57.             v2f o;
  58.             UNITY_SETUP_INSTANCE_ID(v);
  59.             UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  60.             float3 rotated = RotateAroundYInDegrees(v.vertex, _Rotation);
  61.             o.vertex = UnityObjectToClipPos(rotated);
  62.             o.texcoord = v.vertex.xyz;
  63.             return o;
  64.         }
  65.  
  66.         fixed4 frag (v2f i) : SV_Target
  67.         {
  68.             half4 tex = texCUBE (_Tex, i.texcoord);
  69.             half3 c = DecodeHDR (tex, _Tex_HDR);
  70.             c = c * _Tint.rgb * unity_ColorSpaceDouble.rgb;
  71.             c *= _Exposure;
  72.             return half4(c, 1);
  73.         }
  74.         ENDCG
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement