Files
Interferometre-de-Michelson/michelson_web.frag
2025-12-29 13:43:05 +01:00

72 lines
2.1 KiB
GLSL

#version 100
precision highp float;
varying vec2 fragTexCoord;
varying vec4 fragColor;
uniform vec2 center;
uniform float screenHeight;
uniform float d1;
uniform float d2;
uniform float angleM1;
uniform float angleM1_Y;
uniform float zoom;
uniform float lambdas[10];
uniform int lambdasCount;
const float PI = 3.14159265359;
vec3 WavelengthToRGB(float l) {
float r = 0.0; float g = 0.0; float b = 0.0;
if (l >= 380.0 && l < 440.0) { r = -(l - 440.0) / (440.0 - 380.0); b = 1.0; }
else if (l >= 440.0 && l < 490.0) { g = (l - 440.0) / (490.0 - 440.0); b = 1.0; }
else if (l >= 490.0 && l < 510.0) { g = 1.0; b = -(l - 510.0) / (510.0 - 490.0); }
else if (l >= 510.0 && l < 580.0) { r = (l - 510.0) / (580.0 - 510.0); g = 1.0; }
else if (l >= 580.0 && l < 645.0) { r = 1.0; g = -(l - 645.0) / (645.0 - 580.0); }
else if (l >= 645.0 && l <= 780.0) { r = 1.0; }
float factor = 1.0;
if (l >= 380.0 && l < 420.0) factor = 0.3 + 0.7 * (l - 380.0) / (420.0 - 380.0);
else if (l >= 380.0 && l <= 645.0) factor = 1.0;
else if (l > 700.0 && l <= 780.0) factor = 0.3 + 0.7 * (780.0 - l) / (780.0 - 700.0);
return vec3(r * factor, g * factor, b * factor);
}
void main() {
float pixelX = gl_FragCoord.x;
float pixelY = screenHeight - gl_FragCoord.y;
float deltaLnm = 2.0 * (d1 - d2) * 1000.0;
float relX = (pixelX - center.x) * zoom;
float relY = (pixelY - center.y) * zoom;
float radiusSq = relX * relX + relY * relY;
float ringFactorBase = radiusSq * 0.065;
float wDelta = (relX * angleM1 + relY * angleM1_Y) * 200.0;
float currDeltaBase = deltaLnm + wDelta;
vec3 accumColor = vec3(0.0);
for(int i = 0; i < 10; i++) {
if (i >= lambdasCount) break;
float l = lambdas[i];
if (l < 1.0) l = 550.0;
vec3 baseColorVec = WavelengthToRGB(l);
float currDelta = currDeltaBase - ringFactorBase;
float K = PI / l;
float phase = currDelta * K;
float intensity = cos(phase);
intensity = intensity * intensity;
accumColor += baseColorVec * intensity;
}
gl_FragColor = vec4(accumColor, 1.0);
}