diff --git a/CHANGELOG.md b/CHANGELOG.md index 41a8706..daa063f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [3.2.9] - 2023-09-18 +- Removed bakery meta pass because of performance issues + +## [3.2.8] - 2023-08-31 +## Added +- Support for using custom drawers in the inspector +- Refactored Importer Code + ## [3.2.7] - 2023-07-20 ## Added - New automatic PBR material setup with texture packing @@ -26,7 +34,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Adjustable height blending (Mask Map Blue channel) - Doesn't work with more than 4 layers currently - Possible bugs since I avoid using Unity terrain - - Ported over `SurfaceDescriptionInputs` and `VertexDescriptionInputs` functions from Shader Graph for getting shader data when creating new shaders in [Structs](/ShaderLibrary/Structs.hlsl) ## [3.2.6] - 2023-07-03 diff --git a/Editor/Graph.meta b/Editor/Graph.meta deleted file mode 100644 index 3fb821c..0000000 --- a/Editor/Graph.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: f795eaf22be992d4582305f22730a2b9 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/Importer/LitImporter.cs b/Editor/Importer/LitImporter.cs index 4f0805e..33402c2 100644 --- a/Editor/Importer/LitImporter.cs +++ b/Editor/Importer/LitImporter.cs @@ -12,7 +12,7 @@ namespace z3y.Shaders { - [ScriptedImporter(4, Ext, 0)] + [ScriptedImporter(5, Ext, 0)] public class LitImporter : ScriptedImporter { public const string Ext = "litshader"; @@ -492,8 +492,8 @@ private string GetShaderLabCode(AssetImportContext ctx) sb.AppendLine("Pass"); // Meta sb.AppendLine("{"); { - sb.AppendLine("Name \"META_BAKERY\""); - //sb.AppendLine("Name \"META_BAKERY\""); + // sb.AppendLine("Name \"META_BAKERY\""); + sb.AppendLine("Name \"META\""); sb.AppendLine("Tags { \"LightMode\" = \"Meta\"}"); sb.AppendLine("Cull Off"); diff --git a/Editor/Importer/LitImporterDefaultProperties.cs b/Editor/Importer/LitImporterDefaultProperties.cs index 7cac6a1..6c90aea 100644 --- a/Editor/Importer/LitImporterDefaultProperties.cs +++ b/Editor/Importer/LitImporterDefaultProperties.cs @@ -10,7 +10,6 @@ public static class LitImporterConstants [Enum(Off, 0, On, 1)] _ZWrite(""ZWrite"", Float) = 1 [Enum(Off, 0, On, 1)] _AlphaToMask(""AlphaToMask"", Float) = 0 [Enum(UnityEngine.Rendering.CullMode)] _Cull(""Cull"", Float) = 2 -[HideInInspector] BAKERY_META_ALPHA_ENABLE(""Enable Bakery alpha meta pass"", Float) = 1 "; public const string DefaultPropertiesIncludeAfter = @" @@ -18,6 +17,7 @@ [ToggleUI] _BakeryAlphaDither(""Bakery Alpha Dither"", Float) = 0 [ToggleOff(_GLOSSYREFLECTIONS_OFF)] _GlossyReflections(""Reflections"", Float) = 1 [ToggleOff(_SPECULARHIGHLIGHTS_OFF)] _SpecularHighlights(""Specular Highlights"", Float) = 1 [HideInInspector] [NonModifiableTextureData] [NoScaleOffset] _DFG(""DFG"", 2D) = ""white"" {} +[HideInInspector] [NonModifiableTextureData] [NoScaleOffset] BlueNoise(""BlueNoise"", 2D) = ""white"" {} "; public const string AreaLitProperties = @" diff --git a/README.md b/README.md index 26b7965..c9c3bd6 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,6 @@ https://github.com/z3y/shaders.git |Emission GI Multiplier| Adjusts emission intensity used for baking lightmaps in the Meta pass | |Transparency Modes | Cutout, Fade, Premultiply, Additive, Multiply| |Non-Important lights per pixel| Cheaper real-time lights done in one pass. Does not work with lightmapped object | -|Bakery Alpha Meta| Surface inputs used in the shader are properly passed to the meta pass for baking instead of just reading the main texture and main color| |Bakery Alpha Dither|Semi-Transparent baked shadows. Available only in Bakery L1 mode| |Baked Area Light Specular Approximation| Reduced smoothness in areas where there is less directionality for more accurate lightmapped specular| |Centroid Lightmap UVs|Fix for lightmap bleeding with very tight packing| diff --git a/ShaderLibrary/ForwardLighting.hlsl b/ShaderLibrary/ForwardLighting.hlsl index 09f9a71..bf7abdf 100644 --- a/ShaderLibrary/ForwardLighting.hlsl +++ b/ShaderLibrary/ForwardLighting.hlsl @@ -188,14 +188,6 @@ namespace CustomLighting #if defined(LIGHTMAP_ON) float2 lightmapUV = unpacked.lightmapUV.xy; - #if defined(HANDLE_SHADOWS_BLENDING_IN_GI) - half bakedAtten = UnitySampleBakedOcclusion(lightmapUV.xy, unpacked.positionWS); - float zDist = dot(_WorldSpaceCameraPos - unpacked.positionWS, UNITY_MATRIX_V[2].xyz); - float fadeDist = UnityComputeShadowFadeDistance(unpacked.positionWS, zDist); - half atten = UnityMixRealtimeAndBakedShadows(light.attenuation, bakedAtten, UnityComputeShadowFade(fadeDist)); - #endif - - #if defined(BICUBIC_LIGHTMAP) float4 lightmapTexelSize = BicubicSampling::GetTexelSize(unity_Lightmap); half4 bakedColorTex = BicubicSampling::SampleBicubic(unity_Lightmap, custom_bilinear_clamp_sampler, lightmapUV, lightmapTexelSize); @@ -231,8 +223,8 @@ namespace CustomLighting #endif #if defined(LIGHTMAP_SHADOW_MIXING) && !defined(SHADOWS_SHADOWMASK) && defined(SHADOWS_SCREEN) + lightMap = SubtractMainLightWithRealtimeAttenuationFromLightmap(lightMap, light.attenuation, float4(0,0,0,0), sd.normalWS); light = (CustomLightData)0; - lightMap = SubtractMainLightWithRealtimeAttenuationFromLightmap(lightMap, atten, float4(0,0,0,0), sd.normalWS); #endif indirectDiffuse = lightMap; diff --git a/ShaderLibrary/FragmentMeta.hlsl b/ShaderLibrary/FragmentMeta.hlsl index 561e74a..acdacbe 100644 --- a/ShaderLibrary/FragmentMeta.hlsl +++ b/ShaderLibrary/FragmentMeta.hlsl @@ -80,31 +80,32 @@ half3 UnityLightmappingAlbedo (half3 diffuse, half3 specular, half smoothness) // o.Albedo = UnityLightmappingAlbedo(diffuseColor, specColor, surfaceDescription.Smoothness); o.Albedo = surfaceDescription.Albedo; #endif - o.SpecularColor = specColor; - o.Emission = surfaceDescription.Emission; + + o.SpecularColor = specColor; + o.Emission = surfaceDescription.Emission; #ifndef EDITOR_VISUALIZATION - #if defined(_ALPHATEST_ON) - clip(surfaceDescription.Alpha - surfaceDescription.AlphaClipThreshold); - #endif - - #if !defined(_ALPHAFADE_ON) && !defined(_ALPHATEST_ON) && !defined(_ALPHAPREMULTIPLY_ON) && !defined(_ALPHAMODULATE_ON) - surfaceDescription.Alpha = 1.0f; - #endif + #if defined(_ALPHATEST_ON) + clip(surfaceDescription.Alpha - surfaceDescription.AlphaClipThreshold); + #endif - // bakery alpha - if (unity_MetaFragmentControl.w != 0) - { - #ifdef _ALPHAPREMULTIPLY_ON - if (_BakeryAlphaDither > 0.5) - { - half dither = Unity_Dither(surfaceDescription.Alpha, unpacked.positionCS.xy); - return dither < 0.0 ? 0 : 1; - } + #if !defined(_ALPHAFADE_ON) && !defined(_ALPHATEST_ON) && !defined(_ALPHAPREMULTIPLY_ON) && !defined(_ALPHAMODULATE_ON) + surfaceDescription.Alpha = 1.0f; #endif - return surfaceDescription.Alpha; - } + + // bakery alpha + // if (unity_MetaFragmentControl.w != 0) + // { + // #ifdef _ALPHAPREMULTIPLY_ON + // if (_BakeryAlphaDither > 0.5) + // { + // half dither = Unity_Dither(surfaceDescription.Alpha, unpacked.positionCS.xy); + // return dither < 0.0 ? 0 : 1; + // } + // #endif + // return surfaceDescription.Alpha; + // } #endif return UnityMetaFragment(o); diff --git a/ShaderLibrary/ShaderPass.hlsl b/ShaderLibrary/ShaderPass.hlsl index dd0a6b2..8339551 100644 --- a/ShaderLibrary/ShaderPass.hlsl +++ b/ShaderLibrary/ShaderPass.hlsl @@ -160,7 +160,6 @@ bool IsInMirror() #include "Packages/com.z3y.shaders/ShaderLibrary/CoreRP/CommonMaterial.hlsl" #endif - #ifdef PIPELINE_BUILTIN #ifdef FORCE_SPECCUBE_BOX_PROJECTION @@ -171,6 +170,15 @@ bool IsInMirror() #undef GLOBAL_CBUFFER_START // dont need reg #define GLOBAL_CBUFFER_START(name) CBUFFER_START(name) + + #undef SAMPLE_DEPTH_TEXTURE + #undef SAMPLE_DEPTH_TEXTURE_LOD + #undef UNITY_MATRIX_P + #undef UNITY_MATRIX_MVP + #undef UNITY_MATRIX_MV + #undef UNITY_MATRIX_T_MV + #undef UNITY_MATRIX_IT_MV + #include "UnityShaderVariables.cginc" half4 _LightColor0; half4 _SpecColor; diff --git a/ShaderLibrary/Shaders.meta b/ShaderLibrary/Shaders.meta deleted file mode 100644 index ddbc18b..0000000 --- a/ShaderLibrary/Shaders.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 27afb16f5c536244daf71ab1dba51272 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ShaderLibrary/Structs.hlsl b/ShaderLibrary/Structs.hlsl index 387d30d..d55f484 100644 --- a/ShaderLibrary/Structs.hlsl +++ b/ShaderLibrary/Structs.hlsl @@ -17,7 +17,14 @@ CustomLightData GetCustomMainLightData(Varyings unpacked) #endif UNITY_LIGHT_ATTENUATION(lightAttenuation, legacyVaryings, unpacked.positionWS.xyz); -#if defined(UNITY_PASS_FORWARDBASE) && !defined(SHADOWS_SCREEN) + #if defined(HANDLE_SHADOWS_BLENDING_IN_GI) && defined(SHADOWS_SCREEN) && defined(LIGHTMAP_ON) + half bakedAtten = UnitySampleBakedOcclusion(unpacked.lightmapUV, unpacked.positionWS); + float zDist = dot(_WorldSpaceCameraPos - unpacked.positionWS, UNITY_MATRIX_V[2].xyz); + float fadeDist = UnityComputeShadowFadeDistance(unpacked.positionWS, zDist); + lightAttenuation = UnityMixRealtimeAndBakedShadows(lightAttenuation, bakedAtten, UnityComputeShadowFade(fadeDist)); + #endif + +#if defined(UNITY_PASS_FORWARDBASE) && !defined(SHADOWS_SCREEN) && !defined(SHADOWS_SHADOWMASK) lightAttenuation = 1.0; #endif data.attenuation = lightAttenuation; diff --git a/Shaders/Default.litshader b/Shaders/Default.litshader index ca52f05..a829093 100644 --- a/Shaders/Default.litshader +++ b/Shaders/Default.litshader @@ -36,7 +36,9 @@ DEFINES_START // #define DISABLE_LIGHT_PROBE_PROXY_VOLUME // avoid unnecessary calculations and reduce the compiled size if LPPV arent used #define APPROXIMATE_AREALIGHT_SPECULAR // lower the smoothness in areas where theres less directionality in directional lightmaps // #undef UNITY_SPECCUBE_BLENDING // disable blending of 2 reflection probes - #define UNITY_SPECCUBE_BOX_PROJECTION // force enable box projection on quest + #ifndef UNITY_SPECCUBE_BOX_PROJECTION + #define UNITY_SPECCUBE_BOX_PROJECTION // force enable box projection on quest + #endif // #define NONLINEAR_LIGHTPROBESH // used with L1 bakery probes, not recommended for VRChat #pragma shader_feature_local _MASKMAP diff --git a/Shaders/Layered.litshader b/Shaders/Layered.litshader index cde529e..56ac2d2 100644 --- a/Shaders/Layered.litshader +++ b/Shaders/Layered.litshader @@ -7,7 +7,7 @@ [TexturePacking(AO, Normal Y, Roughness, Normal X, true)] [Tooltip(AO (R), Normal Y (G),Roughness (B), Normal X (A))] [Linear] [NoScaleOffset] [ExtraProperty] [Toggle(_PACKEDTEXTURE)] _PackedTexture ("Packed Texture", 2D) = "linearGray" {} - BumpScale ("Normal Scale", Float) = 1 + _BumpScale ("Normal Scale", Float) = 1 [Indent]_Metallic ("Metallic", Range(0,1)) = 0 _Roughness ("Roughness", Range(0,1)) = 0.5 [UnIndent]_OcclusionStrength1 ("Occlusion", Range(0,1)) = 0 diff --git a/Shaders/Lit.litshader b/Shaders/Lit.litshader index f44f875..4c085c8 100644 --- a/Shaders/Lit.litshader +++ b/Shaders/Lit.litshader @@ -95,7 +95,9 @@ DEFINES_START // Keywords, Defines // #pragma multi_compile _ LOD_FADE_CROSSFADE // disabled by defualt, too many variants // #define _SSR // Screen-Space Reflections, expensive, requires Grab Pass enabled // #undef UNITY_SPECCUBE_BLENDING // disable blending of 2 reflection probes - #define UNITY_SPECCUBE_BOX_PROJECTION // force enable box projection on quest + #ifndef UNITY_SPECCUBE_BOX_PROJECTION + #define UNITY_SPECCUBE_BOX_PROJECTION // force enable box projection on quest + #endif // #define NONLINEAR_LIGHTPROBESH // used with L1 bakery probes, not recommended for VRChat #pragma shader_feature_local _MASKMAP diff --git a/Shaders/Lit/Lit/Vertex.hlsl b/Shaders/Lit/Lit/Vertex.hlsl index 1809b82..8e262ec 100644 --- a/Shaders/Lit/Lit/Vertex.hlsl +++ b/Shaders/Lit/Lit/Vertex.hlsl @@ -81,11 +81,11 @@ v2f vert (appdata_all v) #endif #ifdef UNITY_PASS_SHADOWCASTER - o.pos = UnityClipSpaceShadowCasterPos(v.vertex, v.normal); - o.pos = UnityApplyLinearShadowBias(o.pos); + //o.pos = UnityClipSpaceShadowCasterPos(v.vertex, v.normal); + //o.pos = UnityApplyLinearShadowBias(o.pos); TRANSFER_SHADOW_CASTER_NOPOS(o, o.pos); #else - UNITY_TRANSFER_SHADOW(o, o.uv01.zw); + UNITY_TRANSFER_SHADOW(o, v.uv1); UNITY_TRANSFER_FOG(o, o.pos); #endif diff --git a/Shaders/Lit/ShaderLibrary/Common.hlsl b/Shaders/Lit/ShaderLibrary/Common.hlsl index 665bd56..52836a3 100644 --- a/Shaders/Lit/ShaderLibrary/Common.hlsl +++ b/Shaders/Lit/ShaderLibrary/Common.hlsl @@ -457,7 +457,15 @@ void InitializeMainLightData(inout LightData lightData, float3 normalWS, float3 lightData.NoH = saturate(dot(normalWS, lightData.HalfVector)); UNITY_LIGHT_ATTENUATION(lightAttenuation, input, input.worldPos.xyz); - #if defined(UNITY_PASS_FORWARDBASE) && !defined(SHADOWS_SCREEN) + + #if defined(HANDLE_SHADOWS_BLENDING_IN_GI) && defined(SHADOWS_SCREEN) && defined(LIGHTMAP_ON) + half bakedAtten = UnitySampleBakedOcclusion(input.uv01.zw * unity_LightmapST.xy + unity_LightmapST.zw, input.worldPos.xyz); + float zDist = dot(_WorldSpaceCameraPos - input.worldPos.xyz, UNITY_MATRIX_V[2].xyz); + float fadeDist = UnityComputeShadowFadeDistance(input.worldPos.xyz, zDist); + lightAttenuation = UnityMixRealtimeAndBakedShadows(lightAttenuation, bakedAtten, UnityComputeShadowFade(fadeDist)); + #endif + + #if defined(UNITY_PASS_FORWARDBASE) && !defined(SHADOWS_SCREEN) && !defined(SHADOWS_SHADOWMASK) lightAttenuation = 1.0; #endif lightData.Attenuation = lightAttenuation; @@ -469,10 +477,6 @@ void InitializeMainLightData(inout LightData lightData, float3 normalWS, float3 lightData.FinalColor *= Fd_Burley(perceptualRoughness, NoV, lightData.NoL, lightData.LoH); #endif - #if defined(LIGHTMAP_SHADOW_MIXING) && defined(SHADOWS_SHADOWMASK) && defined(SHADOWS_SCREEN) && defined(LIGHTMAP_ON) - lightData.FinalColor *= UnityComputeForwardShadows(input.uv01.zw * unity_LightmapST.xy + unity_LightmapST.zw, input.worldPos, input._ShadowCoord); - #endif - #ifdef _ANISOTROPY lightData.Specular = LightSpecularAnisotropic(lightData, NoV, perceptualRoughness, f0, input.tangent, input.bitangent, viewDir, surf); #else diff --git a/package.json b/package.json index 4bb1320..f27461b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.z3y.shaders", "description": "A Standard Shader and Surface Shaders replacement for Unity for Built-In pipeline and forward rendering (VRChat)", - "version": "3.2.7", + "version": "3.2.9", "unity": "2019.4", "displayName": "z3y - Shaders", "hideInEditor": false,