Skip to content

Instantly share code, notes, and snippets.

@hiepnd
Created July 20, 2016 08:46
Show Gist options
  • Save hiepnd/523bbb86ab5929d490e59fccc0c00fc0 to your computer and use it in GitHub Desktop.
Save hiepnd/523bbb86ab5929d490e59fccc0c00fc0 to your computer and use it in GitHub Desktop.
Screen Space UV Map
Shader "Screw/Custom Shadow" {
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_Factor ("Factor", Float) = 0.0125
_Shift ("UV Shift", Float) = 0.5
_Rotation ("Rotation", Float) = 0
}
CGINCLUDE
#include "UnityCG.cginc"
#include "AutoLight.cginc"
#include "Lighting.cginc"
ENDCG
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
Pass
{
Lighting On
Tags {"LightMode" = "ForwardBase"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
struct VSInt {
half4 vertex : POSITION;
};
struct VSOut
{
float4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
};
uniform sampler2D _MainTex;
half _Factor;
half _Shift;
float _Rotation;
VSOut vert(VSInt v)
{
VSOut o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
half4 screenPos = ComputeScreenPos(o.pos);
half4 c = half4(0, 0, 0, 1);
c = mul(UNITY_MATRIX_MVP, c);
half4 center = ComputeScreenPos(c);
half2 uv = (screenPos.xy/screenPos.w - center.xy/center.w)
* _ScreenParams.xy
* _Factor;
half cosalpha = cos(_Rotation * _Time.y);
half sinalpha = sin(_Rotation * _Time.y);
o.uv.x = uv.x * cosalpha - uv.y * sinalpha;
o.uv.y = uv.x * sinalpha + uv.y * cosalpha;
o.uv += _Shift;
return o;
}
float4 frag(VSOut i) : COLOR
{
half4 tex = tex2D(_MainTex, i.uv);
return tex;
}
ENDCG
}
}
FallBack "Diffuse"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment