yum-archive/Tooner
A toon shader for Unity's BIRP.
git clone https://git.yummers.dev/yum-archive/Tooner
2af60b2
master
1#ifndef MOCHIE_STANDARD_SSS_INCLUDED 2#define MOCHIE_STANDARD_SSS_INCLUDED 3 4/* 5 * MIT License 6 * 7 * Copyright (c) 2020 MochiesCode 8 * 9 * Permission is hereby granted, free of charge, to any person obtaining a copy 10 * of this software and associated documentation files (the "Software"), to 11 * deal 12 * in the Software without restriction, including without limitation the rights 13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 * copies of the Software, and to permit persons to whom the Software is 15 * furnished to do so, subject to the following conditions: 16 * 17 * The above copyright notice and this permission notice shall be included in 18 * all 19 * copies or substantial portions of the Software. 20 * 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 * FROM, 27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 28 * THE 29 * SOFTWARE. 30 */ 31 32float3 GetSubsurfaceLight( 33 float3 lightColor, float3 lightDirection, float3 normalDirection, float3 viewDirection, 34 float attenuation, float3 thickness, float3 indirectLight, float3 subsurfaceColor 35){ 36 float3 vLTLight = lightDirection + normalDirection * _ScatterDist; // Distortion 37 float3 fLTDot = pow(saturate(dot(viewDirection, -vLTLight)), _ScatterPow) * _ScatterIntensity * 1.0/UNITY_PI; 38 39 return lerp(1, attenuation, float(any(_WorldSpaceLightPos0.xyz))) 40 * (fLTDot + _ScatterAmbient) * thickness 41 * (lightColor + indirectLight) * subsurfaceColor; 42 43} 44 45float3 GeneralWrapSH(float fA){ 46 // Normalization factor for our model. 47 float norm = 0.5 * (2 + fA) / (1 + fA); 48 float4 t = float4(2 * (fA + 1), fA + 2, fA + 3, fA + 4); 49 return norm * float3(t.x / t.y, 2 * t.x / (t.y * t.z), 50 t.x * (fA * fA - t.x + 5) / (t.y * t.z * t.w)); 51} 52 53float3 ShadeSH9_wrappedCorrect(float3 normal, float3 conv){ 54 const float3 cosconv_inv = float3(1, 1.5, 4); // Inverse of the pre-applied cosine convolution 55 float3 x0, x1, x2; 56 conv *= cosconv_inv; // Undo pre-applied cosine convolution 57 //conv *= _Bands.xyz; // debugging 58 59 // Constant (L0) 60 x0 = float3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w); 61 // Remove the constant part from L2 and add it back with correct convolution 62 float3 otherband = float3(unity_SHBr.z, unity_SHBg.z, unity_SHBb.z) / 3.0; 63 x0 = (x0 + otherband) * conv.x - otherband * conv.z; 64 65 // Linear (L1) polynomial terms 66 x1.r = (dot(unity_SHAr.xyz, normal)); 67 x1.g = (dot(unity_SHAg.xyz, normal)); 68 x1.b = (dot(unity_SHAb.xyz, normal)); 69 70 // 4 of the quadratic (L2) polynomials 71 float4 vB = normal.xyzz * normal.yzzx; 72 x2.r = dot(unity_SHBr, vB); 73 x2.g = dot(unity_SHBg, vB); 74 x2.b = dot(unity_SHBb, vB); 75 76 // Final (5th) quadratic (L2) polynomial 77 float vC = normal.x * normal.x - normal.y * normal.y; 78 x2 += unity_SHC.rgb * vC; 79 80 return x0 + x1 * conv.y + x2 * conv.z; 81} 82 83#endif // UNITY_STANDARD_SSS_INCLUDED