Skip to content

Commit a88ec6b

Browse files
committed
Minimum Brightness support.
1 parent ab5f9cd commit a88ec6b

File tree

7 files changed

+46
-3
lines changed

7 files changed

+46
-3
lines changed

CGIncludes/PlusStuff.cginc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ float _VRC_Visible_Mirror_Camera;
1717
float _VRC_Visible_Mirror_VRCLens;
1818
float _VRC_Visible_Mirror_Screenshot;
1919

20+
float _LightingMinLightBrightness;
21+
2022

2123
void check_visibility()
2224
{

CGIncludes/UnityStandardCore Plus.cginc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,12 @@ half4 fragForwardBaseInternal (VertexOutputForwardBase i)
466466
UnityGI gi = FragmentGI (s, occlusion, i.ambientOrLightmapUV, atten, mainLight);
467467

468468
half4 c = UNITY_BRDF_PBS (s.diffColor, s.specColor, s.oneMinusReflectivity, s.smoothness, s.normalWorld, -s.eyeVec, gi.light, gi.indirect);
469+
470+
#ifndef _ALPHAPREMULTIPLY_ON
471+
// Plus - Minimum Brightness
472+
c.rgb = max(c.rgb / s.diffColor, _LightingMinLightBrightness) * s.diffColor;
473+
#endif
474+
469475
c.rgb += Emission(i.tex.xy);
470476

471477
#ifdef _SPECULARS_ON
@@ -702,6 +708,11 @@ void fragDeferred (
702708

703709
half3 emissiveColor = UNITY_BRDF_PBS (s.diffColor, s.specColor, s.oneMinusReflectivity, s.smoothness, s.normalWorld, -s.eyeVec, gi.light, gi.indirect).rgb;
704710

711+
#ifndef _ALPHAPREMULTIPLY_ON
712+
// Plus - Minimum Brightness
713+
emissiveColor.rgb = max(emissiveColor.rgb / s.diffColor, _LightingMinLightBrightness) * s.diffColor;
714+
#endif
715+
705716
#ifdef _EMISSION
706717
emissiveColor += Emission (i.tex.xy);
707718
#endif

CGIncludes/UnityStandardCoreForwardSimple Plus.cginc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ half4 fragForwardBaseSimpleInternal (VertexOutputBaseSimple i)
228228

229229
half3 c = BRDF3_Indirect(s.diffColor, s.specColor, gi.indirect, PerVertexGrazingTerm(i, s), PerVertexFresnelTerm(i));
230230
c += BRDF3DirectSimple(s.diffColor, s.specColor, s.smoothness, rl) * attenuatedLightColor;
231+
232+
#ifndef _ALPHAPREMULTIPLY_ON
233+
// Plus - Minimum Brightness
234+
c.rgb = max(c.rgb / s.diffColor, _LightingMinLightBrightness) * s.diffColor;
235+
#endif
236+
231237
c += Emission(i.tex.xy);
232238

233239
#ifdef _SPECULARS_ON

DefaultResourcesExtra/Standard Plus.shader

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ Shader "ShingenPizza/Standard Plus"
5252
[ToggleOff] _VRC_Visible_Mirror_VRCLens("Visible In Mirrors To VRCLens", Float) = 1.0
5353
[ToggleOff] _VRC_Visible_Mirror_Screenshot("Visible In Mirrors On Screenshots", Float) = 1.0
5454

55+
// Plus - Minimum Brightness
56+
_LightingMinLightBrightness("Minimum Brightness", Range(0.0, 1.0)) = 0.0
57+
5558
// Plus - Culling
5659
[HideInInspector] _Cull("__cull", Float) = 2.0
5760

DefaultResourcesExtra/StandardSpecular Plus.shader

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ Shader "ShingenPizza/Standard (Specular setup) Plus"
5252
[ToggleOff] _VRC_Visible_Mirror_VRCLens("Visible In Mirrors To VRCLens", Float) = 1.0
5353
[ToggleOff] _VRC_Visible_Mirror_Screenshot("Visible In Mirrors On Screenshots", Float) = 1.0
5454

55+
// Plus - Minimum Brightness
56+
_LightingMinLightBrightness("Minimum Brightness", Range(0.0, 1.0)) = 0.0
57+
5558
// Plus - Culling
5659
[HideInInspector] _Cull("__cull", Float) = 2.0
5760

Editor/ShaderGUI Plus.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ private static class Styles
2626
MaterialProperty light_volumes_speculars;
2727
MaterialProperty light_volumes_dominant_speculars;
2828

29+
protected MaterialProperty min_brightness;
30+
2931
protected MaterialProperty cullMode;
3032

3133
protected MaterialEditor m_MaterialEditor;
@@ -34,6 +36,7 @@ protected void FindPropertiesPlus(MaterialProperty[] props)
3436
{
3537
FindPropertiesPlusVisibility(props);
3638
FindPropertiesPlusLightVolumes(props);
39+
FindPropertiesPlusMinBrightness(props);
3740
FindPropertiesPlusCull(props);
3841
}
3942

@@ -57,11 +60,16 @@ protected void FindPropertiesPlusLightVolumes(MaterialProperty[] props)
5760
light_volumes_dominant_speculars = FindProperty("_DominantDirSpeculars", props);
5861
}
5962

63+
public void FindPropertiesPlusMinBrightness(MaterialProperty[] props)
64+
{
65+
min_brightness = FindProperty("_LightingMinLightBrightness", props);
66+
}
67+
6068
public void FindPropertiesPlusCull(MaterialProperty[] props)
6169
{
6270
cullMode = FindProperty("_Cull", props);
6371
}
64-
72+
6573
protected void PlusOptions(Material material)
6674
{
6775
GUILayout.Label("Plus Options", EditorStyles.largeLabel);
@@ -167,9 +175,15 @@ protected void LightVolumesOptions(Material material)
167175
protected void OtherOptions()
168176
{
169177
GUILayout.Label("Other Options", EditorStyles.boldLabel);
178+
MinBrightnessOptions();
170179
TwoSidedPopup();
171180
}
172181

182+
protected void MinBrightnessOptions()
183+
{
184+
m_MaterialEditor.ShaderProperty(min_brightness, EditorGUIUtility.TrTextContent(min_brightness.displayName));
185+
}
186+
173187
protected void TwoSidedPopup()
174188
{
175189
if (cullMode == null) { return; }

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ toggles for visibility in VRChat when seen directly, in mirrors, on screenshots,
3232
- [**VRC Light Volumes**](https://github.com/REDSIM/VRCLightVolumes)<br>
3333
<img src="https://github.com/user-attachments/assets/2cfe3af9-1d6c-470c-901a-218bae1a55cf" width="512" alt="presenting the VRC Light Volumes support" /><br>
3434
support for the cool new "voxel based light probes replacement" (v2.1).
35+
- **Minimum Brightness**<br>
36+
support for the "Minimum Brightness" property, allowing you to remain visible in darker areas of VRC worlds \[a\].
3537
- **Two Sided**<br>
36-
turning off backface culling if you need a mesh to be visible from both sides, to avoid having to duplicate mesh faces\*.
38+
turning off backface culling if you need a mesh to be visible from both sides, to avoid having to duplicate mesh faces \[a\]\[b\].
3739

38-
\* Available in some built-in shaders, simply copied to the others. Also, see "Known issues" section below.
40+
\[a\] See the "Known issues" section below.<br>
41+
\[b\] Available in some built-in shaders, simply copied to the others.<br>
3942

4043

4144
### Example
@@ -69,6 +72,7 @@ Voilà!<br>
6972
### Known issues:
7073
- The Two Sided option doesn't work when toggled in VRChat - it needs to be set before upload.
7174
- Since I had to create a custom editor for Unlit shaders, the Inspector view doesn't look exactly the way the default one does. (The shaders themselves work just fine, though.)
75+
- I disabled the "Minimum Brightness" property in "Transparent" Rendering Mode (or, more technically speaking, whenever the `_ALPHAPREMULTIPLY_ON` keyword is on), because it won't work correctly (or at least I don't know how to make it work).
7276

7377

7478
### Contact

0 commit comments

Comments
 (0)