Skip to content

Commit

Permalink
Scope: bug fix and heightPadding
Browse files Browse the repository at this point in the history
  • Loading branch information
ludzeller committed Feb 4, 2022
1 parent 839a625 commit 11c0b4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions Assets/Resources/Prefabs/Scope.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -2953,6 +2953,7 @@ MonoBehaviour:
onlineMaterial: {fileID: 2100000, guid: b2ea714ecc13cb54a9f1173f22538e09, type: 2}
waveWidth: 1024
waveHeight: 512
heightPadding: 10
sampleStep: 512
doTriggering: 1
offset: 0
Expand Down
12 changes: 10 additions & 2 deletions Assets/Scripts/Oscillator/waveViz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 11c0b4e

Please sign in to comment.