summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-06-23 00:40:33 -0700
committeryum <yum.food.vr@gmail.com>2025-06-23 00:40:33 -0700
commit6576484d1f9f1407fc40d36a1d46f5232869926c (patch)
tree3dade4e75ef55d72cfc30d9fc577abbb4b29ce95
parent5393f1c9a3b6cfeae53ebba4fb10f4eb6d91fbf7 (diff)
add support for bakery normal maps
-rw-r--r--2ner.shader8
-rw-r--r--features.cginc7
-rw-r--r--filamented.cginc54
-rw-r--r--yum_lighting.cginc10
4 files changed, 69 insertions, 10 deletions
diff --git a/2ner.shader b/2ner.shader
index fa03778..2ef0b51 100644
--- a/2ner.shader
+++ b/2ner.shader
@@ -1905,6 +1905,14 @@ Shader "yum_food/2ner"
_LTCGI_DiffuseColor("Diffuse color", Color) = (1, 1, 1, 1)
[HideInInspector] m_end_LTCGI("LTCGI", Float) = 0
//endex
+ //ifex _Bakery_Enabled==0
+ [HideInInspector] m_start_Bakery("Bakery Lightmapping", Float) = 0
+ [ThryToggle(_BAKERY)] _Bakery_Enabled("Enable", Float) = 0
+ [ThryToggle(_BAKERY_RNM)] _Bakery_RNM_Enabled("RNM", Float) = 0
+ [ThryToggle(_BAKERY_SH)] _Bakery_SH_Enabled("SH", Float) = 0
+ [ThryToggle(_BAKERY_MONOSH)] _Bakery_MONOSH_Enabled("MonoSH", Float) = 0
+ [HideInInspector] m_end_Bakery("Bakery Lightmapping", Float) = 0
+ //endex
//ifex _Grayscale_Lightmaps_Enabled==0
[HideInInspector] m_start_Grayscale_Lightmaps("Grayscale Lightmaps", Float) = 0
[ThryToggle(_GRAYSCALE_LIGHTMAPS)] _Grayscale_Lightmaps_Enabled("Enable", Float) = 0
diff --git a/features.cginc b/features.cginc
index 98f1141..1e46f48 100644
--- a/features.cginc
+++ b/features.cginc
@@ -373,5 +373,12 @@
#pragma shader_feature_local _GRAYSCALE_LIGHTMAPS
//endex
+//ifex _Bakery_Enabled==0
+#pragma shader_feature_local _BAKERY
+#pragma shader_feature_local _BAKERY_RNM
+#pragma shader_feature_local _BAKERY_SH
+#pragma shader_feature_local _BAKERY_MONOSH
+//endex
+
#endif // __FEATURES_INC
diff --git a/filamented.cginc b/filamented.cginc
index dda261d..ecdfb1c 100644
--- a/filamented.cginc
+++ b/filamented.cginc
@@ -236,6 +236,21 @@ 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.
*/
+// Check if Bakery is available
+#if defined(_BAKERY_RNM) || defined(_BAKERY_SH) || defined(_BAKERY_MONOSH)
+ #define USING_BAKERY 1
+#endif
+
+// Bakery textures (Unity auto-binds these)
+#if defined(_BAKERY_RNM) || defined(_BAKERY_SH) || defined(_BAKERY_MONOSH)
+TEXTURE2D(_RNM0);
+TEXTURE2D(_RNM1);
+TEXTURE2D(_RNM2);
+SAMPLER(sampler_RNM0);
+#endif
+
+
+
#define MIN_PERCEPTUAL_ROUGHNESS 0.045
UNITY_DECLARE_TEX2D_FLOAT(_DFG);
@@ -1097,7 +1112,7 @@ float3 UnityGI_Irradiance(
#if defined(USING_BAKERY)
#if defined(_BAKERY_RNM)
// bakery rnm mode
- irradiance = DecodeRNMLightmap(bakedColor, lightmapUV.xy, tangentNormal, tangentToWorld, derivedLight);
+ irradiance = DecodeRNMLightmap(0, lightmapUV.xy, tangentNormal, tangentToWorld, derivedLight);
#endif
#if defined(_BAKERY_SH)
@@ -1125,6 +1140,7 @@ float3 UnityGI_Irradiance(
#endif
#endif
}
+
#if defined(USING_BAKERY_VERTEXLM)
if (getIsBakeryVertexMode() == true)
{
@@ -1206,5 +1222,39 @@ float3 UnityGI_Irradiance(
return irradiance;
}
-#endif
+// Simplified integration function using existing Unity/Bakery functions
+float3 BakeryGI_Irradiance(
+ float3 worldNormal,
+ float3 worldPos,
+ float4 lightmapUV, // xy = uv0, zw = uv1
+ float3 ambient,
+ float attenuation,
+ float3 tangentNormal,
+ float3x3 tangentToWorld,
+ out float occlusion,
+ out Light derivedLight)
+{
+ // The existing UnityGI_Irradiance function already handles all Bakery modes correctly,
+ // including MonoSH via the DecodeMonoSHLightmap function that's already defined above
+ float3 ambientSH[3] = {float3(0,0,0), float3(0,0,0), float3(0,0,0)};
+ float3 ambientDir = float3(0,0,0);
+
+ return UnityGI_Irradiance(
+ worldNormal,
+ worldPos,
+ lightmapUV,
+ ambient,
+ attenuation,
+ tangentNormal,
+ tangentToWorld,
+ #if defined(USING_BAKERY_VERTEXLMSH)
+ ambientSH,
+ #elif defined(USING_BAKERY_VERTEXLMDIR)
+ ambientDir,
+ #endif
+ occlusion,
+ derivedLight
+ );
+}
+#endif // __FILAMENTED_INC
diff --git a/yum_lighting.cginc b/yum_lighting.cginc
index 22d1a0b..9dab2d8 100644
--- a/yum_lighting.cginc
+++ b/yum_lighting.cginc
@@ -241,7 +241,8 @@ YumLighting GetYumLighting(v2f i, YumPbr pbr) {
float3 tangentNormal = mul(pbr.normal, transpose(float3x3(i.tangent, i.binormal, i.normal)));
float3x3 tangentToWorld = float3x3(i.tangent, i.binormal, i.normal);
- light.diffuse = UnityGI_Irradiance(
+ // Use Bakery-aware irradiance function
+ light.diffuse = BakeryGI_Irradiance(
pbr.normal, // worldNormal
i.worldPos, // worldPos
float4(i.uv01.zw, 0, 0), // lightmapUV (xy = uv0, zw = uv1)
@@ -249,13 +250,6 @@ YumLighting GetYumLighting(v2f i, YumPbr pbr) {
light.attenuation, // attenuation
tangentNormal, // tangentNormal
tangentToWorld, // tangentToWorld
- #if defined(USING_BAKERY_VERTEXLMSH)
- // You'll need to add these to your v2f if using Bakery vertex SH
- i.bakeryVertexSH,
- #elif defined(USING_BAKERY_VERTEXLMDIR)
- // You'll need to add this to your v2f if using Bakery vertex directional
- i.bakeryVertexDir,
- #endif
light.occlusion, // out occlusion
light.derivedLight // out Light
);