Skip to content

Instantly share code, notes, and snippets.

@EmmaEwert
Last active April 11, 2019 20:58
Show Gist options
  • Save EmmaEwert/36af4e43c35237d65c2932bc351ddb01 to your computer and use it in GitHub Desktop.
Save EmmaEwert/36af4e43c35237d65c2932bc351ddb01 to your computer and use it in GitHub Desktop.
Reflection Camera -> Render Texture -> Material with Reflection shader
Shader "Unlit/Custom/Reflection" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_Tint ("Tint", Color) = (1,1,1,1)
_Intensity ("Intensity", Range(0, 1)) = 0.5
_Speed ("Speed", Range(0, 1)) = 0.5
_Scale ("Scale", Range(0, 1)) = 0.5
_Contrast ("Contrast", Range(0, 1)) = 0.5
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 100
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f {
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Tint;
float _Intensity;
float _Speed;
float _Scale;
float _Contrast;
v2f vert (appdata input) {
v2f output;
output.vertex = UnityObjectToClipPos(input.vertex);
output.uv = TRANSFORM_TEX(input.uv, _MainTex);
UNITY_TRANSFER_FOG(output, output.vertex);
return output;
}
float4 frag (v2f input) : SV_Target {
float2 uv = input.uv;
float wave = (1 - pow(uv.y, 2) / ((1 - (_Intensity / 2)))) * 64;
float falloff = pow(1.125 - uv.y, 1 + (1 - _Intensity / 2) * 4);
float power = (1 - pow(1 - _Intensity / 2, 3.0));
float scale = 1 + (1 - _Scale) * 2;
uv.y = scale - uv.y * scale;
uv.x += sin(_Time.w * _Speed * 8 + wave) * falloff * power;
float4 color = tex2D(_MainTex, uv);
color = pow(color, 1 + _Contrast * _Contrast);
color *= _Tint;
UNITY_APPLY_FOG(input.fogCoord, color);
return color;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment