diff options
author | Freya Murphy <freya@freyacat.org> | 2024-12-27 00:56:58 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-12-27 00:58:02 -0500 |
commit | 799e6680d40119dc9c2a9e0b320054a40324bebe (patch) | |
tree | dbcd308d59eb6e4f937a5547dd77d9f91d4fec20 /VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes | |
parent | move to self host (diff) | |
download | unityprojects-799e6680d40119dc9c2a9e0b320054a40324bebe.tar.gz unityprojects-799e6680d40119dc9c2a9e0b320054a40324bebe.tar.bz2 unityprojects-799e6680d40119dc9c2a9e0b320054a40324bebe.zip |
VRCSDK3Avatars found!
Diffstat (limited to 'VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes')
16 files changed, 1614 insertions, 0 deletions
diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSDefines.cginc b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSDefines.cginc new file mode 100644 index 00000000..b59d96f7 --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSDefines.cginc @@ -0,0 +1,216 @@ +#include "UnityPBSLighting.cginc" +#include "AutoLight.cginc" +#include "UnityCG.cginc" + +struct VertexInput +{ + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + float2 uv1 : TEXCOORD1; + float2 uv2 : TEXCOORD2; + float3 normal : NORMAL; + float4 tangent : TANGENT; + float4 color : COLOR; +}; + +struct VertexOutput +{ + #if defined(Geometry) + float4 pos : CLIP_POS; + float4 vertex : SV_POSITION; // We need both of these in order to shadow Outlines correctly + #else + float4 pos : SV_POSITION; + #endif + + float2 uv : TEXCOORD0; + float2 uv1 : TEXCOORD1; + float3 ntb[3] : TEXCOORD2; //texcoord 3, 4 || Holds World Normal, Tangent, and Bitangent + float4 worldPos : TEXCOORD5; + float4 color : TEXCOORD6; + float3 normal : TEXCOORD8; + float4 screenPos : TEXCOORD9; + float3 objPos : TEXCOORD11; + float2 uv2 : TEXCOORD12; + + #if !defined(UNITY_PASS_SHADOWCASTER) + SHADOW_COORDS(7) + UNITY_FOG_COORDS(10) + #endif +}; + +#if defined(Geometry) + struct v2g + { + float4 pos : CLIP_POS; + float4 vertex : SV_POSITION; + float2 uv : TEXCOORD0; + float2 uv1 : TEXCOORD1; + float3 ntb[3] : TEXCOORD2; //texcoord 3, 4 || Holds World Normal, Tangent, and Bitangent + float4 worldPos : TEXCOORD5; + float4 color : TEXCOORD6; + float3 normal : TEXCOORD8; + float4 screenPos : TEXCOORD9; + float3 objPos : TEXCOORD11; + float2 uv2 : TEXCOORD12; + + #if !defined(UNITY_PASS_SHADOWCASTER) + SHADOW_COORDS(7) + UNITY_FOG_COORDS(10) + #endif + }; + + struct g2f + { + float4 pos : SV_POSITION; + float2 uv : TEXCOORD0; + float2 uv1 : TEXCOORD1; + float3 ntb[3] : TEXCOORD2; //texcoord 3, 4 || Holds World Normal, Tangent, and Bitangent + float4 worldPos : TEXCOORD5; + float4 color : TEXCOORD6; + float4 screenPos : TEXCOORD8; + float3 objPos : TEXCOORD10; + + #if !defined(UNITY_PASS_SHADOWCASTER) + SHADOW_COORDS(7) + UNITY_FOG_COORDS(9) + #endif + }; +#endif + +struct XSLighting +{ + half4 albedo; + half4 normalMap; + half4 detailNormal; + half4 detailMask; + half4 metallicGlossMap; + half4 reflectivityMask; + half4 specularMap; + half4 thickness; + half4 occlusion; + half4 emissionMap; + half4 rampMask; + half4 hsvMask; + half4 clipMap; + half4 dissolveMask; + half3 diffuseColor; + half attenuation; + half3 normal; + half3 tangent; + half3 bitangent; + half4 worldPos; + half3 color; + half alpha; + float isOutline; + float4 screenPos; + float2 screenUV; + float3 objPos; +}; + +struct TextureUV +{ + half2 uv0; + half2 uv1; + half2 albedoUV; + half2 specularMapUV; + half2 metallicGlossMapUV; + half2 detailMaskUV; + half2 normalMapUV; + half2 detailNormalUV; + half2 thicknessMapUV; + half2 occlusionUV; + half2 reflectivityMaskUV; + half2 emissionMapUV; + half2 outlineMaskUV; + half2 clipMapUV; + half2 dissolveUV; +}; + +struct DotProducts +{ + half ndl; + half vdn; + half vdh; + half tdh; + half bdh; + half ndh; + half rdv; + half ldh; + half svdn; +}; + +struct VertexLightInformation { + float3 Direction[4]; + float3 ColorFalloff[4]; + float Attenuation[4]; +}; + +UNITY_DECLARE_TEX2D(_MainTex); half4 _MainTex_ST; +UNITY_DECLARE_TEX2D_NOSAMPLER(_ClipMap); half4 _ClipMap_ST; +UNITY_DECLARE_TEX2D_NOSAMPLER(_DissolveTexture); half4 _DissolveTexture_ST; +UNITY_DECLARE_TEX2D_NOSAMPLER(_BumpMap); half4 _BumpMap_ST; +UNITY_DECLARE_TEX2D_NOSAMPLER(_DetailNormalMap); half4 _DetailNormalMap_ST; +UNITY_DECLARE_TEX2D_NOSAMPLER(_DetailMask); half4 _DetailMask_ST; +UNITY_DECLARE_TEX2D_NOSAMPLER(_SpecularMap); half4 _SpecularMap_ST; +UNITY_DECLARE_TEX2D_NOSAMPLER(_MetallicGlossMap); half4 _MetallicGlossMap_ST; +UNITY_DECLARE_TEX2D_NOSAMPLER(_ReflectivityMask); half4 _ReflectivityMask_ST; +UNITY_DECLARE_TEX2D_NOSAMPLER(_ThicknessMap); half4 _ThicknessMap_ST; +UNITY_DECLARE_TEX2D_NOSAMPLER(_EmissionMap); half4 _EmissionMap_ST; +UNITY_DECLARE_TEX2D_NOSAMPLER(_RampSelectionMask); +UNITY_DECLARE_TEX2D_NOSAMPLER(_HSVMask); +sampler2D _OcclusionMap; half4 _OcclusionMap_ST; +sampler2D _OutlineMask; +sampler2D _Matcap; +sampler2D _Ramp; +samplerCUBE _BakedCubemap; +sampler2D _GrabTexture; +float4 _GrabTexture_TexelSize; + +#if defined(UNITY_PASS_SHADOWCASTER) + sampler3D _DitherMaskLOD; +#endif + +half4 _Color; +half4 _ClipAgainstVertexColorGreaterZeroFive, _ClipAgainstVertexColorLessZeroFive; +half _Cutoff; +half _DissolveProgress, _DissolveStrength; +int _DissolveCoordinates; +int _UseClipsForDissolve; + +half4 _ShadowRim, + _OutlineColor, _SSColor, + _EmissionColor, _MatcapTint, + _RimColor, _DissolveColor; + +half _MatcapTintToDiffuse; + +half _FadeDitherDistance; +half _EmissionToDiffuse, _ScaleWithLightSensitivity; +half _Hue, _Saturation, _Value; +half _Metallic, _Glossiness, _OcclusionIntensity, _Reflectivity, _ClearcoatStrength, _ClearcoatSmoothness; +half _BumpScale, _DetailNormalMapScale; +half _SpecularIntensity, _SpecularSharpness, _SpecularArea, _AnisotropicSpecular, _AnisotropicReflection, _SpecularAlbedoTint; +half _IOR; +half _HalftoneDotSize, _HalftoneDotAmount, _HalftoneLineAmount, _HalftoneLineIntensity; +half _RimRange, _RimThreshold, _RimIntensity, _RimSharpness, _RimAlbedoTint, _RimCubemapTint, _RimAttenEffect; +half _ShadowRimRange, _ShadowRimThreshold, _ShadowRimSharpness, _ShadowSharpness, _ShadowRimAlbedoTint; +half _SSDistortion, _SSPower, _SSScale; +half _OutlineWidth; + +int _HalftoneType; +int _FadeDither; +int _BlendMode; +int _OcclusionMode; +int _UseRefraction; +int _ReflectionMode, _ReflectionBlendMode, _ClearCoat; +int _TilingMode, _VertexColorAlbedo, _ScaleWithLight; +int _OutlineAlbedoTint, _OutlineLighting, _OutlineNormalMode; +int _UVSetAlbedo, _UVSetNormal, _UVSetDetNormal, + _UVSetDetMask, _UVSetMetallic, _UVSetSpecular, + _UVSetThickness, _UVSetOcclusion, _UVSetReflectivity, + _UVSetEmission, _UVSetClipMap, _UVSetDissolve; +int _NormalMapMode, _OutlineUVSelect; + +//Defines for helper functions +#define grayscaleVec float3(0.2125, 0.7154, 0.0721) +#define WorldNormalVector(normal0, normal) half3(dot(normal0,normal), dot(normal0, normal), dot(normal0,normal))
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSDefines.cginc.meta b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSDefines.cginc.meta new file mode 100644 index 00000000..d41dd6af --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSDefines.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 475129dd3056c984bbe2c6c2203c9759 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSFrag.cginc b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSFrag.cginc new file mode 100644 index 00000000..eef3aef5 --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSFrag.cginc @@ -0,0 +1,88 @@ +float4 frag ( + #if defined(Geometry) + g2f i + #else + VertexOutput i + #endif + , uint facing : SV_IsFrontFace + ) : SV_Target +{ + TextureUV t = (TextureUV)0; // Populate UVs + if(_TilingMode != 1) { InitializeTextureUVs(i, t); } else { InitializeTextureUVsMerged(i, t); }; + + #ifdef UNITY_PASS_SHADOWCASTER + XSLighting o = (XSLighting)0; //Populate Lighting Struct, but only with important shadowcaster stuff! + o.albedo = UNITY_SAMPLE_TEX2D(_MainTex, t.albedoUV) * _Color * lerp(1, float4(i.color.rgb, 1), _VertexColorAlbedo); + o.clipMap = UNITY_SAMPLE_TEX2D_SAMPLER(_ClipMap, _MainTex, t.clipMapUV); + o.dissolveMask = UNITY_SAMPLE_TEX2D_SAMPLER(_DissolveTexture, _MainTex, t.dissolveUV); + + o.worldPos = i.worldPos; + o.screenUV = calcScreenUVs(i.screenPos); + o.screenPos = i.screenPos; + o.objPos = i.objPos; + + float4 outCol = 0; + calcAlpha(o); + calcDissolve(o, outCol); + SHADOW_CASTER_FRAGMENT(i); + #else + UNITY_LIGHT_ATTENUATION(attenuation, i, i.worldPos.xyz); + + // fix for rare bug where light atten is 0 when there is no directional light in the scene + #ifdef UNITY_PASS_FORWARDBASE + if(all(_LightColor0.rgb == 0.0)) + { + attenuation = 1.0; + } + #endif + + #if defined(DIRECTIONAL) + half sharp = _ShadowSharpness * 0.5; + attenuation = smoothstep(sharp, 1-sharp, attenuation); //Converge at the center line + #endif + + bool face = facing > 0; // True if on front face, False if on back face + if (!face) // Invert Normals based on face + { + if(i.color.a > 0.99) { discard; }//Discard outlines front face always. This way cull off and outlines can be enabled. + + i.ntb[0] = -i.ntb[0]; + i.ntb[1] = -i.ntb[1]; + i.ntb[2] = -i.ntb[2]; + } + + XSLighting o = (XSLighting)0; //Populate Lighting Struct + o.albedo = UNITY_SAMPLE_TEX2D(_MainTex, t.albedoUV) * _Color * lerp(1, float4(i.color.rgb, 1), _VertexColorAlbedo); + o.specularMap = UNITY_SAMPLE_TEX2D_SAMPLER(_SpecularMap, _MainTex, t.specularMapUV); + o.metallicGlossMap = UNITY_SAMPLE_TEX2D_SAMPLER(_MetallicGlossMap, _MainTex, t.metallicGlossMapUV); + o.detailMask = UNITY_SAMPLE_TEX2D_SAMPLER(_DetailMask, _MainTex, t.detailMaskUV); + o.normalMap = UNITY_SAMPLE_TEX2D_SAMPLER(_BumpMap, _MainTex, t.normalMapUV); + o.detailNormal = UNITY_SAMPLE_TEX2D_SAMPLER(_DetailNormalMap, _MainTex, t.detailNormalUV); + o.thickness = UNITY_SAMPLE_TEX2D_SAMPLER(_ThicknessMap, _MainTex, t.thicknessMapUV); + o.occlusion = tex2D(_OcclusionMap, t.occlusionUV); + o.reflectivityMask = UNITY_SAMPLE_TEX2D_SAMPLER(_ReflectivityMask, _MainTex, t.reflectivityMaskUV) * _Reflectivity; + o.emissionMap = UNITY_SAMPLE_TEX2D_SAMPLER(_EmissionMap, _MainTex, t.emissionMapUV) * _EmissionColor; + o.rampMask = UNITY_SAMPLE_TEX2D_SAMPLER(_RampSelectionMask, _MainTex, i.uv); // This texture doesn't need to ever be on a second uv channel, and doesn't need tiling, convince me otherwise. + o.hsvMask = UNITY_SAMPLE_TEX2D_SAMPLER(_HSVMask, _MainTex, t.albedoUV); + o.clipMap = UNITY_SAMPLE_TEX2D_SAMPLER(_ClipMap, _MainTex, t.clipMapUV); + o.dissolveMask = UNITY_SAMPLE_TEX2D_SAMPLER(_DissolveTexture, _MainTex, t.dissolveUV); + + o.diffuseColor = o.albedo.rgb; //Store this to separate the texture color and diffuse color for later. + o.attenuation = attenuation; + o.normal = i.ntb[0]; + o.tangent = i.ntb[1]; + o.bitangent = i.ntb[2]; + o.worldPos = i.worldPos; + o.color = i.color.rgb; + o.isOutline = i.color.a; + o.screenUV = calcScreenUVs(i.screenPos); + o.screenPos = i.screenPos; + o.objPos = i.objPos; + + float4 col = BRDF_XSLighting(o); + calcAlpha(o); + calcDissolve(o, col); + UNITY_APPLY_FOG(i.fogCoord, col); + return float4(col.rgb, o.alpha); + #endif +}
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSFrag.cginc.meta b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSFrag.cginc.meta new file mode 100644 index 00000000..02ff2f77 --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSFrag.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: b6800622dae7e6f4bba02dffcc5f5868 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSGeom.cginc b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSGeom.cginc new file mode 100644 index 00000000..f1077558 --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSGeom.cginc @@ -0,0 +1,95 @@ +#if defined(Geometry) + #define TRANSFER_SHADOW_CASTER_NOPOS_GEOMETRY(o, opos, vertexPosition, vertexNormal) \ + opos = UnityClipSpaceShadowCasterPos(vertexPosition, vertexNormal); \ + opos = UnityApplyLinearShadowBias(opos); + + [maxvertexcount(6)] + void geom(triangle v2g IN[3], inout TriangleStream<g2f> tristream) + { + g2f o = (g2f)0; + + //Main Mesh loop + for (int i = 0; i < 3; i++) + { + o.pos = UnityObjectToClipPos(IN[i].vertex); + o.worldPos = IN[i].worldPos; + o.ntb[0] = IN[i].ntb[0]; + o.ntb[1] = IN[i].ntb[1]; + o.ntb[2] = IN[i].ntb[2]; + o.uv = IN[i].uv; + o.uv1 = IN[i].uv1; + o.color = float4(IN[i].color.rgb,0); // store if outline in alpha channel of vertex colors | 0 = not an outline + o.screenPos = ComputeScreenPos(o.pos); + o.objPos = normalize(IN[i].vertex); + + #if !defined(UNITY_PASS_SHADOWCASTER) + UNITY_TRANSFER_SHADOW(o, o.uv); + UNITY_TRANSFER_FOG(o, o.pos); + #else + TRANSFER_SHADOW_CASTER_NOPOS_GEOMETRY(o, o.pos, IN[i].vertex, IN[i].ntb[0]); + #endif + tristream.Append(o); + } + tristream.RestartStrip(); + + //Outlines loop + for (int i = 2; i >= 0; i--) + { + float4 worldPos = (mul(unity_ObjectToWorld, IN[i].vertex)); + half outlineWidthMask = tex2Dlod(_OutlineMask, float4(IN[i].uv, 0, 0)); + float3 outlineWidth = outlineWidthMask * _OutlineWidth * .01; + outlineWidth *= min(distance(worldPos, _WorldSpaceCameraPos) * 3, 1); + + float3 vc = IN[i].color.rgb; + if(_OutlineNormalMode == 2) + { + float2 xy = IN[i].uv1; + if(_OutlineUVSelect == 1) + xy = IN[i].uv2; + + float reconstructedZ = sqrt(1-saturate(dot(xy, xy))); + vc = normalize(float3(xy, reconstructedZ)); + } + vc = vc * 2 - 1; + float3 t = mul(unity_WorldToObject, IN[i].ntb[1]); + float3 b = mul(unity_WorldToObject, IN[i].ntb[2]); + float3 n = mul(unity_WorldToObject, IN[i].ntb[0]); + half3 tspace0 = half3(t.x, b.x, n.x); + half3 tspace1 = half3(t.y, b.y, n.y); + half3 tspace2 = half3(t.z, b.z, n.z); + + half3 calcedNormal; + calcedNormal.x = dot(tspace0, vc); + calcedNormal.y = dot(tspace1, vc); + calcedNormal.z = dot(tspace2, vc); + + half3 normalDir = normalize(lerp(IN[i].normal, calcedNormal, saturate(_OutlineNormalMode))); + float4 outlinePos = float4(IN[i].vertex + normalDir * outlineWidth, 1); + + if(outlineWidthMask == 0) + return; + + o.pos = UnityObjectToClipPos(outlinePos); + o.worldPos = worldPos; + o.ntb[0] = IN[i].ntb[0]; + o.ntb[1] = IN[i].ntb[1]; + o.ntb[2] = IN[i].ntb[2]; + o.uv = IN[i].uv; + o.uv1 = IN[i].uv1; + o.color = float4(IN[i].color.rgb, 1); // store if outline in alpha channel of vertex colors | 1 = is an outline + o.screenPos = ComputeScreenPos(o.pos); + o.objPos = normalize(outlinePos); + + #if !defined(UNITY_PASS_SHADOWCASTER) + UNITY_TRANSFER_SHADOW(o, o.uv); + UNITY_TRANSFER_FOG(o, o.pos); + #else + TRANSFER_SHADOW_CASTER_NOPOS_GEOMETRY(o, o.pos, outlinePos, IN[i].ntb[0]); + #endif + tristream.Append(o); + } + tristream.RestartStrip(); + + + } +#endif
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSGeom.cginc.meta b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSGeom.cginc.meta new file mode 100644 index 00000000..857ba3e7 --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSGeom.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 8ab351cd01215a74fbe8f1227faf9487 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSHelperFunctions.cginc b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSHelperFunctions.cginc new file mode 100644 index 00000000..011fe0fe --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSHelperFunctions.cginc @@ -0,0 +1,395 @@ +void calcNormal(inout XSLighting i) +{ + if(_NormalMapMode == 0) + { + half3 nMap = UnpackScaleNormal(i.normalMap, _BumpScale); + half3 detNMap = UnpackScaleNormal(i.detailNormal, _DetailNormalMapScale); + + half3 blendedNormal = lerp(nMap, BlendNormals(nMap, detNMap), i.detailMask.r); + + half3 tspace0 = half3(i.tangent.x, i.bitangent.x, i.normal.x); + half3 tspace1 = half3(i.tangent.y, i.bitangent.y, i.normal.y); + half3 tspace2 = half3(i.tangent.z, i.bitangent.z, i.normal.z); + + half3 calcedNormal; + calcedNormal.x = dot(tspace0, blendedNormal); + calcedNormal.y = dot(tspace1, blendedNormal); + calcedNormal.z = dot(tspace2, blendedNormal); + + calcedNormal = normalize(calcedNormal); + half3 bumpedTangent = cross(i.bitangent, calcedNormal); + half3 bumpedBitangent = cross(calcedNormal, bumpedTangent); + + i.normal = calcedNormal; + i.tangent = bumpedTangent; + i.bitangent = bumpedBitangent; + } + else + { + float3 vcol = i.color.rgb * 2 - 1; + + half3 tspace0 = half3(i.tangent.x, i.bitangent.x, i.normal.x); + half3 tspace1 = half3(i.tangent.y, i.bitangent.y, i.normal.y); + half3 tspace2 = half3(i.tangent.z, i.bitangent.z, i.normal.z); + + half3 calcedNormal; + calcedNormal.x = dot(tspace0, vcol); + calcedNormal.y = dot(tspace1, vcol); + calcedNormal.z = dot(tspace2, vcol); + + //calcedNormal = calcedNormal; + i.normal = normalize(calcedNormal); + } +} + +void InitializeTextureUVs( + #if defined(Geometry) + in g2f i, + #else + in VertexOutput i, + #endif + inout TextureUV t) +{ + #if defined(PatreonEyeTracking) + float2 eyeUvOffset = eyeOffsets(i.uv, i.objPos, i.worldPos, i.ntb[0]); + i.uv = eyeUvOffset; + i.uv1 = eyeUvOffset; + #endif + + half2 uvSetAlbedo = (_UVSetAlbedo == 0) ? i.uv : i.uv1; + t.albedoUV = TRANSFORM_TEX(uvSetAlbedo, _MainTex); + + half2 uvSetClipMap = (_UVSetClipMap == 0) ? i.uv : i.uv1; + t.clipMapUV = TRANSFORM_TEX(uvSetClipMap, _ClipMap); + + half2 uvSetDissolveMap = (_UVSetDissolve == 0) ? i.uv : i.uv1; + t.dissolveUV = TRANSFORM_TEX(uvSetDissolveMap, _DissolveTexture); + + #if !defined(UNITY_PASS_SHADOWCASTER) + half2 uvSetNormalMap = (_UVSetNormal == 0) ? i.uv : i.uv1; + t.normalMapUV = TRANSFORM_TEX(uvSetNormalMap, _BumpMap); + + half2 uvSetEmissionMap = (_UVSetEmission == 0) ? i.uv : i.uv1; + t.emissionMapUV = TRANSFORM_TEX(uvSetEmissionMap, _EmissionMap); + + half2 uvSetMetallicGlossMap = (_UVSetMetallic == 0) ? i.uv : i.uv1; + t.metallicGlossMapUV = TRANSFORM_TEX(uvSetMetallicGlossMap, _MetallicGlossMap); + + half2 uvSetOcclusion = (_UVSetOcclusion == 0) ? i.uv : i.uv1; + t.occlusionUV = TRANSFORM_TEX(uvSetOcclusion, _OcclusionMap); + + half2 uvSetDetailNormal = (_UVSetDetNormal == 0) ? i.uv : i.uv1; + t.detailNormalUV = TRANSFORM_TEX(uvSetDetailNormal, _DetailNormalMap); + + half2 uvSetDetailMask = (_UVSetDetMask == 0) ? i.uv : i.uv1; + t.detailMaskUV = TRANSFORM_TEX(uvSetDetailMask, _DetailMask); + + half2 uvSetSpecularMap = (_UVSetSpecular == 0) ? i.uv : i.uv1; + t.specularMapUV = TRANSFORM_TEX(uvSetSpecularMap, _SpecularMap); + + half2 uvSetThickness = (_UVSetThickness == 0) ? i.uv : i.uv1; + t.thicknessMapUV = TRANSFORM_TEX(uvSetThickness, _ThicknessMap); + + half2 uvSetReflectivityMask = (_UVSetReflectivity == 0) ? i.uv : i.uv1; + t.reflectivityMaskUV = TRANSFORM_TEX(uvSetReflectivityMask, _ReflectivityMask); + #endif +} + +float Remap_Float(float In, float2 InMinMax, float2 OutMinMax) +{ + return OutMinMax.x + (In - InMinMax.x) * (OutMinMax.y - OutMinMax.x) / (InMinMax.y - InMinMax.x); +} + +half3 rgb2hsv(half3 c) +{ + half4 K = half4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + half4 p = lerp(half4(c.bg, K.wz), half4(c.gb, K.xy), step(c.b, c.g)); + half4 q = lerp(half4(p.xyw, c.r), half4(c.r, p.yzx), step(p.x, c.r)); + + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + return half3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); +} + +half3 hsv2rgb(half3 c) +{ + half4 K = half4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + half3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} + +void InitializeTextureUVsMerged( + #if defined(Geometry) + in g2f i, + #else + in VertexOutput i, + #endif + inout TextureUV t) +{ + half2 uvSetAlbedo = (_UVSetAlbedo == 0) ? i.uv : i.uv1; + t.albedoUV = TRANSFORM_TEX(uvSetAlbedo, _MainTex); + t.normalMapUV = t.albedoUV; + t.emissionMapUV = t.albedoUV; + t.metallicGlossMapUV = t.albedoUV; + t.occlusionUV = t.albedoUV; + t.detailNormalUV = t.albedoUV; + t.detailMaskUV = t.albedoUV; + t.specularMapUV = t.albedoUV; + t.thicknessMapUV = t.albedoUV; + t.reflectivityMaskUV = t.albedoUV; + t.clipMapUV = t.albedoUV; + + //Dissolve map makes sense to be on a sep. UV always. + half2 uvSetDissolveMap = (_UVSetDissolve == 0) ? i.uv : i.uv1; + t.dissolveUV = TRANSFORM_TEX(uvSetDissolveMap, _DissolveTexture); +} + +bool IsInMirror() +{ + return unity_CameraProjection[2][0] != 0.f || unity_CameraProjection[2][1] != 0.f; +} + +inline half Dither8x8Bayer( int x, int y ) +{ + const half dither[ 64 ] = { + 1, 49, 13, 61, 4, 52, 16, 64, + 33, 17, 45, 29, 36, 20, 48, 32, + 9, 57, 5, 53, 12, 60, 8, 56, + 41, 25, 37, 21, 44, 28, 40, 24, + 3, 51, 15, 63, 2, 50, 14, 62, + 35, 19, 47, 31, 34, 18, 46, 30, + 11, 59, 7, 55, 10, 58, 6, 54, + 43, 27, 39, 23, 42, 26, 38, 22}; + int r = y * 8 + x; + return dither[r] / 64; +} + +half calcDither(half2 screenPos) +{ + half dither = Dither8x8Bayer(fmod(screenPos.x, 8), fmod(screenPos.y, 8)); + return dither; +} + +half2 calcScreenUVs(half4 screenPos) +{ + half2 uv = screenPos / (screenPos.w + 0.0000000001); //0.0x1 Stops division by 0 warning in console. + #if UNITY_SINGLE_PASS_STEREO + uv.xy *= half2(_ScreenParams.x * 2, _ScreenParams.y); + #else + uv.xy *= _ScreenParams.xy; + #endif + + return uv; +} + +half3 calcViewDir(half3 worldPos) +{ + half3 viewDir = _WorldSpaceCameraPos - worldPos; + return normalize(viewDir); +} + +half3 calcStereoViewDir(half3 worldPos) +{ + #if UNITY_SINGLE_PASS_STEREO + half3 cameraPos = half3((unity_StereoWorldSpaceCameraPos[0]+ unity_StereoWorldSpaceCameraPos[1])*.5); + #else + half3 cameraPos = _WorldSpaceCameraPos; + #endif + half3 viewDir = cameraPos - worldPos; + return normalize(viewDir); +} + +half2 matcapSample(half3 worldUp, half3 viewDirection, half3 normalDirection) +{ + half3 worldViewUp = normalize(worldUp - viewDirection * dot(viewDirection, worldUp)); + half3 worldViewRight = normalize(cross(viewDirection, worldViewUp)); + half2 matcapUV = half2(dot(worldViewRight, normalDirection), dot(worldViewUp, normalDirection)) * 0.5 + 0.5; + return matcapUV; +} + //Reflection direction, worldPos, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax +half3 getReflectionUV(half3 direction, half3 position, half4 cubemapPosition, half3 boxMin, half3 boxMax) +{ + #if UNITY_SPECCUBE_BOX_PROJECTION + if (cubemapPosition.w > 0) { + half3 factors = ((direction > 0 ? boxMax : boxMin) - position) / direction; + half scalar = min(min(factors.x, factors.y), factors.z); + direction = direction * scalar + (position - cubemapPosition); + } + #endif + return direction; +} + +half3 getEnvMap(XSLighting i, DotProducts d, float blur, half3 reflDir, half3 indirectLight, half3 wnormal) +{//This function handls Unity style reflections, Matcaps, and a baked in fallback cubemap. + half3 envMap = half3(0,0,0); + + #if defined(UNITY_PASS_FORWARDBASE) //Indirect PBR specular should only happen in the forward base pass. Otherwise each extra light adds another indirect sample, which could mean you're getting too much light. + half3 reflectionUV1 = getReflectionUV(reflDir, i.worldPos, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax); + half4 probe0 = UNITY_SAMPLE_TEXCUBE_LOD(unity_SpecCube0, reflectionUV1, blur); + half3 probe0sample = DecodeHDR(probe0, unity_SpecCube0_HDR); + + half3 indirectSpecular; + half interpolator = unity_SpecCube0_BoxMin.w; + + UNITY_BRANCH + if (interpolator < 0.99999) + { + half3 reflectionUV2 = getReflectionUV(reflDir, i.worldPos, unity_SpecCube1_ProbePosition, unity_SpecCube1_BoxMin, unity_SpecCube1_BoxMax); + half4 probe1 = UNITY_SAMPLE_TEXCUBE_SAMPLER_LOD(unity_SpecCube1, unity_SpecCube0, reflectionUV2, blur); + half3 probe1sample = DecodeHDR(probe1, unity_SpecCube1_HDR); + indirectSpecular = lerp(probe1sample, probe0sample, interpolator); + } + else + { + indirectSpecular = probe0sample; + } + + envMap = indirectSpecular; + #endif + + return envMap; +} + +float AlphaAdjust(float alphaToAdj, float3 vColor) +{ + _ClipAgainstVertexColorGreaterZeroFive = saturate(_ClipAgainstVertexColorGreaterZeroFive); //So the lerp doesn't go crazy + _ClipAgainstVertexColorLessZeroFive = saturate(_ClipAgainstVertexColorLessZeroFive); + + float modR = vColor.r < 0.5 ? _ClipAgainstVertexColorLessZeroFive.r : _ClipAgainstVertexColorGreaterZeroFive.r; + float modG = vColor.g < 0.5 ? _ClipAgainstVertexColorLessZeroFive.g : _ClipAgainstVertexColorGreaterZeroFive.g; + float modB = vColor.b < 0.5 ? _ClipAgainstVertexColorLessZeroFive.b : _ClipAgainstVertexColorGreaterZeroFive.b; + + alphaToAdj *= lerp(0, 1, lerp(1, modR, step(0.01, vColor.r))); + alphaToAdj *= lerp(0, 1, lerp(1, modG, step(0.01, vColor.g))); + alphaToAdj *= lerp(0, 1, lerp(1, modB, step(0.01, vColor.b))); + + return alphaToAdj; +} + +void calcDissolve(inout XSLighting i, inout float4 col) +{ + #ifdef _ALPHATEST_ON + half dissolveAmt = Remap_Float(i.dissolveMask.x, float2(0,1), float2(0.1, 0.9)); + half dissolveProgress = saturate(_DissolveProgress + lerp(0, 1-AlphaAdjust(1, i.clipMap.rgb), _UseClipsForDissolve)); + half dissolve = 0; + if (_DissolveCoordinates == 0) + { + dissolve = dissolveAmt - dissolveProgress; + clip(dissolve); + } + + if(_DissolveCoordinates == 1) + { + half distToCenter = 1-length(i.objPos); + dissolve = ((distToCenter + dissolveAmt) * 0.5) - dissolveProgress; + clip(dissolve); + } + + if(_DissolveCoordinates == 2) + { + half distToCenter = (1-i.objPos.y) * 0.5 + 0.5; + dissolve = ((distToCenter + dissolveAmt) * 0.5) - dissolveProgress; + clip(dissolve); + } + + #if !defined(UNITY_PASS_SHADOWCASTER) + float4 dissCol = _DissolveColor; + dissCol.rgb = rgb2hsv(dissCol.rgb); + dissCol.x += fmod(_Hue, 360); + dissCol.y = saturate(dissCol.y * _Saturation); + dissCol.z *= _Value; + dissCol.rgb = hsv2rgb(dissCol.rgb); + + half dissolveEdge = smoothstep(dissolve, dissolve - (_DissolveStrength * 0.01), dissolve * dissolveAmt); + col.rgb += (1-dissolveEdge) * dissCol.rgb; + #endif + #endif +} + +void calcAlpha(inout XSLighting i) +{ + i.alpha = 1; + + #ifdef _ALPHABLEND_ON + i.alpha = i.albedo.a; + + #ifdef UNITY_PASS_SHADOWCASTER + half dither = calcDither(i.screenUV.xy); + clip(i.alpha - dither); + #endif + #endif + + #ifdef _ALPHATEST_ON + float modifiedAlpha = lerp(AlphaAdjust(i.albedo.a, i.clipMap.rgb), i.albedo.a, _UseClipsForDissolve); + if(_BlendMode >= 3) + { + half dither = calcDither(i.screenUV.xy); + i.alpha = modifiedAlpha - (dither * (1-i.albedo.a) * 0.15); + } + + if(_BlendMode == 2) + { + half dither = calcDither(i.screenUV.xy); + float fadeDist = abs(_FadeDitherDistance); + float d = distance(_WorldSpaceCameraPos, i.worldPos); + d = smoothstep(fadeDist, fadeDist + 0.05, d); + d = lerp(d, 1-d, saturate(step(0, _FadeDitherDistance))); + dither += lerp(0, d, saturate(_FadeDither)); + clip(modifiedAlpha - dither); + } + + if(_BlendMode == 1) + { + clip(modifiedAlpha - _Cutoff); + } + #endif +} + +// //Halftone functions, finish implementing later.. Not correct right now. +float2 SphereUV( float3 coords /*viewDir?*/) +{ + float3 nc = normalize(coords); + float lat = acos(nc.y); + float lon = atan2(nc.z, nc.x); + float2 coord = 1.0 - (float2(lon, lat) * float2(1.0/UNITY_PI, 1.0/UNITY_PI)); + return (coord + float4(0, 1-unity_StereoEyeIndex,1,1.0).xy) * float4(0, 1-unity_StereoEyeIndex,1,1.0).zw; +} + +half2 rotateUV(half2 uv, half rotation) +{ + half mid = 0.5; + return half2( + cos(rotation) * (uv.x - mid) + sin(rotation) * (uv.y - mid) + mid, + cos(rotation) * (uv.y - mid) - sin(rotation) * (uv.x - mid) + mid + ); +} + +half DotHalftone(XSLighting i, half scalar) //Scalar can be anything from attenuation to a dot product +{ + bool inMirror = IsInMirror(); + half2 uv = SphereUV(calcViewDir(i.worldPos)); + uv.xy *= _HalftoneDotAmount; + half2 nearest = 2 * frac(100 * uv) - 1; + half dist = length(nearest); + half dotSize = 100 * _HalftoneDotSize * scalar; + half dotMask = step(dotSize, dist); + + return lerp(1, 1-dotMask, smoothstep(0, 0.4, 1/distance(i.worldPos, _WorldSpaceCameraPos)));; +} + +half LineHalftone(XSLighting i, half scalar) +{ + // #if defined(DIRECTIONAL) + // scalar = saturate(scalar + ((1-i.attenuation) * 0.2)); + // #endif + bool inMirror = IsInMirror(); + half2 uv = SphereUV(calcViewDir(i.worldPos)); + uv = rotateUV(uv, -0.785398); + uv.x = sin(uv.x * _HalftoneLineAmount * scalar); + + half2 steppedUV = smoothstep(0,0.2,uv.x); + half lineMask = lerp(1, steppedUV, smoothstep(0, 0.4, 1/distance(i.worldPos, _WorldSpaceCameraPos))); + + return saturate(lineMask); +} +//
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSHelperFunctions.cginc.meta b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSHelperFunctions.cginc.meta new file mode 100644 index 00000000..0177033b --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSHelperFunctions.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: ebd21331063545043946502d33e9244f +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSLighting.cginc b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSLighting.cginc new file mode 100644 index 00000000..fead4f8d --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSLighting.cginc @@ -0,0 +1,118 @@ +half4 BRDF_XSLighting(XSLighting i) +{ + float3 untouchedNormal = i.normal; + i.tangent = normalize(i.tangent); + i.bitangent = normalize(i.bitangent); + calcNormal(i); + + half3 indirectDiffuse = calcIndirectDiffuse(i); + bool lightEnv = any(_WorldSpaceLightPos0.xyz); + half3 lightDir = calcLightDir(i); + half3 viewDir = calcViewDir(i.worldPos); + half3 stereoViewDir = calcStereoViewDir(i.worldPos); + half4 metallicSmoothness = calcMetallicSmoothness(i); + half3 halfVector = normalize(lightDir + viewDir); + half3 reflView = calcReflView(viewDir, i.normal); + half3 reflLight = calcReflLight(lightDir, i.normal); + half3 reflViewAniso = getAnisotropicReflectionVector(viewDir, i.bitangent, i.tangent, i.normal, metallicSmoothness.a, _AnisotropicReflection); + + DotProducts d = (DotProducts)0; + d.ndl = dot(i.normal, lightDir); + d.vdn = abs(dot(viewDir, i.normal)); + d.vdh = DotClamped(viewDir, halfVector); + d.tdh = dot(i.tangent, halfVector); + d.bdh = dot(i.bitangent, halfVector); + d.ndh = DotClamped(i.normal, halfVector); + d.rdv = saturate(dot(reflLight, float4(-viewDir, 0))); + d.ldh = DotClamped(lightDir, halfVector); + d.svdn = abs(dot(stereoViewDir, i.normal)); + + i.albedo.rgb = rgb2hsv(i.albedo.rgb); + i.albedo.x += fmod(lerp(0, _Hue, i.hsvMask.r), 360); + i.albedo.y = saturate(i.albedo.y * lerp(1, _Saturation, i.hsvMask.g)); + i.albedo.z *= lerp(1, _Value, i.hsvMask.b); + i.albedo.rgb = hsv2rgb(i.albedo.rgb); + + i.diffuseColor.rgb = i.albedo.rgb; + i.albedo.rgb *= (1-metallicSmoothness.x); + half occlusion = lerp(1, i.occlusion.r, _OcclusionIntensity); + indirectDiffuse *= lerp(occlusion, 1, _OcclusionMode); + + half4 lightCol = half4(0,0,0,0); + calcLightCol(lightEnv, indirectDiffuse, lightCol); + + float3 vertexLightDiffuse = 0; + float3 vertexLightSpec = 0; + #if defined(VERTEXLIGHT_ON) + VertexLightInformation vLight = (VertexLightInformation)0; + float4 vertexLightAtten = float4(0,0,0,0); + float3 vertexLightColor = get4VertexLightsColFalloff(vLight, i.worldPos, i.normal, vertexLightAtten); + float3 vertexLightDir = getVertexLightsDir(vLight, i.worldPos, vertexLightAtten); + vertexLightDiffuse = getVertexLightsDiffuse(i, vLight); + indirectDiffuse += vertexLightDiffuse; + + vertexLightSpec = getVertexLightSpecular(i, d, vLight, i.normal, viewDir, _AnisotropicSpecular) * occlusion; + #endif + + half lightAvg = (dot(indirectDiffuse.rgb, grayscaleVec) + dot(lightCol.rgb, grayscaleVec)) / 2; + half3 envMapBlurred = getEnvMap(i, d, 5, reflView, indirectDiffuse, i.normal); + + half4 ramp = calcRamp(i,d); + half4 diffuse = calcDiffuse(i, d, indirectDiffuse, lightCol, ramp); + half4 rimLight = calcRimLight(i, d, lightCol, indirectDiffuse, envMapBlurred); + half4 shadowRim = calcShadowRim(i, d, indirectDiffuse); + + float3 f0 = 0.16 * _Reflectivity * _Reflectivity * (1.0 - metallicSmoothness.r) + i.diffuseColor * metallicSmoothness.r; + float3 fresnel = F_Schlick(d.vdn, f0); + half3 indirectSpecular = calcIndirectSpecular(i, d, metallicSmoothness, reflViewAniso, indirectDiffuse, viewDir, fresnel, ramp) * occlusion; + half3 directSpecular = calcDirectSpecular(i, d.ndl, d.ndh, d.vdn, d.ldh, lightCol, halfVector, _AnisotropicSpecular) * d.ndl * occlusion * i.attenuation; + half4 subsurface = calcSubsurfaceScattering(i, d, lightDir, viewDir, i.normal, lightCol, indirectDiffuse); + half4 outlineColor = calcOutlineColor(i, d, indirectDiffuse, lightCol); + + half lineHalftone = 0; + half stipplingDirect = 0; + half stipplingRim = 0; + half stipplingIndirect = 0; + bool usingLineHalftone = 0; + if(_HalftoneType == 0 || _HalftoneType == 2) + { + lineHalftone = lerp(1, LineHalftone(i, 1), 1-saturate(dot(shadowRim * ramp, grayscaleVec))); + usingLineHalftone = 1; + } + + if(_HalftoneType == 1 || _HalftoneType == 2) + { + stipplingDirect = DotHalftone(i, saturate(dot(directSpecular, grayscaleVec))) * saturate(dot(shadowRim * ramp, grayscaleVec)); + stipplingRim = DotHalftone(i, saturate(dot(rimLight, grayscaleVec))) * saturate(dot(shadowRim * ramp, grayscaleVec)); + stipplingIndirect = DotHalftone(i, saturate(dot(indirectSpecular, grayscaleVec))) * saturate(dot(shadowRim * ramp, grayscaleVec)); + + directSpecular *= stipplingDirect; + rimLight *= stipplingRim; + indirectSpecular *= lerp(0.5, 1, stipplingIndirect); // Don't want these to go completely black, looks weird + } + + #if defined(_COLOROVERLAY_ON) + float refractFresnel = 1-d.vdn; + float distanceToPixel = distance(_WorldSpaceCameraPos, i.worldPos); + float distanceScalar = saturate(1 / distanceToPixel) * saturate(distanceToPixel); + float3 refractDir = refract(viewDir, i.normal, max(0, _IOR - 1) * 0.03 * distanceScalar * refractFresnel); + float3x3 worldToTangentMatrix = float3x3(i.tangent, i.bitangent, i.normal); + refractDir = mul(worldToTangentMatrix, refractDir); + float4 backgroundColor = tex2Dproj(_GrabTexture, float4(i.screenPos.xyz + refractDir, i.screenPos.w)); + #endif + + half4 col; + #if !defined(_COLOROVERLAY_ON) + col = diffuse * shadowRim; + #else + col = backgroundColor * diffuse * shadowRim; + #endif + calcReflectionBlending(i, col, indirectSpecular.xyzz); + col += max(directSpecular.xyzz, rimLight); + col.rgb += max(vertexLightSpec.rgb, rimLight); + col += subsurface; + calcClearcoat(col, i, d, untouchedNormal, indirectDiffuse, lightCol, viewDir, lightDir, ramp); + col += calcEmission(i, lightAvg); + float4 finalColor = lerp(col, outlineColor, i.isOutline) * lerp(1, lineHalftone, _HalftoneLineIntensity * usingLineHalftone); + return finalColor; +}
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSLighting.cginc.meta b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSLighting.cginc.meta new file mode 100644 index 00000000..b11ced2b --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSLighting.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 786da05e6d64ae844853fdca78e33aef +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSLightingFunctions.cginc b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSLightingFunctions.cginc new file mode 100644 index 00000000..f28f6f29 --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSLightingFunctions.cginc @@ -0,0 +1,428 @@ +//Helper Functions for Reflections +float pow5(float a) +{ + return a * a * a * a * a; +} + +float3 F_Schlick(float u, float3 f0) +{ + return f0 + (1.0 - f0) * pow(1.0 - u, 5.0); +} + +float3 F_FresnelLerp (float3 F0, float3 F90, float cosA) +{ + float t = pow5(1 - cosA); // ala Schlick interpoliation + return lerp (F0, F90, t); +} + +float D_GGX(float NoH, float roughness) +{ + float a2 = roughness * roughness; + float f = (NoH * a2 - NoH) * NoH + 1.0; + return a2 / (UNITY_PI * f * f); +} + +float D_GGX_Anisotropic(float NoH, const float3 h, const float3 t, const float3 b, float at, float ab) +{ + float ToH = dot(t, h); + float BoH = dot(b, h); + float a2 = at * ab; + float3 v = float3(ab * ToH, at * BoH, a2 * NoH); + float v2 = dot(v, v); + float w2 = a2 / v2; + return a2 * w2 * w2 * (1.0 / UNITY_PI); +} + +float V_SmithGGXCorrelated(float NoV, float NoL, float a) +{ + float a2 = a * a; + float GGXL = NoV * sqrt((-NoL * a2 + NoL) * NoL + a2); + float GGXV = NoL * sqrt((-NoV * a2 + NoV) * NoV + a2); + return 0.5 / (GGXV + GGXL); +} + +half3 calcReflView(half3 viewDir, half3 normal) +{ + return reflect(-viewDir, normal); +} + +half3 calcReflLight(half3 lightDir, half3 normal) +{ + return reflect(lightDir, normal); +} +// + +//Returns the average direction of all lights and writes to a struct contraining individual directions +float3 getVertexLightsDir(inout VertexLightInformation vLights, float3 worldPos, float4 vertexLightAtten) +{ + float3 dir = float3(0,0,0); + float3 toLightX = float3(unity_4LightPosX0.x, unity_4LightPosY0.x, unity_4LightPosZ0.x); + float3 toLightY = float3(unity_4LightPosX0.y, unity_4LightPosY0.y, unity_4LightPosZ0.y); + float3 toLightZ = float3(unity_4LightPosX0.z, unity_4LightPosY0.z, unity_4LightPosZ0.z); + float3 toLightW = float3(unity_4LightPosX0.w, unity_4LightPosY0.w, unity_4LightPosZ0.w); + + float3 dirX = toLightX - worldPos; + float3 dirY = toLightY - worldPos; + float3 dirZ = toLightZ - worldPos; + float3 dirW = toLightW - worldPos; + + dirX *= length(toLightX) * vertexLightAtten.x; + dirY *= length(toLightY) * vertexLightAtten.y; + dirZ *= length(toLightZ) * vertexLightAtten.z; + dirW *= length(toLightW) * vertexLightAtten.w; + + vLights.Direction[0] = dirX; + vLights.Direction[1] = dirY; + vLights.Direction[2] = dirZ; + vLights.Direction[3] = dirW; + + dir = (dirX + dirY + dirZ + dirW) / 4; + return dir; +} + +// Get the most intense light Dir from probes OR from a light source. Method developed by Xiexe / Merlin +half3 calcLightDir(XSLighting i) +{ + half3 lightDir = UnityWorldSpaceLightDir(i.worldPos); + half3 probeLightDir = unity_SHAr.xyz + unity_SHAg.xyz + unity_SHAb.xyz; + lightDir = (lightDir + probeLightDir); //Make light dir the average of the probe direction and the light source direction. + #if !defined(POINT) && !defined(SPOT)// if the average length of the light probes is null, and we don't have a directional light in the scene, fall back to our fallback lightDir + if(length(unity_SHAr.xyz*unity_SHAr.w + unity_SHAg.xyz*unity_SHAg.w + unity_SHAb.xyz*unity_SHAb.w) == 0 && length(lightDir) < 0.1) + { + lightDir = half4(1, 1, 1, 0); + } + #endif + return normalize(lightDir); +} + +void calcLightCol(bool lightEnv, inout half3 indirectDiffuse, inout half4 lightColor) +{ + //If we're in an environment with a realtime light, then we should use the light color, and indirect color raw. + //... + if(lightEnv) + { + lightColor = _LightColor0; + indirectDiffuse = indirectDiffuse; + } + else + { + lightColor = indirectDiffuse.xyzz * 0.6; // ...Otherwise + indirectDiffuse = indirectDiffuse * 0.4; // Keep overall light to 100% - these should never go over 100% + // ex. If we have indirect 100% as the light color and Indirect 50% as the indirect color, + // we end up with 150% of the light from the scene. + } +} + +float3 get4VertexLightsColFalloff(inout VertexLightInformation vLight, float3 worldPos, float3 normal, inout float4 vertexLightAtten) +{ + float3 lightColor = 0; + #if defined(VERTEXLIGHT_ON) + float4 toLightX = unity_4LightPosX0 - worldPos.x; + float4 toLightY = unity_4LightPosY0 - worldPos.y; + float4 toLightZ = unity_4LightPosZ0 - worldPos.z; + + float4 lengthSq = 0; + lengthSq += toLightX * toLightX; + lengthSq += toLightY * toLightY; + lengthSq += toLightZ * toLightZ; + + float4 atten = 1.0 / (1.0 + lengthSq * unity_4LightAtten0); + float4 atten2 = saturate(1 - (lengthSq * unity_4LightAtten0 / 25)); + atten = min(atten, atten2 * atten2); + // Cleaner, nicer looking falloff. Also prevents the "Snapping in" effect that Unity's normal integration of vertex lights has. + vertexLightAtten = atten; + + lightColor.rgb += unity_LightColor[0] * atten.x; + lightColor.rgb += unity_LightColor[1] * atten.y; + lightColor.rgb += unity_LightColor[2] * atten.z; + lightColor.rgb += unity_LightColor[3] * atten.w; + + vLight.ColorFalloff[0] = unity_LightColor[0] * atten.x; + vLight.ColorFalloff[1] = unity_LightColor[1] * atten.y; + vLight.ColorFalloff[2] = unity_LightColor[2] * atten.z; + vLight.ColorFalloff[3] = unity_LightColor[3] * atten.w; + + vLight.Attenuation[0] = atten.x; + vLight.Attenuation[1] = atten.y; + vLight.Attenuation[2] = atten.z; + vLight.Attenuation[3] = atten.w; + #endif + return lightColor; +} + +half4 calcRamp(XSLighting i, DotProducts d) +{ + half remapRamp; + remapRamp = (d.ndl * 0.5 + 0.5) * lerp(1, i.occlusion.r, _OcclusionMode) ; + #if defined(UNITY_PASS_FORWARDBASE) + remapRamp *= i.attenuation; + #endif + half4 ramp = tex2D(_Ramp, half2(remapRamp, i.rampMask.r)); + return ramp; +} + +half4 calcRampShadowOverride(XSLighting i, float ndl) +{ + half remapRamp; + remapRamp = (ndl * 0.5 + 0.5) * lerp(1, i.occlusion.r, _OcclusionMode); + half4 ramp = tex2D(_Ramp, half2(remapRamp, i.rampMask.r)); + return ramp; +} + +float3 getVertexLightsDiffuse(XSLighting i, VertexLightInformation vLight) +{ + float3 vertexLightsDiffuse = 0; + #if defined(VERTEXLIGHT_ON) + for(int light = 0; light < 4; light++) // I know, I know, not using i. Blame my structs. + { + float vLightNdl = dot(vLight.Direction[light], i.normal); + vertexLightsDiffuse += calcRampShadowOverride(i, vLightNdl) * vLight.ColorFalloff[light]; + } + #endif + return vertexLightsDiffuse; +} + +half4 calcMetallicSmoothness(XSLighting i) +{ + half roughness = 1-(_Glossiness * i.metallicGlossMap.a); + roughness *= 1.7 - 0.7 * roughness; + half metallic = lerp(0, i.metallicGlossMap.r * _Metallic, i.reflectivityMask.r); + return half4(metallic, 0, 0, roughness); +} + +half4 calcRimLight(XSLighting i, DotProducts d, half4 lightCol, half3 indirectDiffuse, half3 envMap) +{ + half rimIntensity = saturate((1-d.svdn)) * pow(d.ndl, _RimThreshold); + rimIntensity = smoothstep(_RimRange - _RimSharpness, _RimRange + _RimSharpness, rimIntensity); + half4 rim = rimIntensity * _RimIntensity * (lightCol + indirectDiffuse.xyzz); + rim *= lerp(1, i.attenuation + indirectDiffuse.xyzz, _RimAttenEffect); + return rim * _RimColor * lerp(1, i.diffuseColor.rgbb, _RimAlbedoTint) * lerp(1, envMap.rgbb, _RimCubemapTint); +} + +half4 calcShadowRim(XSLighting i, DotProducts d, half3 indirectDiffuse) +{ + half rimIntensity = saturate((1-d.svdn)) * pow(1-d.ndl, _ShadowRimThreshold * 2); + rimIntensity = smoothstep(_ShadowRimRange - _ShadowRimSharpness, _ShadowRimRange + _ShadowRimSharpness, rimIntensity); + half4 shadowRim = lerp(1, (_ShadowRim * lerp(1, i.diffuseColor.rgbb, _ShadowRimAlbedoTint)) + (indirectDiffuse.xyzz * 0.1), rimIntensity); + + return shadowRim ; +} + +float3 getAnisotropicReflectionVector(float3 viewDir, float3 bitangent, float3 tangent, float3 normal, float roughness, float anisotropy) +{ + //_Anisotropy = lerp(-0.2, 0.2, sin(_Time.y / 20)); //This is pretty fun + float3 anisotropicDirection = anisotropy >= 0.0 ? bitangent : tangent; + float3 anisotropicTangent = cross(anisotropicDirection, viewDir); + float3 anisotropicNormal = cross(anisotropicTangent, anisotropicDirection); + float bendFactor = abs(anisotropy) * saturate(5.0 * roughness); + float3 bentNormal = normalize(lerp(normal, anisotropicNormal, bendFactor)); + return reflect(-viewDir, bentNormal); +} + +half3 calcDirectSpecular(XSLighting i, float ndl, float ndh, float vdn, float ldh, half4 lightCol, half3 halfVector, half anisotropy) +{ + half specularIntensity = _SpecularIntensity * i.specularMap.r; + half3 specular = half3(0,0,0); + half smoothness = max(0.01, (_SpecularArea * i.specularMap.b)); + smoothness *= 1.7 - 0.7 * smoothness; + + float rough = max(smoothness * smoothness, 0.0045); + float Dn = D_GGX(ndh, rough); + float3 F = 1-F_Schlick(ldh, 0); + float V = V_SmithGGXCorrelated(vdn, ndl, rough); + float3 directSpecularNonAniso = max(0, (Dn * V) * F); + + anisotropy *= saturate(5.0 * smoothness); + float at = max(rough * (1.0 + anisotropy), 0.001); + float ab = max(rough * (1.0 - anisotropy), 0.001); + float D = D_GGX_Anisotropic(ndh, halfVector, i.tangent, i.bitangent, at, ab); + float3 directSpecularAniso = max(0, (D * V) * F); + + specular = lerp(directSpecularNonAniso, directSpecularAniso, saturate(abs(anisotropy * 100))); + specular = lerp(specular, smoothstep(0.5, 0.51, specular), _SpecularSharpness) * 3 * lightCol * specularIntensity; // Multiply by 3 to bring up to brightness of standard + specular *= lerp(1, i.diffuseColor, _SpecularAlbedoTint * i.specularMap.g); + return specular; +} + +float3 getVertexLightSpecular(XSLighting i, DotProducts d, VertexLightInformation vLight, float3 normal, float3 viewDir, float anisotropy) +{ + float3 vertexLightSpec = 0; + #if defined(VERTEXLIGHT_ON) + for(int light = 0; light < 4; light++) + { + // All of these need to be recalculated for each individual light to treat them how we want to treat them. + float3 vHalfVector = normalize(vLight.Direction[light] + viewDir); + float vNDL = saturate(dot(vLight.Direction[light], normal)); + float vLDH = saturate(dot(vLight.Direction[light], vHalfVector)); + float vNDH = saturate(dot(normal, vHalfVector)); + vertexLightSpec += calcDirectSpecular(i, vNDL, vNDH, d.vdn, vLDH, vLight.ColorFalloff[light].rgbb, vHalfVector, anisotropy) * vNDL; + } + #endif + return vertexLightSpec; +} + +half3 calcIndirectSpecular(XSLighting i, DotProducts d, half4 metallicSmoothness, half3 reflDir, half3 indirectLight, half3 viewDir, float3 fresnel, half4 ramp) +{//This function handls Unity style reflections, Matcaps, and a baked in fallback cubemap. + half3 spec = half3(0,0,0); + + UNITY_BRANCH + if(_ReflectionMode == 0) // PBR + { + #if defined(UNITY_PASS_FORWARDBASE) //Indirect PBR specular should only happen in the forward base pass. Otherwise each extra light adds another indirect sample, which could mean you're getting too much light. + half3 reflectionUV1 = getReflectionUV(reflDir, i.worldPos, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax); + half4 probe0 = UNITY_SAMPLE_TEXCUBE_LOD(unity_SpecCube0, reflectionUV1, metallicSmoothness.w * UNITY_SPECCUBE_LOD_STEPS); + half3 probe0sample = DecodeHDR(probe0, unity_SpecCube0_HDR); + + half3 indirectSpecular; + half interpolator = unity_SpecCube0_BoxMin.w; + + UNITY_BRANCH + if (interpolator < 0.99999) + { + half3 reflectionUV2 = getReflectionUV(reflDir, i.worldPos, unity_SpecCube1_ProbePosition, unity_SpecCube1_BoxMin, unity_SpecCube1_BoxMax); + half4 probe1 = UNITY_SAMPLE_TEXCUBE_SAMPLER_LOD(unity_SpecCube1, unity_SpecCube0, reflectionUV2, metallicSmoothness.w * UNITY_SPECCUBE_LOD_STEPS); + half3 probe1sample = DecodeHDR(probe1, unity_SpecCube1_HDR); + indirectSpecular = lerp(probe1sample, probe0sample, interpolator); + } + else + { + indirectSpecular = probe0sample; + } + + if (!any(indirectSpecular)) + { + indirectSpecular = texCUBElod(_BakedCubemap, half4(reflDir, metallicSmoothness.w * UNITY_SPECCUBE_LOD_STEPS)); + indirectSpecular *= indirectLight; + } + spec = indirectSpecular * fresnel; + #endif + } + else if(_ReflectionMode == 1) //Baked Cubemap + { + half3 indirectSpecular = texCUBElod(_BakedCubemap, half4(reflDir, metallicSmoothness.w * UNITY_SPECCUBE_LOD_STEPS));; + spec = indirectSpecular * fresnel; + + if(_ReflectionBlendMode != 1) + { + spec *= (indirectLight + (_LightColor0 * i.attenuation) * 0.5); + } + } + else if (_ReflectionMode == 2) //Matcap + { + half3 upVector = half3(0,1,0); + half2 remapUV = matcapSample(upVector, viewDir, i.normal); + spec = tex2Dlod(_Matcap, half4(remapUV, 0, ((1-metallicSmoothness.w) * UNITY_SPECCUBE_LOD_STEPS))) * _MatcapTint; + + if(_ReflectionBlendMode != 1) + { + spec *= (indirectLight + (_LightColor0 * i.attenuation) * 0.5); + } + + spec *= lerp(1, i.diffuseColor, _MatcapTintToDiffuse); + } + return spec; +} + +half4 calcOutlineColor(XSLighting i, DotProducts d, half3 indirectDiffuse, half4 lightCol) +{ + half3 outlineColor = half3(0,0,0); + #if defined(Geometry) + half3 ol = lerp(_OutlineColor, _OutlineColor * i.diffuseColor, _OutlineAlbedoTint); + outlineColor = ol * saturate(i.attenuation * d.ndl) * lightCol.rgb; + outlineColor += indirectDiffuse * ol; + outlineColor = lerp(outlineColor, ol, _OutlineLighting); + #endif + return half4(outlineColor,1); +} + +half3 calcIndirectDiffuse(XSLighting i) +{// We don't care about anything other than the color from probes for toon lighting. + half3 indirectDiffuse = ShadeSH9(float4(0,0.5,0,1));//half3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w); + return indirectDiffuse; +} + +half4 calcDiffuse(XSLighting i, DotProducts d, half3 indirectDiffuse, half4 lightCol, half4 ramp) +{ + half4 diffuse; + half4 indirect = indirectDiffuse.xyzz; + + half grayIndirect = dot(indirectDiffuse, float3(1,1,1)); + half attenFactor = lerp(i.attenuation, 1, smoothstep(0, 0.2, grayIndirect)); + + diffuse = ramp * attenFactor * lightCol + indirect; + diffuse = i.albedo * diffuse; + return diffuse; +} + +//Subsurface Scattering - Based on a 2011 GDC Conference from by Colin Barre-Bresebois & Marc Bouchard +//Modified by Xiexe +half4 calcSubsurfaceScattering(XSLighting i, DotProducts d, half3 lightDir, half3 viewDir, half3 normal, half4 lightCol, half3 indirectDiffuse) +{ + UNITY_BRANCH + if(any(_SSColor.rgb)) // Skip all the SSS stuff if the color is 0. + { + //d.ndl = smoothstep(_SSSRange - _SSSSharpness, _SSSRange + _SSSSharpness, d.ndl); + half attenuation = saturate(i.attenuation * (d.ndl * 0.5 + 0.5)); + half3 H = normalize(lightDir + normal * _SSDistortion); + half VdotH = pow(saturate(dot(viewDir, -H)), _SSPower); + half3 I = _SSColor * (VdotH + indirectDiffuse) * attenuation * i.thickness * _SSScale; + half4 SSS = half4(lightCol.rgb * I * i.albedo.rgb, 1); + SSS = max(0, SSS); // Make sure it doesn't go NaN + + return SSS; + } + else + { + return 0; + } +} + +half4 calcEmission(XSLighting i, half lightAvg) +{ + #if defined(UNITY_PASS_FORWARDBASE) // Emission only in Base Pass, and vertex lights + float4 emission = lerp(i.emissionMap, i.emissionMap * i.diffuseColor.xyzz, _EmissionToDiffuse); + float4 scaledEmission = emission * saturate(smoothstep(1-_ScaleWithLightSensitivity, 1+_ScaleWithLightSensitivity, 1-lightAvg)); + float4 em = lerp(scaledEmission, emission, _ScaleWithLight); + + em.rgb = rgb2hsv(em.rgb); + em.x += fmod(_Hue, 360); + em.y = saturate(em.y * _Saturation); + em.z *= _Value; + em.rgb = hsv2rgb(em.rgb); + + return em; + #else + return 0; + #endif +} + +void calcReflectionBlending(XSLighting i, inout half4 col, half3 indirectSpecular) +{ + if(_ReflectionBlendMode == 0) // Additive + col += indirectSpecular.xyzz * i.reflectivityMask.r; + else if(_ReflectionBlendMode == 1) //Multiplicitive + col = lerp(col, col * indirectSpecular.xyzz, i.reflectivityMask.r); + else if(_ReflectionBlendMode == 2) //Subtractive + col -= indirectSpecular.xyzz * i.reflectivityMask.r; +} + +void calcClearcoat(inout half4 col, XSLighting i, DotProducts d, half3 untouchedNormal, half3 indirectDiffuse, half3 lightCol, half3 viewDir, half3 lightDir, half4 ramp) +{ + UNITY_BRANCH + if(_ClearCoat != 0) + { + untouchedNormal = normalize(untouchedNormal); + half clearcoatSmoothness = _ClearcoatSmoothness * i.metallicGlossMap.g; + half clearcoatStrength = _ClearcoatStrength * i.metallicGlossMap.b; + + half3 reflView = calcReflView(viewDir, untouchedNormal); + half3 reflLight = calcReflLight(lightDir, untouchedNormal); + half rdv = saturate( dot( reflLight, half4(-viewDir, 0) )); + half3 clearcoatIndirect = calcIndirectSpecular(i, d, half4(0, 0, 0, 1-clearcoatSmoothness), reflView, indirectDiffuse, viewDir, 1, ramp); + half3 clearcoatDirect = saturate(pow(rdv, clearcoatSmoothness * 256)) * i.attenuation * lightCol; + + half3 clearcoat = (clearcoatIndirect + clearcoatDirect) * clearcoatStrength; + clearcoat = lerp(clearcoat * 0.5, clearcoat, saturate(pow(1-dot(viewDir, untouchedNormal), 0.8)) ); + col += clearcoat.xyzz; + } +} diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSLightingFunctions.cginc.meta b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSLightingFunctions.cginc.meta new file mode 100644 index 00000000..c2e52936 --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSLightingFunctions.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 6a2a36080e04c18489c0c9d2ddc2543a +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSShadowCaster.cginc b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSShadowCaster.cginc new file mode 100644 index 00000000..c3baae39 --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSShadowCaster.cginc @@ -0,0 +1,170 @@ +#include "UnityCG.cginc" +#include "UnityShaderVariables.cginc" + +// Do dithering for alpha blended shadows on SM3+/desktop, and Dithered transparency; +// on lesser systems do simple alpha-tested shadows +#if defined(_ALPHABLEND_ON) || defined(_ALPHATEST_ON) + #if !((SHADER_TARGET < 30) || defined (SHADER_API_MOBILE) || defined(SHADER_API_D3D11_9X) || defined (SHADER_API_PSP2) || defined (SHADER_API_PSM)) + #define UNITY_STANDARD_USE_DITHER_MASK 1 + #endif +#endif + +// Need to output UVs in shadow caster, since we need to sample texture and do clip/dithering based on it +#if defined(_ALPHABLEND_ON) || defined(_ALPHATEST_ON) + #define UNITY_STANDARD_USE_SHADOW_UVS 1 +#endif + +uniform float4 _ClipAgainstVertexColorGreaterZeroFive, _ClipAgainstVertexColorLessZeroFive; +uniform float4 _Color; +uniform float _Cutoff; +uniform sampler2D _MainTex; +uniform sampler2D _CutoutMask; +uniform sampler2D _ClipMap; +uniform float4 _MainTex_ST; +uniform float _FadeDither; +uniform float _FadeDitherDistance; +uniform int _BlendMode; +#ifdef UNITY_STANDARD_USE_DITHER_MASK + uniform sampler3D _DitherMaskLOD; +#endif + +struct VertexInput +{ + float4 vertex : POSITION; + float3 normal : NORMAL; + float2 uv0 : TEXCOORD0; + float4 color : COLOR; +}; + + +// Don't make the structure if it's empty (it's an error to have empty structs on some platforms...) +#if !defined(V2F_SHADOW_CASTER_NOPOS_IS_EMPTY) || defined(UNITY_STANDARD_USE_SHADOW_UVS) +struct VertexOutputShadowCaster +{ + V2F_SHADOW_CASTER_NOPOS + // Need to output UVs in shadow caster, since we need to sample texture and do clip/dithering based on it + #if defined(UNITY_STANDARD_USE_SHADOW_UVS) + float2 tex : TEXCOORD1; + #endif + + float4 worldPos : TEXCOORD2; + float4 screenPos : TEXCOORD3; + float4 color : COLOR; +}; +#endif + +half2 calcScreenUVs(half4 screenPos) +{ + half2 uv = screenPos / (screenPos.w + 0.0000000001); //0.0x1 Stops division by 0 warning in console. + #if UNITY_SINGLE_PASS_STEREO + uv.xy *= half2(_ScreenParams.x * 2, _ScreenParams.y); + #else + uv.xy *= _ScreenParams.xy; + #endif + + return uv; +} + +inline half Dither8x8Bayer( int x, int y ) +{ + const half dither[ 64 ] = { + 1, 49, 13, 61, 4, 52, 16, 64, + 33, 17, 45, 29, 36, 20, 48, 32, + 9, 57, 5, 53, 12, 60, 8, 56, + 41, 25, 37, 21, 44, 28, 40, 24, + 3, 51, 15, 63, 2, 50, 14, 62, + 35, 19, 47, 31, 34, 18, 46, 30, + 11, 59, 7, 55, 10, 58, 6, 54, + 43, 27, 39, 23, 42, 26, 38, 22}; + int r = y * 8 + x; + return dither[r] / 64; +} + +half calcDither(half2 screenPos) +{ + half dither = Dither8x8Bayer(fmod(screenPos.x, 8), fmod(screenPos.y, 8)); + return dither; +} + +// We have to do these dances of outputting SV_POSITION separately from the vertex shader, +// and inputting VPOS in the pixel shader, since they both map to "POSITION" semantic on +// some platforms, and then things don't go well. + + +void vertShadowCaster(VertexInput v, + #if !defined(V2F_SHADOW_CASTER_NOPOS_IS_EMPTY) || defined(UNITY_STANDARD_USE_SHADOW_UVS) + out VertexOutputShadowCaster o, + #endif + out float4 opos : SV_POSITION) +{ + TRANSFER_SHADOW_CASTER_NOPOS(o, opos) + #if defined(UNITY_STANDARD_USE_SHADOW_UVS) + o.tex = TRANSFORM_TEX(v.uv0, _MainTex); + o.color = v.color; + o.worldPos = mul(unity_ObjectToWorld, v.vertex); + o.screenPos = ComputeScreenPos(opos); + #endif +} + +float AlphaAdjust(float alphaToAdj, float3 vColor) +{ + _ClipAgainstVertexColorGreaterZeroFive = saturate(_ClipAgainstVertexColorGreaterZeroFive); //So the lerp doesn't go crazy + _ClipAgainstVertexColorLessZeroFive = saturate(_ClipAgainstVertexColorLessZeroFive); + + float modR = vColor.r < 0.5 ? _ClipAgainstVertexColorLessZeroFive.r : _ClipAgainstVertexColorGreaterZeroFive.r; + float modG = vColor.g < 0.5 ? _ClipAgainstVertexColorLessZeroFive.g : _ClipAgainstVertexColorGreaterZeroFive.g; + float modB = vColor.b < 0.5 ? _ClipAgainstVertexColorLessZeroFive.b : _ClipAgainstVertexColorGreaterZeroFive.b; + + alphaToAdj *= lerp(0, 1, lerp(1, modR, step(0.01, vColor.r))); + alphaToAdj *= lerp(0, 1, lerp(1, modG, step(0.01, vColor.g))); + alphaToAdj *= lerp(0, 1, lerp(1, modB, step(0.01, vColor.b))); + + return alphaToAdj; +} + +half4 fragShadowCaster( + #if !defined(V2F_SHADOW_CASTER_NOPOS_IS_EMPTY) || defined(UNITY_STANDARD_USE_SHADOW_UVS) + VertexOutputShadowCaster i + #endif + #ifdef UNITY_STANDARD_USE_DITHER_MASK + , UNITY_VPOS_TYPE vpos : VPOS + #endif +) : SV_Target +{ + #if defined(UNITY_STANDARD_USE_SHADOW_UVS) + half alpha = 1; + float4 albedo = tex2D(_MainTex, i.tex).a * _Color.a; + float4 clipMap = tex2D(_ClipMap, i.tex); + float modifiedAlpha = AlphaAdjust(albedo.a, clipMap.rgb); + + #if defined(_ALPHABLEND_ON) || defined(_ALPHATEST_ON) + float2 screenUV = calcScreenUVs(i.screenPos); + if(_BlendMode >= 3) + { + half dither = calcDither(screenUV); + alpha = modifiedAlpha - (dither * (1-albedo.a) * 0.15); + } + + if(_BlendMode == 2) + { + half dither = calcDither(screenUV); + + float fadeDist = abs(_FadeDitherDistance); + float d = distance(_WorldSpaceCameraPos, i.worldPos); + d = smoothstep(fadeDist, fadeDist + 0.05, d); + d = lerp(d, 1-d, saturate(step(0, _FadeDitherDistance))); + dither += lerp(0, d, saturate(_FadeDither)); + clip(modifiedAlpha - dither); + } + + if(_BlendMode == 1) + { + clip(modifiedAlpha - _Cutoff); + } + #else + alpha = modifiedAlpha; + #endif + #endif + + SHADOW_CASTER_FRAGMENT(i) +}
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSShadowCaster.cginc.meta b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSShadowCaster.cginc.meta new file mode 100644 index 00000000..03c14eb0 --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSShadowCaster.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: cc6de506a13e7c347814e14820c6f710 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSVert.cginc b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSVert.cginc new file mode 100644 index 00000000..90a36907 --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSVert.cginc @@ -0,0 +1,32 @@ +VertexOutput vert (VertexInput v) +{ + VertexOutput o = (VertexOutput)0; + float3 wnormal = UnityObjectToWorldNormal(v.normal); + float3 tangent = UnityObjectToWorldDir(v.tangent.xyz); + half tangentSign = v.tangent.w * unity_WorldTransformParams.w; + float3 bitangent = cross(wnormal, tangent) * tangentSign; + + #if defined(Geometry) + o.vertex = v.vertex; + #endif + + o.pos = UnityObjectToClipPos(v.vertex); + o.worldPos = mul(unity_ObjectToWorld, v.vertex); + o.ntb[0] = wnormal; + o.ntb[1] = tangent; + o.ntb[2] = bitangent; + o.uv = v.uv; + o.uv1 = v.uv1; + o.color = float4(v.color.rgb, 0); // store if outline in alpha channel of vertex colors | 0 = not an outline + o.normal = v.normal; + o.screenPos = ComputeScreenPos(o.pos); + o.objPos = normalize(v.vertex); + + #if !defined(UNITY_PASS_SHADOWCASTER) + UNITY_TRANSFER_SHADOW(o, o.uv); + UNITY_TRANSFER_FOG(o, o.pos); + #else + TRANSFER_SHADOW_CASTER_NOPOS(o, o.pos); + #endif + return o; +}
\ No newline at end of file diff --git a/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSVert.cginc.meta b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSVert.cginc.meta new file mode 100644 index 00000000..d38ab884 --- /dev/null +++ b/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Main/CGIncludes/XSVert.cginc.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: c7cd982b7344d2c42b273a1734f935e3 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: |