Skip to content

Commit

Permalink
Merge pull request #1 from momoma-null/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
momoma-null authored Jan 24, 2025
2 parents 1220404 + 1e60d78 commit f3879da
Show file tree
Hide file tree
Showing 18 changed files with 142 additions and 33 deletions.
45 changes: 37 additions & 8 deletions Editor/BlendModeDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ sealed class BlendModeDrawer : MaterialPropertyDrawer
new GUIContent("Opaque"),
new GUIContent("Cutout"),
new GUIContent("Fade"),
new GUIContent("Transparent") };
new GUIContent("Transparent"),
new GUIContent("Additive"),
new GUIContent("Multiply") };

public override void Apply(MaterialProperty prop)
{
foreach (Material mat in prop.targets)
{
SetupBlendMode(mat, mat.GetInt(prop.name));
SetupBlendMode(mat, mat.GetInt(prop.name), false);
}
}

Expand All @@ -30,14 +32,15 @@ public override void OnGUI(Rect position, MaterialProperty prop, GUIContent labe
prop.floatValue = newValue;
foreach (Material material in prop.targets)
{
SetupBlendMode(material, newValue);
SetupBlendMode(material, newValue, true);
}
}
MaterialEditor.EndProperty();
}

static void SetupBlendMode(Material material, int blendMode)
static void SetupBlendMode(Material material, int blendMode, bool overrideRenderQueue)
{
var renderQueue = -1;
switch (blendMode)
{
case 0:
Expand All @@ -52,7 +55,7 @@ static void SetupBlendMode(Material material, int blendMode)
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = -1;
renderQueue = -1;
break;
case 1:
material.SetOverrideTag("RenderType", "TransparentCutout");
Expand All @@ -63,7 +66,7 @@ static void SetupBlendMode(Material material, int blendMode)
material.EnableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
break;
case 2:
material.SetOverrideTag("RenderType", "Transparent");
Expand All @@ -74,7 +77,7 @@ static void SetupBlendMode(Material material, int blendMode)
material.DisableKeyword("_ALPHATEST_ON");
material.EnableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
break;
case 3:
material.SetOverrideTag("RenderType", "Transparent");
Expand All @@ -85,8 +88,34 @@ static void SetupBlendMode(Material material, int blendMode)
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
break;
case 4:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_ZWrite", 0);
material.SetInt("_AlphaToMask", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.EnableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
break;
case 5:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 0);
material.SetInt("_AlphaToMask", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
break;
}
if (overrideRenderQueue)
{
material.renderQueue = renderQueue;
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions Editor/DecalDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

using UnityEditor;
using UnityEngine;

namespace MomomaAssets.GeneLit
{
sealed class DecalDrawer : MaterialPropertyDrawer
{
readonly GUIContent[] options = new[] { new GUIContent("None"), new GUIContent("Decal") };
readonly int[] optionValues = new[] { 0, -1 };

public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor)
{
MaterialEditor.BeginProperty(position, prop);
using (var change = new EditorGUI.ChangeCheckScope())
{
var newValue = EditorGUI.IntPopup(position, label, (int)prop.floatValue, options, optionValues);
if (change.changed)
{
prop.floatValue = newValue;
}
}
MaterialEditor.EndProperty();
}
}
}
11 changes: 11 additions & 0 deletions Editor/DecalDrawer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Editor/MomomaAssets.GeneLit.asmdef
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "MomomaAssets.GeneLit",
"rootNamespace": "MomomaAssets.GeneLit",
"references": [],
"includePlatforms": [
"Editor"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ More beautiful and accurate rendering than Unity Standard shaders.
- Alpha to coverage
- Transparent
- Fade
- Additive
- Multiply
- Culling Mode
- Decal Mode
- Detail Map
- Choice of UV0~UV3
- Vertex Color
Expand Down Expand Up @@ -77,6 +80,7 @@ More beautiful and accurate rendering than Unity Standard shaders.
- Skybox Fog
- Using vertex light as pixel light
- Specular AO
- Support for LTCGI

# Map Channel
Basically same as [Unity HDRP mapping](https://docs.unity3d.com/Packages/[email protected]/manual/Mask-Map-and-Detail-Map.html)
Expand Down
7 changes: 6 additions & 1 deletion Shaders/Include/GeneLit_Core.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
#ifdef LIGHTMAP_ON
ambientOrLightmapUV.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
#elif UNITY_SHOULD_SAMPLE_SH
#if defined (VERTEXLIGHT_ON) && !defined(VERTEX_LIGHT_AS_PIXEL_LIGHT)
#if defined(VERTEXLIGHT_ON) && !defined(VERTEX_LIGHT_AS_PIXEL_LIGHT)
float range = GENELIT_ACCESS_PROP(_VertexLightRangeMultiplier);
float4 atten = unity_4LightAtten0 / (range * range);
ambientOrLightmapUV.rgb = Shade4PointLights(
unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
atten, posWorld, normalWorld);
#elif defined(VERTEXLIGHT_ON)
ambientOrLightmapUV.a = 1;
#endif

ambientOrLightmapUV.rgb = ShadeSHPerVertex(normalWorld, ambientOrLightmapUV.rgb);
Expand Down Expand Up @@ -92,15 +94,18 @@
#if defined(LIGHTMAP_ON)
half4 bakedColorTex = UNITY_SAMPLE_TEX2D(unity_Lightmap, IN.ambientOrLightmapUV.xy);
shadingData.ambient = DecodeLightmap(bakedColorTex);
shadingData.vertexLightOn = 0;
shadingData.lightmapUV = IN.ambientOrLightmapUV;
#if defined(DIRLIGHTMAP_COMBINED)
shadingData.bakedDir = UNITY_SAMPLE_TEX2D_SAMPLER(unity_LightmapInd, unity_Lightmap, IN.ambientOrLightmapUV.xy);
#endif
#elif defined(DYNAMICLIGHTMAP_ON)
shadingData.ambient = 0;
shadingData.vertexLightOn = 0;
shadingData.lightmapUV = IN.ambientOrLightmapUV;
#else
shadingData.ambient = IN.ambientOrLightmapUV.rgb;
shadingData.vertexLightOn = IN.ambientOrLightmapUV.a;
shadingData.lightmapUV = 0;
#endif

Expand Down
1 change: 1 addition & 0 deletions Shaders/Include/GeneLit_LightingCommon.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
float2 normalizedViewportCoord;
float atten;
half3 ambient;
bool vertexLightOn;
half4 lightmapUV;
UVCoord uv;

Expand Down
7 changes: 7 additions & 0 deletions Shaders/Include/GeneLit_LightingIndirect.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include "GeneLit_Brdf.cginc"
#include "GeneLit_AmbientOcclusion.cginc"

#if defined(LTCGI)
#include "Packages/at.pimaker.ltcgi/Shaders/LTCGI.cginc"
#endif

//------------------------------------------------------------------------------
// Image based lighting configuration
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -449,6 +453,9 @@

GENELIT_EVALUATE_CUSTOM_INDIRECT(pixel, shadingData, irradiance, Fd, Fr)

#if defined(LTCGI)
LTCGI_Contribution(shadingData.position, shadingData.normal, shadingData.view, pixel.roughness, shadingData.lightmapUV.xy, Fd, Fr);
#endif
// extra ambient occlusion term for the base and subsurface layers
multiBounceAO(diffuseAO, pixel.diffuseColor, Fd);
multiBounceSpecularAO(specAO, pixel.f0, Fr);
Expand Down
20 changes: 12 additions & 8 deletions Shaders/Include/GeneLit_Shading.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,18 @@
color.rgb += surfaceShading(pixel, light, shadingData, visibility);

#if defined(UNITY_PASS_FORWARDBASE) && defined(VERTEX_LIGHT_AS_PIXEL_LIGHT) && !defined(LIGHTMAP_ON) && !defined(DYNAMICLIGHTMAP_ON)
FilamentLight lights[4];
float4 lightAttenSq = unity_4LightAtten0 / (material.vertexLightRangeMultiplier * material.vertexLightRangeMultiplier);
getVertexPunctualLights(shadingData, lightAttenSq, lights);
visibility = 1.0;
color.rgb += surfaceShading(pixel, lights[0], shadingData, visibility);
color.rgb += surfaceShading(pixel, lights[1], shadingData, visibility);
color.rgb += surfaceShading(pixel, lights[2], shadingData, visibility);
color.rgb += surfaceShading(pixel, lights[3], shadingData, visibility);
UNITY_BRANCH
if (shadingData.vertexLightOn)
{
FilamentLight lights[4];
float4 lightAttenSq = unity_4LightAtten0 / (material.vertexLightRangeMultiplier * material.vertexLightRangeMultiplier);
getVertexPunctualLights(shadingData, lightAttenSq, lights);
visibility = 1.0;
color.rgb += surfaceShading(pixel, lights[0], shadingData, visibility);
color.rgb += surfaceShading(pixel, lights[1], shadingData, visibility);
color.rgb += surfaceShading(pixel, lights[2], shadingData, visibility);
color.rgb += surfaceShading(pixel, lights[3], shadingData, visibility);
}
#endif

return float4(color, computeDiffuseAlpha(material));
Expand Down
2 changes: 1 addition & 1 deletion Shaders/Include/GeneLit_Utils.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define saturateMediump(x) x
#endif

#define atan2(x, y) atan(y, x)
// #define atan2(x, y) atan(y, x)

//------------------------------------------------------------------------------
// Scalar operations
Expand Down
10 changes: 7 additions & 3 deletions Shaders/MS_GeneLit.shader
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[BlendMode] _Mode ("Blend Mode", Float) = 0.0
[Enum(UnityEngine.Rendering.CullMode)] _CullMode ("Cull Mode", Float) = 2.0
[IfDef(_ALPHATEST_ON)] _Cutoff ("Alpha Cutoff", Range(0,1)) = 0.5
[Decal] _Offset ("Decal Mode", Float) = 0

[ShurikenHeader(Surface Inputs)]
[KeywordEnum(Normal_Tile, No_Tile, TriPlanar)] _TileMode ("Tile Mode", Float) = 0
Expand Down Expand Up @@ -67,6 +68,7 @@
[Toggle(VERTEX_LIGHT_AS_PIXEL_LIGHT)] _VertexLightAsPixelLight ("Use Vertex Light As Pixel Light", float) = 0.0
_VertexLightRangeMultiplier ("Vertex Light Range Multiplier", Range(0.01, 25)) = 1.0
_SpecularAO ("Specular AO", Range(0, 1)) = 0.8
[Toggle(LTCGI)] _LTCGI("LTCGI", Int) = 0

[HideInInspector][NonModifiableTextureData] _DFG ("_DFG", 2D) = "black" {}

Expand All @@ -80,6 +82,7 @@
Tags { "RenderType"="Opaque" }

AlphaToMask [_AlphaToMask]
Offset [_Offset], [_Offset]

CGINCLUDE
#define FILAMENT_QUALITY FILAMENT_QUALITY_HIGH
Expand All @@ -92,7 +95,7 @@
Pass
{
Name "FORWARD"
Tags { "LightMode"="ForwardBase" }
Tags { "LightMode"="ForwardBase" "LTCGI" = "_LTCGI" }

Cull [_CullMode]
Blend [_SrcBlend] [_DstBlend]
Expand All @@ -113,12 +116,13 @@
#pragma shader_feature_local _MASKMAP
#pragma shader_feature_local _NORMALMAP
#pragma shader_feature_local _BENTNORMALMAP
#pragma shader_feature_local _PARALLAX_OCCLUSION _PARALLAXMAP
#pragma shader_feature_local _ _PARALLAX_OCCLUSION _PARALLAXMAP
#pragma shader_feature_local _DETAIL_MAP
#pragma shader_feature_local CAPSULE_AO
#pragma shader_feature_local REFRACTION_TYPE_NONE REFRACTION_TYPE_SOLID REFRACTION_TYPE_THIN
#pragma shader_feature_local REFLECTION_SPACE_CUBE REFLECTION_SPACE_CYLINDER REFLECTION_SPACE_ADDITIONAL_BOX
#pragma shader_feature_local VERTEX_LIGHT_AS_PIXEL_LIGHT
#pragma shader_feature_local_fragment LTCGI

#include "Include/GeneLit_Core.cginc"
ENDCG
Expand Down Expand Up @@ -147,7 +151,7 @@
#pragma shader_feature_local _SHEEN
#pragma shader_feature_local _MASKMAP
#pragma shader_feature_local _NORMALMAP
#pragma shader_feature_local _PARALLAXMAP
#pragma shader_feature_local _ _PARALLAX_OCCLUSION _PARALLAXMAP
#pragma shader_feature_local _DETAIL_MAP
#pragma shader_feature_local REFRACTION_TYPE_NONE REFRACTION_TYPE_SOLID REFRACTION_TYPE_THIN

Expand Down
10 changes: 7 additions & 3 deletions Shaders/MS_GeneLit_Cloth.shader
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[BlendMode] _Mode ("Blend Mode", Float) = 0.0
[Enum(UnityEngine.Rendering.CullMode)] _CullMode ("Cull Mode", Float) = 2.0
[IfDef(_ALPHATEST_ON)] _Cutoff ("Alpha Cutoff", Range(0,1)) = 0.5
[Decal] _Offset ("Decal Mode", Float) = 0

[ShurikenHeader(Surface Inputs)]
[KeywordEnum(Normal_Tile, No_Tile, TriPlanar)] _TileMode ("Tile Mode", Float) = 0
Expand Down Expand Up @@ -60,6 +61,7 @@
[Toggle(VERTEX_LIGHT_AS_PIXEL_LIGHT)] _VertexLightAsPixelLight ("Use Vertex Light As Pixel Light", float) = 0.0
_VertexLightRangeMultiplier ("Vertex Light Range Multiplier", Range(0.01, 25)) = 1.0
_SpecularAO ("Specular AO", Range(0, 1)) = 0.8
[Toggle(LTCGI)] _LTCGI("LTCGI", Int) = 0

[HideInInspector][NonModifiableTextureData] _DFG ("_DFG", 2D) = "black" {}

Expand All @@ -73,6 +75,7 @@
Tags { "RenderType"="Opaque" }

AlphaToMask [_AlphaToMask]
Offset [_Offset], [_Offset]

CGINCLUDE
#define FILAMENT_QUALITY FILAMENT_QUALITY_HIGH
Expand All @@ -85,7 +88,7 @@
Pass
{
Name "FORWARD"
Tags { "LightMode"="ForwardBase" }
Tags { "LightMode"="ForwardBase" "LTCGI" = "_LTCGI" }

Cull [_CullMode]
Blend [_SrcBlend] [_DstBlend]
Expand All @@ -105,12 +108,13 @@
#pragma shader_feature_local _MASKMAP
#pragma shader_feature_local _NORMALMAP
#pragma shader_feature_local _BENTNORMALMAP
#pragma shader_feature_local _PARALLAX_OCCLUSION _PARALLAXMAP
#pragma shader_feature_local _ _PARALLAX_OCCLUSION _PARALLAXMAP
#pragma shader_feature_local _DETAIL_MAP
#pragma shader_feature_local CUSTOM_SHEEN
#pragma shader_feature_local CAPSULE_AO
#pragma shader_feature_local REFLECTION_SPACE_CUBE REFLECTION_SPACE_CYLINDER REFLECTION_SPACE_ADDITIONAL_BOX
#pragma shader_feature_local VERTEX_LIGHT_AS_PIXEL_LIGHT
#pragma shader_feature_local_fragment LTCGI

#include "Include/GeneLit_Core.cginc"
ENDCG
Expand All @@ -136,7 +140,7 @@
#pragma shader_feature_local _TILEMODE_NORMAL_TILE _TILEMODE_NO_TILE _TILEMODE_TRIPLANAR
#pragma shader_feature_local _MASKMAP
#pragma shader_feature_local _NORMALMAP
#pragma shader_feature_local _PARALLAXMAP
#pragma shader_feature_local _ _PARALLAX_OCCLUSION _PARALLAXMAP
#pragma shader_feature_local _DETAIL_MAP

#include "Include/GeneLit_Core.cginc"
Expand Down
Loading

0 comments on commit f3879da

Please sign in to comment.