diff options
| author | yum <yum.food.vr@gmail.com> | 2024-07-14 15:54:16 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2024-07-14 15:54:16 -0700 |
| commit | 2af60b243f15a4aa609176a6b0259bb4d2f1984f (patch) | |
| tree | 22d45fc72c238be4542894c1091a15dd60d6c11e /MochieStandardSSS.cginc | |
| parent | eed8c3622c6d1ff7e54fd971bf470c70492e55bb (diff) | |
Switch to Mochie's BRDF
Better than Unity BRDF and supports things like parameterizable
half-lambertian lighting.
Diffstat (limited to 'MochieStandardSSS.cginc')
| -rw-r--r-- | MochieStandardSSS.cginc | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/MochieStandardSSS.cginc b/MochieStandardSSS.cginc new file mode 100644 index 0000000..1d5ffbf --- /dev/null +++ b/MochieStandardSSS.cginc @@ -0,0 +1,83 @@ +#ifndef MOCHIE_STANDARD_SSS_INCLUDED +#define MOCHIE_STANDARD_SSS_INCLUDED + +/* + * MIT License + * + * Copyright (c) 2020 MochiesCode + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE + * SOFTWARE. + */ + +float3 GetSubsurfaceLight( + float3 lightColor, float3 lightDirection, float3 normalDirection, float3 viewDirection, + float attenuation, float3 thickness, float3 indirectLight, float3 subsurfaceColor +){ + float3 vLTLight = lightDirection + normalDirection * _ScatterDist; // Distortion + float3 fLTDot = pow(saturate(dot(viewDirection, -vLTLight)), _ScatterPow) * _ScatterIntensity * 1.0/UNITY_PI; + + return lerp(1, attenuation, float(any(_WorldSpaceLightPos0.xyz))) + * (fLTDot + _ScatterAmbient) * thickness + * (lightColor + indirectLight) * subsurfaceColor; + +} + +float3 GeneralWrapSH(float fA){ + // Normalization factor for our model. + float norm = 0.5 * (2 + fA) / (1 + fA); + float4 t = float4(2 * (fA + 1), fA + 2, fA + 3, fA + 4); + return norm * float3(t.x / t.y, 2 * t.x / (t.y * t.z), + t.x * (fA * fA - t.x + 5) / (t.y * t.z * t.w)); +} + +float3 ShadeSH9_wrappedCorrect(float3 normal, float3 conv){ + const float3 cosconv_inv = float3(1, 1.5, 4); // Inverse of the pre-applied cosine convolution + float3 x0, x1, x2; + conv *= cosconv_inv; // Undo pre-applied cosine convolution + //conv *= _Bands.xyz; // debugging + + // Constant (L0) + x0 = float3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w); + // Remove the constant part from L2 and add it back with correct convolution + float3 otherband = float3(unity_SHBr.z, unity_SHBg.z, unity_SHBb.z) / 3.0; + x0 = (x0 + otherband) * conv.x - otherband * conv.z; + + // Linear (L1) polynomial terms + x1.r = (dot(unity_SHAr.xyz, normal)); + x1.g = (dot(unity_SHAg.xyz, normal)); + x1.b = (dot(unity_SHAb.xyz, normal)); + + // 4 of the quadratic (L2) polynomials + float4 vB = normal.xyzz * normal.yzzx; + x2.r = dot(unity_SHBr, vB); + x2.g = dot(unity_SHBg, vB); + x2.b = dot(unity_SHBb, vB); + + // Final (5th) quadratic (L2) polynomial + float vC = normal.x * normal.x - normal.y * normal.y; + x2 += unity_SHC.rgb * vC; + + return x0 + x1 * conv.y + x2 * conv.z; +} + +#endif // UNITY_STANDARD_SSS_INCLUDED |
