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,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;

View File

@@ -1,14 +1,14 @@
using System;
using System.Linq;
using UnityEngine;
using Random = UnityEngine.Random;
using UnityEngine;
/// <summary>
/// A simple Grid Rendering Controller using MeshRenderer.
/// </summary>
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() {