diff --git a/Climb/Assets/GridShader.shader b/Climb/Assets/GridShader.shader index 868b5b3..8369cc5 100644 --- a/Climb/Assets/GridShader.shader +++ b/Climb/Assets/GridShader.shader @@ -74,30 +74,23 @@ Shader "PDT Shaders/TestGrid" { float brightness = _InactiveColor.w; // Line Color Check - if (frac(uv.x*gsize) <= _LineSize || frac(uv.y*gsize) <= _LineSize){ + if (_LineSize > 0.0 && (frac(uv.x*gsize) <= _LineSize || frac(uv.y*gsize) <= _LineSize)){ color = _LineColor; brightness = color.w; - // Selected Cell Check - } else if (round(_SelectCell) == 1.0 && id.x == _SelectedCellX && id.y == _SelectedCellY) { - color = _ActiveColor; - brightness = color.w; - // Heatmap Value Fallback + // Heatmap Value Fallback } else { float pos = id.y * _GridSize + id.x; - if(pos < _valueLength && _values[pos] >= 0.5) { + if(pos < _valueLength) { color = lerp(_InactiveColor, _ActiveColor, _values[pos]); brightness = color.w; } } - - //Clip transparent spots using alpha cutout - if (brightness == 0.0) { + // Clip transparent spots using alpha cutout + if (brightness == 0.0) clip(c.a - 1.0); - } - - o.Albedo = float4( color.x*brightness,color.y*brightness,color.z*brightness,brightness); + o.Albedo = float4(color.x * brightness,color.y * brightness,color.z * brightness, brightness); // Metallic and smoothness come from slider variables o.Metallic = 0.0; o.Smoothness = 0.0; diff --git a/Climb/Assets/Scripts/GridController.cs b/Climb/Assets/Scripts/GridController.cs index a265dea..6c0ce1e 100644 --- a/Climb/Assets/Scripts/GridController.cs +++ b/Climb/Assets/Scripts/GridController.cs @@ -1,14 +1,14 @@ -using System; -using System.Linq; -using UnityEngine; -using Random = UnityEngine.Random; +using UnityEngine; /// /// A simple Grid Rendering Controller using MeshRenderer. /// public class GridController : MonoBehaviour { public int size = 32; - + public float perlinScale = 16; + public Vector2 offsetChange = new Vector2(1, 0); + private Vector2 offset; + public Material gridMaterial; private float[] _values; private ComputeBuffer buffer; @@ -18,18 +18,18 @@ public class GridController : MonoBehaviour { _values = new float[size * size]; for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { - SetValue(x, y, Random.value); + SetValue(x, y, Mathf.PerlinNoise((x + offset.x) * perlinScale, (y + offset.y) * perlinScale)); } } - Debug.Log($"{_values.Length} values regenerated."); + // Debug.Log($"{_values.Length} values regenerated."); // Debug.Log(String.Join(", ", _values.ToList().ConvertAll(i => i.ToString()).ToArray())); } private void Start() { - buffer = new ComputeBuffer(size * size, 4); + offset = new Vector2(0, 0); + buffer = new ComputeBuffer((int) Mathf.Pow(2048, 2), 4); regenerateValues(); - UpdateShader(); } @@ -41,13 +41,15 @@ public class GridController : MonoBehaviour { } private void Update() { - if (Input.GetKey("space")) { - Debug.Log("Reloading values..."); + // if (Input.GetKey("space")) { + // Debug.Log("Reloading values..."); regenerateValues(); - Debug.Log("Values generated. Updating Shader..."); + // Debug.Log("Values generated. Updating Shader..."); UpdateShader(); - Debug.Log("Done."); - } + // Debug.Log("Done."); + offset += offsetChange * Time.deltaTime; + // } + } private void OnApplicationQuit() {