Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 76ebf99
Author: z3y <[email protected]>
Date:   Mon Sep 18 19:29:21 2023 +0200

    removed bakery alpha meta pass

commit d120dc3
Author: z3y <[email protected]>
Date:   Thu Sep 7 15:26:46 2023 +0200

    layered shader fixed bump scale wrong property name

commit 9fc3d49
Author: z3y <[email protected]>
Date:   Mon Sep 4 14:34:41 2023 +0200

    Delete Shaders.meta

commit b5b1f71
Author: z3y <[email protected]>
Date:   Mon Sep 4 14:29:49 2023 +0200

    fixed shadowmask, subtractive, directional shadow fade issues

commit 0e3dbda
Author: z3y <[email protected]>
Date:   Sun Sep 3 20:00:41 2023 +0200

    shadowmask bug fix at a distance

commit 1989b19
Author: z3y <[email protected]>
Date:   Sun Sep 3 19:41:25 2023 +0200

    prevent some macro redefinition warnings

commit a5db54d
Author: z3y <[email protected]>
Date:   Thu Aug 31 18:57:45 2023 +0200

    Update CHANGELOG.md

commit 421b775
Author: z3y <[email protected]>
Date:   Sat Aug 26 19:12:47 2023 +0200

    custom attribute drawer

commit 4b8c5a1
Author: z3y <[email protected]>
Date:   Sat Jul 22 00:37:31 2023 +0200

    Update LitImporter.cs

commit d614982
Author: z3y <[email protected]>
Date:   Sat Jul 22 00:31:01 2023 +0200

    refactor importer code
  • Loading branch information
z3y committed Sep 18, 2023
1 parent 15ae487 commit 8487052
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 65 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 0 additions & 8 deletions Editor/Graph.meta

This file was deleted.

6 changes: 3 additions & 3 deletions Editor/Importer/LitImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace z3y.Shaders
{
[ScriptedImporter(4, Ext, 0)]
[ScriptedImporter(5, Ext, 0)]
public class LitImporter : ScriptedImporter
{
public const string Ext = "litshader";
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion Editor/Importer/LitImporterDefaultProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ 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 = @"
[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 = @"
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
10 changes: 1 addition & 9 deletions ShaderLibrary/ForwardLighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
41 changes: 21 additions & 20 deletions ShaderLibrary/FragmentMeta.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion ShaderLibrary/ShaderPass.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ bool IsInMirror()
#include "Packages/com.z3y.shaders/ShaderLibrary/CoreRP/CommonMaterial.hlsl"
#endif


#ifdef PIPELINE_BUILTIN

#ifdef FORCE_SPECCUBE_BOX_PROJECTION
Expand All @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions ShaderLibrary/Shaders.meta

This file was deleted.

9 changes: 8 additions & 1 deletion ShaderLibrary/Structs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion Shaders/Default.litshader
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Shaders/Layered.litshader
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Shaders/Lit.litshader
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Shaders/Lit/Lit/Vertex.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 9 additions & 5 deletions Shaders/Lit/ShaderLibrary/Common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 8487052

Please sign in to comment.