Skip to content

Instantly share code, notes, and snippets.

@eddietree
Last active June 26, 2017 05:37
Show Gist options
  • Save eddietree/2f90bd2985e174375691b23ab96a9e85 to your computer and use it in GitHub Desktop.
Save eddietree/2f90bd2985e174375691b23ab96a9e85 to your computer and use it in GitHub Desktop.
Shader "Unlit/Zelda"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_HatchTex("Hatch Texture", 2D) = "white" {}
_WatercolorTex("WaterColor Texture", 2D) = "white" {}
_HatchPowCoeff("Hatch Pow", Range(0.0,10.15)) = 3.0
_HatchThreshold("Hatch Threshold", Range(0.0,1.0)) = 0.25
_HatchFadeWidth("Hatch Fade", Range(0.0,1.0)) = 0.1
_WaterColorContrast("Water Color Contrast", Range(0.0,2.0)) = 0.1
_Contrast("Contrast", Range(0.0,10.0)) = 0.1
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 screenPos : TEXCOORD1;
float3 worldPos : TEXCOORD2;
float3 viewNormal : TEXCOORD3;
float4 vertex : SV_POSITION;
float3 normal : NORMAL;
};
sampler2D _MainTex;
sampler2D _HatchTex;
sampler2D _WatercolorTex;
float _HatchPowCoeff;
float _HatchThreshold;
float _HatchFadeWidth;
float _WaterColorContrast;
float _Contrast;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.normal = v.normal;
o.viewNormal = normalize(mul(UNITY_MATRIX_IT_MV, v.normal.xyz));
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
// movement
float4 vertPos = v.vertex;
float3 camPos = _WorldSpaceCameraPos;
float3 dirToCam = normalize(camPos - o.worldPos);
float rim = 1.0 - pow(dot(dirToCam, v.normal), 1.0);// *0.5 + 0.5;
vertPos.xyz += (rim) * o.normal.xyz * 0.004 * step(sin(_Time.z + (o.normal.x+ o.normal.z) * 100.0),0.5);
o.vertex = UnityObjectToClipPos(vertPos);
o.screenPos = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float2 screenPos = i.screenPos.xy / i.screenPos.w;
float3 normal = normalize(i.normal);
float3 viewNormal = normalize(i.viewNormal);
// view-space lightosurces
float3 dirTopRight = normalize(float3(1.0, 1.0, 0.0));
float3 dirBotRight = normalize(float3(-1.0, -1.0, 0.0));
float topRightVal = pow(dot(dirTopRight, viewNormal), _HatchPowCoeff);
float botRightVal = pow(dot(dirBotRight, viewNormal), _HatchPowCoeff);
// hatch sampling
float2 hatchUv = screenPos*0.5 + float2(0.5, 0.5);
hatchUv.x = 1.0 - hatchUv.x;
float hatch = 1.0-tex2D(_HatchTex, hatchUv*1.0).x;
// hatch application
fixed4 col = tex2D(_MainTex, i.uv);
col += hatch *0.15 * smoothstep(_HatchThreshold - _HatchFadeWidth, _HatchThreshold, topRightVal);
col -= hatch *0.2 * smoothstep(_HatchThreshold - _HatchFadeWidth, _HatchThreshold, botRightVal);
// water color overlay
float2 watercColorUv = screenPos*0.5 + float2(0.5, 0.5);
float4 waterColor = tex2D(_WatercolorTex, watercColorUv);
col.xyz *= pow(waterColor.xyz, _WaterColorContrast);
col.xyz = pow(col.xyz, _Contrast);
return col;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment