-
Notifications
You must be signed in to change notification settings - Fork 8
Aspect ratio of shader patterns
The shader file SquareWaveGratingMix3.cl
illustrates how to consider the display's aspect ratio. In future versions it is planned that shaders get access to the current aspect ration set in QDSpy; currently, this value needs to be defined explictiely.
The aspect ratio is defined as y-to-x:
#define ar_xy 2.0
To account for that, I modified/added the following lines:
rot_deg = obj_xy_rot[2] /pi2 *360;
l = perLen_um *(ar_xy +(1.-ar_xy) *abs(mod(rot_deg, 180.) -90.) /90.);
inten = round((sin(((b.x)/l +time_s/perDur_s) *pi2) +1.0)/2.0);
rot_deg
is the angle in degrees (from radians); it probably can be simplified using radians, but for me it was easier to understand with angles.
l
is the bar widh; it is scaled depending on the angle. The scaling is a linear function of the angle, of course, no sin()
or something. The bar width is scaled by a factor between the aspect ratio (e.g. 2) and 1. This factor just depends on the angle (accounting for periodicity).
It works for the "the y axis is stretched by a factor of 2" case; for aspect ratios smaller than 1 (x is wider than y), it needs to be tested. On my screen, when the stimulus play, the bar is wider the more the angle approaches the horizontal and gets narrower, when the angle approaches the vertical.
This python script (e.g. for a jupyter notebook) illustrates the factor:
import numpy as np
import matplotlib.pyplot as plt
a_deg = [a*10 for a in range(37)]
ar_xy = 0.5
cfs = []
for a in a_deg:
cf = ar_xy +(1 -ar_xy)* (abs((a % 180) -90) /90)
cfs.append(cf)
print(f"{a:3.0f}° = {cf:3.3f}")
fig, ax = plt.subplots()
ax.plot(a_deg, cfs, linewidth=2.0)
plt.show()
- Release notes
- Installation
2.1. ... under Windows
2.2. ... under Linux (experimental) - Using a LightCrafter DLP 230NP
- Notes
4.1. Aspect ratio of shader patterns