Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Dvornik/Distort" {
- Properties{
- _Refraction("Refraction", Range(-10.00, 10.0)) = 0
- _MainTex("Sprite Texture", 2D) = "white" {}
- _DistortTex("Distort",2D) = "white" {}
- }
- SubShader{
- Tags{ "RenderType" = "Transparent" "Queue" = "Overlay" }
- LOD 100
- GrabPass{
- }
- CGPROGRAM
- #pragma surface surf NoLighting
- #pragma vertex vert
- fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten) {
- fixed4 c;
- c.rgb = s.Albedo;
- c.a = s.Alpha;
- return c;
- }
- sampler2D _GrabTexture;
- sampler2D _MainTex;
- sampler2D _DistortTex;
- float _Refraction;
- float4 _DistortTex_TexelSize;
- struct Input {
- float2 uv_MainTex;
- float2 uv_DistortTex;
- float3 color;
- float4 grabScreenPos;
- INTERNAL_DATA
- };
- void vert(inout appdata_full v, out Input o) {
- UNITY_INITIALIZE_OUTPUT(Input,o);
- o.color = v.color;
- float4 clipPos = mul(UNITY_MATRIX_MVP, v.vertex);
- o.grabScreenPos = ComputeGrabScreenPos(clipPos);
- }
- void surf(Input IN, inout SurfaceOutput o) {
- float4 main = tex2D(_MainTex, IN.uv_MainTex);
- float4 dist = tex2D(_DistortTex, IN.uv_DistortTex);
- float3 distort = float3(dist.r - 0.5, dist.g - 0.5, dist.b - 0.5);
- float2 offset = distort * _Refraction * _DistortTex_TexelSize.xy;
- //float4 bgColor = tex2Dproj(_GrabTexture, IN.screenPos);
- IN.grabScreenPos.xy = offset + IN.grabScreenPos.xy;
- float4 refrColor = tex2Dproj(_GrabTexture, IN.grabScreenPos);
- float alph = (main.a-0.5)*2;
- //if (alph <= 0) {
- //o.Emission = refrColor.rgb;
- o.Emission = main.rgb * main.a * main.a + (1 - main.a) * refrColor.rgb;
- /*}
- else {
- o.Emission = main.rgb * alph + (1-alph) * refrColor.rgb;
- }*/
- o.Alpha = alph;
- }
- ENDCG
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement