summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-10-04 19:18:47 -0700
committeryum <yum.food.vr@gmail.com>2025-10-04 19:18:47 -0700
commitdc8a6dfb9d78316b8c58c587bc606468377b0fe3 (patch)
treeca4994a0e552179b63a88ed7306fddc5984cd359
parent42dbd067eb455d4b67d6ae8c57f1cbe4ec7dccfa (diff)
add unlit toggle, adjust IBL
-rw-r--r--3ner.cginc10
-rw-r--r--3ner.shader38
-rw-r--r--LUTS/dfg_standard.exr.meta2
-rw-r--r--brdf.cginc29
-rw-r--r--cnlohr.cginc102
-rw-r--r--features.cginc8
-rw-r--r--globals.cginc4
-rw-r--r--pema99.cginc36
8 files changed, 206 insertions, 23 deletions
diff --git a/3ner.cginc b/3ner.cginc
index d50f553..1b5e358 100644
--- a/3ner.cginc
+++ b/3ner.cginc
@@ -161,14 +161,22 @@ v2f domain(
return o;
}
-float4 frag(v2f i, uint facing : SV_IsFrontFace) : SV_Target {
+float4 frag(v2f i, uint facing : SV_IsFrontFace
+#if defined(_CUSTOM31_TUBES)
+, out float depth : SV_DepthLessEqual
+#endif
+) : SV_Target {
i.normal *= facing ? 1 : -1;
i.normal = normalize(i.normal);
i.tangent.xyz = normalize(i.tangent.xyz);
Pbr pbr = getPbr(i);
+#if defined(_UNLIT)
+ return pbr.albedo;
+#else
LightData light_data;
GetLighting(i, pbr, light_data);
return brdf(pbr, light_data);
+#endif
}
#endif // __3NER_INC
diff --git a/3ner.shader b/3ner.shader
index a3d64f7..d4954f5 100644
--- a/3ner.shader
+++ b/3ner.shader
@@ -40,16 +40,29 @@ Shader "yum_food/3ner"
[HideInInspector] m_end_Main("Main", Float) = 0
[HideInInspector] m_start_Gimmicks("Gimmicks", Float) = 0
- //ifex _Marble_Enabled==0
- [HideInInspector] m_start_Marble("Marble", Float) = 0
- [ThryToggle(_MARBLE)] _Marble_Enabled("Enable", Float) = 0
- [Gradient] _Marble_U_Ramp("U Ramp", 2D) = "white" {}
- [Gradient] _Marble_V_Ramp("V Ramp", 2D) = "white" {}
- [Gradient] _Marble_W_Ramp("W Ramp", 2D) = "white" {}
- _Marble_Scale("Scale", Vector) = (1, 1, 1, 0)
- _Marble_Strength("Strength", Float) = 1
- _Marble_Octaves("Octaves", Range(1, 10)) = 3
- [HideInInspector] m_end_Marble("Marble", Float) = 0
+ //ifex _Custom31_Enabled==0
+ [HideInInspector] m_start_Custom31("Custom31", Float) = 0
+ [ToggleUI] _Custom31_Enabled("Enable", Float) = 0
+
+ //ifex _Custom31_Tubes_Enabled==0
+ [HideInInspector] m_start_Custom31_Tubes("Tubes", Float) = 0
+ [ToggleUI] _Custom31_Tubes_Enabled("Enable", Float) = 0
+ [HideInInspector] m_end_Custom31_Tubes("Tubes", Float) = 0
+ //endex
+
+ //ifex _Marble_Enabled==0
+ [HideInInspector] m_start_Marble("Marble", Float) = 0
+ [ThryToggle(_MARBLE)] _Marble_Enabled("Enable", Float) = 0
+ [Gradient] _Marble_U_Ramp("U Ramp", 2D) = "white" {}
+ [Gradient] _Marble_V_Ramp("V Ramp", 2D) = "white" {}
+ [Gradient] _Marble_W_Ramp("W Ramp", 2D) = "white" {}
+ _Marble_Scale("Scale", Vector) = (1, 1, 1, 0)
+ _Marble_Strength("Strength", Float) = 1
+ _Marble_Octaves("Octaves", Range(1, 10)) = 3
+ [HideInInspector] m_end_Marble("Marble", Float) = 0
+ //endex
+
+ [HideInInspector] m_end_Custom31("Custom31", Float) = 0
//endex
[HideInInspector] m_end_Gimmicks("Gimmicks", Float) = 0
@@ -69,6 +82,10 @@ Shader "yum_food/3ner"
[HideInInspector] m_start_Rendering_Options("Rendering Options", Float) = 0
+ //ifex _Unlit==0
+ [ThryToggle(_UNLIT)] _Unlit("Unlit", Float) = 0
+ //endex
+
[HideInInspector] m_start_BRDF("BRDF", Float) = 0
_DFG_LUT("DFG LUT", 2D) = "white" {}
_BRDF_Specular_Min_Denom("Specular minimum denominator", Float) = 0.000001
@@ -91,7 +108,6 @@ Shader "yum_food/3ner"
_Cloth_Sheen_Color("Color", Color) = (1, 1, 1, 1)
[HideInInspector] m_end_Cloth_Sheen("Cloth Sheen", Float) = 0
//endex
-
[HideInInspector] m_end_BRDF("BRDF", Float) = 0
[HideInInspector] m_start_blending ("Blending--{button_help:{text:Tutorial,action:{type:URL,data:https://www.poiyomi.com/rendering/blending},hover:Documentation}}", Float) = 0
diff --git a/LUTS/dfg_standard.exr.meta b/LUTS/dfg_standard.exr.meta
index a0002af..68554f4 100644
--- a/LUTS/dfg_standard.exr.meta
+++ b/LUTS/dfg_standard.exr.meta
@@ -5,7 +5,7 @@ TextureImporter:
externalObjects: {}
serializedVersion: 12
mipmaps:
- mipMapMode: 0
+ mipMapMode: 1
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
diff --git a/brdf.cginc b/brdf.cginc
index 5a24307..d89558c 100644
--- a/brdf.cginc
+++ b/brdf.cginc
@@ -1,6 +1,7 @@
#ifndef __BRDF_INC
#define __BRDF_INC
+#include "pema99.cginc"
#include "pbr.cginc"
#include "lighting.cginc"
#include "lysenko.cginc"
@@ -184,14 +185,14 @@ float4 brdf(Pbr pbr, LightData data) {
#if defined(FORWARD_BASE_PASS)
{
float remainder = 1.0f;
- float2 dfg_uv = float2(data.common.NoV, pbr.roughness);
+ float2 dfg_uv = float2(pbr.roughness, data.common.NoV);
#if defined(_CLEARCOAT)
float cc_f0 = 0.04f;
float Fcc = F_Schlick(data.common.NoV, cc_f0, 1.0f);
float3 indirect_specular_cc = Fcc * data.indirect.specular_cc * pbr.cc_strength;
specular += indirect_specular_cc;
- remainder *= (1.0f - Fcc * pbr.cc_strength);
+ remainder -= Fcc * pbr.cc_strength;
#endif
#if defined(_CLOTH_SHEEN)
@@ -201,19 +202,27 @@ float4 brdf(Pbr pbr, LightData data) {
// Energy conservation for cloth is tricky with IBL.
// A simple approximation is to use the Fresnel of the sheen layer.
float Fcl = F_Schlick(data.common.NoV, 0.04, 1.0);
- remainder *= (1.0f - Fcl * pbr.cl_strength);
+ remainder -= Fcl * pbr.cl_strength;
#endif
// Standard PBR IBL using split-sum approximation
- float2 dfg = _DFG_LUT.Sample(bilinear_clamp_s, dfg_uv).rg;
- float3 f0_spec = lerp(0.04f, pbr.albedo.xyz, pbr.metallic);
+ // Specular lobe
+ float2 dfg;
+ [branch]
+ if (textureExists(_DFG_LUT)) {
+ dfg = _DFG_LUT.SampleLevel(bilinear_clamp_s, dfg_uv, 0).rg;
+ } else {
+ dfg = float2(0, 1);
+ }
+ float3 f0_spec = lerp(f0, pbr.albedo.xyz, pbr.metallic);
float3 ibl_specular_reflectance = f0_spec * dfg.x + dfg.y;
float3 indirect_specular = data.indirect.specular * ibl_specular_reflectance;
- specular += indirect_specular * remainder;
-
- // For energy conservation with the diffuse term, we use the view-dependent Fresnel.
- float3 F = F_Schlick(data.common.NoV, f0_spec, 1.0f);
- remainder *= (1.0f - F);
+ // surface reduction term lifted from here:
+ // UnityStandardBRDF.cginc :: BRDF1_Unity_PBS
+ float surface_reduction = 1.0f / (pbr.roughness * pbr.roughness + 1.0f);
+ const float F = F_Schlick(data.indirect.NoL, f0_spec, f90);
+ specular += surface_reduction * indirect_specular * F;
+ remainder -= F;
// Diffuse is Lambertian, which is pre-integrated into the SH diffuse probe
float3 indirect_diffuse = pbr.albedo.xyz * data.indirect.diffuse * remainder * (1.0 - pbr.metallic);
diff --git a/cnlohr.cginc b/cnlohr.cginc
new file mode 100644
index 0000000..4962805
--- /dev/null
+++ b/cnlohr.cginc
@@ -0,0 +1,102 @@
+#ifndef __CNLOHR_INC
+#define __CNLOHR_INC
+
+#include "globals.cginc"
+#include "interpolators.cginc"
+
+/*
+ * MIT License
+ *
+ * NOTE: Much content here is originally from others. Content in third party
+ * folder may not be fully MIT-licensable.
+ *
+ * Copyright (c) 2021 cnlohr, et. al.
+ *
+ * All other content in this repository falls under the following terms:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE
+ * SOFTWARE.
+ */
+
+// Source:
+// https://github.com/cnlohr/shadertrixx?tab=readme-ov-file#eye-center-position
+bool isMirror() { return _VRChatMirrorMode != 0; }
+
+// Source:
+// https://github.com/cnlohr/shadertrixx?tab=readme-ov-file#eye-center-position
+float3 getCenterCamPos() {
+#if defined(USING_STEREO_MATRICES) || defined(UNITY_SINGLE_PASS_STEREO)
+ return (unity_StereoWorldSpaceCameraPos[0] + unity_StereoWorldSpaceCameraPos[1]) * 0.5;
+#else
+ return isMirror() ? _VRChatMirrorCameraPos : _WorldSpaceCameraPos.xyz;
+#endif
+}
+
+bool isVR() {
+#if defined(USING_STEREO_MATRICES)
+ return true;
+#else
+ return false;
+#endif
+}
+
+float GetLinearZFromZDepth_WorksWithMirrors(float zDepthFromMap, float2 screenUV)
+{
+ #if defined(UNITY_REVERSED_Z)
+ zDepthFromMap = 1 - zDepthFromMap;
+
+ // When using a mirror, the far plane is whack. This just checks for it and aborts.
+ if( zDepthFromMap >= 1.0 ) return _ProjectionParams.z;
+ #endif
+
+ float4 clipPos = float4(screenUV.xy, zDepthFromMap, 1.0);
+ clipPos.xyz = 2.0f * clipPos.xyz - 1.0f;
+ float4 camPos = mul(unity_CameraInvProjection, clipPos);
+ return -camPos.z / camPos.w;
+}
+
+void GetScreenUVAndPerspectiveFactor(float3 worldPos, float4 clipPos, out float2 screen_uv, out float perspective_factor) {
+ float3 full_vec_eye_to_geometry = worldPos - _WorldSpaceCameraPos;
+ float perspective_divide = 1.0f / clipPos.w;
+ perspective_factor = length(full_vec_eye_to_geometry * perspective_divide);
+ screen_uv = ComputeScreenPos(clipPos).xy;
+}
+
+#if defined(_SSAO)
+float GetDepthOfWorldPos(float3 worldPos, out float2 debug)
+{
+ float3 objPos = mul(unity_WorldToObject, float4(worldPos, 1));
+ float4 clipPos = UnityObjectToClipPos(objPos);
+ float4 screenPos = ComputeScreenPos(clipPos);
+ const float2 screen_uv = screenPos.xy / screenPos.w;
+
+ float zDepthFromMap = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, screen_uv);
+ float linearZ =
+ GetLinearZFromZDepth_WorksWithMirrors(zDepthFromMap, screen_uv);
+ linearZ = min(1E3, linearZ);
+
+ debug = screen_uv;
+ return linearZ;
+}
+#endif
+
+#endif // __CNLOHR_INC
diff --git a/features.cginc b/features.cginc
index 705939c..e3e7f6a 100644
--- a/features.cginc
+++ b/features.cginc
@@ -23,4 +23,12 @@
#pragma shader_feature_local _CLOTH_SHEEN
//endex
+//ifex _Custom31_Tubes_Enabled==0
+#pragma shader_feature_local _CUSTOM31_TUBES
+//endex
+
+//ifex _Unlit==0
+#pragma shader_feature_local _UNLIT
+//endex
+
#endif // __FEATURES_INC
diff --git a/globals.cginc b/globals.cginc
index 3ccaac4..ee997e9 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -57,4 +57,8 @@ float3 _Cloth_Sheen_Color;
texture2D _Cloth_Sheen_DFG_LUT;
#endif // _CLOTH_SHEEN
+#if defined(_CUSTOM31_TUBES)
+float _Custom31_Tubes_Speed;
+#endif // _CUSTOM31_TUBES
+
#endif // __GLOBALS_INC
diff --git a/pema99.cginc b/pema99.cginc
new file mode 100644
index 0000000..b05f36e
--- /dev/null
+++ b/pema99.cginc
@@ -0,0 +1,36 @@
+#ifndef __PEMA_99_INC
+#define __PEMA_99_INC
+
+/*
+MIT License
+
+Copyright (c) 2022 Pema Malling
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+bool textureExists(texture2D tex)
+{
+ int width, height;
+ tex.GetDimensions(width, height);
+ return width > 16;
+}
+
+#endif // __PEMA_99_INC
+