@@ -21,189 +21,6 @@ describe('function visualizer example', () => {
2121 device ,
2222 ) ;
2323
24- expect ( shaderCodes ) . toMatchInlineSnapshot ( `
25- "@group(0) @binding(0) var<uniform> sizeUniform: vec3u;
26-
27- struct Properties {
28- transformation: mat4x4f,
29- inverseTransformation: mat4x4f,
30- interpolationPoints: u32,
31- lineWidth: f32,
32- }
33-
34- @group(0) @binding(1) var<uniform> propertiesUniform: Properties;
35-
36- fn interpolatedFunction(x: f32) -> f32 {
37- return x;
38- }
39-
40- @group(1) @binding(0) var<storage, read_write> lineVertices: array<vec2f>;
41-
42- fn computePointsFn(x: u32, _arg_1: u32, _arg_2: u32) {
43- let properties = (&propertiesUniform);
44- let start = ((*properties).transformation * vec4f(-1, 0, 0, 1)).x;
45- let end = ((*properties).transformation * vec4f(1, 0, 0, 1)).x;
46- let pointX = (start + (((end - start) / (f32((*properties).interpolationPoints) - 1f)) * f32(x)));
47- let pointY = interpolatedFunction(pointX);
48- var result = ((*properties).inverseTransformation * vec4f(pointX, pointY, 0f, 1f));
49- lineVertices[x] = result.xy;
50- }
51-
52- @compute @workgroup_size(256, 1, 1) fn mainCompute(@builtin(global_invocation_id) id: vec3u) {
53- if (any(id >= sizeUniform)) {
54- return;
55- }
56- computePointsFn(id.x, id.y, id.z);
57- }
58-
59- @group(0) @binding(0) var<uniform> sizeUniform: vec3u;
60-
61- struct Properties {
62- transformation: mat4x4f,
63- inverseTransformation: mat4x4f,
64- interpolationPoints: u32,
65- lineWidth: f32,
66- }
67-
68- @group(0) @binding(1) var<uniform> propertiesUniform: Properties;
69-
70- fn interpolatedFunction(x: f32) -> f32 {
71- return cos(x*5)/3-x;
72- }
73-
74- @group(1) @binding(0) var<storage, read_write> lineVertices: array<vec2f>;
75-
76- fn computePointsFn(x: u32, _arg_1: u32, _arg_2: u32) {
77- let properties = (&propertiesUniform);
78- let start = ((*properties).transformation * vec4f(-1, 0, 0, 1)).x;
79- let end = ((*properties).transformation * vec4f(1, 0, 0, 1)).x;
80- let pointX = (start + (((end - start) / (f32((*properties).interpolationPoints) - 1f)) * f32(x)));
81- let pointY = interpolatedFunction(pointX);
82- var result = ((*properties).inverseTransformation * vec4f(pointX, pointY, 0f, 1f));
83- lineVertices[x] = result.xy;
84- }
85-
86- @compute @workgroup_size(256, 1, 1) fn mainCompute(@builtin(global_invocation_id) id: vec3u) {
87- if (any(id >= sizeUniform)) {
88- return;
89- }
90- computePointsFn(id.x, id.y, id.z);
91- }
92-
93- @group(0) @binding(0) var<uniform> sizeUniform: vec3u;
94-
95- struct Properties {
96- transformation: mat4x4f,
97- inverseTransformation: mat4x4f,
98- interpolationPoints: u32,
99- lineWidth: f32,
100- }
101-
102- @group(0) @binding(1) var<uniform> propertiesUniform: Properties;
103-
104- fn interpolatedFunction(x: f32) -> f32 {
105- return x*sin(log(abs(x)));
106- }
107-
108- @group(1) @binding(0) var<storage, read_write> lineVertices: array<vec2f>;
109-
110- fn computePointsFn(x: u32, _arg_1: u32, _arg_2: u32) {
111- let properties = (&propertiesUniform);
112- let start = ((*properties).transformation * vec4f(-1, 0, 0, 1)).x;
113- let end = ((*properties).transformation * vec4f(1, 0, 0, 1)).x;
114- let pointX = (start + (((end - start) / (f32((*properties).interpolationPoints) - 1f)) * f32(x)));
115- let pointY = interpolatedFunction(pointX);
116- var result = ((*properties).inverseTransformation * vec4f(pointX, pointY, 0f, 1f));
117- lineVertices[x] = result.xy;
118- }
119-
120- @compute @workgroup_size(256, 1, 1) fn mainCompute(@builtin(global_invocation_id) id: vec3u) {
121- if (any(id >= sizeUniform)) {
122- return;
123- }
124- computePointsFn(id.x, id.y, id.z);
125- }
126-
127- struct Properties {
128- transformation: mat4x4f,
129- inverseTransformation: mat4x4f,
130- interpolationPoints: u32,
131- lineWidth: f32,
132- }
133-
134- @group(0) @binding(0) var<uniform> propertiesUniform: Properties;
135-
136- struct backgroundVertex_Output {
137- @builtin(position) pos: vec4f,
138- }
139-
140- @vertex fn backgroundVertex(@builtin(vertex_index) vid: u32, @builtin(instance_index) iid: u32) -> backgroundVertex_Output {
141- let properties = (&propertiesUniform);
142- var leftBot = ((*properties).transformation * vec4f(-1, -1, 0, 1));
143- var rightTop = ((*properties).transformation * vec4f(1, 1, 0, 1));
144- let aspectRatio = ((rightTop.x - leftBot.x) / (rightTop.y - leftBot.y));
145- var transformedPoints = array<vec2f, 4>(vec2f(leftBot.x, 0f), vec2f(rightTop.x, 0f), vec2f(0f, leftBot.y), vec2f(0f, rightTop.y));
146- var currentPoint = ((*properties).inverseTransformation * vec4f(transformedPoints[((2u * iid) + u32((f32(vid) / 2f)))].xy, 0f, 1f));
147- return backgroundVertex_Output(vec4f((currentPoint.x + (((f32(iid) * select(-1f, 1f, ((vid % 2u) == 0u))) * 5e-3f) / aspectRatio)), (currentPoint.y + ((f32((1u - iid)) * select(-1f, 1f, ((vid % 2u) == 0u))) * 5e-3f)), currentPoint.zw));
148- }
149-
150- @fragment fn backgroundFragment() -> @location(0) vec4f {
151- return vec4f(0.8999999761581421, 0.8999999761581421, 0.8999999761581421, 1);
152- }
153-
154- struct Properties {
155- transformation: mat4x4f,
156- inverseTransformation: mat4x4f,
157- interpolationPoints: u32,
158- lineWidth: f32,
159- }
160-
161- @group(0) @binding(0) var<uniform> propertiesUniform: Properties;
162-
163- @group(1) @binding(0) var<storage, read> lineVertices_1: array<vec2f>;
164-
165- fn orthonormalForLine(p1: vec2f, p2: vec2f) -> vec2f {
166- var line = (p2 - p1);
167- var ortho = vec2f(-(line.y), line.x);
168- return normalize(ortho);
169- }
170-
171- fn orthonormalForVertex(index: f32) -> vec2f {
172- if (((index == 0f) || (index == 255f))) {
173- return vec2f(0, 1);
174- }
175- let lineVertices = (&lineVertices_1);
176- let previous = (&(*lineVertices)[u32((index - 1f))]);
177- let current = (&(*lineVertices)[u32(index)]);
178- let next = (&(*lineVertices)[u32((index + 1f))]);
179- var n1 = orthonormalForLine((*previous), (*current));
180- var n2 = orthonormalForLine((*current), (*next));
181- var avg = ((n1 + n2) / 2f);
182- return normalize(avg);
183- }
184-
185- struct vertex_Output {
186- @builtin(position) pos: vec4f,
187- }
188-
189- @vertex fn vertex(@builtin(vertex_index) vid: u32) -> vertex_Output {
190- let properties = (&propertiesUniform);
191- let lineVertices = (&lineVertices_1);
192- let currentVertex = (f32(vid) / 2f);
193- var orthonormal = orthonormalForVertex(currentVertex);
194- var offset = ((orthonormal * (*properties).lineWidth) * select(-1f, 1f, ((vid % 2u) == 0u)));
195- var leftBot = ((*properties).transformation * vec4f(-1, -1, 0, 1));
196- var rightTop = ((*properties).transformation * vec4f(1, 1, 0, 1));
197- let canvasRatio = ((rightTop.x - leftBot.x) / (rightTop.y - leftBot.y));
198- var adjustedOffset = vec2f((offset.x / canvasRatio), offset.y);
199- return vertex_Output(vec4f(((*lineVertices)[u32(currentVertex)] + adjustedOffset), 0f, 1f));
200- }
201-
202- @group(1) @binding(1) var<uniform> color: vec4f;
203-
204- @fragment fn fragment() -> @location(0) vec4f {
205- return color;
206- }"
207- ` ) ;
24+ expect ( shaderCodes ) . toMatchInlineSnapshot ( `""` ) ;
20825 } ) ;
20926} ) ;
0 commit comments