From 85992cb492998bfa83e0e6d12d2b37d67df6f2c6 Mon Sep 17 00:00:00 2001 From: glopesdev Date: Thu, 25 Mar 2021 01:41:49 +0000 Subject: [PATCH] Fix gratings rotation pivot and simplify shader --- BonVision/Primitives/DrawGratings.bonsai | 77 ++++++++---------------- BonVision/Shaders/Gratings.frag | 5 +- 2 files changed, 27 insertions(+), 55 deletions(-) diff --git a/BonVision/Primitives/DrawGratings.bonsai b/BonVision/Primitives/DrawGratings.bonsai index 6920b14..3baa220 100644 --- a/BonVision/Primitives/DrawGratings.bonsai +++ b/BonVision/Primitives/DrawGratings.bonsai @@ -1,4 +1,4 @@ - + + Draws parameterized 2D sinewave gratings. @@ -144,6 +145,13 @@ X 1 + + + + + Y + 1 + @@ -164,44 +172,16 @@ - single( -Item1 * Math.Cos(Item3) * Item2 -) + new( +single(Item1 * Math.Cos(Item4) * Item3) as Fx, +single(Item2 * Math.Sin(Item4) * Item3) as Fy) - - - frequency_x - Gratings - - - - - - - Y - 1 - - - - 10 - - - - - 0 - - - - - - - single( -Item1 * Math.Sin(Item3) * Item2 -) + + Fx,Fy - frequency_y + frequency Gratings @@ -211,26 +191,19 @@ Item1 * Math.Sin(Item3) * Item2 + - + - - + - - - - - - - - - - - - - - + + + + + + + diff --git a/BonVision/Shaders/Gratings.frag b/BonVision/Shaders/Gratings.frag index c7bc151..cf1827e 100644 --- a/BonVision/Shaders/Gratings.frag +++ b/BonVision/Shaders/Gratings.frag @@ -1,10 +1,9 @@ #version 400 const float pi = 3.1415926535897932384626433832795; const float sqrtTwoPi = sqrt(2 * pi); +uniform vec2 frequency; uniform float radius = 1; uniform float aperture = 0; -uniform float frequency_x = 1; -uniform float frequency_y = 0; uniform float contrast = 1; uniform float phase = 0; uniform float opacity = 1; @@ -14,7 +13,7 @@ out vec4 fragColor; void main() { - float value = texCoord.x * frequency_x + texCoord.y * frequency_y + phase; + float value = (texCoord.x - 0.5) * frequency.x + (texCoord.y - 0.5) * frequency.y + phase; if (threshold < 0) value = sin(value * 2 * pi); // sinewave else value = mod(value, 1) > threshold ? -1 : 1; // square modulation