Created
February 16, 2018 21:01
-
-
Save cabbibo/d8b6b28c283f60c76f3839bbcc8b9afa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Custom/HexPostTransfer" { | |
Properties{ | |
_Hue("Hue", float) = 0 | |
_Texture( "Texture" , 2D ) = "white" {} | |
} | |
SubShader { | |
// COLOR PASS | |
Pass { | |
Tags{ "LightMode" = "ForwardBase" } | |
Cull Off | |
CGPROGRAM | |
#pragma target 4.5 | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight | |
#include "UnityCG.cginc" | |
#include "AutoLight.cginc" | |
#include "Chunks/hsv.cginc" | |
uniform float _Hue; | |
uniform sampler2D _Texture; | |
uniform sampler2D _AudioMap; | |
uniform float _transferOffset; | |
struct Transfer { | |
float3 vertex; | |
float3 normal; | |
float2 uv; | |
}; | |
StructuredBuffer<Transfer> _transferBuffer; | |
struct varyings { | |
float4 pos : SV_POSITION; | |
float3 nor : TEXCOORD0; | |
float2 uv : TEXCOORD1; | |
float3 eye : TEXCOORD5; | |
float3 worldPos : TEXCOORD6; | |
float3 debug : TEXCOORD7; | |
SHADOW_COORDS(2) | |
}; | |
varyings vert(uint id : SV_VertexID) { | |
float3 fPos = _transferBuffer[id + _transferOffset].vertex; | |
float3 fNor = _transferBuffer[id + _transferOffset].normal; | |
float2 fUV = _transferBuffer[id + _transferOffset].uv; | |
varyings o; | |
//fPos = float3(0,0,0); | |
o.pos = mul(UNITY_MATRIX_VP, float4(fPos,1)); | |
o.worldPos = fPos; | |
o.eye = _WorldSpaceCameraPos - fPos; | |
o.nor = fNor; | |
o.uv = fUV; | |
TRANSFER_SHADOW(o); | |
return o; | |
} | |
float4 frag(varyings v) : COLOR { | |
fixed shadow = SHADOW_ATTENUATION(v) * .8 + .2; | |
float3 lightDir = normalize(_WorldSpaceLightPos0.xyz-v.worldPos); | |
float m =-dot(lightDir, v.nor); | |
float3 refl = reflect(lightDir , v.nor ); | |
float eyeM = -dot( refl , normalize(v.eye)); | |
float3 norCol = v.nor * .3 + .7; | |
float3 col = max(m,0)*float3(.4,.2,1); | |
//float3 aCol = tex2D(_AudioMap,float2( (v.worldPos.x+10) * .1 , 0)).xyz; | |
float3 aCol = tex2D(_AudioMap,float2( v.uv.x * .03 + v.uv.y * .9 , 0)).xyz; | |
col =norCol * aCol * max(m,0); | |
col += float3(.6 ,.3,2) * pow( max(eyeM,0) , 20 ); | |
//col = float3(0,1,0); | |
return float4( col, 1.); | |
} | |
ENDCG | |
} | |
// SHADOW PASS | |
Pass | |
{ | |
Tags{ "LightMode" = "ShadowCaster" } | |
Fog{ Mode Off } | |
ZWrite On | |
ZTest LEqual | |
Cull Off | |
Offset 1, 1 | |
CGPROGRAM | |
#pragma target 4.5 | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma multi_compile_shadowcaster | |
#pragma fragmentoption ARB_precision_hint_fastest | |
#include "UnityCG.cginc" | |
struct Transfer { | |
float3 vertex; | |
float3 normal; | |
float2 uv; | |
}; | |
uniform sampler2D _Texture; | |
struct v2f { | |
V2F_SHADOW_CASTER; | |
float2 uv : TEXCOORD7; | |
}; | |
uniform float _transferOffset; | |
StructuredBuffer<Transfer> _transferBuffer; | |
v2f vert(appdata_base v, uint id : SV_VertexID) | |
{ | |
v2f o; | |
o.pos = mul(UNITY_MATRIX_VP, float4(_transferBuffer[id + _transferOffset].vertex, 1)); | |
o.uv = _transferBuffer[id + _transferOffset].uv; | |
return o; | |
} | |
float4 frag(v2f i) : COLOR | |
{ | |
SHADOW_CASTER_FRAGMENT(i) | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment