summaryrefslogtreecommitdiffhomepage
path: root/Assets
diff options
context:
space:
mode:
Diffstat (limited to 'Assets')
-rw-r--r--Assets/Point URP.shadergraph133
-rw-r--r--Assets/Scripts/Graph.cs91
-rw-r--r--Assets/Scripts/MathFunctionLibrary.cs57
-rw-r--r--Assets/Scripts/MathFunctionLibrary.cs.meta11
4 files changed, 254 insertions, 38 deletions
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": [],
@@ -73,6 +76,20 @@
},
"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"
},
"m_SlotId": 0
@@ -347,6 +364,30 @@
{
"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",
"m_ObjectId": "2d2befee35b14009b4a8540d6902b7f8",
"m_Id": 0,
@@ -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
}
@@ -575,6 +616,46 @@
{
"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",
"m_ObjectId": "568bac9af43546aab9fdb713700ad212",
"m_Group": {
@@ -750,6 +831,30 @@
{
"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",
"m_ObjectId": "6b318e2445ef42b6aa1f980fe807f4ac",
"m_Group": {
@@ -1198,6 +1303,30 @@
{
"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",
"m_ObjectId": "d94d700bcc024849ad8e90f3fcbdb000",
"m_Group": {
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: