Advertisement
Guest User

Projector shader code

a guest
Feb 17th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Projector" {
  2.    Properties {
  3.       _ShadowTex ("Projected Image", 2D) = "white" {}
  4.       _speed("Speed",Range(0.01,0.1)) = 0.05
  5.       _ShadowIntensity ("Opacity of the shadows",Range(3,10)) = 5
  6.    }
  7.    SubShader {
  8.       Pass {      
  9.          Blend One One
  10.             // add color of _ShadowTex to the color in the framebuffer
  11.          ZWrite Off // don't change depths
  12.          Offset -1, -1 // avoid depth fighting
  13.  
  14.          CGPROGRAM
  15.  
  16.          #pragma vertex vert  
  17.          #pragma fragment frag
  18.  
  19.          // User-specified properties
  20.          uniform sampler2D _ShadowTex;
  21.          float _speed;
  22.          float _ShadowIntensity;
  23.  
  24.         // Projector-specific uniforms
  25.         uniform float4x4 unity_Projector; // transformation matrix
  26.         // from object space to projector space
  27.  
  28.           struct vertexInput {
  29.             float4 vertex : POSITION;
  30.             float3 normal : NORMAL;
  31.          };
  32.          struct vertexOutput {
  33.             float4 pos : SV_POSITION;
  34.             float4 posProj : TEXCOORD0;
  35.                // position in projector space
  36.          };
  37.  
  38.          vertexOutput vert(vertexInput input)
  39.          {
  40.             vertexOutput output;
  41.  
  42.             output.posProj = mul(unity_Projector, input.vertex);
  43.             output.pos = UnityObjectToClipPos(input.vertex);
  44.  
  45.             return output;
  46.          }
  47.  
  48.  
  49.          float4 frag(vertexOutput input) : COLOR
  50.          {
  51.             if (input.posProj.w > 0.0)
  52.             {
  53.                 fixed2 scrolledUV = input.posProj.xy / input.posProj.w;
  54.                
  55.                 //Makes the texture moves
  56.                 fixed xScrollValue = frac(_speed * _Time.y);
  57.                 fixed yScrollValue = frac(_speed * _Time.y);
  58.                 scrolledUV += fixed2(xScrollValue, yScrollValue);
  59.  
  60.  
  61.                 float4 color =  tex2D(_ShadowTex , scrolledUV);
  62.                 color.a = 1 - color.a;
  63.                 return color/(1-_ShadowIntensity);
  64.             }
  65.             else
  66.             {
  67.                return float4(0.0, 0.0, 0.0, 0.0);
  68.             }
  69.          }
  70.  
  71.          ENDCG
  72.       }
  73.    }  
  74.    Fallback "Projector/Light"
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement