Skip to content

Commit

Permalink
Fix gratings rotation pivot and simplify shader
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Mar 25, 2021
1 parent edaf04e commit 85992cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 55 deletions.
77 changes: 25 additions & 52 deletions BonVision/Primitives/DrawGratings.bonsai
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.6.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bv="clr-namespace:BonVision;assembly=BonVision"
Expand All @@ -7,6 +7,7 @@
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns="https://bonsai-rx.org/2018/workflow">
<Description>Draws parameterized 2D sinewave gratings.</Description>
<Workflow>
<Nodes>
<Expression xsi:type="WorkflowInput">
Expand Down Expand Up @@ -144,6 +145,13 @@
<MemberName>X</MemberName>
<Value>1</Value>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="ExtentY" />
</Expression>
<Expression xsi:type="PropertySource" TypeArguments="gl:Scale,sys:Single">
<MemberName>Y</MemberName>
<Value>1</Value>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="Angle" />
</Expression>
Expand All @@ -164,44 +172,16 @@
<Combinator xsi:type="rx:Zip" />
</Expression>
<Expression xsi:type="scr:ExpressionTransform">
<scr:Expression>single(
Item1 * Math.Cos(Item3) * Item2
)</scr:Expression>
<scr:Expression>new(
single(Item1 * Math.Cos(Item4) * Item3) as Fx,
single(Item2 * Math.Sin(Item4) * Item3) as Fy)</scr:Expression>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="gl:UpdateUniform">
<gl:UniformName>frequency_x</gl:UniformName>
<gl:ShaderName>Gratings</gl:ShaderName>
</Combinator>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="ExtentY" />
</Expression>
<Expression xsi:type="PropertySource" TypeArguments="gl:Scale,sys:Single">
<MemberName>Y</MemberName>
<Value>1</Value>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="FloatProperty">
<Value>10</Value>
</Combinator>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="FloatProperty">
<Value>0</Value>
</Combinator>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Zip" />
</Expression>
<Expression xsi:type="scr:ExpressionTransform">
<scr:Expression>single(
Item1 * Math.Sin(Item3) * Item2
)</scr:Expression>
<Expression xsi:type="MemberSelector">
<Selector>Fx,Fy</Selector>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="gl:UpdateUniform">
<gl:UniformName>frequency_y</gl:UniformName>
<gl:UniformName>frequency</gl:UniformName>
<gl:ShaderName>Gratings</gl:ShaderName>
</Combinator>
</Expression>
Expand All @@ -211,26 +191,19 @@ Item1 * Math.Sin(Item3) * Item2
<Edge From="0" To="2" Label="Source1" />
<Edge From="0" To="4" Label="Source1" />
<Edge From="0" To="6" Label="Source1" />
<Edge From="0" To="8" Label="Source1" />
<Edge From="1" To="2" Label="Source2" />
<Edge From="2" To="7" Label="Source1" />
<Edge From="2" To="9" Label="Source1" />
<Edge From="3" To="4" Label="Source2" />
<Edge From="3" To="13" Label="Source2" />
<Edge From="4" To="7" Label="Source3" />
<Edge From="4" To="9" Label="Source2" />
<Edge From="5" To="6" Label="Source2" />
<Edge From="5" To="12" Label="Source2" />
<Edge From="6" To="7" Label="Source2" />
<Edge From="7" To="8" Label="Source1" />
<Edge From="8" To="9" Label="Source1" />
<Edge From="9" To="11" Label="Source1" />
<Edge From="9" To="12" Label="Source1" />
<Edge From="9" To="13" Label="Source1" />
<Edge From="10" To="11" Label="Source2" />
<Edge From="11" To="14" Label="Source1" />
<Edge From="12" To="14" Label="Source2" />
<Edge From="13" To="14" Label="Source3" />
<Edge From="14" To="15" Label="Source1" />
<Edge From="15" To="16" Label="Source1" />
<Edge From="16" To="17" Label="Source1" />
<Edge From="6" To="9" Label="Source4" />
<Edge From="7" To="8" Label="Source2" />
<Edge From="8" To="9" Label="Source3" />
<Edge From="9" To="10" Label="Source1" />
<Edge From="10" To="11" Label="Source1" />
<Edge From="11" To="12" Label="Source1" />
<Edge From="12" To="13" Label="Source1" />
</Edges>
</Workflow>
</Expression>
Expand Down
5 changes: 2 additions & 3 deletions BonVision/Shaders/Gratings.frag
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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

Expand Down

0 comments on commit 85992cb

Please sign in to comment.