Skip to content

Interactive 2D wave optics simulator. Turn any image into a refractive scene, add sources, watch waves refract, diffract and interfere. Probes, intensity maps, video export.

C#

Absorbing parts: a lens or shape paints its absorption into the blue channel over a quadratic ramp

Alexander Graef54974d39752c
diff --git a/CLAUDE.md b/CLAUDE.md
index 91629c0..59e5906 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -179,7 +179,8 @@ FrameStore: native memory up to the budget, the rest in a temp file (%LOCALAPPDA
the shapes under `ShapePart` (`PolygonPart` regular, `RectanglePart`, `EllipsePart` as a polygon of a vertex per 3 px of
circumference, 2026-10-20; both carry a `Linked` flag, the chain toggle between width and length of the image editors,
which keeps them equal through the boxes, the grip and the file, `TrianglePart` by base and base angles with presets, `OutlinePart` by points), `FiberPart`, `BraggReflectorPart`, `GrinLensPart` in `Project.Parts`, one XML element
- per kind; painted into the scene's red channel (4 × 4 supersampled, a mirror by the pixel-centre test as red 0, a
+ per kind; a lens or shape can absorb (2026-10-20, Jeroen's point 11: Absorption 0..255 painted into blue over a quadratic
+ ramp from the outline, the larger blue kept; measured, see `OpticalParts.md` 6a); painted into the scene's red channel (4 × 4 supersampled, a mirror by the pixel-centre test as red 0, a
coating band of √n, later parts over earlier ones; a part's centre is the corner of pixel (X, Y), so even sizes cover
whole pixels). A part edit is a simulation edit. Tree folder "Parts", "+ Part" opens a menu of kinds (Space, arrows,
Enter), a handle plus a rotation lever on the pictures; while selected, the outline as painted in the accent colour,
diff --git a/OpticalParts.md b/OpticalParts.md
index 02fc008..fb81254 100644
--- a/OpticalParts.md
+++ b/OpticalParts.md
@@ -43,8 +43,10 @@ diameter, cladding index and thickness; a "Shape coordinates (list)" box). Mirro
before the pixels go anywhere. Both engines, the glowing outline over the pictures (`GlowingEdges.Compute` in
`PreviewPane.OnScenePixelsChanged`), the export outline (`MainWindow.Export.cs`) and the scratch frames then
work unchanged. The price is Jeroen's own range: index 1.00 to 2.55 in steps of 0.01 (red = index × 100).
-2. **Red only.** The painter writes the red channel and never touches green or blue. Green shades are source
- frequencies (WaveSimulator2D's warning: never anti-alias green), blue is damping; both stay as the image has them.
+2. **Red, and blue for absorbers.** The painter writes the red channel and never touches green: green shades are
+ source frequencies (WaveSimulator2D's warning: never anti-alias green). Blue is damping (each step a cell's
+ velocity times 1 − blue / 255); a lens or shape with an Absorption above 0 (Jeroen's point 11, 2026-10-20) paints
+ it there, keeping the larger of its value and the blue already there (the image's or an earlier part's).
3. **A red value of 0 is a mirror** (index 1000, commit `5dbefa6`, Jeroen's V0.30 rule). Red 1..99 is index 1.
4. **One subclass per kind, one XML element name per kind** (the user's choice: a schema can then say which
attributes each element requires). `OpticalPart` is abstract; `LensPart`, `PolygonPart`, `FiberPart`,
@@ -58,6 +60,16 @@ diameter, cladding index and thickness; a "Shape coordinates (list)" box). Mirro
outer boundary gets the index √n (rounded to 0.01), the quarter-wave idea without a wavelength tie. The hint
may say that a quarter-wave coating is λ / (4 √n) pixels thick, λ being the wavelength the source form shows.
Mirrors and Bragg reflectors ignore it.
+6a. **Absorption** (lens and shapes): Absorption (int, 0..255 as blue, 0) rising over AbsorptionRamp (int px,
+ 1..400, 40) from 0 at the outline as blue = round(Absorption × (δ / ramp)²), δ the depth of the pixel centre
+ (no supersampling: the profile is continuous and 0 at the outline); the ramp is cut to the deepest pixel centre
+ of a part thinner than twice it. A jump in damping reflects like a jump in index, so the profile and strength
+ were measured (2026-10-20): a pulse from an open grid onto a deep absorbing slab, the reflected peak against a
+ mirror slab's, for waves of level 120 and 60. At absorption 255 every profile reflects a lot (a 40 px ramp:
+ linear 9 / 25 %, quadratic 2 / 11 %, cubic 1.7 / 9 %, a smooth step 4.7 / 20 %, an error-function step
+ 4.2 / 18 %, Jeroen's √ band 4.5 / 16 %); at 64 a quadratic 80 px ramp reflects 0.5 / 1.5 % and lets nothing
+ through 160 px; at 16 the reflection is lower still but up to 6 % passes through 160 px. Quadratic was chosen.
+ Mirrors ignore it.
7. **Rasterisation**: 4 × 4 supersampling per pixel for refractive parts; each sample is classified (outside,
coating, body, or a GRIN/fibre zone), the sample indices are averaged (an existing red of 0 counts as index 1 in
that average) and rounded to red. A mirror part uses the pixel-centre test alone and writes red 0 (a half-covered
@@ -86,14 +98,14 @@ written `model:OpticalPart.X` and kind members `model:LensPart.R1`. Positions an
| `Normalize()` | abstract | | | |
**`LensPart`** — Mirror (bool, false), RefractiveIndex (1.00..2.55, 1.50; hidden/disabled while Mirror),
-Coating (int px, 0..50, 0), Diameter (int, 200, ≥ 2), R1 (double, 300), R2 (double, −300), Thickness (int, 40, ≥ 1).
+Coating (int px, 0..50, 0), Absorption (int, 0..255, 0), AbsorptionRamp (int px, 1..400, 40), Diameter (int, 200, ≥ 2), R1 (double, 300), R2 (double, −300), Thickness (int, 40, ≥ 1).
R is signed: R1 > 0 and R2 < 0 bulge outward (biconvex); 0 means flat; |R| < Diameter / 2 is clamped to Diameter / 2.
Shape in the part frame (x' along the axis, y' across): the strip |y'| ≤ D/2 between the surfaces
x'₁(y') = −t/2 + s₁(y') and x'₂(y') = t/2 + s₂(y'), with the sag s(y') = R − sign(R)·√(R² − y'²) for R ≠ 0 and
0 for flat; a point is inside when x'₁ ≤ x' ≤ x'₂ (empty where convex surfaces cross, which caps a thin lens).
A curved mirror is the same shape with Mirror on, e.g. R1 = −400, R2 = 0, Thickness 20.
-**`PolygonPart`** — Mirror, RefractiveIndex, Coating as the lens; Sides (int, 6, 3..64), Side (int px, 60, ≥ 2);
+**`PolygonPart`** — Mirror, RefractiveIndex, Coating, Absorption, AbsorptionRamp as the lens; Sides (int, 6, 3..64), Side (int px, 60, ≥ 2);
`Points` (a list, `[XmlElement("Point")]` of a small `PartPoint { X, Y }` record class, relative to the centre,
before rotation; empty by default). A non-empty list replaces the regular polygon. Regular: circumradius
R = Side / (2 sin(π / Sides)), the first vertex on +x'. A flat mirror is a thin rectangle from four points.
diff --git a/WaveDudeNext.WPF/Strings/Strings.DE.xaml b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
index 53b10ab..1fe572c 100644
--- a/WaveDudeNext.WPF/Strings/Strings.DE.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
@@ -534,11 +534,15 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Label.PartPoint.Y">Y</s:String>
<s:String x:Key="Hint.PartPoint.Y">Y relativ zum Mittelpunkt des Bauteils in Leinwandpixeln, vor der Drehung.</s:String>
<s:String x:Key="Label.LensPart.Mirror">Spiegel</s:String>
- <s:String x:Key="Hint.LensPart.Mirror">Das Bauteil als Spiegel statt als Linse. Brechungsindex und Entspiegelung werden dann ignoriert.</s:String>
+ <s:String x:Key="Hint.LensPart.Mirror">Das Bauteil als Spiegel statt als Linse. Brechungsindex, Entspiegelung und Absorption werden dann ignoriert.</s:String>
<s:String x:Key="Label.LensPart.RefractiveIndex">Brechungsindex</s:String>
<s:String x:Key="Hint.LensPart.RefractiveIndex">Brechungsindex des Glases, 1,00 bis 2,55 in Schritten von 0,01.</s:String>
<s:String x:Key="Label.LensPart.Coating">Entspiegelung</s:String>
<s:String x:Key="Hint.LensPart.Coating">Dicke in Pixeln des entspiegelnden Bands direkt innerhalb des Umrisses mit dem Index √n; 0 für keines. Eine λ/4-Schicht ist λ / (4 √n) Pixel dick, λ die Wellenlänge aus dem Quellenformular.</s:String>
+ <s:String x:Key="Label.LensPart.Absorption">Absorption</s:String>
+ <s:String x:Key="Hint.LensPart.Absorption">Wie stark das Bauteil Wellen absorbiert, 0 (gar nicht) bis 255, wie der Blaukanal des Szenenbilds. Sie steigt über die Absorptionsrampe vom Umriss an von null an, damit eine Welle in das Bauteil eindringt statt reflektiert zu werden. Ein Spiegel ignoriert sie.</s:String>
+ <s:String x:Key="Label.LensPart.AbsorptionRamp">Absorptionsrampe</s:String>
+ <s:String x:Key="Hint.LensPart.AbsorptionRamp">Tiefe in Pixeln, über die die Absorption vom Umriss an von null auf ihren vollen Wert steigt; je länger, desto weniger einer Welle wird reflektiert. Ein Bauteil, das dünner als die doppelte Rampe ist, erreicht seine volle Absorption in der Mitte.</s:String>
<s:String x:Key="Label.LensPart.Diameter">Durchmesser</s:String>
<s:String x:Key="Hint.LensPart.Diameter">Ausdehnung quer zur Achse in Pixeln.</s:String>
<s:String x:Key="Label.LensPart.IsConcave">Konkav (zerstreuend)</s:String>
@@ -550,11 +554,15 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Label.LensPart.Thickness">Mittendicke</s:String>
<s:String x:Key="Hint.LensPart.Thickness">Abstand der beiden Flächen auf der Achse in Pixeln.</s:String>
<s:String x:Key="Label.ShapePart.Mirror">Spiegel</s:String>
- <s:String x:Key="Hint.ShapePart.Mirror">Das Bauteil als Spiegel statt als Glas. Brechungsindex und Entspiegelung werden dann ignoriert.</s:String>
+ <s:String x:Key="Hint.ShapePart.Mirror">Das Bauteil als Spiegel statt als Glas. Brechungsindex, Entspiegelung und Absorption werden dann ignoriert.</s:String>
<s:String x:Key="Label.ShapePart.RefractiveIndex">Brechungsindex</s:String>
<s:String x:Key="Hint.ShapePart.RefractiveIndex">Brechungsindex des Glases, 1,00 bis 2,55 in Schritten von 0,01.</s:String>
<s:String x:Key="Label.ShapePart.Coating">Entspiegelung</s:String>
<s:String x:Key="Hint.ShapePart.Coating">Dicke in Pixeln des entspiegelnden Bands direkt innerhalb des Umrisses mit dem Index √n; 0 für keines. Eine λ/4-Schicht ist λ / (4 √n) Pixel dick, λ die Wellenlänge aus dem Quellenformular.</s:String>
+ <s:String x:Key="Label.ShapePart.Absorption">Absorption</s:String>
+ <s:String x:Key="Hint.ShapePart.Absorption">Wie stark das Bauteil Wellen absorbiert, 0 (gar nicht) bis 255, wie der Blaukanal des Szenenbilds. Sie steigt über die Absorptionsrampe vom Umriss an von null an, damit eine Welle in das Bauteil eindringt statt reflektiert zu werden. Ein Spiegel ignoriert sie.</s:String>
+ <s:String x:Key="Label.ShapePart.AbsorptionRamp">Absorptionsrampe</s:String>
+ <s:String x:Key="Hint.ShapePart.AbsorptionRamp">Tiefe in Pixeln, über die die Absorption vom Umriss an von null auf ihren vollen Wert steigt; je länger, desto weniger einer Welle wird reflektiert. Ein Bauteil, das dünner als die doppelte Rampe ist, erreicht seine volle Absorption in der Mitte.</s:String>
<s:String x:Key="Label.PolygonPart.Sides">Anzahl Seiten</s:String>
<s:String x:Key="Hint.PolygonPart.Sides">Anzahl der Seiten, 3 bis 64.</s:String>
<s:String x:Key="Label.PolygonPart.Side">Seitenlänge</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.EN.xaml b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
index 5f3035a..83a701a 100644
--- a/WaveDudeNext.WPF/Strings/Strings.EN.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
@@ -536,11 +536,15 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Label.PartPoint.Y">Y</s:String>
<s:String x:Key="Hint.PartPoint.Y">Y relative to the part's centre in canvas pixels, before rotation.</s:String>
<s:String x:Key="Label.LensPart.Mirror">Mirror</s:String>
- <s:String x:Key="Hint.LensPart.Mirror">Make the part a mirror instead of a lens. The refractive index and the coating are ignored then.</s:String>
+ <s:String x:Key="Hint.LensPart.Mirror">Make the part a mirror instead of a lens. The refractive index, the coating and the absorption are ignored then.</s:String>
<s:String x:Key="Label.LensPart.RefractiveIndex">Refractive index</s:String>
<s:String x:Key="Hint.LensPart.RefractiveIndex">Refractive index of the glass, 1.00 to 2.55 in steps of 0.01.</s:String>
<s:String x:Key="Label.LensPart.Coating">AR coating</s:String>
<s:String x:Key="Hint.LensPart.Coating">Thickness in pixels of the anti-reflection band just inside the outline, with the index √n; 0 for none. A quarter-wave coating is λ / (4 √n) pixels thick, λ being the wavelength the source form shows.</s:String>
+ <s:String x:Key="Label.LensPart.Absorption">Absorption</s:String>
+ <s:String x:Key="Hint.LensPart.Absorption">How strongly the part absorbs waves, 0 (not at all) to 255, as the scene image's blue channel. It rises from nothing at the outline over the absorption ramp, so a wave enters the part instead of being reflected. A mirror ignores it.</s:String>
+ <s:String x:Key="Label.LensPart.AbsorptionRamp">Absorption ramp</s:String>
+ <s:String x:Key="Hint.LensPart.AbsorptionRamp">Depth in pixels over which the absorption rises from nothing at the outline to its full value; the longer, the less of a wave is reflected. A part thinner than twice the ramp reaches its full absorption in its middle.</s:String>
<s:String x:Key="Label.LensPart.Diameter">Diameter</s:String>
<s:String x:Key="Hint.LensPart.Diameter">Extent across the axis in pixels.</s:String>
<s:String x:Key="Label.LensPart.IsConcave">Concave (diverging)</s:String>
@@ -552,11 +556,15 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Label.LensPart.Thickness">Centre thickness</s:String>
<s:String x:Key="Hint.LensPart.Thickness">Distance between the two surfaces on the axis in pixels.</s:String>
<s:String x:Key="Label.ShapePart.Mirror">Mirror</s:String>
- <s:String x:Key="Hint.ShapePart.Mirror">Make the part a mirror instead of glass. The refractive index and the coating are ignored then.</s:String>
+ <s:String x:Key="Hint.ShapePart.Mirror">Make the part a mirror instead of glass. The refractive index, the coating and the absorption are ignored then.</s:String>
<s:String x:Key="Label.ShapePart.RefractiveIndex">Refractive index</s:String>
<s:String x:Key="Hint.ShapePart.RefractiveIndex">Refractive index of the glass, 1.00 to 2.55 in steps of 0.01.</s:String>
<s:String x:Key="Label.ShapePart.Coating">AR coating</s:String>
<s:String x:Key="Hint.ShapePart.Coating">Thickness in pixels of the anti-reflection band just inside the outline, with the index √n; 0 for none. A quarter-wave coating is λ / (4 √n) pixels thick, λ being the wavelength the source form shows.</s:String>
+ <s:String x:Key="Label.ShapePart.Absorption">Absorption</s:String>
+ <s:String x:Key="Hint.ShapePart.Absorption">How strongly the part absorbs waves, 0 (not at all) to 255, as the scene image's blue channel. It rises from nothing at the outline over the absorption ramp, so a wave enters the part instead of being reflected. A mirror ignores it.</s:String>
+ <s:String x:Key="Label.ShapePart.AbsorptionRamp">Absorption ramp</s:String>
+ <s:String x:Key="Hint.ShapePart.AbsorptionRamp">Depth in pixels over which the absorption rises from nothing at the outline to its full value; the longer, the less of a wave is reflected. A part thinner than twice the ramp reaches its full absorption in its middle.</s:String>
<s:String x:Key="Label.PolygonPart.Sides">Number of sides</s:String>
<s:String x:Key="Hint.PolygonPart.Sides">Number of sides, 3 to 64.</s:String>
<s:String x:Key="Label.PolygonPart.Side">Side length</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.FR.xaml b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
index b275111..0b59346 100644
--- a/WaveDudeNext.WPF/Strings/Strings.FR.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
@@ -534,11 +534,15 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Label.PartPoint.Y">Y</s:String>
<s:String x:Key="Hint.PartPoint.Y">Y par rapport au centre du composant en pixels de la toile, avant rotation.</s:String>
<s:String x:Key="Label.LensPart.Mirror">Miroir</s:String>
- <s:String x:Key="Hint.LensPart.Mirror">Faire du composant un miroir au lieu d'une lentille. L'indice de réfraction et le traitement antireflet sont alors ignorés.</s:String>
+ <s:String x:Key="Hint.LensPart.Mirror">Faire du composant un miroir au lieu d'une lentille. L'indice de réfraction, le traitement antireflet et l'absorption sont alors ignorés.</s:String>
<s:String x:Key="Label.LensPart.RefractiveIndex">Indice de réfraction</s:String>
<s:String x:Key="Hint.LensPart.RefractiveIndex">Indice de réfraction du verre, de 1,00 à 2,55 par pas de 0,01.</s:String>
<s:String x:Key="Label.LensPart.Coating">Traitement antireflet</s:String>
<s:String x:Key="Hint.LensPart.Coating">Épaisseur en pixels de la bande antireflet juste à l'intérieur du contour, d'indice √n ; 0 pour aucune. Une couche quart d'onde fait λ / (4 √n) pixels, λ étant la longueur d'onde affichée dans le formulaire de la source.</s:String>
+ <s:String x:Key="Label.LensPart.Absorption">Absorption</s:String>
+ <s:String x:Key="Hint.LensPart.Absorption">Force avec laquelle le composant absorbe les ondes, de 0 (pas du tout) à 255, comme le canal bleu de l'image de la scène. Elle croît depuis zéro au contour le long de la rampe d'absorption, pour qu'une onde entre dans le composant au lieu d'être réfléchie. Un miroir l'ignore.</s:String>
+ <s:String x:Key="Label.LensPart.AbsorptionRamp">Rampe d'absorption</s:String>
+ <s:String x:Key="Hint.LensPart.AbsorptionRamp">Profondeur en pixels sur laquelle l'absorption croît de zéro au contour jusqu'à sa pleine valeur ; plus elle est longue, moins une onde est réfléchie. Un composant plus mince que deux fois la rampe atteint sa pleine absorption en son milieu.</s:String>
<s:String x:Key="Label.LensPart.Diameter">Diamètre</s:String>
<s:String x:Key="Hint.LensPart.Diameter">Étendue perpendiculaire à l'axe en pixels.</s:String>
<s:String x:Key="Label.LensPart.IsConcave">Concave (divergente)</s:String>
@@ -550,11 +554,15 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Label.LensPart.Thickness">Épaisseur au centre</s:String>
<s:String x:Key="Hint.LensPart.Thickness">Distance entre les deux surfaces sur l'axe en pixels.</s:String>
<s:String x:Key="Label.ShapePart.Mirror">Miroir</s:String>
- <s:String x:Key="Hint.ShapePart.Mirror">Faire du composant un miroir au lieu du verre. L'indice de réfraction et le traitement antireflet sont alors ignorés.</s:String>
+ <s:String x:Key="Hint.ShapePart.Mirror">Faire du composant un miroir au lieu du verre. L'indice de réfraction, le traitement antireflet et l'absorption sont alors ignorés.</s:String>
<s:String x:Key="Label.ShapePart.RefractiveIndex">Indice de réfraction</s:String>
<s:String x:Key="Hint.ShapePart.RefractiveIndex">Indice de réfraction du verre, de 1,00 à 2,55 par pas de 0,01.</s:String>
<s:String x:Key="Label.ShapePart.Coating">Traitement antireflet</s:String>
<s:String x:Key="Hint.ShapePart.Coating">Épaisseur en pixels de la bande antireflet juste à l'intérieur du contour, d'indice √n ; 0 pour aucune. Une couche quart d'onde fait λ / (4 √n) pixels, λ étant la longueur d'onde affichée dans le formulaire de la source.</s:String>
+ <s:String x:Key="Label.ShapePart.Absorption">Absorption</s:String>
+ <s:String x:Key="Hint.ShapePart.Absorption">Force avec laquelle le composant absorbe les ondes, de 0 (pas du tout) à 255, comme le canal bleu de l'image de la scène. Elle croît depuis zéro au contour le long de la rampe d'absorption, pour qu'une onde entre dans le composant au lieu d'être réfléchie. Un miroir l'ignore.</s:String>
+ <s:String x:Key="Label.ShapePart.AbsorptionRamp">Rampe d'absorption</s:String>
+ <s:String x:Key="Hint.ShapePart.AbsorptionRamp">Profondeur en pixels sur laquelle l'absorption croît de zéro au contour jusqu'à sa pleine valeur ; plus elle est longue, moins une onde est réfléchie. Un composant plus mince que deux fois la rampe atteint sa pleine absorption en son milieu.</s:String>
<s:String x:Key="Label.PolygonPart.Sides">Nombre de côtés</s:String>
<s:String x:Key="Hint.PolygonPart.Sides">Nombre de côtés, de 3 à 64.</s:String>
<s:String x:Key="Label.PolygonPart.Side">Longueur de côté</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.NL.xaml b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
index a95156c..aa18fba 100644
--- a/WaveDudeNext.WPF/Strings/Strings.NL.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
@@ -534,11 +534,15 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Label.PartPoint.Y">Y</s:String>
<s:String x:Key="Hint.PartPoint.Y">Y ten opzichte van het middelpunt van het onderdeel in canvaspixels, vóór rotatie.</s:String>
<s:String x:Key="Label.LensPart.Mirror">Spiegel</s:String>
- <s:String x:Key="Hint.LensPart.Mirror">Het onderdeel een spiegel maken in plaats van een lens. De brekingsindex en de coating worden dan genegeerd.</s:String>
+ <s:String x:Key="Hint.LensPart.Mirror">Het onderdeel een spiegel maken in plaats van een lens. De brekingsindex, de coating en de absorptie worden dan genegeerd.</s:String>
<s:String x:Key="Label.LensPart.RefractiveIndex">Brekingsindex</s:String>
<s:String x:Key="Hint.LensPart.RefractiveIndex">Brekingsindex van het glas, 1,00 tot 2,55 in stappen van 0,01.</s:String>
<s:String x:Key="Label.LensPart.Coating">AR-coating</s:String>
<s:String x:Key="Hint.LensPart.Coating">Dikte in pixels van de antireflectieband net binnen de omtrek, met index √n; 0 voor geen. Een kwartgolfcoating is λ / (4 √n) pixels dik, λ de golflengte die het bronformulier toont.</s:String>
+ <s:String x:Key="Label.LensPart.Absorption">Absorptie</s:String>
+ <s:String x:Key="Hint.LensPart.Absorption">Hoe sterk het onderdeel golven absorbeert, 0 (helemaal niet) tot 255, zoals het blauwe kanaal van de scèneafbeelding. Ze stijgt vanaf nul bij de omtrek over de absorptiehelling, zodat een golf het onderdeel binnengaat in plaats van te worden teruggekaatst. Een spiegel negeert haar.</s:String>
+ <s:String x:Key="Label.LensPart.AbsorptionRamp">Absorptiehelling</s:String>
+ <s:String x:Key="Hint.LensPart.AbsorptionRamp">Diepte in pixels waarover de absorptie van nul bij de omtrek tot haar volle waarde stijgt; hoe langer, hoe minder van een golf wordt teruggekaatst. Een onderdeel dunner dan twee keer de helling bereikt zijn volle absorptie in het midden.</s:String>
<s:String x:Key="Label.LensPart.Diameter">Diameter</s:String>
<s:String x:Key="Hint.LensPart.Diameter">Afmeting dwars op de as in pixels.</s:String>
<s:String x:Key="Label.LensPart.IsConcave">Hol (divergerend)</s:String>
@@ -550,11 +554,15 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="Label.LensPart.Thickness">Middendikte</s:String>
<s:String x:Key="Hint.LensPart.Thickness">Afstand tussen de twee oppervlakken op de as in pixels.</s:String>
<s:String x:Key="Label.ShapePart.Mirror">Spiegel</s:String>
- <s:String x:Key="Hint.ShapePart.Mirror">Het onderdeel een spiegel maken in plaats van glas. De brekingsindex en de coating worden dan genegeerd.</s:String>
+ <s:String x:Key="Hint.ShapePart.Mirror">Het onderdeel een spiegel maken in plaats van glas. De brekingsindex, de coating en de absorptie worden dan genegeerd.</s:String>
<s:String x:Key="Label.ShapePart.RefractiveIndex">Brekingsindex</s:String>
<s:String x:Key="Hint.ShapePart.RefractiveIndex">Brekingsindex van het glas, 1,00 tot 2,55 in stappen van 0,01.</s:String>
<s:String x:Key="Label.ShapePart.Coating">AR-coating</s:String>
<s:String x:Key="Hint.ShapePart.Coating">Dikte in pixels van de antireflectieband net binnen de omtrek, met index √n; 0 voor geen. Een kwartgolfcoating is λ / (4 √n) pixels dik, λ de golflengte die het bronformulier toont.</s:String>
+ <s:String x:Key="Label.ShapePart.Absorption">Absorptie</s:String>
+ <s:String x:Key="Hint.ShapePart.Absorption">Hoe sterk het onderdeel golven absorbeert, 0 (helemaal niet) tot 255, zoals het blauwe kanaal van de scèneafbeelding. Ze stijgt vanaf nul bij de omtrek over de absorptiehelling, zodat een golf het onderdeel binnengaat in plaats van te worden teruggekaatst. Een spiegel negeert haar.</s:String>
+ <s:String x:Key="Label.ShapePart.AbsorptionRamp">Absorptiehelling</s:String>
+ <s:String x:Key="Hint.ShapePart.AbsorptionRamp">Diepte in pixels waarover de absorptie van nul bij de omtrek tot haar volle waarde stijgt; hoe langer, hoe minder van een golf wordt teruggekaatst. Een onderdeel dunner dan twee keer de helling bereikt zijn volle absorptie in het midden.</s:String>
<s:String x:Key="Label.PolygonPart.Sides">Aantal zijden</s:String>
<s:String x:Key="Hint.PolygonPart.Sides">Aantal zijden, 3 tot 64.</s:String>
<s:String x:Key="Label.PolygonPart.Side">Zijdelengte</s:String>
diff --git a/WaveDudeNext.WPF/Views/LensPartView.xaml b/WaveDudeNext.WPF/Views/LensPartView.xaml
index 54669d0..5ebadfd 100644
--- a/WaveDudeNext.WPF/Views/LensPartView.xaml
+++ b/WaveDudeNext.WPF/Views/LensPartView.xaml
@@ -28,7 +28,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<UserControl.Resources>
<converters:LensEdgeConverter x:Key="EdgeThickness" />
- <!-- a mirror has no index and no coating -->
+ <!-- a mirror has no index, no coating and no absorption -->
<Style x:Key="GlassOnly" TargetType="{x:Type controls:NumberBox}" BasedOn="{StaticResource {x:Type controls:NumberBox}}">
<Style.Triggers>
<DataTrigger Binding="{Binding Mirror}" Value="True">
@@ -54,6 +54,14 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:LensPart.Coating}" />
<controls:NumberBox Style="{StaticResource GlassOnly}" Text="{Binding Coating}" Minimum="0" Maximum="50"
ToolTip="{meta:Hint model:LensPart.Coating}" AutomationProperties.AutomationId="PartCoating" />
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:LensPart.Absorption}" />
+ <controls:NumberBox Style="{StaticResource GlassOnly}" Text="{Binding Absorption}" Minimum="0" Maximum="255" Increment="5"
+ ToolTip="{meta:Hint model:LensPart.Absorption}" AutomationProperties.AutomationId="PartAbsorption" />
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:LensPart.AbsorptionRamp}" />
+ <controls:NumberBox Style="{StaticResource GlassOnly}" Text="{Binding AbsorptionRamp}" Minimum="1" Maximum="400" Increment="5"
+ ToolTip="{meta:Hint model:LensPart.AbsorptionRamp}" AutomationProperties.AutomationId="PartAbsorptionRamp" />
</controls:FormPanel>
<Label Style="{StaticResource FormSection}" Content="{DynamicResource SectionShape}" />
diff --git a/WaveDudeNext.WPF/Views/ShapeMaterialView.xaml b/WaveDudeNext.WPF/Views/ShapeMaterialView.xaml
index 04e8f2b..f0762e1 100644
--- a/WaveDudeNext.WPF/Views/ShapeMaterialView.xaml
+++ b/WaveDudeNext.WPF/Views/ShapeMaterialView.xaml
@@ -25,7 +25,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
xmlns:model="clr-namespace:WaveDudeNext.Model;assembly=WaveDudeNext">
<UserControl.Resources>
- <!-- a mirror has no index and no coating -->
+ <!-- a mirror has no index, no coating and no absorption -->
<Style x:Key="GlassOnly" TargetType="{x:Type controls:NumberBox}" BasedOn="{StaticResource {x:Type controls:NumberBox}}">
<Style.Triggers>
<DataTrigger Binding="{Binding Mirror}" Value="True">
@@ -35,7 +35,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
</Style>
</UserControl.Resources>
- <!-- the material of a shape part (polygon, rectangle, triangle, outline): mirror or glass, the index, the coating -->
+ <!-- the material of a shape part (polygon, rectangle, triangle, outline): mirror or glass, the index, the coating, the absorption -->
<StackPanel>
<Label Style="{StaticResource FormSection}" Content="{DynamicResource SectionMaterial}" />
<controls:FormPanel>
@@ -49,6 +49,14 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:ShapePart.Coating}" />
<controls:NumberBox Style="{StaticResource GlassOnly}" Text="{Binding Coating}" Minimum="0" Maximum="50"
ToolTip="{meta:Hint model:ShapePart.Coating}" AutomationProperties.AutomationId="PartCoating" />
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:ShapePart.Absorption}" />
+ <controls:NumberBox Style="{StaticResource GlassOnly}" Text="{Binding Absorption}" Minimum="0" Maximum="255" Increment="5"
+ ToolTip="{meta:Hint model:ShapePart.Absorption}" AutomationProperties.AutomationId="PartAbsorption" />
+
+ <TextBlock Style="{StaticResource FormLabel}" Text="{meta:Label model:ShapePart.AbsorptionRamp}" />
+ <controls:NumberBox Style="{StaticResource GlassOnly}" Text="{Binding AbsorptionRamp}" Minimum="1" Maximum="400" Increment="5"
+ ToolTip="{meta:Hint model:ShapePart.AbsorptionRamp}" AutomationProperties.AutomationId="PartAbsorptionRamp" />
</controls:FormPanel>
</StackPanel>
</UserControl>
diff --git a/WaveDudeNext/Model/OpticalPart.cs b/WaveDudeNext/Model/OpticalPart.cs
index 0f53648..70e458d 100644
--- a/WaveDudeNext/Model/OpticalPart.cs
+++ b/WaveDudeNext/Model/OpticalPart.cs
@@ -62,6 +62,12 @@ public abstract class OpticalPart : ObservableObject, IMovable
public const double MaxIndex = 2.55;
/// <summary>Largest coating thickness in pixels.</summary>
public const int MaxCoating = 50;
+ /// <summary>Largest absorption (blue 255, the velocity damped away in one step).</summary>
+ public const int MaxAbsorption = 255;
+ /// <summary>Default absorption ramp in pixels.</summary>
+ public const int DefaultAbsorptionRamp = 40;
+ /// <summary>Largest absorption ramp in pixels.</summary>
+ public const int MaxAbsorptionRamp = 400;
private string _name = "";
private bool _enabled = true;
@@ -269,6 +275,8 @@ public sealed class LensPart : OpticalPart
private bool _mirror;
private double _refractiveIndex = DefaultIndex;
private int _coating;
+ private int _absorption;
+ private int _absorptionRamp = DefaultAbsorptionRamp;
private int _diameter = DefaultDiameter;
private double _r1 = DefaultR1;
private double _r2 = DefaultR2;
@@ -277,11 +285,11 @@ public sealed class LensPart : OpticalPart
/// <inheritdoc/>
public override PartKind Kind => PartKind.Lens;
- /// <summary>Whether the part is a mirror (red 0, a wall no wave gets through) instead of a lens; the index and the coating are ignored then.</summary>
+ /// <summary>Whether the part is a mirror (red 0, a wall no wave gets through) instead of a lens; the index, the coating and the absorption are ignored then.</summary>
[XmlAttribute]
[DefaultValue(false)]
[Category("Material")]
- [Description("Make the part a mirror instead of a lens. The refractive index and the coating are ignored then.")]
+ [Description("Make the part a mirror instead of a lens. The refractive index, the coating and the absorption are ignored then.")]
public bool Mirror
{
get => _mirror;
@@ -312,6 +320,32 @@ public sealed class LensPart : OpticalPart
set => SetProperty(ref _coating, value);
}
+ /// <summary>
+ /// How strongly the part absorbs, 0 (not at all) to 255, painted into the scene's blue channel (the engines damp a
+ /// cell's velocity by 1 − blue / 255 each step) where it rises over <see cref="AbsorptionRamp"/>; a mirror ignores it.
+ /// </summary>
+ [XmlAttribute]
+ [DefaultValue(0)]
+ [Category("Material")]
+ [Description("How strongly the part absorbs waves, 0 (not at all) to 255, as the scene image's blue channel. It rises from nothing at the outline over the absorption ramp, so a wave enters the part instead of being reflected. A mirror ignores it.")]
+ public int Absorption
+ {
+ get => _absorption;
+ set => SetProperty(ref _absorption, value);
+ }
+
+ /// <summary>Depth in pixels over which the absorption rises from 0 at the outline to <see cref="Absorption"/>; at most half the part's thickness takes effect.</summary>
+ [XmlAttribute]
+ [DefaultValue(DefaultAbsorptionRamp)]
+ [Category("Material")]
+ [DisplayName("Absorption ramp")]
+ [Description("Depth in pixels over which the absorption rises from nothing at the outline to its full value; the longer, the less of a wave is reflected. A part thinner than twice the ramp reaches its full absorption in its middle.")]
+ public int AbsorptionRamp
+ {
+ get => _absorptionRamp;
+ set => SetProperty(ref _absorptionRamp, value);
+ }
+
/// <summary>Extent across the axis in pixels.</summary>
[XmlAttribute]
[DefaultValue(DefaultDiameter)]
@@ -504,6 +538,8 @@ public sealed class LensPart : OpticalPart
base.Normalize();
RefractiveIndex = NormalizeIndex(RefractiveIndex);
Coating = Math.Clamp(Coating, 0, MaxCoating);
+ Absorption = Math.Clamp(Absorption, 0, MaxAbsorption);
+ AbsorptionRamp = Math.Clamp(AbsorptionRamp, 1, MaxAbsorptionRamp);
Diameter = Math.Max(2, Diameter);
Thickness = Math.Max(1, Thickness);
(double r1, double r2) = FitRadii(Diameter, Thickness, R1, R2);
@@ -529,12 +565,14 @@ public abstract class ShapePart : OpticalPart
private bool _mirror;
private double _refractiveIndex = DefaultIndex;
private int _coating;
+ private int _absorption;
+ private int _absorptionRamp = DefaultAbsorptionRamp;
- /// <summary>Whether the part is a mirror (red 0, a wall no wave gets through) instead of glass; the index and the coating are ignored then.</summary>
+ /// <summary>Whether the part is a mirror (red 0, a wall no wave gets through) instead of glass; the index, the coating and the absorption are ignored then.</summary>
[XmlAttribute]
[DefaultValue(false)]
[Category("Material")]
- [Description("Make the part a mirror instead of glass. The refractive index and the coating are ignored then.")]
+ [Description("Make the part a mirror instead of glass. The refractive index, the coating and the absorption are ignored then.")]
public bool Mirror
{
get => _mirror;
@@ -565,6 +603,32 @@ public abstract class ShapePart : OpticalPart
set => SetProperty(ref _coating, value);
}
+ /// <summary>
+ /// How strongly the part absorbs, 0 (not at all) to 255, painted into the scene's blue channel (the engines damp a
+ /// cell's velocity by 1 − blue / 255 each step) where it rises over <see cref="AbsorptionRamp"/>; a mirror ignores it.
+ /// </summary>
+ [XmlAttribute]
+ [DefaultValue(0)]
+ [Category("Material")]
+ [Description("How strongly the part absorbs waves, 0 (not at all) to 255, as the scene image's blue channel. It rises from nothing at the outline over the absorption ramp, so a wave enters the part instead of being reflected. A mirror ignores it.")]
+ public int Absorption
+ {
+ get => _absorption;
+ set => SetProperty(ref _absorption, value);
+ }
+
+ /// <summary>Depth in pixels over which the absorption rises from 0 at the outline to <see cref="Absorption"/>; at most half the part's thickness takes effect.</summary>
+ [XmlAttribute]
+ [DefaultValue(DefaultAbsorptionRamp)]
+ [Category("Material")]
+ [DisplayName("Absorption ramp")]
+ [Description("Depth in pixels over which the absorption rises from nothing at the outline to its full value; the longer, the less of a wave is reflected. A part thinner than twice the ramp reaches its full absorption in its middle.")]
+ public int AbsorptionRamp
+ {
+ get => _absorptionRamp;
+ set => SetProperty(ref _absorptionRamp, value);
+ }
+
/// <summary>The outline's vertices relative to the centre, before rotation, in canvas pixels; fewer than three paint nothing. Out-of-range values are guarded, not written back.</summary>
public abstract (double X, double Y)[] Vertices();
@@ -580,6 +644,8 @@ public abstract class ShapePart : OpticalPart
base.Normalize();
RefractiveIndex = NormalizeIndex(RefractiveIndex);
Coating = Math.Clamp(Coating, 0, MaxCoating);
+ Absorption = Math.Clamp(Absorption, 0, MaxAbsorption);
+ AbsorptionRamp = Math.Clamp(AbsorptionRamp, 1, MaxAbsorptionRamp);
}
}
diff --git a/WaveDudeNext/Parts/PartPainter.cs b/WaveDudeNext/Parts/PartPainter.cs
index 121c9c4..2664796 100644
--- a/WaveDudeNext/Parts/PartPainter.cs
+++ b/WaveDudeNext/Parts/PartPainter.cs
@@ -24,8 +24,9 @@ namespace WaveDudeNext.Parts;
/// <summary>
/// Paints the enabled <see cref="OpticalPart"/>s of a project into the red channel of the scene pixels, the
/// channel the engines read as the refractive index (red = index × 100; red 0 is a mirror, see
-/// <see cref="Engine.SceneData.MirrorRefractiveIndex"/>). Green (image sources) and blue (damping) are never
-/// touched. Parts are painted in list order, a later one over an earlier one. Refractive parts are supersampled
+/// <see cref="Engine.SceneData.MirrorRefractiveIndex"/>), and an absorbing part's absorption into the blue channel
+/// (damping, see <see cref="PaintAbsorption"/>). Green (image sources) is never touched. Parts are painted in list
+/// order, a later one's index over an earlier one's. Refractive parts are supersampled
/// 4 × 4 per pixel and the sample indices averaged, a sample outside the part counting the pixel's existing index
/// (red 0 as 1); a mirror part tests the pixel centre alone and writes red 0, since an averaged mirror edge would
/// clamp to glass. Only pixels near an edge (the outline, the coating band's inner edge, a Bragg layer) are
@@ -94,7 +95,7 @@ public static class PartPainter
return new ScenePixels(width, height, stride, bgra);
}
- /// <summary>Paints one part into the red channel of <paramref name="bgra"/> (rows <paramref name="stride"/> bytes apart).</summary>
+ /// <summary>Paints one part into the red channel of <paramref name="bgra"/> (rows <paramref name="stride"/> bytes apart), and its absorption into the blue channel.</summary>
public static void Paint(byte[] bgra, int width, int height, int stride, OpticalPart part)
{
PartShape? shape = PartShape.For(part);
@@ -110,6 +111,10 @@ public static class PartPainter
return;
}
Logger.Debug("Painting part '{Name}' ({Kind}) at ({X}, {Y}), {Angle}°, rows {Y0}..{Y1}", part.Name, part.Kind, part.X, part.Y, part.Angle, y0, y1);
+ if (shape.Absorption > 0)
+ {
+ PaintAbsorption(bgra, stride, shape, x0, y0, x1, y1);
+ }
if (shape.IsMirror)
{
Parallel.For(y0, y1 + 1, y =>
@@ -177,4 +182,54 @@ public static class PartPainter
}
});
}
+
+ /// <summary>
+ /// Paints a part's absorption into the blue channel: at a pixel whose centre lies at depth δ inside the outline,
+ /// round(<see cref="PartShape.Absorption"/> × <see cref="PartShape.AbsorptionProfile"/>(δ / ramp)), the ramp being
+ /// the part's, shortened to the deepest pixel centre when the part is thinner than twice it (so a thin part still
+ /// reaches its full absorption in its middle). The larger of that and the blue already there is kept, so a part
+ /// never lowers the damping of the image or of an earlier part. The profile is continuous and 0 at the outline, so
+ /// the pixel centre alone stands for the pixel; no supersampling.
+ /// </summary>
+ private static void PaintAbsorption(byte[] bgra, int stride, PartShape shape, int x0, int y0, int x1, int y1)
+ {
+ int columns = x1 - x0 + 1;
+ float[] depths = new float[columns * (y1 - y0 + 1)];
+ double deepest = 0.0;
+ var gate = new Lock();
+ Parallel.For(y0, y1 + 1, () => 0.0, (y, _, local) =>
+ {
+ int row = (y - y0) * columns;
+ for (int x = x0; x <= x1; x++)
+ {
+ double depth = shape.DepthAt(x + 0.5, y + 0.5);
+ depths[row + x - x0] = (float)depth;
+ local = Math.Max(local, depth);
+ }
+ return local;
+ }, local =>
+ {
+ lock (gate)
+ {
+ deepest = Math.Max(deepest, local);
+ }
+ });
+ double ramp = Math.Min(shape.AbsorptionRamp, deepest);
+ int full = shape.Absorption;
+ Logger.Debug("Absorption {Absorption} over a ramp of {Ramp:0.#} px (the part reaches {Deepest:0.#} px deep)", full, ramp, deepest);
+ Parallel.For(y0, y1 + 1, y =>
+ {
+ int row = (y - y0) * columns;
+ for (int x = x0; x <= x1; x++)
+ {
+ float depth = depths[row + x - x0];
+ if (depth >= 0f)
+ {
+ int offset = y * stride + x * 4;
+ int blue = (int)Math.Round(full * PartShape.AbsorptionProfile(ramp > 0.0 ? depth / ramp : 1.0));
+ bgra[offset] = (byte)Math.Max(bgra[offset], blue);
+ }
+ }
+ });
+ }
}
diff --git a/WaveDudeNext/Parts/PartShape.cs b/WaveDudeNext/Parts/PartShape.cs
index 2e54401..6bf0f45 100644
--- a/WaveDudeNext/Parts/PartShape.cs
+++ b/WaveDudeNext/Parts/PartShape.cs
@@ -71,6 +71,26 @@ public abstract class PartShape
/// <summary>The coating band's thickness in pixels, for the painter's shortcut past pixels well inside the body or the band.</summary>
public int CoatingWidth => Coating;
+ /// <summary>The absorption at full depth, 0 to 255 as the blue channel; 0 for none (and always for a mirror).</summary>
+ public virtual int Absorption => 0;
+
+ /// <summary>Depth in pixels over which the absorption rises from 0 at the outline to <see cref="Absorption"/>, at least 1.</summary>
+ public virtual int AbsorptionRamp => 1;
+
+ /// <summary>
+ /// The share of the full absorption at <paramref name="t"/>, the depth inside the outline over the ramp: 0 at the
+ /// outline, 1 from the ramp's end on, t² between. Chosen by measuring what a ramp reflects (2026-10-20, a pulse on a
+ /// deep absorbing slab against a mirror slab): a jump in damping reflects like a jump in index, and of linear,
+ /// quadratic, cubic, smooth-step, error-function and √ ramps the quadratic did best over the strengths that absorb,
+ /// cubic close behind; see OpticalParts.md.
+ /// </summary>
+ /// <param name="t">Depth over ramp; clamped to 0..1.</param>
+ public static double AbsorptionProfile(double t)
+ {
+ t = Math.Clamp(t, 0.0, 1.0);
+ return t * t;
+ }
+
/// <summary>
/// Whether the index steps somewhere inside the outline (a Bragg stack's layers), so a pixel well inside still
/// needs its samples; false where the inside is one index or varies smoothly (the GRIN profile).
@@ -136,6 +156,12 @@ public abstract class PartShape
/// <summary>A refractive index within the part range.</summary>
protected static double GuardIndex(double index) => double.IsFinite(index) ? Math.Clamp(index, OpticalPart.MinIndex, OpticalPart.MaxIndex) : OpticalPart.MinIndex;
+ /// <summary>An absorption within range.</summary>
+ protected static int GuardAbsorption(int absorption) => Math.Clamp(absorption, 0, OpticalPart.MaxAbsorption);
+
+ /// <summary>An absorption ramp within range.</summary>
+ protected static int GuardAbsorptionRamp(int ramp) => Math.Clamp(ramp, 1, OpticalPart.MaxAbsorptionRamp);
+
/// <summary>A coating thickness within range.</summary>
protected static int GuardCoating(int coating) => Math.Clamp(coating, 0, OpticalPart.MaxCoating);
@@ -192,6 +218,8 @@ public abstract class PartShape
_index = GuardIndex(lens.RefractiveIndex);
IsMirror = lens.Mirror;
Coating = lens.Mirror ? 0 : GuardCoating(lens.Coating);
+ Absorption = lens.Mirror ? 0 : GuardAbsorption(lens.Absorption);
+ AbsorptionRamp = GuardAbsorptionRamp(lens.AbsorptionRamp);
// the surfaces stay within the vertex and its sag at the lens edge, convex or concave
double reach = _vertex2 + Math.Max(Sag(_r1), Sag(_r2));
_extent = Math.Sqrt(reach * reach + _half * _half);
@@ -199,6 +227,8 @@ public abstract class PartShape
public override bool IsMirror { get; }
protected override int Coating { get; }
+ public override int Absorption { get; }
+ public override int AbsorptionRamp { get; }
protected override double Extent => _extent;
protected override double BodyIndex(double x, double y) => _index;
@@ -249,11 +279,15 @@ public abstract class PartShape
_index = GuardIndex(shape.RefractiveIndex);
IsMirror = shape.Mirror;
Coating = shape.Mirror ? 0 : GuardCoating(shape.Coating);
+ Absorption = shape.Mirror ? 0 : GuardAbsorption(shape.Absorption);
+ AbsorptionRamp = GuardAbsorptionRamp(shape.AbsorptionRamp);
_extent = _vertices.Max(v => Math.Sqrt(v.X * v.X + v.Y * v.Y));
}
public override bool IsMirror { get; }
protected override int Coating { get; }
+ public override int Absorption { get; }
+ public override int AbsorptionRamp { get; }
protected override double Extent => _extent;
protected override double Depth(double x, double y) => PolygonDepth(_vertices, x, y);
protected override double BodyIndex(double x, double y) => _index;
diff --git a/_tools/library_check/Program.cs b/_tools/library_check/Program.cs
index e475087..4c03a11 100644
--- a/_tools/library_check/Program.cs
+++ b/_tools/library_check/Program.cs
@@ -265,6 +265,7 @@ internal static class Program
CheckProbeGraph();
CheckImport();
CheckParts();
+ CheckAbsorbingParts();
CheckRun();
ExportChecks.Run(Check);
@@ -2161,6 +2162,103 @@ internal static class Program
watched.Dispose();
}
+ private static int BlueAt(ScenePixels pixels, int x, int y) => pixels.Bgra[y * pixels.StrideBytes + x * 4];
+
+ private static void CheckAbsorbingParts()
+ {
+ Console.WriteLine("--- absorbing parts");
+ const int W = 200, H = 120;
+ var project = new Project();
+ project.Scene.Width = W;
+ project.Scene.Height = H;
+ // a 100 × 100 square of index 1 centred on the corner of pixel (100, 60): x = 50..149, y = 10..109
+ var square = (RectanglePart)project.AddPart(PartKind.Rectangle);
+ square.X = 100;
+ square.Y = 60;
+ square.Length = 100;
+ square.Width = 100;
+ square.RefractiveIndex = 1.0;
+ ScenePixels painted = PartPainter.Paint(null, W, H, 1.0, project.Parts)!;
+ Check(square.Absorption == 0 && square.AbsorptionRamp == OpticalPart.DefaultAbsorptionRamp && painted.Bgra.Where((_, i) => i % 4 == 0).All(b => b == 0), "a part without absorption paints no blue");
+ square.Absorption = 200;
+ square.AbsorptionRamp = 20;
+ painted = PartPainter.Paint(null, W, H, 1.0, project.Parts)!;
+ int Expected(double depth) => (int)Math.Round(200 * PartShape.AbsorptionProfile(depth / 20));
+ Check(BlueAt(painted, 49, 60) == 0 && BlueAt(painted, 50, 60) == Expected(0.5) && BlueAt(painted, 59, 60) == Expected(9.5) && BlueAt(painted, 69, 60) == Expected(19.5) && BlueAt(painted, 70, 60) == 200 && BlueAt(painted, 100, 60) == 200 && BlueAt(painted, 149, 60) == Expected(0.5),
+ "absorption 200 over a 20 px ramp: the profile of the depth at the pixel centre, full from 20 px in, nothing outside (" + string.Join(" ", new[] { 50, 59, 69, 70 }.Select(x => BlueAt(painted, x, 60))) + ")");
+ Check(RedAt(painted, 100, 60) == 100 && RedAt(painted, 50, 60) == 100 && painted.Bgra.Where((_, i) => i % 4 == 1).All(g => g == 0), "the index stays as set (red 100) and green untouched");
+ Check(PartShape.AbsorptionProfile(0) == 0 && PartShape.AbsorptionProfile(1) == 1 && PartShape.AbsorptionProfile(2) == 1 && PartShape.AbsorptionProfile(0.3) < PartShape.AbsorptionProfile(0.6), "the profile rises from 0 at the outline to 1 at the ramp's end");
+ // the image's blue and an earlier part's: the larger value is kept
+ (byte[] bgra, int stride) = ScenePixels(W, H);
+ bgra[60 * stride + 51 * 4] = 230; // strong damping in the ramp
+ bgra[60 * stride + 100 * 4] = 10; // weak damping in the full part
+ bgra[5 * stride + 5 * 4] = 77; // outside
+ ScenePixels over = PartPainter.Paint(new ScenePixels(W, H, stride, bgra), W, H, 1.0, project.Parts)!;
+ Check(BlueAt(over, 51, 60) == 230 && BlueAt(over, 100, 60) == 200 && BlueAt(over, 5, 5) == 77, "over the image's blue the larger value wins: 230 stays in the ramp, 10 becomes 200, 77 outside stays");
+ // a part thinner than twice the ramp reaches its full absorption in its middle
+ square.Length = 10;
+ painted = PartPainter.Paint(null, W, H, 1.0, project.Parts)!;
+ int deepest = painted.Bgra.Where((_, i) => i % 4 == 0).Max(b => (int)b);
+ Check(deepest == 200, "a 10 px thin part with a 20 px ramp: the ramp is cut to its middle, which gets the full 200 (" + deepest + ")");
+ square.Length = 100;
+ square.Mirror = true;
+ painted = PartPainter.Paint(null, W, H, 1.0, project.Parts)!;
+ Check(painted.Bgra.Where((_, i) => i % 4 == 0).All(b => b == 0), "a mirror ignores its absorption");
+ square.Mirror = false;
+ // the lens carries the same two settings
+ project.Remove(square);
+ var lens = (LensPart)project.AddPart(PartKind.Lens);
+ lens.X = 100;
+ lens.Y = 60;
+ lens.Diameter = 100;
+ lens.Thickness = 40;
+ lens.Absorption = 120;
+ lens.AbsorptionRamp = 10;
+ painted = PartPainter.Paint(null, W, H, 1.0, project.Parts)!;
+ Check(BlueAt(painted, 100, 60) == 120 && BlueAt(painted, 80, 60) == (int)Math.Round(120 * PartShape.AbsorptionProfile(0.05)) && BlueAt(painted, 79, 60) == 0 && RedAt(painted, 100, 60) == 150,
+ "an absorbing lens: 120 inside, the ramp from its surface, glass of 1.5 still");
+ // the file: attributes only where they differ from the defaults; Normalize clamps
+ string xml;
+ using (var stream = new MemoryStream())
+ {
+ project.Save(stream);
+ xml = System.Text.Encoding.UTF8.GetString(stream.ToArray());
+ }
+ Check(xml.Contains("Absorption=\"120\" AbsorptionRamp=\"10\""), "the lens's absorption and ramp are written as attributes");
+ lens.AbsorptionRamp = OpticalPart.DefaultAbsorptionRamp;
+ lens.Absorption = 0;
+ using (var stream = new MemoryStream())
+ {
+ project.Save(stream);
+ xml = System.Text.Encoding.UTF8.GetString(stream.ToArray());
+ }
+ Check(!xml.Contains("Absorption"), "at their defaults neither is written");
+ lens.Absorption = 300;
+ lens.AbsorptionRamp = 0;
+ lens.Normalize();
+ Check(lens.Absorption == 255 && lens.AbsorptionRamp == 1, "Normalize clamps the absorption to 255 and the ramp to at least 1");
+ // CPU = GPU on an absorbing part
+ lens.Absorption = 64;
+ lens.AbsorptionRamp = 15;
+ painted = PartPainter.Paint(null, W, H, 1.0, project.Parts)!;
+ SceneData scene = SceneData.FromBgra(painted.Bgra, W, H, painted.StrideBytes, false, 0, true);
+ var wave = new List<Emitter> { Make(20, 60, 120, 1.0) };
+ float[] cpuField = RunCpu(scene, wave, 300);
+ Check(scene.D[60 * W + 100] < 0.76f && scene.D[60 * W + 100] > 0.74f, "the engines read blue 64 as a damping of 1 − 64/255");
+ GpuWaveSimulator? gpu = GpuWaveSimulator.TryCreate(scene, new EngineOptions(1.0, 1.0, false, false, 10.0, 1.0), wave, out string problems);
+ if (gpu == null)
+ {
+ Console.WriteLine(" skip GPU: " + problems);
+ return;
+ }
+ using (gpu)
+ {
+ Run(gpu, 300);
+ float diff = MaxDiff(cpuField, gpu.FieldData);
+ Check(diff < 1e-3f * Math.Max(1f, MaxAbs(cpuField)), "GPU agrees with the CPU through an absorbing lens (max diff " + diff + ")");
+ }
+ }
+
private static void CheckRun()
{
Console.WriteLine("--- run");