From ba11c1f9a934ebb59d56348b78ac0bd687135585 Mon Sep 17 00:00:00 2001 From: realtradam Date: Wed, 7 Dec 2022 02:02:12 -0500 Subject: isolate graph functions --- Assets/Point URP.shadergraph | 133 ++++++++++++++++++++++++++++- Assets/Scripts/Graph.cs | 91 ++++++++++++-------- Assets/Scripts/MathFunctionLibrary.cs | 57 +++++++++++++ Assets/Scripts/MathFunctionLibrary.cs.meta | 11 +++ UserSettings/Layouts/default-2021.dwlt | 58 ++++++------- 5 files changed, 283 insertions(+), 67 deletions(-) create mode 100644 Assets/Scripts/MathFunctionLibrary.cs create mode 100644 Assets/Scripts/MathFunctionLibrary.cs.meta diff --git a/Assets/Point URP.shadergraph b/Assets/Point URP.shadergraph index a100837..c0fc845 100644 --- a/Assets/Point URP.shadergraph +++ b/Assets/Point URP.shadergraph @@ -59,6 +59,9 @@ }, { "m_Id": "59ed6d217c714d9dbd4545bc6c0cdfd1" + }, + { + "m_Id": "51e08799760f4c19a36812a1d7291a64" } ], "m_GroupDatas": [], @@ -71,6 +74,20 @@ }, "m_SlotId": 0 }, + "m_InputSlot": { + "m_Node": { + "m_Id": "51e08799760f4c19a36812a1d7291a64" + }, + "m_SlotId": 0 + } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "51e08799760f4c19a36812a1d7291a64" + }, + "m_SlotId": 2 + }, "m_InputSlot": { "m_Node": { "m_Id": "5e32574aed6a44ad9d7cf4982c06a98d" @@ -345,6 +362,30 @@ "m_SerializedDescriptor": "SurfaceDescription.NormalTS" } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot", + "m_ObjectId": "20ae198dedc24f188a1d8f6d4b734412", + "m_Id": 0, + "m_DisplayName": "A", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "A", + "m_StageCapability": 3, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot", @@ -483,8 +524,8 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": -1705.0, - "y": 31.999940872192384, + "x": -2088.0, + "y": 32.0, "width": 208.0, "height": 315.0 } @@ -573,6 +614,46 @@ "m_SerializedDescriptor": "SurfaceDescription.Smoothness" } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.ModuloNode", + "m_ObjectId": "51e08799760f4c19a36812a1d7291a64", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Modulo", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -1687.0, + "y": 32.0, + "width": 208.0, + "height": 302.0 + } + }, + "m_Slots": [ + { + "m_Id": "20ae198dedc24f188a1d8f6d4b734412" + }, + { + "m_Id": "d41377341799452ca2e6d47c57c5151c" + }, + { + "m_Id": "697562210b0544a59d24e7d57bfbfab6" + } + ], + "synonyms": [ + "fmod" + ], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.PropertyNode", @@ -748,6 +829,30 @@ "m_Space": 0 } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot", + "m_ObjectId": "697562210b0544a59d24e7d57bfbfab6", + "m_Id": 2, + "m_DisplayName": "Out", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 3, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.AddNode", @@ -1196,6 +1301,30 @@ "m_SerializedDescriptor": "SurfaceDescription.Metallic" } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot", + "m_ObjectId": "d41377341799452ca2e6d47c57c5151c", + "m_Id": 1, + "m_DisplayName": "B", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "B", + "m_StageCapability": 3, + "m_Value": { + "x": 5.0, + "y": 5.0, + "z": 5.0, + "w": 1.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.BlockNode", diff --git a/Assets/Scripts/Graph.cs b/Assets/Scripts/Graph.cs index 1486990..760d4c8 100644 --- a/Assets/Scripts/Graph.cs +++ b/Assets/Scripts/Graph.cs @@ -2,44 +2,63 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; + public class Graph : MonoBehaviour { - [SerializeField] - Transform pointPrefab; - - [SerializeField, Range(10, 100)] - int resolution = 10; - - Transform[] points; - - void Awake() { - points = new Transform[resolution]; - float step = 8f / points.Length; - for(int i = 0; i < points.Length; i++) { - Transform point = Instantiate(pointPrefab); - points[i] = point; - Vector3 position = pointPrefab.localPosition; - point.SetParent(transform, false); - position.x = (i + 0.5f) * step - 4f; + [SerializeField] + Transform pointPrefab; + + [SerializeField, Range(10, 200)] + int resolution = 100; + + [SerializeField, Range(0.1f, 2f)] + float size = 0.3f; + + [SerializeField, Range(0, 2)] + int function = 1; + + Transform[] points; + + void Awake() { + points = new Transform[resolution]; + float step = 8f / points.Length; + for(int i = 0; i < points.Length; i++) { + Transform point = Instantiate(pointPrefab); + points[i] = point; + Vector3 position = pointPrefab.localPosition; + point.SetParent(transform, false); + position.x = (i + 0.5f) * step - 4f; point.localPosition = position; - } - } - - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { + point.localScale *= size; + } + } + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { float time = Time.time; - for(int i = 0; i < points.Length; i++) { - Transform point = points[i]; - Vector3 position = point.localPosition; - position.y = Mathf.Sin(Mathf.PI * (position.x + time));// * position.x * position.x; - point.localPosition = position; - } - } + for(int i = 0; i < points.Length; i++) { + Transform point = points[i]; + Vector3 position = point.localPosition; + if(function == 0) + { + position.y = MathFunctionLibrary.Wave(position.x, time); + } + else if(function == 1) + { + position.y = MathFunctionLibrary.MultiWave(position.x, time); + } + else if(function == 2) + { + position.y = MathFunctionLibrary.Ripple(position.x, time); + } + point.localPosition = position; + } + } } diff --git a/Assets/Scripts/MathFunctionLibrary.cs b/Assets/Scripts/MathFunctionLibrary.cs new file mode 100644 index 0000000..d83b673 --- /dev/null +++ b/Assets/Scripts/MathFunctionLibrary.cs @@ -0,0 +1,57 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +using static UnityEngine.Mathf; + +public static class MathFunctionLibrary +{ + public delegate float Function(float x, float t); + + public static float GetFunction(float x, float t) + { + if(index == 0) + { + return Wave; + } + else if(index == 1) + { + return MultiWave; + } + else //if(index == 2) + { + return Ripple; + } + } + + public static float Wave(float x, float t) + { + return Sin(PI * (x + t)); + } + + public static float MultiWave(float x, float t) + { + float y = MathFunctionLibrary.Wave(x, t * 0.5f); + y += Sin(2f * PI * (x + t)) * 0.5f; + return y * (2f / 3f); + } + + public static float Ripple(float x, float t) { + float d = Abs(x); + float y = Sin(PI * (4f * d - (2f * t))); + return y / (1f + 10f * d); + } + /* + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + */ +} diff --git a/Assets/Scripts/MathFunctionLibrary.cs.meta b/Assets/Scripts/MathFunctionLibrary.cs.meta new file mode 100644 index 0000000..e29eae2 --- /dev/null +++ b/Assets/Scripts/MathFunctionLibrary.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fe3850924a36450d5af9e18ad7bef1b6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UserSettings/Layouts/default-2021.dwlt b/UserSettings/Layouts/default-2021.dwlt index aa38a41..758f132 100644 --- a/UserSettings/Layouts/default-2021.dwlt +++ b/UserSettings/Layouts/default-2021.dwlt @@ -14,8 +14,8 @@ MonoBehaviour: m_EditorClassIdentifier: m_PixelRect: serializedVersion: 2 - x: 15 - y: 15 + x: 16 + y: 16 width: 1568 height: 816 m_ShowMode: 4 @@ -48,7 +48,7 @@ MonoBehaviour: m_MinSize: {x: 300, y: 200} m_MaxSize: {x: 24288, y: 16192} vertical: 0 - controlID: 19 + controlID: 34 --- !u!114 &3 MonoBehaviour: m_ObjectHideFlags: 52 @@ -64,9 +64,9 @@ MonoBehaviour: m_Children: [] m_Position: serializedVersion: 2 - x: 955 + x: 953 y: 0 - width: 613 + width: 615 height: 766 m_MinSize: {x: 276, y: 71} m_MaxSize: {x: 4001, y: 4021} @@ -92,7 +92,7 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 0 - width: 233 + width: 231 height: 506 m_MinSize: {x: 201, y: 221} m_MaxSize: {x: 4001, y: 4021} @@ -118,7 +118,7 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 506 - width: 955 + width: 953 height: 260 m_MinSize: {x: 231, y: 271} m_MaxSize: {x: 10001, y: 10021} @@ -218,12 +218,12 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 0 - width: 955 + width: 953 height: 766 m_MinSize: {x: 200, y: 200} m_MaxSize: {x: 16192, y: 16192} vertical: 1 - controlID: 20 + controlID: 35 --- !u!114 &10 MonoBehaviour: m_ObjectHideFlags: 52 @@ -243,12 +243,12 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 0 - width: 955 + width: 953 height: 506 m_MinSize: {x: 200, y: 100} m_MaxSize: {x: 16192, y: 8096} vertical: 0 - controlID: 21 + controlID: 36 --- !u!114 &11 MonoBehaviour: m_ObjectHideFlags: 52 @@ -264,7 +264,7 @@ MonoBehaviour: m_Children: [] m_Position: serializedVersion: 2 - x: 233 + x: 231 y: 0 width: 722 height: 506 @@ -298,7 +298,7 @@ MonoBehaviour: serializedVersion: 2 x: 16 y: 579 - width: 954 + width: 952 height: 239 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: @@ -330,9 +330,9 @@ MonoBehaviour: m_IsLocked: 0 m_FolderTreeState: scrollPos: {x: 0, y: 0} - m_SelectedIDs: 246a0000 - m_LastClickedID: 27172 - m_ExpandedIDs: 00000000a068000000ca9a3bffffff7f + m_SelectedIDs: 286a0000 + m_LastClickedID: 27176 + m_ExpandedIDs: 00000000a468000000ca9a3bffffff7f m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -360,7 +360,7 @@ MonoBehaviour: scrollPos: {x: 0, y: 0} m_SelectedIDs: m_LastClickedID: 0 - m_ExpandedIDs: 00000000a0680000 + m_ExpandedIDs: 00000000a4680000 m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -385,8 +385,8 @@ MonoBehaviour: m_Icon: {fileID: 0} m_ResourceFile: m_ListAreaState: - m_SelectedInstanceIDs: - m_LastClickedInstanceID: 0 + m_SelectedInstanceIDs: be200000 + m_LastClickedInstanceID: 8382 m_HadKeyboardFocusLastEvent: 1 m_ExpandedInstanceIDs: c6230000 m_RenameOverlay: @@ -436,9 +436,9 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 971 + x: 969 y: 73 - width: 612 + width: 614 height: 745 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: @@ -479,7 +479,7 @@ MonoBehaviour: serializedVersion: 2 x: 16 y: 73 - width: 232 + width: 230 height: 485 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: @@ -488,9 +488,9 @@ MonoBehaviour: m_SceneHierarchy: m_TreeViewState: scrollPos: {x: 0, y: 0} - m_SelectedIDs: bc200000 + m_SelectedIDs: be200000 m_LastClickedID: 0 - m_ExpandedIDs: 24f4ffffd8f4ffffaaf6ffff38fbffff + m_ExpandedIDs: 38fbffff m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -534,7 +534,7 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 249 + x: 247 y: 73 width: 720 height: 485 @@ -739,9 +739,9 @@ MonoBehaviour: m_PlayAudio: 0 m_AudioPlay: 0 m_Position: - m_Target: {x: -3.4933767, y: -0.25820988, z: 2.0115154} + m_Target: {x: -3.8439417, y: -0.015294582, z: 0.6269157} speed: 2 - m_Value: {x: -3.4933767, y: -0.25820988, z: 2.0115154} + m_Value: {x: -3.8439417, y: -0.015294582, z: 0.6269157} m_RenderMode: 0 m_CameraMode: drawMode: 0 @@ -792,9 +792,9 @@ MonoBehaviour: speed: 2 m_Value: {x: 0.014170349, y: 0.6117241, z: 0.010960259, w: -0.79087114} m_Size: - m_Target: 5.412328 + m_Target: 5.598848 speed: 2 - m_Value: 5.412328 + m_Value: 5.598848 m_Ortho: m_Target: 0 speed: 2 -- cgit v1.2.3