feat(shader): add ambient lighting to Toon shadergraph

main
uc-hoba 2 weeks ago
parent 8cfe2019c5
commit 33e9c4a119
  1. 4
      Assets/Main.unity
  2. 5
      Assets/Resources/Toon.cginc
  3. 40
      Assets/Resources/Toon.shadergraph

@ -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

@ -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
}

@ -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": [

Loading…
Cancel
Save