├── Comic-Like-Tone ├── hatch0.png ├── hatch1.png ├── hatch2.png ├── hatch3.png ├── hatch4.png └── hatch5.png ├── HatchingShader.shader ├── HatchingShaderLerpTes.shader ├── HatchingShaderTes.shader ├── LICENSE ├── Pencil-Like-Stroke ├── hatch0.jpg ├── hatch1.jpg ├── hatch2.jpg ├── hatch3.jpg ├── hatch4.jpg └── hatch5.jpg ├── README.md ├── Unity_2018-08-20_20-00-57.png └── Unity_2018-08-29_03-33-28.jpg /Comic-Like-Tone/hatch0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkihrk/HatchingShader/9acbc5f7cea28c9c14c782c7cd7314b09adb1da9/Comic-Like-Tone/hatch0.png -------------------------------------------------------------------------------- /Comic-Like-Tone/hatch1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkihrk/HatchingShader/9acbc5f7cea28c9c14c782c7cd7314b09adb1da9/Comic-Like-Tone/hatch1.png -------------------------------------------------------------------------------- /Comic-Like-Tone/hatch2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkihrk/HatchingShader/9acbc5f7cea28c9c14c782c7cd7314b09adb1da9/Comic-Like-Tone/hatch2.png -------------------------------------------------------------------------------- /Comic-Like-Tone/hatch3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkihrk/HatchingShader/9acbc5f7cea28c9c14c782c7cd7314b09adb1da9/Comic-Like-Tone/hatch3.png -------------------------------------------------------------------------------- /Comic-Like-Tone/hatch4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkihrk/HatchingShader/9acbc5f7cea28c9c14c782c7cd7314b09adb1da9/Comic-Like-Tone/hatch4.png -------------------------------------------------------------------------------- /Comic-Like-Tone/hatch5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkihrk/HatchingShader/9acbc5f7cea28c9c14c782c7cd7314b09adb1da9/Comic-Like-Tone/hatch5.png -------------------------------------------------------------------------------- /HatchingShader.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/HatchingShader" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" { } 6 | _NormalTex ("Normal Texture", 2D) = "bump" { } 7 | _Hatch0 ("Hatch0", 2D) = "white" { } 8 | _Hatch1 ("Hatch1", 2D) = "white" { } 9 | _Hatch2 ("Hatch2", 2D) = "white" { } 10 | _Hatch3 ("Hatch3", 2D) = "white" { } 11 | _Hatch4 ("Hatch4", 2D) = "white" { } 12 | _Hatch5 ("Hatch5", 2D) = "white" { } 13 | _OutlineMask ("Outline Mask Texture", 2D) = "black" { } 14 | _OutlineColor ("Outline Color", Color) = (0, 0, 0, 1) 15 | _OutlineWidth ("Outline Width", Float) = 0 16 | [Enum(OFF, 0, ON, 1)] _Hoge2 ("Toggle Billboard", int) = 0 17 | _Angle ("Angle", Range(0.0, 360.0)) = 0.0 18 | _Xcomp ("_Xcomp", Range(0.0, 0.99)) = 0.0 19 | _Ycomp ("_Ycomp", Range(0.0, 0.99)) = 0.0 20 | _Zcomp ("_Zcomp", Range(0.0, 0.99)) = 0.0 21 | _RimPower ("Rim Power", Float) = 0.0 22 | _RimAmplitude ("Rim Amplitude", Float) = 0.0 23 | _Threshold ("Threshold", Range(0.0, 1.0)) = 0.5 24 | _Adjust ("NdotL or NdotV", Range(0.0, 1.0)) = 0.6 25 | _Density ("Density", Range(0.0, 1.0)) = 0.6 26 | _Roughness ("Roughness", Range(0.1, 30)) = 8.0 27 | [Enum(OFF, 0, ON, 1)] _Hoge ("Toggle Gray Scale", int) = 0 28 | [Enum(OFF, 0, FRONT, 1, BACK, 2)] _CullMode ("Cull Mode", int) = 0 29 | } 30 | 31 | SubShader 32 | { 33 | Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } 34 | Blend SrcAlpha OneMinusSrcAlpha 35 | Cull[_CullMode] 36 | LOD 100 37 | 38 | CGINCLUDE 39 | #pragma target 3.0 40 | #pragma vertex vert 41 | #pragma fragment frag 42 | #pragma multi_compile_fog 43 | 44 | #include "UnityCG.cginc" 45 | #include "AutoLight.cginc" 46 | #include "UnityPBSLighting.cginc" 47 | 48 | float2x2 rotateFnc(float b) 49 | { 50 | float alpha = b * UNITY_PI / 180.0; 51 | float sina, cosa; 52 | sincos(alpha, sina, cosa); 53 | return float2x2(cosa, -sina, sina, cosa); 54 | } 55 | 56 | float4 Rotate(float4 a, float b) 57 | { 58 | float2x2 m = rotateFnc(b); 59 | return float4(mul(m, a.xz), a.yw).xzyw; 60 | } 61 | 62 | #ifdef USING_STEREO_MATRICES 63 | static float3 centerCameraPos = 0.5 * (unity_StereoWorldSpaceCameraPos[0] + unity_StereoWorldSpaceCameraPos[1]); 64 | #else 65 | static float3 centerCameraPos = _WorldSpaceCameraPos; 66 | #endif 67 | 68 | ENDCG 69 | 70 | Pass 71 | { 72 | Cull Front 73 | CGPROGRAM 74 | 75 | struct appdata 76 | { 77 | float4 vertex: POSITION; 78 | float2 uvM: TEXCOORD0; 79 | float3 normal: NORMAL; 80 | }; 81 | 82 | struct v2f 83 | { 84 | float2 uv: TEXCOORD0; 85 | UNITY_FOG_COORDS(1) 86 | float4 vertex: SV_POSITION; 87 | float2 uvM: TEXCOORD0; 88 | float3 normal: TEXCOORD1; 89 | float4 wpos: TEXCOORD2; 90 | }; 91 | 92 | uniform sampler2D _MainTex; uniform float4 _MainTex_ST; 93 | uniform sampler2D _OutlineMask; uniform float4 _OutlineMask_ST; 94 | uniform int _Hoge; 95 | uniform int _Hoge2; 96 | uniform fixed4 _OutlineColor; 97 | uniform float _RimPower; 98 | uniform float _RimAmplitude; 99 | uniform float _OutlineWidth; 100 | uniform float _Xcomp; 101 | uniform float _Ycomp; 102 | uniform float _Zcomp; 103 | uniform float _Angle; 104 | 105 | v2f vert(appdata v) 106 | { 107 | v2f o; 108 | _OutlineWidth /= 1000; 109 | o.uvM = v.uvM; 110 | float3 outlineMask = tex2Dlod(_OutlineMask, float4(TRANSFORM_TEX(o.uvM, _OutlineMask), 0.0, 0)).rgb; 111 | v.vertex.xyz += lerp(0, v.normal * (1.0 - outlineMask.rgb) * _OutlineWidth, saturate(_OutlineWidth * 1000)); 112 | v.vertex = Rotate(v.vertex, _Angle); 113 | v.vertex.xyz = v.vertex.xyz * (1 - float3(_Xcomp, _Ycomp, _Zcomp)); 114 | float4 pos = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0, 0, 0, 1)) + float4(v.vertex.x, v.vertex.y, v.vertex.z, 0)); 115 | o.vertex = lerp(UnityObjectToClipPos(v.vertex), pos, _Hoge2); 116 | o.normal = UnityObjectToWorldNormal(v.normal); 117 | o.wpos = mul(unity_ObjectToWorld, v.vertex); 118 | UNITY_TRANSFER_FOG(o, o.vertex); 119 | return o; 120 | } 121 | 122 | fixed4 frag(v2f i): SV_Target 123 | { 124 | float3 N = i.normal; 125 | float3 V = normalize(centerCameraPos.xyz - i.wpos.xyz); 126 | 127 | float NdotV = max(0, dot(N, V)); 128 | float NNdotV = 1.01 - dot(N, V); 129 | float rim = pow(NNdotV, _RimPower) * _RimAmplitude; 130 | 131 | fixed4 col = _OutlineColor; 132 | col.rgb = lerp(col.rgb, dot(col.rgb, half3(0.2326, 0.7152, 0.0722)), _Hoge); 133 | 134 | fixed3 colRim = col.rgb * 1.0 + rim * fixed3(1.0, 1.0, 1.0); 135 | 136 | col.rgb = lerp(col.rgb, colRim, V); 137 | 138 | UNITY_APPLY_FOG(i.fogCoord, col); 139 | return col; 140 | } 141 | ENDCG 142 | 143 | } 144 | 145 | Pass 146 | { 147 | Tags { "LightMode" = "ForwardBase" } 148 | CGPROGRAM 149 | 150 | #pragma multi_compile_fwdbase 151 | #pragma multi_compile _ VERTEXLIGHT_ON 152 | 153 | struct appdata 154 | { 155 | float4 vertex: POSITION; 156 | float2 uv: TEXCOORD0; 157 | float3 normal: NORMAL; 158 | float3 tangent: TANGENT; 159 | }; 160 | 161 | struct v2f 162 | { 163 | float2 uv: TEXCOORD0; 164 | UNITY_FOG_COORDS(1) 165 | float4 vertex: SV_POSITION; 166 | float3 normal: TEXCOORD2; 167 | float2 huv: TEXCOORD3; 168 | float4 wpos: TEXCOORD4; 169 | LIGHTING_COORDS(5, 6) 170 | float3 tangent: TEXCOORD7; 171 | float3 binormal: TEXCOORD8; 172 | #if defined(VERTEXLIGHT_ON) 173 | fixed3 vertexLightColor: TEXCOORD9; 174 | #endif 175 | }; 176 | 177 | uniform sampler2D _MainTex; uniform float4 _MainTex_ST; 178 | uniform sampler2D _NormalTex; uniform float4 _NormalTex_ST; 179 | uniform sampler2D _Hatch0; 180 | uniform sampler2D _Hatch1; 181 | uniform sampler2D _Hatch2; 182 | uniform sampler2D _Hatch3; 183 | uniform sampler2D _Hatch4; 184 | uniform sampler2D _Hatch5; 185 | uniform float _Xcomp; 186 | uniform float _Ycomp; 187 | uniform float _Zcomp; 188 | uniform float _RimPower; 189 | uniform float _RimAmplitude; 190 | uniform float _Threshold; 191 | uniform float _Adjust; 192 | uniform float _Density; 193 | uniform float _Roughness; 194 | uniform int _Hoge; 195 | uniform int _Hoge2; 196 | uniform float _Angle; 197 | 198 | void ComputeVertexLightColor(inout v2f i) 199 | { 200 | #if defined(VERTEXLIGHT_ON) 201 | i.vertexLightColor = Shade4PointLights( 202 | unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0, 203 | unity_LightColor[0].rgb, unity_LightColor[1].rgb, 204 | unity_LightColor[2].rgb, unity_LightColor[3].rgb, 205 | unity_4LightAtten0, i.wpos, i.normal 206 | ); 207 | #endif 208 | } 209 | 210 | v2f vert(appdata v) 211 | { 212 | v2f o = (v2f)0; 213 | o.wpos = mul(unity_ObjectToWorld, v.vertex); 214 | v.vertex = Rotate(v.vertex, _Angle); 215 | v.vertex.xyz = v.vertex.xyz * (1 - float3(_Xcomp, _Ycomp, _Zcomp)); 216 | float4 pos = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0, 0, 0, 1)) + float4(v.vertex.x, v.vertex.y, v.vertex.z, 0)); 217 | o.vertex = lerp(UnityObjectToClipPos(v.vertex), pos, _Hoge2); 218 | o.uv = TRANSFORM_TEX(v.uv, _MainTex); 219 | o.huv = TRANSFORM_TEX(v.uv, _MainTex) * _Roughness; 220 | o.normal = UnityObjectToWorldNormal(v.normal); 221 | o.tangent = UnityObjectToWorldNormal(v.tangent); 222 | o.binormal = normalize(cross(o.tangent, o.normal)); 223 | ComputeVertexLightColor(o); 224 | UNITY_TRANSFER_FOG(o, o.vertex); 225 | return o; 226 | } 227 | 228 | fixed4 frag(v2f i): SV_Target 229 | { 230 | float3 tangentNormal = float4(UnpackNormal(tex2D(_NormalTex, i.uv)), 1); 231 | float3x3 TBN = float3x3(i.tangent, i.binormal, i.normal); 232 | TBN = transpose(TBN); 233 | float3 worldNormal = mul(TBN, tangentNormal); 234 | float3 N = lerp(i.normal, worldNormal, saturate(length(tangentNormal) * 100)); 235 | 236 | float3 lightDir; 237 | #if defined(POINT) || defined(POINT_COOKIE) || defined(SPOT) 238 | lightDir = normalize(_WorldSpaceLightPos0.xyz - i.wpos.xyz); 239 | #else 240 | lightDir = _WorldSpaceLightPos0.xyz; 241 | #endif 242 | 243 | fixed4 lightCol; 244 | #if defined(VERTEXLIGHT_ON) 245 | lightCol = fixed4(i.vertexLightColor, 1); 246 | #else 247 | lightCol = _LightColor0; 248 | #endif 249 | 250 | lightCol.rgb += max(0, ShadeSH9(float4(N, 1))); 251 | 252 | float3 L = lightDir; 253 | float3 V = normalize(centerCameraPos.xyz - i.wpos.xyz); 254 | 255 | float NdotV = max(0, dot(N, V)); 256 | float NNdotV = 1.01 - dot(N, V); 257 | float rim = pow(NNdotV, _RimPower) * _RimAmplitude; 258 | 259 | float NdotL = max(0, dot(L, N)); 260 | UNITY_LIGHT_ATTENUATION(attenuation, i, N) 261 | lightCol *= attenuation; 262 | 263 | fixed4 col = tex2D(_MainTex, i.uv); 264 | 265 | fixed4 hatch0 = tex2D(_Hatch0, i.huv); 266 | fixed4 hatch1 = tex2D(_Hatch1, i.huv); 267 | fixed4 hatch2 = tex2D(_Hatch2, i.huv); 268 | fixed4 hatch3 = tex2D(_Hatch3, i.huv); 269 | fixed4 hatch4 = tex2D(_Hatch4, i.huv); 270 | fixed4 hatch5 = tex2D(_Hatch5, i.huv); 271 | 272 | if (length(lightCol.rgb) < _Threshold) 273 | { 274 | float3 diffuse = col.rgb * NdotV; 275 | float intensity = lerp(saturate(length(diffuse)), 0.5 * saturate(dot(diffuse, half3(0.2326, 0.7152, 0.0722))), _Density); 276 | 277 | if(0.6 < intensity) 278 | { 279 | col *= fixed4(1, 1, 1, 1); 280 | } 281 | else if(0.5 < intensity && intensity <= 0.6) 282 | { 283 | col *= lerp(hatch0, hatch1, 1 - intensity); 284 | } 285 | else if(0.4 < intensity && intensity <= 0.5) 286 | { 287 | col *= lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity); 288 | } 289 | else if(0.3 < intensity && intensity <= 0.4) 290 | { 291 | col *= lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity); 292 | } 293 | else if(0.2 < intensity && intensity <= 0.3) 294 | { 295 | col *= lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity); 296 | } 297 | else if(0.1 < intensity && intensity <= 0.2) 298 | { 299 | col *= lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity); 300 | } 301 | else if(intensity <= 0.1) 302 | { 303 | col *= lerp(lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), hatch5 * 0.5, NdotV * 1.5); 304 | } 305 | } 306 | else 307 | { 308 | float manipulate = lerp(NdotL, NdotV, _Adjust); 309 | float3 diffuse = lerp(col.rgb * manipulate, lightCol, 1.0 / pow(3, length(lightCol))); 310 | float intensity = lerp(saturate(length(diffuse)), 0.5 * saturate(dot(diffuse, half3(0.2326, 0.7152, 0.0722))), _Density); 311 | 312 | if(0.6 < intensity) 313 | { 314 | col *= fixed4(1, 1, 1, 1); 315 | } 316 | else if(0.5 < intensity && intensity <= 0.6) 317 | { 318 | col *= lerp(hatch0, hatch1, 1 - intensity); 319 | } 320 | else if(0.4 < intensity && intensity <= 0.5) 321 | { 322 | col *= lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity); 323 | } 324 | else if(0.3 < intensity && intensity <= 0.4) 325 | { 326 | col *= lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity); 327 | } 328 | else if(0.2 < intensity && intensity <= 0.3) 329 | { 330 | col *= lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity); 331 | } 332 | else if(0.1 < intensity && intensity <= 0.2) 333 | { 334 | col *= lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity); 335 | } 336 | else if(intensity <= 0.1) 337 | { 338 | col *= lerp(lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), hatch5 * 0.5, (1 - NdotL) * 1.5); 339 | } 340 | } 341 | 342 | col.rgb = lerp(col.rgb, dot(col.rgb, half3(0.2326, 0.7152, 0.0722)), _Hoge) * _LightColor0.rgb; 343 | 344 | fixed3 colRim = col.rgb * 1.0 + rim * fixed3(1.0, 1.0, 1.0); 345 | col.rgb = lerp(col.rgb, colRim, V); 346 | col.a = 1; 347 | 348 | UNITY_APPLY_FOG(i.fogCoord, col); 349 | return saturate(col); 350 | } 351 | ENDCG 352 | 353 | } 354 | Pass 355 | { 356 | Tags { "LightMode" = "ForwardAdd" } 357 | Blend One One 358 | CGPROGRAM 359 | 360 | #pragma multi_compile_fwdadd 361 | 362 | struct appdata 363 | { 364 | float4 vertex: POSITION; 365 | float2 uv: TEXCOORD0; 366 | float3 normal: NORMAL; 367 | float3 tangent: TANGENT; 368 | }; 369 | 370 | struct v2f 371 | { 372 | float2 uv: TEXCOORD0; 373 | UNITY_FOG_COORDS(1) 374 | float4 vertex: SV_POSITION; 375 | float3 normal: TEXCOORD2; 376 | float2 huv: TEXCOORD3; 377 | float4 wpos: TEXCOORD4; 378 | LIGHTING_COORDS(5, 6) 379 | float3 tangent: TEXCOORD7; 380 | float3 binormal: TEXCOORD8; 381 | }; 382 | 383 | uniform sampler2D _MainTex; uniform float4 _MainTex_ST; 384 | uniform sampler2D _NormalTex; uniform float4 _NormalTex_ST; 385 | uniform sampler2D _Hatch0; 386 | uniform sampler2D _Hatch1; 387 | uniform sampler2D _Hatch2; 388 | uniform sampler2D _Hatch3; 389 | uniform sampler2D _Hatch4; 390 | uniform sampler2D _Hatch5; 391 | uniform float _Xcomp; 392 | uniform float _Ycomp; 393 | uniform float _Zcomp; 394 | uniform float _RimPower; 395 | uniform float _RimAmplitude; 396 | uniform float _Threshold; 397 | uniform float _Adjust; 398 | uniform float _Density; 399 | uniform float _Roughness; 400 | uniform int _Hoge; 401 | uniform int _Hoge2; 402 | uniform float _Angle; 403 | 404 | v2f vert(appdata v) 405 | { 406 | v2f o = (v2f)0; 407 | o.wpos = mul(unity_ObjectToWorld, v.vertex); 408 | v.vertex = Rotate(v.vertex, _Angle); 409 | v.vertex.xyz = v.vertex.xyz * (1 - float3(_Xcomp, _Ycomp, _Zcomp)); 410 | float4 pos = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0, 0, 0, 1)) + float4(v.vertex.x, v.vertex.y, v.vertex.z, 0)); 411 | o.vertex = lerp(UnityObjectToClipPos(v.vertex), pos, _Hoge2); 412 | o.uv = TRANSFORM_TEX(v.uv, _MainTex); 413 | o.huv = TRANSFORM_TEX(v.uv, _MainTex) * _Roughness; 414 | o.normal = UnityObjectToWorldNormal(v.normal); 415 | o.tangent = UnityObjectToWorldNormal(v.tangent); 416 | o.binormal = normalize(cross(o.tangent, o.normal)); 417 | UNITY_TRANSFER_FOG(o, o.vertex); 418 | return o; 419 | } 420 | 421 | fixed4 frag(v2f i): SV_Target 422 | { 423 | float3 tangentNormal = float4(UnpackNormal(tex2D(_NormalTex, i.uv)), 1); 424 | float3x3 TBN = float3x3(i.tangent, i.binormal, i.normal); 425 | TBN = transpose(TBN); 426 | float3 worldNormal = mul(TBN, tangentNormal); 427 | 428 | float3 N = lerp(i.normal, worldNormal, saturate(length(tangentNormal) * 100)); 429 | float3 V = normalize(centerCameraPos.xyz - i.wpos.xyz); 430 | 431 | float3 lightDir; 432 | #if defined(POINT) || defined(POINT_COOKIE) || defined(SPOT) 433 | lightDir = normalize(_WorldSpaceLightPos0.xyz - i.wpos.xyz); 434 | #else 435 | lightDir = _WorldSpaceLightPos0.xyz; 436 | #endif 437 | fixed4 lightCol = _LightColor0; 438 | lightCol.rgb += max(0, ShadeSH9(float4(N, 1))); 439 | float3 L = lightDir; 440 | 441 | float NdotV = max(0, dot(N, V)); 442 | float NNdotV = 1.01 - dot(N, V); 443 | float rim = pow(NNdotV, _RimPower) * _RimAmplitude; 444 | 445 | float NdotL = max(0, dot(L, N)); 446 | UNITY_LIGHT_ATTENUATION(attenuation, i, N) 447 | lightCol *= attenuation; 448 | 449 | fixed4 col = tex2D(_MainTex, i.uv); 450 | 451 | fixed4 hatch0 = tex2D(_Hatch0, i.huv); 452 | fixed4 hatch1 = tex2D(_Hatch1, i.huv); 453 | fixed4 hatch2 = tex2D(_Hatch2, i.huv); 454 | fixed4 hatch3 = tex2D(_Hatch3, i.huv); 455 | fixed4 hatch4 = tex2D(_Hatch4, i.huv); 456 | fixed4 hatch5 = tex2D(_Hatch5, i.huv); 457 | 458 | if (length(lightCol.rgb) < _Threshold) 459 | { 460 | float3 diffuse = col.rgb * NdotV; 461 | float intensity = lerp(saturate(length(diffuse)), 0.5 * saturate(dot(diffuse, half3(0.2326, 0.7152, 0.0722))), _Density); 462 | 463 | if(0.6 < intensity) 464 | { 465 | col *= fixed4(1, 1, 1, 1); 466 | } 467 | else if(0.5 < intensity && intensity <= 0.6) 468 | { 469 | col *= lerp(hatch0, hatch1, 1 - intensity); 470 | } 471 | else if(0.4 < intensity && intensity <= 0.5) 472 | { 473 | col *= lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity); 474 | } 475 | else if(0.3 < intensity && intensity <= 0.4) 476 | { 477 | col *= lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity); 478 | } 479 | else if(0.2 < intensity && intensity <= 0.3) 480 | { 481 | col *= lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity); 482 | } 483 | else if(0.1 < intensity && intensity <= 0.2) 484 | { 485 | col *= lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity); 486 | } 487 | else if(intensity <= 0.1) 488 | { 489 | col *= lerp(lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), hatch5 * 0.5, NdotV * 1.5); 490 | } 491 | } 492 | else 493 | { 494 | float manipulate = lerp(NdotL, NdotV, _Adjust); 495 | float3 diffuse = lerp(col.rgb * manipulate, lightCol, 1.0 / pow(3, length(lightCol))); 496 | float intensity = lerp(saturate(length(diffuse)), 0.5 * saturate(dot(diffuse, half3(0.2326, 0.7152, 0.0722))), _Density); 497 | 498 | if(0.6 < intensity) 499 | { 500 | col *= fixed4(1, 1, 1, 1); 501 | } 502 | else if(0.5 < intensity && intensity <= 0.6) 503 | { 504 | col *= lerp(hatch0, hatch1, 1 - intensity); 505 | } 506 | else if(0.4 < intensity && intensity <= 0.5) 507 | { 508 | col *= lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity); 509 | } 510 | else if(0.3 < intensity && intensity <= 0.4) 511 | { 512 | col *= lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity); 513 | } 514 | else if(0.2 < intensity && intensity <= 0.3) 515 | { 516 | col *= lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity); 517 | } 518 | else if(0.1 < intensity && intensity <= 0.2) 519 | { 520 | col *= lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity); 521 | } 522 | else if(intensity <= 0.1) 523 | { 524 | col *= lerp(lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), hatch5 * 0.5, (1 - NdotL) * 1.5); 525 | } 526 | } 527 | 528 | col.rgb = lerp(col.rgb, dot(col.rgb, half3(0.2326, 0.7152, 0.0722)), _Hoge) * _LightColor0.rgb; 529 | 530 | fixed3 colRim = col.rgb * 1.0 + rim * fixed3(1.0, 1.0, 1.0); 531 | col.rgb = lerp(col.rgb, colRim, V); 532 | col.a = 1; 533 | 534 | UNITY_APPLY_FOG(i.fogCoord, col); 535 | return saturate(col); 536 | } 537 | ENDCG 538 | 539 | } 540 | } 541 | Fallback "Diffuse" 542 | } 543 | -------------------------------------------------------------------------------- /HatchingShaderLerpTes.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/HatchingShaderLerpTes" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" { } 6 | _NormalTex ("Normal Texture", 2D) = "bump" { } 7 | _NoiseTex ("Noise Texture", 2D) = "black" { } 8 | _Hatch0 ("Hatch0", 2D) = "white" { } 9 | _Hatch1 ("Hatch1", 2D) = "white" { } 10 | _Hatch2 ("Hatch2", 2D) = "white" { } 11 | _Hatch3 ("Hatch3", 2D) = "white" { } 12 | _Hatch4 ("Hatch4", 2D) = "white" { } 13 | _Hatch5 ("Hatch5", 2D) = "white" { } 14 | _MinDist ("Min Distance", Range(0.1, 50)) = 10 15 | _MaxDist ("Max Distance", Range(0.1, 50)) = 25 16 | _TessFactor ("Tessellation", Range(1, 50)) = 10 17 | _NoiseSpeed ("Noise Speed", Range(0.0, 10)) = 0.0 18 | _NoisePower ("Noise Power", Range(1.0, 3.0)) = 1.0 19 | _NoiseFactor ("Noise Factor", Range(0.0, 10)) = 0.0 20 | [Enum(OFF, 0, ON, 1)] _Hoge2 ("Toggle Billboard", int) = 0 21 | _Angle ("Angle", Range(0.0, 360.0)) = 0.0 22 | _Xcomp ("_Xcomp", Range(0.0, 0.99)) = 0.0 23 | _Ycomp ("_Ycomp", Range(0.0, 0.99)) = 0.0 24 | _Zcomp ("_Zcomp", Range(0.0, 0.99)) = 0.0 25 | _RimPower ("Rim Power", Float) = 0.0 26 | _RimAmplitude ("Rim Amplitude", Float) = 0.0 27 | _Threshold ("Threshold", Range(0.0, 1.0)) = 0.5 28 | _Adjust ("NdotL or NdotV", Range(0.0, 1.0)) = 0.6 29 | _Density ("Density", Range(0.0, 1.0)) = 0.6 30 | _Roughness ("Roughness", Range(0.1, 30)) = 8.0 31 | [Enum(OFF, 0, ON, 1)] _Hoge ("Toggle Gray Scale", int) = 0 32 | [Enum(OFF, 0, FRONT, 1, BACK, 2)] _CullMode ("Cull Mode", int) = 0 33 | } 34 | 35 | SubShader 36 | { 37 | Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } 38 | Blend SrcAlpha OneMinusSrcAlpha 39 | Cull[_CullMode] 40 | LOD 100 41 | 42 | CGINCLUDE 43 | #pragma target 3.0 44 | #pragma vertex vert 45 | #pragma fragment frag 46 | #pragma multi_compile_fog 47 | 48 | #include "UnityCG.cginc" 49 | #include "AutoLight.cginc" 50 | #include "UnityPBSLighting.cginc" 51 | 52 | 53 | #define one fixed4(1, 1, 1, 1) 54 | 55 | uniform sampler2D _MainTex; uniform float4 _MainTex_ST; 56 | uniform sampler2D _NormalTex; uniform float4 _NormalTex_ST; 57 | uniform sampler2D _NoiseTex; uniform float4 _NoiseTex_ST; 58 | uniform sampler2D _Hatch0; 59 | uniform sampler2D _Hatch1; 60 | uniform sampler2D _Hatch2; 61 | uniform sampler2D _Hatch3; 62 | uniform sampler2D _Hatch4; 63 | uniform sampler2D _Hatch5; 64 | uniform float _MinDist; 65 | uniform float _MaxDist; 66 | uniform float _TessFactor; 67 | uniform float _NoiseSpeed; 68 | uniform float _NoisePower; 69 | uniform float _NoiseFactor; 70 | uniform float _Xcomp; 71 | uniform float _Ycomp; 72 | uniform float _Zcomp; 73 | uniform float _RimPower; 74 | uniform float _RimAmplitude; 75 | uniform float _Threshold; 76 | uniform float _Adjust; 77 | uniform float _Density; 78 | uniform float _Roughness; 79 | uniform int _Hoge; 80 | uniform int _Hoge2; 81 | uniform float _Angle; 82 | 83 | float C2F(float3 Color) 84 | { 85 | int c1 = 255; 86 | int c2 = 255 * 255; 87 | int c3 = 255 * 255 * 255; 88 | return(Color.x * 255 + Color.y * 255 * c1 + Color.z * 255 * c2) / c3; 89 | } 90 | 91 | fixed2 rand(fixed2 st) 92 | { 93 | st = fixed2(dot(st, fixed2(127.1, 311.7)), dot(st, fixed2(269.5, 183.3))); 94 | return - 1.0 + 2.0 * frac(sin(st) * 43758.5453123); 95 | } 96 | 97 | float perlinNoise(fixed2 st) 98 | { 99 | fixed2 p = floor(st); 100 | fixed2 f = frac(st); 101 | fixed2 u = f * f * (3.0 - 2.0 * f); 102 | float v00 = rand(p + fixed2(0, 0)); 103 | float v10 = rand(p + fixed2(1, 0)); 104 | float v01 = rand(p + fixed2(0, 1)); 105 | float v11 = rand(p + fixed2(1, 1)); 106 | return lerp(lerp(dot(v00, f - fixed2(0, 0)), dot(v10, f - fixed2(1, 0)), u.x), lerp(dot(v01, f - fixed2(0, 1)), dot(v11, f - fixed2(1, 1)), u.x), u.y) + 0.5f; 107 | } 108 | 109 | float fBm(fixed2 st) 110 | { 111 | float f = 0; 112 | fixed2 q = st; 113 | f += 0.5000 * perlinNoise(q); q = q * 2.01; 114 | f += 0.2500 * perlinNoise(q); q = q * 2.02; 115 | f += 0.1250 * perlinNoise(q); q = q * 2.03; 116 | f += 0.0625 * perlinNoise(q); q = q * 2.01; 117 | return f; 118 | } 119 | 120 | float2x2 rotateFnc(float b) 121 | { 122 | float alpha = b * UNITY_PI / 180.0; 123 | float sina, cosa; 124 | sincos(alpha, sina, cosa); 125 | return float2x2(cosa, -sina, sina, cosa); 126 | } 127 | 128 | float4 Rotate(float4 a, float b) 129 | { 130 | float2x2 m = rotateFnc(b); 131 | return float4(mul(m, a.xz), a.yw).xzyw; 132 | } 133 | ENDCG 134 | 135 | Pass 136 | { 137 | Tags { "LightMode" = "ForwardBase" } 138 | CGPROGRAM 139 | 140 | #pragma hull hull 141 | #pragma domain domain 142 | #pragma multi_compile_fwdbase 143 | #pragma multi_compile _ VERTEXLIGHT_ON 144 | 145 | #include "Tessellation.cginc" 146 | 147 | struct appdata 148 | { 149 | float4 vertex: POSITION; 150 | float2 uv: TEXCOORD0; 151 | float3 normal: NORMAL; 152 | float3 tangent: TANGENT; 153 | }; 154 | 155 | struct v2h 156 | { 157 | float4 f4Position: TEXCOORD0; 158 | float3 f3Normal: TEXCOORD1; 159 | float2 f2TexCoord: TEXCOORD2; 160 | float3 f3Tangent: TEXCOORD3; 161 | }; 162 | 163 | struct HsControlPointOutput 164 | { 165 | float3 f3Position: TEXCOORD0; 166 | float3 f3Normal: TEXCOORD1; 167 | float2 f2TexCoord: TEXCOORD2; 168 | float3 f3Tangent: TEXCOORD3; 169 | }; 170 | 171 | struct HsConstantOutput 172 | { 173 | float fTessFactor[3]: SV_TESSFACTOR; 174 | float fInsideTessFactor: SV_INSIDETESSFACTOR; 175 | }; 176 | 177 | struct h2f 178 | { 179 | float2 uv: TEXCOORD0; 180 | UNITY_FOG_COORDS(1) 181 | float4 vertex: SV_POSITION; 182 | float3 normal: TEXCOORD2; 183 | float2 huv: TEXCOORD3; 184 | float4 wpos: TEXCOORD4; 185 | LIGHTING_COORDS(5, 6) 186 | float3 tangent: TEXCOORD7; 187 | float3 binormal: TEXCOORD8; 188 | #if defined(VERTEXLIGHT_ON) 189 | fixed3 vertexLightColor: TEXCOORD9; 190 | #endif 191 | }; 192 | 193 | void ComputeVertexLightColor(inout h2f i) 194 | { 195 | #if defined(VERTEXLIGHT_ON) 196 | i.vertexLightColor = Shade4PointLights( 197 | unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0, 198 | unity_LightColor[0].rgb, unity_LightColor[1].rgb, 199 | unity_LightColor[2].rgb, unity_LightColor[3].rgb, 200 | unity_4LightAtten0, i.wpos, i.normal 201 | ); 202 | #endif 203 | } 204 | 205 | v2h vert(appdata i) 206 | { 207 | v2h o; 208 | o.f4Position = i.vertex; 209 | o.f3Normal = i.normal; 210 | o.f2TexCoord = i.uv; 211 | o.f3Tangent = i.tangent; 212 | return o; 213 | } 214 | 215 | [domain("tri")] 216 | [partitioning("integer")] 217 | [outputtopology("triangle_cw")] 218 | [patchconstantfunc("hullConst")] 219 | [outputcontrolpoints(3)] 220 | HsControlPointOutput hull(InputPatch < v2h, 3 > i, uint id: SV_OUTPUTCONTROLPOINTID) 221 | { 222 | HsControlPointOutput o = (HsControlPointOutput)0; 223 | o.f3Position = i[id].f4Position.xyz; 224 | o.f3Normal = i[id].f3Normal; 225 | o.f2TexCoord = i[id].f2TexCoord; 226 | o.f3Tangent = i[id].f3Tangent; 227 | return o; 228 | } 229 | 230 | HsConstantOutput hullConst(InputPatch < v2h, 3 > i) 231 | { 232 | HsConstantOutput o = (HsConstantOutput)0; 233 | float4 p0 = i[0].f4Position; 234 | float4 p1 = i[1].f4Position; 235 | float4 p2 = i[2].f4Position; 236 | float4 tessFactor = UnityDistanceBasedTess(p0, p1, p2, _MinDist, _MaxDist, _TessFactor); 237 | 238 | o.fTessFactor[0] = tessFactor.x; 239 | o.fTessFactor[1] = tessFactor.y; 240 | o.fTessFactor[2] = tessFactor.z; 241 | o.fInsideTessFactor = tessFactor.w; 242 | return o; 243 | } 244 | 245 | [domain("tri")] 246 | h2f domain(HsConstantOutput hsConst, const OutputPatch < HsControlPointOutput, 3 > i, float3 bary: SV_DOMAINLOCATION) 247 | { 248 | h2f o = (h2f)0; 249 | 250 | float3 f3Position = bary.x * i[0].f3Position + bary.y * i[1].f3Position + bary.z * i[2].f3Position; 251 | float3 f3Normal = bary.x * i[0].f3Normal + bary.y * i[1].f3Normal + bary.z * i[2].f3Normal; 252 | float3 f3Tangent = bary.x * i[0].f3Tangent + bary.y * i[1].f3Tangent + bary.z * i[2].f3Tangent; 253 | float2 f2TexCoord = bary.x * i[0].f2TexCoord + bary.y * i[1].f2TexCoord + bary.z * i[2].f2TexCoord; 254 | 255 | float2 uvNoise = TRANSFORM_TEX(f2TexCoord, _NoiseTex); 256 | float angle = 180 * UNITY_PI * (_Time.x / 100 * _NoiseSpeed); 257 | float pivot = 0.5; 258 | float x = (uvNoise.x - pivot) * cos(angle) - (uvNoise.y - pivot) * sin(angle) + pivot; 259 | float y = (uvNoise.x - pivot) * sin(angle) + (uvNoise.y - pivot) * cos(angle) + pivot; 260 | uvNoise = float2(x, y); 261 | fixed4 noiseTex = tex2Dlod(_NoiseTex, float4(uvNoise, 0, 0)); 262 | float c2f = pow(pow(_NoisePower, _NoisePower), C2F(noiseTex.rgb)); 263 | float c = fBm(f2TexCoord.xy * _Time.x * _NoiseSpeed); 264 | fixed4 prlNoise = lerp(fixed4(c, c, c, 1), fixed4(c2f, c2f, c2f, 1), saturate(noiseTex * 100)); 265 | 266 | f3Position.xyz += f3Normal * prlNoise.xyz * _NoiseFactor; 267 | float4 f4Position = mul(unity_ObjectToWorld, float4(f3Position.xyz, 1.0)); 268 | 269 | o.wpos = f4Position; 270 | float4 vertex = Rotate(float4(f3Position.xyz, 1.0), _Angle); 271 | vertex.xyz = vertex.xyz * (1 - float3(_Xcomp, _Ycomp, _Zcomp)); 272 | float4 pos = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0, 0, 0, 1)) + float4(vertex.x, vertex.y, vertex.z, 0)); 273 | o.vertex = lerp(UnityObjectToClipPos(vertex), pos, _Hoge2); 274 | o.uv = TRANSFORM_TEX(f2TexCoord, _MainTex); 275 | o.huv = TRANSFORM_TEX(f2TexCoord, _MainTex) * _Roughness; 276 | o.normal = UnityObjectToWorldNormal(f3Normal); 277 | o.tangent = UnityObjectToWorldNormal(f3Tangent); 278 | o.binormal = normalize(cross(o.tangent, o.normal)); 279 | ComputeVertexLightColor(o); 280 | UNITY_TRANSFER_FOG(o, o.vertex); 281 | return o; 282 | } 283 | 284 | fixed4 frag(h2f i): SV_Target 285 | { 286 | float3 tangentNormal = float4(UnpackNormal(tex2D(_NormalTex, i.uv)), 1); 287 | float3x3 TBN = float3x3(i.tangent, i.binormal, i.normal); 288 | TBN = transpose(TBN); 289 | float3 worldNormal = mul(TBN, tangentNormal); 290 | 291 | float3 N = lerp(i.normal, worldNormal, saturate(length(tangentNormal) * 100)); 292 | 293 | float3 lightDir; 294 | #if defined(POINT) || defined(POINT_COOKIE) || defined(SPOT) 295 | lightDir = normalize(_WorldSpaceLightPos0.xyz - i.wpos.xyz); 296 | #else 297 | lightDir = _WorldSpaceLightPos0.xyz; 298 | #endif 299 | 300 | fixed4 lightCol; 301 | #if defined(VERTEXLIGHT_ON) 302 | lightCol = fixed4(i.vertexLightColor, 1); 303 | #else 304 | lightCol = _LightColor0; 305 | #endif 306 | 307 | lightCol.rgb += max(0, ShadeSH9(float4(N, 1))); 308 | 309 | float3 L = lightDir; 310 | float3 V = normalize(_WorldSpaceCameraPos.xyz - i.wpos.xyz); 311 | 312 | float NdotV = max(0, dot(N, V)); 313 | float NNdotV = 1 - dot(N, V); 314 | float rim = pow(NNdotV, _RimPower) * _RimAmplitude; 315 | 316 | float NdotL = max(0, dot(L, N)); 317 | UNITY_LIGHT_ATTENUATION(attenuation, i, N) 318 | lightCol *= attenuation; 319 | 320 | fixed4 col = tex2D(_MainTex, i.uv); 321 | 322 | fixed4 hatch0 = tex2D(_Hatch0, i.huv); 323 | fixed4 hatch1 = tex2D(_Hatch1, i.huv); 324 | fixed4 hatch2 = tex2D(_Hatch2, i.huv); 325 | fixed4 hatch3 = tex2D(_Hatch3, i.huv); 326 | fixed4 hatch4 = tex2D(_Hatch4, i.huv); 327 | fixed4 hatch5 = tex2D(_Hatch5, i.huv); 328 | 329 | if (length(lightCol.rgb) < _Threshold) 330 | { 331 | float3 diffuse = col.rgb * NdotV; 332 | float intensity = lerp(saturate(length(diffuse)), 0.5 * saturate(dot(diffuse, half3(0.2326, 0.7152, 0.0722))), _Density); 333 | 334 | col *= one; 335 | col *= lerp(one, lerp(hatch0, hatch1, 1 - intensity), step(0.5, step(intensity, 0.6))); 336 | col *= lerp(one, lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), step(0.4, step(intensity, 0.5))); 337 | col *= lerp(one, lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), step(0.3, step(intensity, 0.4))); 338 | col *= lerp(one, lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), step(0.2, step(intensity, 0.3))); 339 | col *= lerp(one, lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), step(0.1, step(intensity, 0.2))); 340 | col *= lerp(one, lerp(lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), hatch5 * 0.5, NdotV * 1.5), step(intensity, 0.1)); 341 | } 342 | else 343 | { 344 | float manipulate = lerp(NdotL, NdotV, _Adjust); 345 | float3 diffuse = lerp(col.rgb * manipulate, lightCol, 1.0 / pow(3, length(lightCol))); 346 | float intensity = lerp(saturate(length(diffuse)), 0.5 * saturate(dot(diffuse, half3(0.2326, 0.7152, 0.0722))), _Density); 347 | 348 | col *= one; 349 | col *= lerp(one, lerp(hatch0, hatch1, 1 - intensity), step(0.5, step(intensity, 0.6))); 350 | col *= lerp(one, lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), step(0.4, step(intensity, 0.5))); 351 | col *= lerp(one, lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), step(0.3, step(intensity, 0.4))); 352 | col *= lerp(one, lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), step(0.2, step(intensity, 0.3))); 353 | col *= lerp(one, lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), step(0.1, step(intensity, 0.2))); 354 | col *= lerp(one, lerp(lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), hatch5 * 0.5, (1 - NdotL) * 1.5), step(intensity, 0.1)); 355 | } 356 | 357 | col.rgb = lerp(col.rgb, dot(col.rgb, half3(0.2326, 0.7152, 0.0722)), _Hoge) * _LightColor0.rgb; 358 | 359 | fixed3 colRim = col.rgb * 1.0 + rim * fixed3(1.0, 1.0, 1.0); 360 | col.rgb = lerp(col.rgb, colRim, V); 361 | col.a = 1; 362 | 363 | UNITY_APPLY_FOG(i.fogCoord, col); 364 | return col; 365 | } 366 | ENDCG 367 | 368 | } 369 | Pass 370 | { 371 | Tags { "LightMode" = "ForwardAdd" } 372 | Blend One One 373 | CGPROGRAM 374 | 375 | #pragma hull hull 376 | #pragma domain domain 377 | #pragma multi_compile_fwdadd 378 | 379 | #include "Tessellation.cginc" 380 | 381 | struct appdata 382 | { 383 | float4 vertex: POSITION; 384 | float2 uv: TEXCOORD0; 385 | float3 normal: NORMAL; 386 | float3 tangent: TANGENT; 387 | }; 388 | 389 | struct v2h 390 | { 391 | float4 f4Position: TEXCOORD0; 392 | float3 f3Normal: TEXCOORD1; 393 | float2 f2TexCoord: TEXCOORD2; 394 | float3 f3Tangent: TEXCOORD3; 395 | }; 396 | 397 | struct HsControlPointOutput 398 | { 399 | float3 f3Position: TEXCOORD0; 400 | float3 f3Normal: TEXCOORD1; 401 | float2 f2TexCoord: TEXCOORD2; 402 | float3 f3Tangent: TEXCOORD3; 403 | }; 404 | 405 | struct HsConstantOutput 406 | { 407 | float fTessFactor[3]: SV_TESSFACTOR; 408 | float fInsideTessFactor: SV_INSIDETESSFACTOR; 409 | }; 410 | 411 | struct h2f 412 | { 413 | float2 uv: TEXCOORD0; 414 | UNITY_FOG_COORDS(1) 415 | float4 vertex: SV_POSITION; 416 | float3 normal: TEXCOORD2; 417 | float2 huv: TEXCOORD3; 418 | float4 wpos: TEXCOORD4; 419 | LIGHTING_COORDS(5, 6) 420 | float3 tangent: TEXCOORD7; 421 | float3 binormal: TEXCOORD8; 422 | }; 423 | 424 | v2h vert(appdata i) 425 | { 426 | v2h o; 427 | o.f4Position = i.vertex; 428 | o.f3Normal = i.normal; 429 | o.f2TexCoord = i.uv; 430 | o.f3Tangent = i.tangent; 431 | return o; 432 | } 433 | 434 | [domain("tri")] 435 | [partitioning("integer")] 436 | [outputtopology("triangle_cw")] 437 | [patchconstantfunc("hullConst")] 438 | [outputcontrolpoints(3)] 439 | HsControlPointOutput hull(InputPatch < v2h, 3 > i, uint id: SV_OUTPUTCONTROLPOINTID) 440 | { 441 | HsControlPointOutput o = (HsControlPointOutput)0; 442 | o.f3Position = i[id].f4Position.xyz; 443 | o.f3Normal = i[id].f3Normal; 444 | o.f2TexCoord = i[id].f2TexCoord; 445 | o.f3Tangent = i[id].f3Tangent; 446 | return o; 447 | } 448 | 449 | HsConstantOutput hullConst(InputPatch < v2h, 3 > i) 450 | { 451 | HsConstantOutput o = (HsConstantOutput)0; 452 | float4 p0 = i[0].f4Position; 453 | float4 p1 = i[1].f4Position; 454 | float4 p2 = i[2].f4Position; 455 | float4 tessFactor = UnityDistanceBasedTess(p0, p1, p2, _MinDist, _MaxDist, _TessFactor); 456 | 457 | o.fTessFactor[0] = tessFactor.x; 458 | o.fTessFactor[1] = tessFactor.y; 459 | o.fTessFactor[2] = tessFactor.z; 460 | o.fInsideTessFactor = tessFactor.w; 461 | return o; 462 | } 463 | 464 | [domain("tri")] 465 | h2f domain(HsConstantOutput hsConst, const OutputPatch < HsControlPointOutput, 3 > i, float3 bary: SV_DOMAINLOCATION) 466 | { 467 | h2f o = (h2f)0; 468 | 469 | float3 f3Position = bary.x * i[0].f3Position + bary.y * i[1].f3Position + bary.z * i[2].f3Position; 470 | float3 f3Normal = bary.x * i[0].f3Normal + bary.y * i[1].f3Normal + bary.z * i[2].f3Normal; 471 | float3 f3Tangent = bary.x * i[0].f3Tangent + bary.y * i[1].f3Tangent + bary.z * i[2].f3Tangent; 472 | float2 f2TexCoord = bary.x * i[0].f2TexCoord + bary.y * i[1].f2TexCoord + bary.z * i[2].f2TexCoord; 473 | 474 | float2 uvNoise = TRANSFORM_TEX(f2TexCoord, _NoiseTex); 475 | float angle = 180 * UNITY_PI * (_Time.x / 100 * _NoiseSpeed); 476 | float pivot = 0.5; 477 | float x = (uvNoise.x - pivot) * cos(angle) - (uvNoise.y - pivot) * sin(angle) + pivot; 478 | float y = (uvNoise.x - pivot) * sin(angle) + (uvNoise.y - pivot) * cos(angle) + pivot; 479 | uvNoise = float2(x, y); 480 | fixed4 noiseTex = tex2Dlod(_NoiseTex, float4(uvNoise, 0, 0)); 481 | float c2f = pow(pow(_NoisePower, _NoisePower), C2F(noiseTex.rgb)); 482 | float c = fBm(f2TexCoord.xy * _Time.x * _NoiseSpeed); 483 | fixed4 prlNoise = lerp(fixed4(c, c, c, 1), fixed4(c2f, c2f, c2f, 1), saturate(noiseTex * 100)); 484 | 485 | f3Position.xyz += f3Normal * prlNoise.xyz * _NoiseFactor; 486 | float4 f4Position = mul(unity_ObjectToWorld, float4(f3Position.xyz, 1.0)); 487 | 488 | o.wpos = f4Position; 489 | float4 vertex = Rotate(float4(f3Position.xyz, 1.0), _Angle); 490 | vertex.xyz = vertex.xyz * (1 - float3(_Xcomp, _Ycomp, _Zcomp)); 491 | float4 pos = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0, 0, 0, 1)) + float4(vertex.x, vertex.y, vertex.z, 0)); 492 | o.vertex = lerp(UnityObjectToClipPos(vertex), pos, _Hoge2); 493 | o.uv = TRANSFORM_TEX(f2TexCoord, _MainTex); 494 | o.huv = TRANSFORM_TEX(f2TexCoord, _MainTex) * _Roughness; 495 | o.normal = UnityObjectToWorldNormal(f3Normal); 496 | o.tangent = UnityObjectToWorldNormal(f3Tangent); 497 | o.binormal = normalize(cross(o.tangent, o.normal)); 498 | UNITY_TRANSFER_FOG(o, o.vertex); 499 | return o; 500 | } 501 | 502 | fixed4 frag(h2f i): SV_Target 503 | { 504 | float3 tangentNormal = float4(UnpackNormal(tex2D(_NormalTex, i.uv)), 1); 505 | float3x3 TBN = float3x3(i.tangent, i.binormal, i.normal); 506 | TBN = transpose(TBN); 507 | float3 worldNormal = mul(TBN, tangentNormal); 508 | 509 | float3 N = lerp(i.normal, worldNormal, saturate(length(tangentNormal) * 100)); 510 | float3 V = normalize(_WorldSpaceCameraPos.xyz - i.wpos.xyz); 511 | 512 | float3 lightDir; 513 | #if defined(POINT) || defined(POINT_COOKIE) || defined(SPOT) 514 | lightDir = normalize(_WorldSpaceLightPos0.xyz - i.wpos.xyz); 515 | #else 516 | lightDir = _WorldSpaceLightPos0.xyz; 517 | #endif 518 | fixed4 lightCol = _LightColor0; 519 | lightCol.rgb += max(0, ShadeSH9(float4(N, 1))); 520 | float3 L = lightDir; 521 | 522 | float NdotV = max(0, dot(N, V)); 523 | float NNdotV = 1 - dot(N, V); 524 | float rim = pow(NNdotV, _RimPower) * _RimAmplitude; 525 | 526 | float NdotL = max(0, dot(L, N)); 527 | UNITY_LIGHT_ATTENUATION(attenuation, i, N) 528 | lightCol *= attenuation; 529 | 530 | fixed4 col = tex2D(_MainTex, i.uv); 531 | 532 | fixed4 hatch0 = tex2D(_Hatch0, i.huv); 533 | fixed4 hatch1 = tex2D(_Hatch1, i.huv); 534 | fixed4 hatch2 = tex2D(_Hatch2, i.huv); 535 | fixed4 hatch3 = tex2D(_Hatch3, i.huv); 536 | fixed4 hatch4 = tex2D(_Hatch4, i.huv); 537 | fixed4 hatch5 = tex2D(_Hatch5, i.huv); 538 | 539 | if(length(lightCol.rgb) < _Threshold) 540 | { 541 | float3 diffuse = col.rgb * NdotV; 542 | float intensity = lerp(saturate(length(diffuse)), 0.5 * saturate(dot(diffuse, half3(0.2326, 0.7152, 0.0722))), _Density); 543 | 544 | col *= one; 545 | col *= lerp(one, lerp(hatch0, hatch1, 1 - intensity), step(0.5, step(intensity, 0.6))); 546 | col *= lerp(one, lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), step(0.4, step(intensity, 0.5))); 547 | col *= lerp(one, lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), step(0.3, step(intensity, 0.4))); 548 | col *= lerp(one, lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), step(0.2, step(intensity, 0.3))); 549 | col *= lerp(one, lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), step(0.1, step(intensity, 0.2))); 550 | col *= lerp(one, lerp(lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), hatch5 * 0.5, NdotV * 1.5), step(intensity, 0.1)); 551 | } 552 | else 553 | { 554 | float manipulate = lerp(NdotL, NdotV, _Adjust); 555 | float3 diffuse = lerp(col.rgb * manipulate, lightCol, 1.0 / pow(3, length(lightCol))); 556 | float intensity = lerp(saturate(length(diffuse)), 0.5 * saturate(dot(diffuse, half3(0.2326, 0.7152, 0.0722))), _Density); 557 | 558 | col *= one; 559 | col *= lerp(one, lerp(hatch0, hatch1, 1 - intensity), step(0.5, step(intensity, 0.6))); 560 | col *= lerp(one, lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), step(0.4, step(intensity, 0.5))); 561 | col *= lerp(one, lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), step(0.3, step(intensity, 0.4))); 562 | col *= lerp(one, lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), step(0.2, step(intensity, 0.3))); 563 | col *= lerp(one, lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), step(0.1, step(intensity, 0.2))); 564 | col *= lerp(one, lerp(lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), hatch5 * 0.5, (1 - NdotL) * 1.5), step(intensity, 0.1)); 565 | } 566 | 567 | col.rgb = lerp(col.rgb, dot(col.rgb, half3(0.2326, 0.7152, 0.0722)), _Hoge) * _LightColor0.rgb; 568 | 569 | fixed3 colRim = col.rgb * 1.0 + rim * fixed3(1.0, 1.0, 1.0); 570 | col.rgb = lerp(col.rgb, colRim, V); 571 | col.a = 1; 572 | 573 | UNITY_APPLY_FOG(i.fogCoord, col); 574 | return col; 575 | } 576 | ENDCG 577 | 578 | } 579 | } 580 | Fallback "Diffuse" 581 | } 582 | -------------------------------------------------------------------------------- /HatchingShaderTes.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/HatchingShaderTes" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" { } 6 | _NormalTex ("Normal Texture", 2D) = "bump" { } 7 | _NoiseTex ("Noise Texture", 2D) = "black" { } 8 | _Hatch0 ("Hatch0", 2D) = "white" { } 9 | _Hatch1 ("Hatch1", 2D) = "white" { } 10 | _Hatch2 ("Hatch2", 2D) = "white" { } 11 | _Hatch3 ("Hatch3", 2D) = "white" { } 12 | _Hatch4 ("Hatch4", 2D) = "white" { } 13 | _Hatch5 ("Hatch5", 2D) = "white" { } 14 | _MinDist ("Min Distance", Range(0.1, 50)) = 10 15 | _MaxDist ("Max Distance", Range(0.1, 50)) = 25 16 | _TessFactor ("Tessellation", Range(1, 50)) = 10 17 | _NoiseSpeed ("Noise Speed", Range(0.0, 10)) = 0.0 18 | _NoisePower ("Noise Power", Range(1.0, 3.0)) = 1.0 19 | _NoiseFactor ("Noise Factor", Range(0.0, 10)) = 0.0 20 | [Enum(OFF, 0, ON, 1)] _Hoge2 ("Toggle Billboard", int) = 0 21 | _Angle ("Angle", Range(0.0, 360.0)) = 0.0 22 | _Xcomp ("_Xcomp", Range(0.0, 0.99)) = 0.0 23 | _Ycomp ("_Ycomp", Range(0.0, 0.99)) = 0.0 24 | _Zcomp ("_Zcomp", Range(0.0, 0.99)) = 0.0 25 | _RimPower ("Rim Power", Float) = 0.0 26 | _RimAmplitude ("Rim Amplitude", Float) = 0.0 27 | _Threshold ("Threshold", Range(0.0, 1.0)) = 0.5 28 | _Adjust ("NdotL or NdotV", Range(0.0, 1.0)) = 0.6 29 | _Density ("Density", Range(0.0, 1.0)) = 0.6 30 | _Roughness ("Roughness", Range(0.1, 30)) = 8.0 31 | [Enum(OFF, 0, ON, 1)] _Hoge ("Toggle Gray Scale", int) = 0 32 | [Enum(OFF, 0, FRONT, 1, BACK, 2)] _CullMode ("Cull Mode", int) = 0 33 | } 34 | 35 | SubShader 36 | { 37 | Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } 38 | Blend SrcAlpha OneMinusSrcAlpha 39 | Cull[_CullMode] 40 | LOD 100 41 | 42 | CGINCLUDE 43 | #pragma target 3.0 44 | #pragma vertex vert 45 | #pragma fragment frag 46 | #pragma multi_compile_fog 47 | 48 | #include "UnityCG.cginc" 49 | #include "AutoLight.cginc" 50 | #include "UnityPBSLighting.cginc" 51 | 52 | 53 | #define one fixed4(1, 1, 1, 1) 54 | 55 | uniform sampler2D _MainTex; uniform float4 _MainTex_ST; 56 | uniform sampler2D _NormalTex; uniform float4 _NormalTex_ST; 57 | uniform sampler2D _NoiseTex; uniform float4 _NoiseTex_ST; 58 | uniform sampler2D _Hatch0; 59 | uniform sampler2D _Hatch1; 60 | uniform sampler2D _Hatch2; 61 | uniform sampler2D _Hatch3; 62 | uniform sampler2D _Hatch4; 63 | uniform sampler2D _Hatch5; 64 | uniform float _MinDist; 65 | uniform float _MaxDist; 66 | uniform float _TessFactor; 67 | uniform float _NoiseSpeed; 68 | uniform float _NoisePower; 69 | uniform float _NoiseFactor; 70 | uniform float _Xcomp; 71 | uniform float _Ycomp; 72 | uniform float _Zcomp; 73 | uniform float _RimPower; 74 | uniform float _RimAmplitude; 75 | uniform float _Threshold; 76 | uniform float _Adjust; 77 | uniform float _Density; 78 | uniform float _Roughness; 79 | uniform int _Hoge; 80 | uniform int _Hoge2; 81 | uniform float _Angle; 82 | 83 | float C2F(float3 Color) 84 | { 85 | int c1 = 255; 86 | int c2 = 255 * 255; 87 | int c3 = 255 * 255 * 255; 88 | return(Color.x * 255 + Color.y * 255 * c1 + Color.z * 255 * c2) / c3; 89 | } 90 | 91 | fixed2 rand(fixed2 st) 92 | { 93 | st = fixed2(dot(st, fixed2(127.1, 311.7)), dot(st, fixed2(269.5, 183.3))); 94 | return - 1.0 + 2.0 * frac(sin(st) * 43758.5453123); 95 | } 96 | 97 | float perlinNoise(fixed2 st) 98 | { 99 | fixed2 p = floor(st); 100 | fixed2 f = frac(st); 101 | fixed2 u = f * f * (3.0 - 2.0 * f); 102 | float v00 = rand(p + fixed2(0, 0)); 103 | float v10 = rand(p + fixed2(1, 0)); 104 | float v01 = rand(p + fixed2(0, 1)); 105 | float v11 = rand(p + fixed2(1, 1)); 106 | return lerp(lerp(dot(v00, f - fixed2(0, 0)), dot(v10, f - fixed2(1, 0)), u.x), lerp(dot(v01, f - fixed2(0, 1)), dot(v11, f - fixed2(1, 1)), u.x), u.y) + 0.5f; 107 | } 108 | 109 | float fBm(fixed2 st) 110 | { 111 | float f = 0; 112 | fixed2 q = st; 113 | f += 0.5000 * perlinNoise(q); q = q * 2.01; 114 | f += 0.2500 * perlinNoise(q); q = q * 2.02; 115 | f += 0.1250 * perlinNoise(q); q = q * 2.03; 116 | f += 0.0625 * perlinNoise(q); q = q * 2.01; 117 | return f; 118 | } 119 | 120 | float2x2 rotateFnc(float b) 121 | { 122 | float alpha = b * UNITY_PI / 180.0; 123 | float sina, cosa; 124 | sincos(alpha, sina, cosa); 125 | return float2x2(cosa, -sina, sina, cosa); 126 | } 127 | 128 | float4 Rotate(float4 a, float b) 129 | { 130 | float2x2 m = rotateFnc(b); 131 | return float4(mul(m, a.xz), a.yw).xzyw; 132 | } 133 | ENDCG 134 | 135 | Pass 136 | { 137 | Tags { "LightMode" = "ForwardBase" } 138 | CGPROGRAM 139 | 140 | #pragma hull hull 141 | #pragma domain domain 142 | #pragma multi_compile_fwdbase 143 | #pragma multi_compile _ VERTEXLIGHT_ON 144 | 145 | #include "Tessellation.cginc" 146 | 147 | struct appdata 148 | { 149 | float4 vertex: POSITION; 150 | float2 uv: TEXCOORD0; 151 | float3 normal: NORMAL; 152 | float3 tangent: TANGENT; 153 | }; 154 | 155 | struct v2h 156 | { 157 | float4 f4Position: TEXCOORD0; 158 | float3 f3Normal: TEXCOORD1; 159 | float2 f2TexCoord: TEXCOORD2; 160 | float3 f3Tangent: TEXCOORD3; 161 | }; 162 | 163 | struct HsControlPointOutput 164 | { 165 | float3 f3Position: TEXCOORD0; 166 | float3 f3Normal: TEXCOORD1; 167 | float2 f2TexCoord: TEXCOORD2; 168 | float3 f3Tangent: TEXCOORD3; 169 | }; 170 | 171 | struct HsConstantOutput 172 | { 173 | float fTessFactor[3]: SV_TESSFACTOR; 174 | float fInsideTessFactor: SV_INSIDETESSFACTOR; 175 | }; 176 | 177 | struct h2f 178 | { 179 | float2 uv: TEXCOORD0; 180 | UNITY_FOG_COORDS(1) 181 | float4 vertex: SV_POSITION; 182 | float3 normal: TEXCOORD2; 183 | float2 huv: TEXCOORD3; 184 | float4 wpos: TEXCOORD4; 185 | LIGHTING_COORDS(5, 6) 186 | float3 tangent: TEXCOORD7; 187 | float3 binormal: TEXCOORD8; 188 | #if defined(VERTEXLIGHT_ON) 189 | fixed3 vertexLightColor: TEXCOORD9; 190 | #endif 191 | }; 192 | 193 | void ComputeVertexLightColor(inout h2f i) 194 | { 195 | #if defined(VERTEXLIGHT_ON) 196 | i.vertexLightColor = Shade4PointLights( 197 | unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0, 198 | unity_LightColor[0].rgb, unity_LightColor[1].rgb, 199 | unity_LightColor[2].rgb, unity_LightColor[3].rgb, 200 | unity_4LightAtten0, i.wpos, i.normal 201 | ); 202 | #endif 203 | } 204 | 205 | v2h vert(appdata i) 206 | { 207 | v2h o; 208 | o.f4Position = i.vertex; 209 | o.f3Normal = i.normal; 210 | o.f2TexCoord = i.uv; 211 | o.f3Tangent = i.tangent; 212 | return o; 213 | } 214 | 215 | [domain("tri")] 216 | [partitioning("integer")] 217 | [outputtopology("triangle_cw")] 218 | [patchconstantfunc("hullConst")] 219 | [outputcontrolpoints(3)] 220 | HsControlPointOutput hull(InputPatch < v2h, 3 > i, uint id: SV_OUTPUTCONTROLPOINTID) 221 | { 222 | HsControlPointOutput o = (HsControlPointOutput)0; 223 | o.f3Position = i[id].f4Position.xyz; 224 | o.f3Normal = i[id].f3Normal; 225 | o.f2TexCoord = i[id].f2TexCoord; 226 | o.f3Tangent = i[id].f3Tangent; 227 | return o; 228 | } 229 | 230 | HsConstantOutput hullConst(InputPatch < v2h, 3 > i) 231 | { 232 | HsConstantOutput o = (HsConstantOutput)0; 233 | float4 p0 = i[0].f4Position; 234 | float4 p1 = i[1].f4Position; 235 | float4 p2 = i[2].f4Position; 236 | float4 tessFactor = UnityDistanceBasedTess(p0, p1, p2, _MinDist, _MaxDist, _TessFactor); 237 | 238 | o.fTessFactor[0] = tessFactor.x; 239 | o.fTessFactor[1] = tessFactor.y; 240 | o.fTessFactor[2] = tessFactor.z; 241 | o.fInsideTessFactor = tessFactor.w; 242 | return o; 243 | } 244 | 245 | [domain("tri")] 246 | h2f domain(HsConstantOutput hsConst, const OutputPatch < HsControlPointOutput, 3 > i, float3 bary: SV_DOMAINLOCATION) 247 | { 248 | h2f o = (h2f)0; 249 | 250 | float3 f3Position = bary.x * i[0].f3Position + bary.y * i[1].f3Position + bary.z * i[2].f3Position; 251 | float3 f3Normal = bary.x * i[0].f3Normal + bary.y * i[1].f3Normal + bary.z * i[2].f3Normal; 252 | float3 f3Tangent = bary.x * i[0].f3Tangent + bary.y * i[1].f3Tangent + bary.z * i[2].f3Tangent; 253 | float2 f2TexCoord = bary.x * i[0].f2TexCoord + bary.y * i[1].f2TexCoord + bary.z * i[2].f2TexCoord; 254 | 255 | float2 uvNoise = TRANSFORM_TEX(f2TexCoord, _NoiseTex); 256 | float angle = 180 * UNITY_PI * (_Time.x / 100 * _NoiseSpeed); 257 | float pivot = 0.5; 258 | float x = (uvNoise.x - pivot) * cos(angle) - (uvNoise.y - pivot) * sin(angle) + pivot; 259 | float y = (uvNoise.x - pivot) * sin(angle) + (uvNoise.y - pivot) * cos(angle) + pivot; 260 | uvNoise = float2(x, y); 261 | fixed4 noiseTex = tex2Dlod(_NoiseTex, float4(uvNoise, 0, 0)); 262 | float c2f = pow(pow(_NoisePower, _NoisePower), C2F(noiseTex.rgb)); 263 | float c = fBm(f2TexCoord.xy * _Time.x * _NoiseSpeed); 264 | fixed4 prlNoise = lerp(fixed4(c, c, c, 1), fixed4(c2f, c2f, c2f, 1), saturate(noiseTex * 100)); 265 | 266 | f3Position.xyz += f3Normal * prlNoise.xyz * _NoiseFactor; 267 | float4 f4Position = mul(unity_ObjectToWorld, float4(f3Position.xyz, 1.0)); 268 | 269 | o.wpos = f4Position; 270 | float4 vertex = Rotate(float4(f3Position.xyz, 1.0), _Angle); 271 | vertex.xyz = vertex.xyz * (1 - float3(_Xcomp, _Ycomp, _Zcomp)); 272 | float4 pos = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0, 0, 0, 1)) + float4(vertex.x, vertex.y, vertex.z, 0)); 273 | o.vertex = lerp(UnityObjectToClipPos(vertex), pos, _Hoge2); 274 | o.uv = TRANSFORM_TEX(f2TexCoord, _MainTex); 275 | o.huv = TRANSFORM_TEX(f2TexCoord, _MainTex) * _Roughness; 276 | o.normal = UnityObjectToWorldNormal(f3Normal); 277 | o.tangent = UnityObjectToWorldNormal(f3Tangent); 278 | o.binormal = normalize(cross(o.tangent, o.normal)); 279 | ComputeVertexLightColor(o); 280 | UNITY_TRANSFER_FOG(o, o.vertex); 281 | return o; 282 | } 283 | 284 | fixed4 frag(h2f i): SV_Target 285 | { 286 | float3 tangentNormal = float4(UnpackNormal(tex2D(_NormalTex, i.uv)), 1); 287 | float3x3 TBN = float3x3(i.tangent, i.binormal, i.normal); 288 | TBN = transpose(TBN); 289 | float3 worldNormal = mul(TBN, tangentNormal); 290 | float3 N = lerp(i.normal, worldNormal, saturate(length(tangentNormal) * 100)); 291 | 292 | float3 lightDir; 293 | #if defined(POINT) || defined(POINT_COOKIE) || defined(SPOT) 294 | lightDir = normalize(_WorldSpaceLightPos0.xyz - i.wpos.xyz); 295 | #else 296 | lightDir = _WorldSpaceLightPos0.xyz; 297 | #endif 298 | 299 | fixed4 lightCol; 300 | #if defined(VERTEXLIGHT_ON) 301 | lightCol = fixed4(i.vertexLightColor, 1); 302 | #else 303 | lightCol = _LightColor0; 304 | #endif 305 | 306 | lightCol.rgb += max(0, ShadeSH9(float4(N, 1))); 307 | 308 | float3 L = lightDir; 309 | float3 V = normalize(_WorldSpaceCameraPos.xyz - i.wpos.xyz); 310 | 311 | float NdotV = max(0, dot(N, V)); 312 | float NNdotV = 1 - dot(N, V); 313 | float rim = pow(NNdotV, _RimPower) * _RimAmplitude; 314 | 315 | float NdotL = max(0, dot(L, N)); 316 | UNITY_LIGHT_ATTENUATION(attenuation, i, N) 317 | lightCol *= attenuation; 318 | 319 | fixed4 col = tex2D(_MainTex, i.uv); 320 | 321 | fixed4 hatch0 = tex2D(_Hatch0, i.huv); 322 | fixed4 hatch1 = tex2D(_Hatch1, i.huv); 323 | fixed4 hatch2 = tex2D(_Hatch2, i.huv); 324 | fixed4 hatch3 = tex2D(_Hatch3, i.huv); 325 | fixed4 hatch4 = tex2D(_Hatch4, i.huv); 326 | fixed4 hatch5 = tex2D(_Hatch5, i.huv); 327 | 328 | if (length(lightCol.rgb) < _Threshold) 329 | { 330 | float3 diffuse = col.rgb * NdotV; 331 | float intensity = lerp(saturate(length(diffuse)), 0.5 * saturate(dot(diffuse, half3(0.2326, 0.7152, 0.0722))), _Density); 332 | 333 | if(0.6 < intensity) 334 | { 335 | col *= fixed4(1, 1, 1, 1); 336 | } 337 | else if(0.5 < intensity && intensity <= 0.6) 338 | { 339 | col *= lerp(hatch0, hatch1, 1 - intensity); 340 | } 341 | else if(0.4 < intensity && intensity <= 0.5) 342 | { 343 | col *= lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity); 344 | } 345 | else if(0.3 < intensity && intensity <= 0.4) 346 | { 347 | col *= lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity); 348 | } 349 | else if(0.2 < intensity && intensity <= 0.3) 350 | { 351 | col *= lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity); 352 | } 353 | else if(0.1 < intensity && intensity <= 0.2) 354 | { 355 | col *= lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity); 356 | } 357 | else if(intensity <= 0.1) 358 | { 359 | col *= lerp(lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), hatch5 * 0.5, NdotV * 1.5); 360 | } 361 | } 362 | else 363 | { 364 | float manipulate = lerp(NdotL, NdotV, _Adjust); 365 | float3 diffuse = lerp(col.rgb * manipulate, lightCol, 1.0 / pow(3, length(lightCol))); 366 | float intensity = lerp(saturate(length(diffuse)), 0.5 * saturate(dot(diffuse, half3(0.2326, 0.7152, 0.0722))), _Density); 367 | 368 | if(0.6 < intensity) 369 | { 370 | col *= fixed4(1, 1, 1, 1); 371 | } 372 | else if(0.5 < intensity && intensity <= 0.6) 373 | { 374 | col *= lerp(hatch0, hatch1, 1 - intensity); 375 | } 376 | else if(0.4 < intensity && intensity <= 0.5) 377 | { 378 | col *= lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity); 379 | } 380 | else if(0.3 < intensity && intensity <= 0.4) 381 | { 382 | col *= lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity); 383 | } 384 | else if(0.2 < intensity && intensity <= 0.3) 385 | { 386 | col *= lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity); 387 | } 388 | else if(0.1 < intensity && intensity <= 0.2) 389 | { 390 | col *= lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity); 391 | } 392 | else if(intensity <= 0.1) 393 | { 394 | col *= lerp(lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), hatch5 * 0.5, (1 - NdotL) * 1.5); 395 | } 396 | } 397 | 398 | col.rgb = lerp(col.rgb, dot(col.rgb, half3(0.2326, 0.7152, 0.0722)), _Hoge) * _LightColor0.rgb; 399 | 400 | fixed3 colRim = col.rgb * 1.0 + rim * fixed3(1.0, 1.0, 1.0); 401 | col.rgb = lerp(col.rgb, colRim, V); 402 | col.a = 1; 403 | 404 | UNITY_APPLY_FOG(i.fogCoord, col); 405 | return col; 406 | } 407 | ENDCG 408 | 409 | } 410 | Pass 411 | { 412 | Tags { "LightMode" = "ForwardAdd" } 413 | Blend One One 414 | CGPROGRAM 415 | 416 | #pragma hull hull 417 | #pragma domain domain 418 | #pragma multi_compile_fwdadd 419 | 420 | #include "Tessellation.cginc" 421 | 422 | struct appdata 423 | { 424 | float4 vertex: POSITION; 425 | float2 uv: TEXCOORD0; 426 | float3 normal: NORMAL; 427 | float3 tangent: TANGENT; 428 | }; 429 | 430 | struct v2h 431 | { 432 | float4 f4Position: TEXCOORD0; 433 | float3 f3Normal: TEXCOORD1; 434 | float2 f2TexCoord: TEXCOORD2; 435 | float3 f3Tangent: TEXCOORD3; 436 | }; 437 | 438 | struct HsControlPointOutput 439 | { 440 | float3 f3Position: TEXCOORD0; 441 | float3 f3Normal: TEXCOORD1; 442 | float2 f2TexCoord: TEXCOORD2; 443 | float3 f3Tangent: TEXCOORD3; 444 | }; 445 | 446 | struct HsConstantOutput 447 | { 448 | float fTessFactor[3]: SV_TESSFACTOR; 449 | float fInsideTessFactor: SV_INSIDETESSFACTOR; 450 | }; 451 | 452 | struct h2f 453 | { 454 | float2 uv: TEXCOORD0; 455 | UNITY_FOG_COORDS(1) 456 | float4 vertex: SV_POSITION; 457 | float3 normal: TEXCOORD2; 458 | float2 huv: TEXCOORD3; 459 | float4 wpos: TEXCOORD4; 460 | LIGHTING_COORDS(5, 6) 461 | float3 tangent: TEXCOORD7; 462 | float3 binormal: TEXCOORD8; 463 | }; 464 | 465 | v2h vert(appdata i) 466 | { 467 | v2h o; 468 | o.f4Position = i.vertex; 469 | o.f3Normal = i.normal; 470 | o.f2TexCoord = i.uv; 471 | o.f3Tangent = i.tangent; 472 | return o; 473 | } 474 | 475 | [domain("tri")] 476 | [partitioning("integer")] 477 | [outputtopology("triangle_cw")] 478 | [patchconstantfunc("hullConst")] 479 | [outputcontrolpoints(3)] 480 | HsControlPointOutput hull(InputPatch < v2h, 3 > i, uint id: SV_OUTPUTCONTROLPOINTID) 481 | { 482 | HsControlPointOutput o = (HsControlPointOutput)0; 483 | o.f3Position = i[id].f4Position.xyz; 484 | o.f3Normal = i[id].f3Normal; 485 | o.f2TexCoord = i[id].f2TexCoord; 486 | o.f3Tangent = i[id].f3Tangent; 487 | return o; 488 | } 489 | 490 | HsConstantOutput hullConst(InputPatch < v2h, 3 > i) 491 | { 492 | HsConstantOutput o = (HsConstantOutput)0; 493 | float4 p0 = i[0].f4Position; 494 | float4 p1 = i[1].f4Position; 495 | float4 p2 = i[2].f4Position; 496 | float4 tessFactor = UnityDistanceBasedTess(p0, p1, p2, _MinDist, _MaxDist, _TessFactor); 497 | 498 | o.fTessFactor[0] = tessFactor.x; 499 | o.fTessFactor[1] = tessFactor.y; 500 | o.fTessFactor[2] = tessFactor.z; 501 | o.fInsideTessFactor = tessFactor.w; 502 | return o; 503 | } 504 | 505 | [domain("tri")] 506 | h2f domain(HsConstantOutput hsConst, const OutputPatch < HsControlPointOutput, 3 > i, float3 bary: SV_DOMAINLOCATION) 507 | { 508 | h2f o = (h2f)0; 509 | 510 | float3 f3Position = bary.x * i[0].f3Position + bary.y * i[1].f3Position + bary.z * i[2].f3Position; 511 | float3 f3Normal = bary.x * i[0].f3Normal + bary.y * i[1].f3Normal + bary.z * i[2].f3Normal; 512 | float3 f3Tangent = bary.x * i[0].f3Tangent + bary.y * i[1].f3Tangent + bary.z * i[2].f3Tangent; 513 | float2 f2TexCoord = bary.x * i[0].f2TexCoord + bary.y * i[1].f2TexCoord + bary.z * i[2].f2TexCoord; 514 | 515 | float2 uvNoise = TRANSFORM_TEX(f2TexCoord, _NoiseTex); 516 | float angle = 180 * UNITY_PI * (_Time.x / 100 * _NoiseSpeed); 517 | float pivot = 0.5; 518 | float x = (uvNoise.x - pivot) * cos(angle) - (uvNoise.y - pivot) * sin(angle) + pivot; 519 | float y = (uvNoise.x - pivot) * sin(angle) + (uvNoise.y - pivot) * cos(angle) + pivot; 520 | uvNoise = float2(x, y); 521 | fixed4 noiseTex = tex2Dlod(_NoiseTex, float4(uvNoise, 0, 0)); 522 | float c2f = pow(pow(_NoisePower, _NoisePower), C2F(noiseTex.rgb)); 523 | float c = fBm(f2TexCoord.xy * _Time.x * _NoiseSpeed); 524 | fixed4 prlNoise = lerp(fixed4(c, c, c, 1), fixed4(c2f, c2f, c2f, 1), saturate(noiseTex * 100)); 525 | 526 | f3Position.xyz += f3Normal * prlNoise.xyz * _NoiseFactor; 527 | float4 f4Position = mul(unity_ObjectToWorld, float4(f3Position.xyz, 1.0)); 528 | 529 | o.wpos = f4Position; 530 | float4 vertex = Rotate(float4(f3Position.xyz, 1.0), _Angle); 531 | vertex.xyz = vertex.xyz * (1 - float3(_Xcomp, _Ycomp, _Zcomp)); 532 | float4 pos = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, float4(0, 0, 0, 1)) + float4(vertex.x, vertex.y, vertex.z, 0)); 533 | o.vertex = lerp(UnityObjectToClipPos(vertex), pos, _Hoge2); 534 | o.uv = TRANSFORM_TEX(f2TexCoord, _MainTex); 535 | o.huv = TRANSFORM_TEX(f2TexCoord, _MainTex) * _Roughness; 536 | o.normal = UnityObjectToWorldNormal(f3Normal); 537 | o.tangent = UnityObjectToWorldNormal(f3Tangent); 538 | o.binormal = normalize(cross(o.tangent, o.normal)); 539 | UNITY_TRANSFER_FOG(o, o.vertex); 540 | return o; 541 | } 542 | 543 | fixed4 frag(h2f i): SV_Target 544 | { 545 | float3 tangentNormal = float4(UnpackNormal(tex2D(_NormalTex, i.uv)), 1); 546 | float3x3 TBN = float3x3(i.tangent, i.binormal, i.normal); 547 | TBN = transpose(TBN); 548 | float3 worldNormal = mul(TBN, tangentNormal); 549 | 550 | float3 N = lerp(i.normal, worldNormal, saturate(length(tangentNormal) * 100)); 551 | float3 V = normalize(_WorldSpaceCameraPos.xyz - i.wpos.xyz); 552 | 553 | float3 lightDir; 554 | #if defined(POINT) || defined(POINT_COOKIE) || defined(SPOT) 555 | lightDir = normalize(_WorldSpaceLightPos0.xyz - i.wpos.xyz); 556 | #else 557 | lightDir = _WorldSpaceLightPos0.xyz; 558 | #endif 559 | fixed4 lightCol = _LightColor0; 560 | lightCol.rgb += max(0, ShadeSH9(float4(N, 1))); 561 | float3 L = lightDir; 562 | 563 | float NdotV = max(0, dot(N, V)); 564 | float NNdotV = 1 - dot(N, V); 565 | float rim = pow(NNdotV, _RimPower) * _RimAmplitude; 566 | 567 | float NdotL = max(0, dot(L, N)); 568 | UNITY_LIGHT_ATTENUATION(attenuation, i, N) 569 | lightCol *= attenuation; 570 | 571 | fixed4 col = tex2D(_MainTex, i.uv); 572 | 573 | fixed4 hatch0 = tex2D(_Hatch0, i.huv); 574 | fixed4 hatch1 = tex2D(_Hatch1, i.huv); 575 | fixed4 hatch2 = tex2D(_Hatch2, i.huv); 576 | fixed4 hatch3 = tex2D(_Hatch3, i.huv); 577 | fixed4 hatch4 = tex2D(_Hatch4, i.huv); 578 | fixed4 hatch5 = tex2D(_Hatch5, i.huv); 579 | 580 | if(length(lightCol.rgb) < _Threshold) 581 | { 582 | float3 diffuse = col.rgb * NdotV; 583 | float intensity = lerp(saturate(length(diffuse)), 0.5 * saturate(dot(diffuse, half3(0.2326, 0.7152, 0.0722))), _Density); 584 | 585 | if(0.6 < intensity) 586 | { 587 | col *= fixed4(1, 1, 1, 1); 588 | } 589 | else if(0.5 < intensity && intensity <= 0.6) 590 | { 591 | col *= lerp(hatch0, hatch1, 1 - intensity); 592 | } 593 | else if(0.4 < intensity && intensity <= 0.5) 594 | { 595 | col *= lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity); 596 | } 597 | else if(0.3 < intensity && intensity <= 0.4) 598 | { 599 | col *= lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity); 600 | } 601 | else if(0.2 < intensity && intensity <= 0.3) 602 | { 603 | col *= lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity); 604 | } 605 | else if(0.1 < intensity && intensity <= 0.2) 606 | { 607 | col *= lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity); 608 | } 609 | else if(intensity <= 0.1) 610 | { 611 | col *= lerp(lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), hatch5 * 0.5, NdotV * 1.5); 612 | } 613 | } 614 | else 615 | { 616 | float manipulate = lerp(NdotL, NdotV, _Adjust); 617 | float3 diffuse = lerp(col.rgb * manipulate, lightCol, 1.0 / pow(3, length(lightCol))); 618 | float intensity = lerp(saturate(length(diffuse)), 0.5 * saturate(dot(diffuse, half3(0.2326, 0.7152, 0.0722))), _Density); 619 | 620 | if(0.6 < intensity) 621 | { 622 | col *= fixed4(1, 1, 1, 1); 623 | } 624 | else if(0.5 < intensity && intensity <= 0.6) 625 | { 626 | col *= lerp(hatch0, hatch1, 1 - intensity); 627 | } 628 | else if(0.4 < intensity && intensity <= 0.5) 629 | { 630 | col *= lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity); 631 | } 632 | else if(0.3 < intensity && intensity <= 0.4) 633 | { 634 | col *= lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity); 635 | } 636 | else if(0.2 < intensity && intensity <= 0.3) 637 | { 638 | col *= lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity); 639 | } 640 | else if(0.1 < intensity && intensity <= 0.2) 641 | { 642 | col *= lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity); 643 | } 644 | else if(intensity <= 0.1) 645 | { 646 | col *= lerp(lerp(lerp(lerp(lerp(lerp(hatch0, hatch1, 1 - intensity), hatch2, 1 - intensity), hatch3, 1 - intensity), hatch4, 1 - intensity), hatch4, 1 - intensity), hatch5 * 0.5, (1 - NdotL) * 1.5); 647 | } 648 | } 649 | 650 | col.rgb = lerp(col.rgb, dot(col.rgb, half3(0.2326, 0.7152, 0.0722)), _Hoge) * _LightColor0.rgb; 651 | 652 | fixed3 colRim = col.rgb * 1.0 + rim * fixed3(1.0, 1.0, 1.0); 653 | col.rgb = lerp(col.rgb, colRim, V); 654 | col.a = 1; 655 | 656 | UNITY_APPLY_FOG(i.fogCoord, col); 657 | return col; 658 | } 659 | ENDCG 660 | 661 | } 662 | } 663 | Fallback "Diffuse" 664 | } 665 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 nkihrk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Pencil-Like-Stroke/hatch0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkihrk/HatchingShader/9acbc5f7cea28c9c14c782c7cd7314b09adb1da9/Pencil-Like-Stroke/hatch0.jpg -------------------------------------------------------------------------------- /Pencil-Like-Stroke/hatch1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkihrk/HatchingShader/9acbc5f7cea28c9c14c782c7cd7314b09adb1da9/Pencil-Like-Stroke/hatch1.jpg -------------------------------------------------------------------------------- /Pencil-Like-Stroke/hatch2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkihrk/HatchingShader/9acbc5f7cea28c9c14c782c7cd7314b09adb1da9/Pencil-Like-Stroke/hatch2.jpg -------------------------------------------------------------------------------- /Pencil-Like-Stroke/hatch3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkihrk/HatchingShader/9acbc5f7cea28c9c14c782c7cd7314b09adb1da9/Pencil-Like-Stroke/hatch3.jpg -------------------------------------------------------------------------------- /Pencil-Like-Stroke/hatch4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkihrk/HatchingShader/9acbc5f7cea28c9c14c782c7cd7314b09adb1da9/Pencil-Like-Stroke/hatch4.jpg -------------------------------------------------------------------------------- /Pencil-Like-Stroke/hatch5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkihrk/HatchingShader/9acbc5f7cea28c9c14c782c7cd7314b09adb1da9/Pencil-Like-Stroke/hatch5.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hatching Shader(ハッチングシェーダー) 2 | 3 | ハッチングを表現したシェーダーです。このシェーダーにはTAM(Tonal Art Map)が必要です。サンプルとしてトーン風と鉛筆風のTAMを用意しておきました。 4 | Unity5.6.3p1(64bit)の環境で作成しました。 5 | 6 | ### 各シェーダーの使用用途 7 | 8 | * HatchingShader……キャラクターなどでの使用を想定して調整しています。 9 | 10 | * HatchingShaderLerpTes/HatchingShaderTes……背景のオブジェクトなどで使うことを想定し、上記のシェーダーに機能を追加したものです。機能に差はありませんが、二つのシェーダーで若干見た目に差があります。 11 | 12 | ![](https://nkihrk.github.io/img/works/shader/ugolino_with_hatching_shader.jpg) 13 | 14 | --------------------------------------------------------------------------------- 15 | 16 | ### インスペクターのパラメーターについて 17 | 18 | * Hatch0~5……作成したTAM(Tonal Art Map)を貼り付けてください。 19 | 20 | * Outline Mask Texture……削除する任意のアウトラインを指定します。黒背景を用意し、消したい箇所を白く塗りつぶしてください。 21 | ※アウトラインを設定した状態でビルボードをオンにするとバグります。ビルボードを使用する場合はアウトラインの設定をオフにしてください。 22 | 23 | * Outline Color……アウトラインの色を設定します。初期は下記のRim Power/Rim Amplitudeの影響を受けるように設定されています。 24 | 25 | * Outline Width……アウトラインの幅を設定します。 26 | 27 | * Toggle Billboard……オブジェクトをビルボード化します。(未調整なのでおいおい対応します) 28 | 29 | * Threshold……ワールドライトの光の色による影響を閾値で制限します。 30 | 解説:ワールドライトの色によってはオブジェクトが黒塗りになってしまう場合があります。これを防ぐためにライトの色RGBのスカラーを算出し、閾値よりも小さい場合ViewBasedに切り替えるようにコードを書いています。 31 | 32 | * Angle……オブジェクトをY軸まわりで回転させます。 33 | 34 | * _[X/Y/Z]comp……該当軸方向に圧縮します。 35 | 36 | * Rim Power/Rim Amplitude……視線ベクトルで色が変異します。通常のRim効果と同じ感覚で設定すればいいです。(ただのおまけ) 37 | 38 | * NdotL or NdotV……0に近いほどワールドのライトベクトルの影響を受けやすく、1に近いほど視線ベクトルの影響を受けやすいです。 39 | 40 | * Density……影の濃淡を調整できます。 41 | 42 | * Roughness……影の粗さを調整できます。 43 | 44 | * Toggle Gray Scale……色をグレースケールにします。 45 | 46 | * Cull Mode……Cullの設定ができます 47 | 48 | 49 | ### [HatchingShaderLerpTes/HatchingShaderTes]で追加されたパラメーターについて 50 | 51 | * Noise Texture……テクスチャの色情報に沿って形が変形します。 52 | 53 | * [Min/Max] Distance……テッセレーション(ポリゴンをGPUで増やす処理)によるポリゴンの増減をプレイヤーの距離によって制御します。 54 | ※テッセレーションによってポリゴンを増やしすぎると、GPUの負荷が急激に上がります。それを軽減するために、[Min/Max] Distanceによって増やすポリゴンを段階的に制御します。 55 | 56 | * Tessellation……オブジェクトのポリゴンを増やします。 57 | 58 | * Noise Speed……Noise Textureを回転させる速度を設定します。 59 | 60 | * Noise Power……Noise Textureによって頂点が押し出される度合いを設定します。 61 | 62 | * Noise Factor……全体的な頂点の押し出しの度合いを調整します。 63 | ※Noise Textureをセットしていない場合、Noise Powerは機能しません。しかし、Noise SpeedおよびNoise Factorに関しては機能します。 64 | 65 | 66 | ### 最後に。 67 | コード自体の最適化、効率化は一切おこなっていない上に、[参考にした論文](http://hhoppe.com/hatching.pdf "Real-Time Hatching")通りにテクスチャを二枚にパックすることもしていません。コードの冗長さには目をつむってください。数列とかアルゴリズム考えるのめんどくさかった(´・_・`) 68 | -------------------------------------------------------------------------------- /Unity_2018-08-20_20-00-57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkihrk/HatchingShader/9acbc5f7cea28c9c14c782c7cd7314b09adb1da9/Unity_2018-08-20_20-00-57.png -------------------------------------------------------------------------------- /Unity_2018-08-29_03-33-28.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkihrk/HatchingShader/9acbc5f7cea28c9c14c782c7cd7314b09adb1da9/Unity_2018-08-29_03-33-28.jpg --------------------------------------------------------------------------------