Created
May 11, 2017 13:20
-
-
Save onotchi/680f24b0c250e690e024df8a7b3bdbe3 to your computer and use it in GitHub Desktop.
おきゅらすたんのスカート用シェーダー
This file contains hidden or 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 "Onoty3D/Toon/Basic Cutout" { | |
Properties{ | |
_Color("Main Color", Color) = (.5,.5,.5,1) | |
_MainTex("Base (RGB)", 2D) = "white" {} | |
_ToonShade("ToonShader Cubemap(RGB)", CUBE) = "" { } | |
_Cutoff("Alpha Cutoff", Range(0,1)) = 0.5 | |
} | |
SubShader{ | |
Tags{ "RenderType" = "Opaque" } | |
Pass{ | |
Name "BASE" | |
Cull Off | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma multi_compile_fog | |
#include "UnityCG.cginc" | |
sampler2D _MainTex; | |
samplerCUBE _ToonShade; | |
float4 _MainTex_ST; | |
float4 _Color; | |
fixed _Cutoff; | |
struct appdata { | |
float4 vertex : POSITION; | |
float2 texcoord : TEXCOORD0; | |
float3 normal : NORMAL; | |
}; | |
struct v2f { | |
float4 pos : SV_POSITION; | |
float2 texcoord : TEXCOORD0; | |
float3 cubenormal : TEXCOORD1; | |
UNITY_FOG_COORDS(2) | |
}; | |
v2f vert(appdata v) | |
{ | |
v2f o; | |
o.pos = UnityObjectToClipPos(v.vertex); | |
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); | |
o.cubenormal = mul(UNITY_MATRIX_MV, float4(v.normal,0)); | |
UNITY_TRANSFER_FOG(o,o.pos); | |
return o; | |
} | |
fixed4 frag(v2f i) : SV_Target | |
{ | |
fixed4 col = _Color * tex2D(_MainTex, i.texcoord); | |
clip(col.a - _Cutoff); | |
fixed4 cube = texCUBE(_ToonShade, i.cubenormal); | |
fixed4 c = fixed4(2.0f * cube.rgb * col.rgb, col.a); | |
UNITY_APPLY_FOG(i.fogCoord, c); | |
return c; | |
} | |
ENDCG | |
} | |
} | |
Fallback "VertexLit" | |
} |
This file contains hidden or 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 "Onoty3D/Toon/Basic Cutout Outline" { | |
Properties{ | |
_Color("Main Color", Color) = (.5,.5,.5,1) | |
_MainTex("Base (RGB)", 2D) = "white" { } | |
_ToonShade("ToonShader Cubemap(RGB)", CUBE) = "" { } | |
_Cutoff("Alpha Cutoff", Range(0,1)) = 0.5 | |
_OutlineColor("Outline Color", Color) = (0,0,0,1) | |
_Outline("Outline width", Range(.00001, 0.03)) = .005 | |
_CutoffOutline("Outline Alpha Cutoff", Range(0,1)) = 0.5 | |
_OutlineZOffset("Outline Z Offset", Range(-1,1)) = 0.001 | |
} | |
CGINCLUDE | |
#include "UnityCG.cginc" | |
struct appdata { | |
float4 vertex : POSITION; | |
float3 normal : NORMAL; | |
float2 texcoord : TEXCOORD0; | |
}; | |
struct v2f { | |
float4 pos : SV_POSITION; | |
UNITY_FOG_COORDS(0) | |
fixed4 color : COLOR; | |
float2 texcoord : TEXCOORD0; | |
}; | |
uniform float4 _Color; | |
uniform float _Outline; | |
uniform float4 _OutlineColor; | |
sampler2D _MainTex; | |
float4 _MainTex_ST; | |
fixed _Cutoff; | |
fixed _CutoffOutline; | |
fixed _OutlineZOffset; | |
v2f vert(appdata v) { | |
v2f o; | |
o.pos = UnityObjectToClipPos(v.vertex); | |
float3 norm = normalize(mul((float3x3)UNITY_MATRIX_IT_MV, v.normal)); | |
float2 offset = TransformViewToProjection(norm.xy); | |
o.pos.xy += offset * o.pos.z * _Outline; | |
o.pos.z += _OutlineZOffset; | |
o.color = _OutlineColor; | |
UNITY_TRANSFER_FOG(o, o.pos); | |
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); | |
return o; | |
} | |
ENDCG | |
SubShader{ | |
Tags{ "RenderType" = "Opaque" } | |
UsePass "Onoty3D/Toon/Basic Cutout/BASE" | |
Pass{ | |
Name "OUTLINE" | |
Tags{ "LightMode" = "Always" } | |
Cull Off | |
ZWrite On | |
ColorMask RGB | |
Blend SrcAlpha OneMinusSrcAlpha | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma multi_compile_fog | |
fixed4 frag(v2f i) : SV_Target | |
{ | |
UNITY_APPLY_FOG(i.fogCoord, i.color); | |
float4 col = _Color * tex2D(_MainTex, i.texcoord); | |
clip(col.a - _CutoffOutline); | |
return i.color; | |
} | |
ENDCG | |
} | |
} | |
Fallback "Onoty3D/Toon/Basic Cutout" | |
} |
This file contains hidden or 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 "Onoty3D/Toon/Lit Cutout" { | |
Properties { | |
_Color ("Main Color", Color) = (0.5,0.5,0.5,1) | |
_MainTex ("Base (RGB)", 2D) = "white" {} | |
_Ramp ("Toon Ramp (RGB)", 2D) = "gray" {} | |
[Enum(OFF,0,FRONT,1,BACK,2)] _CullMode("Cull Mode", int) = 2 //OFF/FRONT/BACK | |
_Cutoff("Alpha cutoff", Range(0,1)) = 0.5 | |
} | |
SubShader{ | |
Tags{ "RenderType" = "Opaque" } | |
LOD 200 | |
Cull[_CullMode] | |
CGPROGRAM | |
#pragma surface surf ToonRamp | |
sampler2D _Ramp; | |
// custom lighting function that uses a texture ramp based | |
// on angle between light direction and normal | |
#pragma lighting ToonRamp exclude_path:prepass | |
inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten) | |
{ | |
#ifndef USING_DIRECTIONAL_LIGHT | |
lightDir = normalize(lightDir); | |
#endif | |
half d = dot (s.Normal, lightDir) * 0.5 + 0.5; | |
half3 ramp = tex2D (_Ramp, float2(d,d)).rgb; | |
half4 c; | |
c.rgb = s.Albedo * _LightColor0.rgb * ramp * atten; | |
c.a = s.Alpha; | |
return c; | |
} | |
sampler2D _MainTex; | |
float4 _Color; | |
fixed _Cutoff; | |
struct Input { | |
float2 uv_MainTex : TEXCOORD0; | |
}; | |
void surf (Input IN, inout SurfaceOutput o) { | |
half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; | |
clip(c.a - _Cutoff); | |
o.Albedo = c.rgb; | |
o.Alpha = c.a; | |
} | |
ENDCG | |
} | |
Fallback "Diffuse" | |
} |
This file contains hidden or 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 "Onoty3D/Toon/Lit Cutout Outline" { | |
Properties { | |
_Color ("Main Color", Color) = (0.5,0.5,0.5,1) | |
_MainTex ("Base (RGB)", 2D) = "white" {} | |
_Ramp ("Toon Ramp (RGB)", 2D) = "gray" {} | |
[Enum(OFF,0,FRONT,1,BACK,2)] _CullMode("Cull Mode", int) = 2 //OFF/FRONT/BACK | |
_Cutoff("Alpha Cutoff", Range(0,1)) = 0.5 | |
_OutlineColor("Outline Color", Color) = (0,0,0,1) | |
_Outline("Outline width", Range(.00001, 0.03)) = .005 | |
_CutoffOutline("Outline Alpha Cutoff", Range(0,1)) = 0.5 | |
_OutlineZOffset("Outline Z Offset", Range(-1,1)) = 0.001 | |
} | |
SubShader { | |
Tags{ "RenderType" = "Opaque" } | |
UsePass "Onoty3D/Toon/Lit Cutout/FORWARD" | |
UsePass "Onoty3D/Toon/Basic Cutout Outline/OUTLINE" | |
} | |
Fallback "Onoty3D/Toon/Lit Cutout" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment