Created
March 7, 2021 15:44
-
-
Save Eldemarkki/145ccdf57f1456970b91b7a5ff78d8e6 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 "Eldemarkki/Triplanar Shader" | |
{ | |
Properties | |
{ | |
XColor("X Color", Color) = (0.42, 0.42, 0.42, 1) | |
YColor("Y Color", Color) = (0.44, 0.74, 0.01, 1) | |
NegativeYColor("Negative Y Color", Color) = (0.32, 0.32, 0.32, 1) | |
Sensitivity("Sensitivity", Range(0,1)) = 0.6 | |
SensitivityBlend("Sensitivity Blend", Range(0, 0.2)) = 0.1 | |
BlendStepCount("Blend Step Count", Int) = 2 | |
} | |
SubShader | |
{ | |
Tags { "RenderType" = "Opaque"} | |
CGPROGRAM | |
#pragma surface surf Standard fullforwardshadows | |
#pragma target 3.0 | |
fixed4 XColor; | |
fixed4 YColor; | |
fixed4 NegativeYColor; | |
fixed Sensitivity; | |
fixed SensitivityBlend; | |
int BlendStepCount; | |
struct Input | |
{ | |
float3 worldNormal; | |
}; | |
void surf(Input IN, inout SurfaceOutputStandard o) | |
{ | |
fixed x = abs(IN.worldNormal.x); | |
fixed yNormal = IN.worldNormal.y; | |
fixed3 col = fixed3(0, 0, 0); | |
fixed dotP = dot(yNormal, fixed3(0, 1, 0)); | |
fixed t = (dotP - (Sensitivity - SensitivityBlend)) / ((Sensitivity + SensitivityBlend) - (Sensitivity - SensitivityBlend)); | |
t = floor(t * (BlendStepCount + 1)) / (BlendStepCount + 1); | |
bool yNormalLessThanZero = yNormal < 0; | |
fixed3 a = (yNormalLessThanZero) * (NegativeYColor); | |
fixed3 b = (!yNormalLessThanZero) * (XColor + clamp(t, 0, 1) * (YColor - XColor)); | |
col = a + b; | |
o.Albedo = col; | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment