1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//! The comparison seam: one frame's data resolved two ways, either side of a
//! vertical line.
//!
//! `docs/plan/sample/17-mirrors.md`'s exit criteria ask for a "split-screen
//! comparison of any two rungs, **from one frame's data**", and
//! sundial and alcove each asked for the same harness on
//! that sample's pattern. This module is the half of it
//! that is the same for all three: where the seam falls, and which pixels each
//! side owns.
//!
//! # What lives here and what does not
//!
//! **The geometry is shared; the switch is not.** A seam is a rectangle pair
//! and that is worth writing once. Which effect is being compared, and what the
//! two sides differ *by*, is a question only that effect can answer — the
//! occlusion chain's two sides differ in a uniform block, and a reflection
//! ladder's would differ in a pipeline — so each effect declares its own
//! console variable and calls [`halves`] with its own target's extent.
//!
//! One variable per effect is also what a person comparing wants: two effects
//! split at once is two questions asked of one picture, and neither answered.
//!
//! # Two shapes, and which client takes which
//!
//! **A full-screen pass records itself twice under a scissor.**
//! `crate::ssao::r_ssao_split` is that client: the effect records its pass
//! twice, each time with [`Rect2d`] restricting which pixels the draw may
//! write, and both write the **same** image. Nothing is allocated, nothing is
//! copied, and the two sides cost together what one full pass costs — a
//! half-width scissor halves the fragments, so a comparison is not a frame at
//! half the frame rate.
//!
//! The viewport stays the whole target. A full-screen pass derives its own
//! coordinates from `SV_Position`, so shrinking the viewport would squash the
//! image into the half rather than showing that half of it; the scissor is the
//! one of the two that crops.
//!
//! **A scene pass selects per pixel out of its uniform block.**
//! `crate::shadow::r_shadow_split` is that client: the two filter modes and
//! [`halves`]' left rectangle's `width` ride in
//! [`crcbl_shaders::mesh::FrameUniforms::shadow_filter`], and `mesh.slang`'s
//! `shadow_filter_mode` compares that column against the fragment's own
//! `SV_Position.x`. The scissor shape is not available to it: the pass draws
//! *geometry*, so a second recording is every triangle, every vertex fetch and
//! every cull again — and the frame would cost two scenes to compare one
//! filter.
//!
//! Nor would the second recording buy the timer row that might justify it. A
//! per-side `PassTimers` entry on a scene pass measures the *scene*, and the
//! difference between two half-scenes is dominated by what each half happens to
//! contain. What prices a filter is the `forward` row across two runs at two
//! settings of `r_shadow_filter`, which needs no seam at all.
//!
//! **What this cannot split is a pass whose output is not where it was
//! written.** A gather that reduces, a blur that reads its neighbours, a chain
//! whose later stages mix the halves — each carries the seam sideways by its own
//! footprint. That is why the occlusion chain splits its *gather* and leaves the
//! filters whole: a few texels of blend at the seam is a better picture than a
//! tear, and the filters are not what the comparison is about.
//!
//! The per-pixel shape has the same limit from the other end: it splits only
//! what the *fragment* decides. A froxel has no `SV_Position` and reads no seam
//! column, so `volumetric.slang`'s shafts are filtered one way either side of a
//! shadow seam — `shaders/mesh.slang`'s header says which way and why.
use Rect2d;
/// The two rectangles `extent`'s pixels are divided into by a seam at `at`.
///
/// `at` is a fraction of the width — 0.5 puts the seam down the middle — and
/// the left rectangle is the one from the edge to it. Returns `None` when
/// either side would be empty, which is what makes a seam at 0 or 1 the same
/// thing as no comparison at all: an effect asking for those gets one pass over
/// the whole target rather than two, one of which draws nothing.
///
/// Rounding is the left side's: it takes the floor, so the two rectangles are
/// exactly `extent.0` wide together and no column is written twice or skipped.
/// A column written twice would be the seam's own pixel showing whichever pass
/// ran last, which is a picture that depends on pass order.
pub