Skip to content

Commit 11c0b4e

Browse files
committed
Scope: bug fix and heightPadding
1 parent 839a625 commit 11c0b4e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Assets/Resources/Prefabs/Scope.prefab

+1
Original file line numberDiff line numberDiff line change
@@ -2953,6 +2953,7 @@ MonoBehaviour:
29532953
onlineMaterial: {fileID: 2100000, guid: b2ea714ecc13cb54a9f1173f22538e09, type: 2}
29542954
waveWidth: 1024
29552955
waveHeight: 512
2956+
heightPadding: 10
29562957
sampleStep: 512
29572958
doTriggering: 1
29582959
offset: 0

Assets/Scripts/Oscillator/waveViz.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class waveViz : MonoBehaviour
3232

3333
public int waveWidth = 256;
3434
public int waveHeight = 64;
35+
public int heightPadding = 2;
3536
public int sampleStep = 512; // should not be higher than buffer size, otherwise looped data?
3637
public bool doTriggering = false;
3738

@@ -110,6 +111,12 @@ void Awake()
110111
void Start()
111112
{
112113
onlineMaterial.mainTexture = onlineTexture;
114+
115+
116+
// init black screen
117+
RenderTexture.active = offlineTexture;
118+
GL.Clear(false, true, Color.black);
119+
Graphics.CopyTexture(offlineTexture, onlineTexture);
113120
}
114121

115122
int tempIndex;
@@ -157,7 +164,7 @@ void RenderGLToTexture(int width, int height, Material material)
157164

158165
while (kk < fullBuffer.Length - renderBuffer.Length)
159166
{ // search for first 0-pass from right and then take as offset
160-
if (/*(fullBuffer[fullBuffer.Length - 1 - kk] > 0f && !lastWasPositive)*/ (fullBuffer[fullBuffer.Length - 1 - kk] < 0f && lastWasPositive)) // triggers on rising zero crossing only
167+
if ((fullBuffer[fullBuffer.Length - 1 - kk] > 0f && !lastWasPositive) /*(fullBuffer[fullBuffer.Length - 1 - kk] < 0f && lastWasPositive)*/) // triggers on rising zero crossing only
161168
{
162169
foundZeroCrossing = true;
163170
break;
@@ -188,7 +195,8 @@ void RenderGLToTexture(int width, int height, Material material)
188195

189196
for (int i = 0; i < renderBuffer.Length; i++)
190197
{
191-
GL.Vertex3(i, (1f - (renderBuffer[i] + 1f) * 0.5f) * height, 0); // 3px padding
198+
//GL.Vertex3(i, height - (renderBuffer[i] + 1f) * 0.5f * height, 0); // 2px padding
199+
GL.Vertex3(i, Utils.map(renderBuffer[i], -1f, 1f, height - heightPadding, heightPadding), 0); // 2px padding
192200
}
193201

194202
GL.End();

0 commit comments

Comments
 (0)