remove select color code, fix line size 0 not displaying correctly, add code to use perlin noise instead of true random

This commit is contained in:
Xevion
2020-07-08 03:04:42 -05:00
parent 911cc1f687
commit 5fc767cede
2 changed files with 22 additions and 27 deletions

View File

@@ -74,28 +74,21 @@ Shader "PDT Shaders/TestGrid" {
float brightness = _InactiveColor.w; float brightness = _InactiveColor.w;
// Line Color Check // 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; color = _LineColor;
brightness = color.w; 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 { } else {
float pos = id.y * _GridSize + id.x; float pos = id.y * _GridSize + id.x;
if(pos < _valueLength && _values[pos] >= 0.5) { if(pos < _valueLength) {
color = lerp(_InactiveColor, _ActiveColor, _values[pos]); color = lerp(_InactiveColor, _ActiveColor, _values[pos]);
brightness = color.w; brightness = color.w;
} }
} }
// Clip transparent spots using alpha cutout // Clip transparent spots using alpha cutout
if (brightness == 0.0) { if (brightness == 0.0)
clip(c.a - 1.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 // Metallic and smoothness come from slider variables

View File

@@ -1,13 +1,13 @@
using System; using UnityEngine;
using System.Linq;
using UnityEngine;
using Random = UnityEngine.Random;
/// <summary> /// <summary>
/// A simple Grid Rendering Controller using MeshRenderer. /// A simple Grid Rendering Controller using MeshRenderer.
/// </summary> /// </summary>
public class GridController : MonoBehaviour { public class GridController : MonoBehaviour {
public int size = 32; public int size = 32;
public float perlinScale = 16;
public Vector2 offsetChange = new Vector2(1, 0);
private Vector2 offset;
public Material gridMaterial; public Material gridMaterial;
private float[] _values; private float[] _values;
@@ -18,18 +18,18 @@ public class GridController : MonoBehaviour {
_values = new float[size * size]; _values = new float[size * size];
for (int x = 0; x < size; x++) { for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) { 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())); // Debug.Log(String.Join(", ", _values.ToList().ConvertAll(i => i.ToString()).ToArray()));
} }
private void Start() { private void Start() {
buffer = new ComputeBuffer(size * size, 4); offset = new Vector2(0, 0);
buffer = new ComputeBuffer((int) Mathf.Pow(2048, 2), 4);
regenerateValues(); regenerateValues();
UpdateShader(); UpdateShader();
} }
@@ -41,13 +41,15 @@ public class GridController : MonoBehaviour {
} }
private void Update() { private void Update() {
if (Input.GetKey("space")) { // if (Input.GetKey("space")) {
Debug.Log("Reloading values..."); // Debug.Log("Reloading values...");
regenerateValues(); regenerateValues();
Debug.Log("Values generated. Updating Shader..."); // Debug.Log("Values generated. Updating Shader...");
UpdateShader(); UpdateShader();
Debug.Log("Done."); // Debug.Log("Done.");
} offset += offsetChange * Time.deltaTime;
// }
} }
private void OnApplicationQuit() { private void OnApplicationQuit() {