edit
This commit is contained in:
7
Makefile
7
Makefile
@ -3,6 +3,13 @@ michelson: main.c
|
||||
|
||||
clean:
|
||||
rm -f michelson
|
||||
rm -r web
|
||||
|
||||
run:
|
||||
./michelson
|
||||
|
||||
web: main.c
|
||||
mkdir -p web && emcc -o web/index.html main.c -Os -Wall -std=c99 -DPLATFORM_WEB -s USE_GLFW=3 -s ALLOW_MEMORY_GROWTH=1 -I. --shell-file minshell.html --preload-file michelson_web.frag libraylib.web.a
|
||||
|
||||
webrun:
|
||||
cd web && python -m http.server 8000 && cd ..
|
||||
|
||||
1
main.c
1
main.c
@ -476,6 +476,7 @@ void UpdateDrawFrame(void) {
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
|
||||
int main () {
|
||||
//SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||
#if !defined(PLATFORM_WEB)
|
||||
|
||||
@ -1,71 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
<!doctypehtml><html lang=fr><head><meta charset=utf-8><meta content="text/html; charset=utf-8"http-equiv=Content-Type><title>Interferometre Michelson - Web</title><style>body{margin:0;padding:0;background-color:#111;overflow:hidden;display:flex;justify-content:center;align-items:center;height:100vh;width:100vw}canvas.emscripten{border:0 none;background-color:#000;display:block;aspect-ratio:16/9;max-width:100vw;max-height:100vh;height:auto;width:auto;box-shadow:0 0 20px rgba(0,0,0,.5);image-rendering:-moz-crisp-edges;image-rendering:-webkit-optimize-contrast;image-rendering:crisp-edges;image-rendering:pixelated}</style></head><body><canvas class=emscripten id=canvas oncontextmenu=event.preventDefault() tabindex=-1></canvas><script>var Module={print:function(n){console.log(n)},printErr:function(n){console.error(n)},canvas:document.getElementById("canvas")}</script><script async src=index.js></script></body></html>
|
||||
File diff suppressed because one or more lines are too long
BIN
web/index.wasm
BIN
web/index.wasm
Binary file not shown.
Reference in New Issue
Block a user