From 33e9c4a119ee5c5e9223312ec1383975dae19495 Mon Sep 17 00:00:00 2001 From: uc-hoba Date: Tue, 9 Jun 2026 18:28:45 +0800 Subject: [PATCH] feat(shader): add ambient lighting to Toon shadergraph --- Assets/Main.unity | 4 ++-- Assets/Resources/Toon.cginc | 5 +++- Assets/Resources/Toon.shadergraph | 40 +++++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/Assets/Main.unity b/Assets/Main.unity index a94dcff..c8f7f24 100644 --- a/Assets/Main.unity +++ b/Assets/Main.unity @@ -1941,7 +1941,7 @@ PrefabInstance: m_Modifications: - target: {fileID: -364223573239433514, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3} propertyPath: m_LocalPosition.x - value: 0.453 + value: 0.746 objectReference: {fileID: 0} - target: {fileID: -364223573239433514, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3} propertyPath: m_LocalPosition.y @@ -1949,7 +1949,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: -364223573239433514, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3} propertyPath: m_LocalPosition.z - value: 0.26 + value: 0.019 objectReference: {fileID: 0} - target: {fileID: -364223573239433514, guid: 0419d2e6e681caa47baeec4f66d9e3eb, type: 3} propertyPath: m_LocalRotation.w diff --git a/Assets/Resources/Toon.cginc b/Assets/Resources/Toon.cginc index c34aa65..c2d16a0 100644 --- a/Assets/Resources/Toon.cginc +++ b/Assets/Resources/Toon.cginc @@ -1,12 +1,13 @@ #ifndef TOON_MAINLIGHT_INCLUDED #define TOON_MAINLIGHT_INCLUDED -void MainLight_float(float3 WorldPos, out float3 Direction, out float3 Color, out float ShadowAtten) +void MainLight_float(float3 WorldPos, out float3 Direction, out float3 Color, out float ShadowAtten, out float3 Ambient) { #ifdef SHADERGRAPH_PREVIEW Direction = normalize(float3(0.5, 0.5, -0.5)); Color = 1; ShadowAtten = 1; + Ambient = 0.2; #else float4 shadowCoord = TransformWorldToShadowCoord(WorldPos); Light mainLight = GetMainLight(); @@ -26,6 +27,8 @@ void MainLight_float(float3 WorldPos, out float3 Direction, out float3 Color, ou // Beyond the max shadow distance -> no shadow ShadowAtten = BEYOND_SHADOW_FAR(shadowCoord) ? 1.0 : atten; + + Ambient = SampleSH(0); #endif } diff --git a/Assets/Resources/Toon.shadergraph b/Assets/Resources/Toon.shadergraph index a453b99..666a07b 100644 --- a/Assets/Resources/Toon.shadergraph +++ b/Assets/Resources/Toon.shadergraph @@ -306,6 +306,29 @@ "m_ColorMode": 0 } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot", + "m_ObjectId": "06d893c395e54484bbf110242f2ea0d1", + "m_Id": 5, + "m_DisplayName": "Ambient", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Ambient", + "m_StageCapability": 3, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_Labels": [] +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", @@ -858,9 +881,9 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -205.00003051757813, - "y": 436.0, - "width": 130.00003051757813, + "x": -200.0, + "y": 406.0, + "width": 130.0, "height": 118.0 } }, @@ -919,6 +942,9 @@ }, { "m_Id": "2a5d996f8d3a4513a9d23991d555c3a7" + }, + { + "m_Id": "06d893c395e54484bbf110242f2ea0d1" } ], "synonyms": [ @@ -951,10 +977,10 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -388.9999694824219, - "y": 313.0000305175781, - "width": 130.0, - "height": 142.0 + "x": -425.99993896484377, + "y": 235.99998474121095, + "width": 129.99996948242188, + "height": 142.00001525878907 } }, "m_Slots": [