Last active
October 6, 2018 22:48
-
-
Save enpel/f115bef04cc9c404da5f3e61380ab245 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 "Unlit/toon" | |
{ | |
Properties | |
{ | |
_MainTex ("Texture", 2D) = "white" {} | |
_ShadowColor ("ShadowColor", Color) = (1,1,1,1) | |
_TextureBorder ("TextureBorder", Range(1,0)) = 0.7 | |
_ShadowBorder ("ShadowBorder", Range(1,0)) = 0.3 | |
_LambertCorrect ("_LambertCorrect", Range(1,0)) = 0.5 | |
_MiddleShadow ("_MiddleShadow", Range(1,0)) = 0.5 | |
} | |
SubShader | |
{ | |
Tags { "RenderType"="Opaque" } | |
LOD 100 | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
// make fog work | |
#pragma multi_compile_fog | |
#include "UnityCG.cginc" | |
#include "Lighting.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float3 normal : NORMAL; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float2 uv : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
float3 normal : NORMAL; | |
}; | |
sampler2D _MainTex; | |
half _ShadowBorder; | |
half _TextureBorder; | |
half _LambertCorrect; | |
half _MiddleShadow; | |
float4 _MainTex_ST; | |
float4 _ShadowColor; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.uv = TRANSFORM_TEX(v.uv, _MainTex); | |
o.normal = UnityObjectToWorldNormal(v.normal); | |
return o; | |
} | |
fixed3 frag (v2f i) : SV_Target | |
{ | |
// sample the texture | |
fixed4 col = tex2D(_MainTex, i.uv); | |
float3 lightDir = normalize(_WorldSpaceLightPos0.xyz); | |
float NdotL = dot( i.normal, lightDir) *0.5 + _LambertCorrect; | |
bool2 texOrShadow; | |
texOrShadow.x = step(_TextureBorder, NdotL); | |
texOrShadow.y = step(NdotL, _ShadowBorder); | |
float3 textureColor = col.xyz * texOrShadow.x; | |
float3 middleColor = (lerp(col.xyz, _ShadowColor,_MiddleShadow ))* step(NdotL, _TextureBorder) * step(_ShadowBorder, NdotL) ; | |
float3 shadowColor = _ShadowColor * texOrShadow.y; | |
return textureColor + middleColor + shadowColor; | |
} | |
ENDCG | |
} | |
} | |
} |
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 "Unlit/toon" | |
{ | |
Properties | |
{ | |
_MainTex ("Texture", 2D) = "white" {} | |
_ShadowColor ("ShadowColor", Color) = (1,1,1,1) | |
_TextureBorder ("TextureBorder", Range(1,0)) = 0.7 | |
_ShadowBorder ("ShadowBorder", Range(1,0)) = 0.3 | |
_LambertCorrect ("_LambertCorrect", Range(1,0)) = 0.5 | |
_MiddleShadow ("_MiddleShadow", Range(1,0)) = 0.5 | |
_OutlineSize ("_OutlineSize", float) = 0.01 | |
_OutlineColor ("OutlineColor", Color) = (1,1,1,1) | |
} | |
SubShader | |
{ | |
Tags { "RenderType"="Opaque" } | |
LOD 100 | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
// make fog work | |
#pragma multi_compile_fog | |
#include "UnityCG.cginc" | |
#include "Lighting.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float3 normal : NORMAL; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float2 uv : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
float3 normal : NORMAL; | |
}; | |
sampler2D _MainTex; | |
half _ShadowBorder; | |
half _TextureBorder; | |
half _LambertCorrect; | |
half _MiddleShadow; | |
float4 _MainTex_ST; | |
float4 _ShadowColor; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.uv = TRANSFORM_TEX(v.uv, _MainTex); | |
o.normal = UnityObjectToWorldNormal(v.normal); | |
return o; | |
} | |
fixed3 frag (v2f i) : SV_Target | |
{ | |
// sample the texture | |
fixed4 col = tex2D(_MainTex, i.uv); | |
float3 lightDir = normalize(_WorldSpaceLightPos0.xyz); | |
float NdotL = dot( i.normal, lightDir) *0.5 + _LambertCorrect; | |
bool2 texOrShadow; | |
texOrShadow.x = step(_TextureBorder, NdotL); | |
texOrShadow.y = step(NdotL, _ShadowBorder); | |
float3 textureColor = col.xyz * texOrShadow.x; | |
float3 middleColor = (lerp(col.xyz, _ShadowColor,_MiddleShadow ))* step(NdotL, _TextureBorder) * step(_ShadowBorder, NdotL) ; | |
float3 shadowColor = _ShadowColor * texOrShadow.y; | |
return textureColor + middleColor + shadowColor; | |
} | |
ENDCG | |
} | |
Pass | |
{ | |
Cull Front | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float3 normal : NORMAL; | |
}; | |
struct v2f | |
{ | |
float4 vertex : SV_POSITION; | |
}; | |
half _OutlineSize; | |
half4 _OutlineColor; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
v.vertex += float4(v.normal * _OutlineSize, 0); | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
return o; | |
} | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
return _OutlineColor; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Toon.shader.shader
ToonWithOutline.shader