From 11c0b4efde3f3c761aa7ea003fea7dbc78f38109 Mon Sep 17 00:00:00 2001 From: Ludwig Zeller Date: Fri, 4 Feb 2022 13:08:43 +0100 Subject: [PATCH] Scope: bug fix and heightPadding --- Assets/Resources/Prefabs/Scope.prefab | 1 + Assets/Scripts/Oscillator/waveViz.cs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Assets/Resources/Prefabs/Scope.prefab b/Assets/Resources/Prefabs/Scope.prefab index 83b674bd1..461ec8869 100644 --- a/Assets/Resources/Prefabs/Scope.prefab +++ b/Assets/Resources/Prefabs/Scope.prefab @@ -2953,6 +2953,7 @@ MonoBehaviour: onlineMaterial: {fileID: 2100000, guid: b2ea714ecc13cb54a9f1173f22538e09, type: 2} waveWidth: 1024 waveHeight: 512 + heightPadding: 10 sampleStep: 512 doTriggering: 1 offset: 0 diff --git a/Assets/Scripts/Oscillator/waveViz.cs b/Assets/Scripts/Oscillator/waveViz.cs index bc866cdd3..7b8dd7250 100644 --- a/Assets/Scripts/Oscillator/waveViz.cs +++ b/Assets/Scripts/Oscillator/waveViz.cs @@ -32,6 +32,7 @@ public class waveViz : MonoBehaviour public int waveWidth = 256; public int waveHeight = 64; + public int heightPadding = 2; public int sampleStep = 512; // should not be higher than buffer size, otherwise looped data? public bool doTriggering = false; @@ -110,6 +111,12 @@ void Awake() void Start() { onlineMaterial.mainTexture = onlineTexture; + + + // init black screen + RenderTexture.active = offlineTexture; + GL.Clear(false, true, Color.black); + Graphics.CopyTexture(offlineTexture, onlineTexture); } int tempIndex; @@ -157,7 +164,7 @@ void RenderGLToTexture(int width, int height, Material material) while (kk < fullBuffer.Length - renderBuffer.Length) { // search for first 0-pass from right and then take as offset - if (/*(fullBuffer[fullBuffer.Length - 1 - kk] > 0f && !lastWasPositive)*/ (fullBuffer[fullBuffer.Length - 1 - kk] < 0f && lastWasPositive)) // triggers on rising zero crossing only + if ((fullBuffer[fullBuffer.Length - 1 - kk] > 0f && !lastWasPositive) /*(fullBuffer[fullBuffer.Length - 1 - kk] < 0f && lastWasPositive)*/) // triggers on rising zero crossing only { foundZeroCrossing = true; break; @@ -188,7 +195,8 @@ void RenderGLToTexture(int width, int height, Material material) for (int i = 0; i < renderBuffer.Length; i++) { - GL.Vertex3(i, (1f - (renderBuffer[i] + 1f) * 0.5f) * height, 0); // 3px padding + //GL.Vertex3(i, height - (renderBuffer[i] + 1f) * 0.5f * height, 0); // 2px padding + GL.Vertex3(i, Utils.map(renderBuffer[i], -1f, 1f, height - heightPadding, heightPadding), 0); // 2px padding } GL.End();