Light Waveguide
Waves travel through a guide that splits into two branches. A simplified light-wave model; colors show the field, not the color of the light.
Published
No video preview yet
Source
use "@hyle/maths";
use models { OpticalField };
// Finite circular dielectric tubes: two outputs diverge in both Y and Z.
// Compute bend positions once per X plane, then sample epsilon at Yee edges.
fn separation(x: Float) -> Float {
let progress=maths::clip((x+8.0)/30.0,0.0,1.0);
return 10.0*progress*progress*(3.0-2.0*progress);
}
fn dielectric(y: Float, z: Float, split: Float) -> Float {
if maths::abs(maths::abs(y)-split) > 3.5 || maths::abs(maths::abs(z)-0.5*split) > 3.5 { return 1.0; }
let upper=(y-split)*(y-split)+(z-0.5*split)*(z-0.5*split);
let lower=(y+split)*(y+split)+(z+0.5*split)*(z+0.5*split);
return 1.0+3.0*maths::clip(3.5-maths::sqrt(maths::minimum(upper,lower)),0.0,1.0);
}
fn source(x: Int, y: Float, z: Float) -> Float {
if x == -22 { return maths::exp(-(y*y+z*z)/3.0); }
return 0.0;
}
// 65 x 41 x 29 field sites, six-cell-wide guides. Vacuum still participates in
// Maxwell's equations; rendering can hide quiet vacuum without removing it.
for x in -32..33 {
let split=separation(x+0.0);
let halfSplit=separation(x+0.5);
let xEdge=(maths::abs(x+0.0)-26.0)/6.0;
place OpticalField in box([x,-20,-14],[x+1,21,15]) {
let y=position.y+0.0; let z=position.z+0.0;
let edge=maths::maximum(0.0,maths::maximum(xEdge,
maths::maximum((maths::abs(y)-14.0)/6.0,(maths::abs(z)-8.0)/6.0)));
set target.epsilonX=dielectric(y,z,halfSplit);
set target.epsilonY=dielectric(y+0.5,z,split);
set target.epsilonZ=dielectric(y,z+0.5,split);
set target.damping=maths::exp(-0.22*edge*edge);
set target.source=source(x,y,z+0.5);
}
}