1
0
mirror of https://github.com/psychopy/psychojs.git synced 2025-05-11 16:18:10 +00:00
psychojs/src/visual/shaders/sqrXsqrShader.frag

32 lines
937 B
GLSL

/**
* Square wave multiplied by another square wave.
* https://en.wikipedia.org/wiki/Square_wave
*
* @author Nikita Agafonov
* @copyright (c) 2020-2022 Open Science Tools Ltd. (https://opensciencetools.org)
* @license Distributed under the terms of the MIT License
* @description Creates an image of two 2d square waves multiplied with each other.
* @usedby GratingStim.js
*/
#version 300 es
precision mediump float;
in vec2 vUvs;
out vec4 shaderOut;
#define M_PI 3.14159265358979
#define PI2 2.* M_PI
uniform float uFreq;
uniform float uPhase;
uniform vec3 uColor;
void main() {
vec2 uv = vUvs;
float sx = sign(sin((uFreq * uv.x + uPhase) * PI2));
float sy = sign(sin((uFreq * uv.y + uPhase) * PI2));
float s = sx * sy;
// it's important to convert to [0, 1] while multiplication to uColor, not before, to preserve desired coloring functionality
shaderOut = vec4(vec3(s) * uColor * .5 + .5, 1.0);
}