1
0
mirror of https://github.com/psychopy/psychojs.git synced 2025-05-10 10:40:54 +00:00

radial stim generation in shaders;

This commit is contained in:
lgtst 2022-07-01 15:24:18 +03:00
parent fa731254bc
commit 36cdf51a87
2 changed files with 48 additions and 1 deletions

View File

@ -26,6 +26,7 @@ import gaussShader from "./shaders/gaussShader.frag";
import crossShader from "./shaders/crossShader.frag";
import radRampShader from "./shaders/radRampShader.frag";
import raisedCosShader from "./shaders/raisedCosShader.frag";
import radialStim from "./shaders/radialShader.frag";
/**
* Grating Stimulus.
@ -263,6 +264,15 @@ export class GratingStim extends VisualStim
uColor: [1., 1., 1.],
uAlpha: 1.0
}
},
radialStim: {
shader: radialStim,
uniforms: {
uFreq: 20.0,
uPhase: 0.0,
uColor: [1., 1., 1.],
uAlpha: 1.0
}
}
};
@ -742,7 +752,8 @@ export class GratingStim extends VisualStim
const maskMesh = this._getPixiMeshFromPredefinedShaders(this._mask);
const rt = PIXI.RenderTexture.create({
width: this._size_px[0],
height: this._size_px[1]
height: this._size_px[1],
scaleMode: this._interpolate ? PIXI.SCALE_MODES.LINEAR : PIXI.SCALE_MODES.NEAREST
});
this.win._renderer.render(maskMesh, {
renderTexture: rt

View File

@ -0,0 +1,36 @@
/**
* Radial grating.
*
* @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 2d radial grating image. Based on https://www.shadertoy.com/view/wtjGzt
* @usedby GratingStim.js
*/
#version 300 es
precision mediump float;
in vec2 vUvs;
out vec4 shaderOut;
uniform float uFreq;
uniform float uPhase;
uniform vec3 uColor;
uniform float uAlpha;
#define M_PI 3.14159265358979
#define PI2 2.* M_PI
float aastep(float x) { // --- antialiased step(.5)
float w = fwidth(x); // pixel width. NB: x must not be discontinuous or factor discont out
return smoothstep(.7,-.7,(abs(fract(x-.25)-.5)-.25)/w); // just use (offseted) smooth squares
}
void main() {
vec2 uv = vUvs * 2. - 1.;
// converting first to [-1, 1] space to get the proper color functionality
// then back to [0, 1]
float v = uFreq * atan(uv.y, uv.x) / 6.28;
float s = aastep(v) * 2. - 1.;
shaderOut = vec4(vec3(s) * uColor * .5 + .5, 1.0) * uAlpha;
}