|
| 1 | +/** |
| 2 | + * @vitest-environment jsdom |
| 3 | + */ |
| 4 | + |
| 5 | +import { describe, expect } from 'vitest'; |
| 6 | +import { it } from '../../utils/extendedIt.ts'; |
| 7 | +import { runExampleTest, setupCommonMocks } from '../utils/baseTest.ts'; |
| 8 | + |
| 9 | +describe('disco example', () => { |
| 10 | + setupCommonMocks(); |
| 11 | + |
| 12 | + it('should produce valid code', async ({ device }) => { |
| 13 | + const shaderCodes = await runExampleTest({ |
| 14 | + category: 'rendering', |
| 15 | + name: 'disco', |
| 16 | + controlTriggers: ['Test Resolution'], |
| 17 | + expectedCalls: 7, |
| 18 | + }, device); |
| 19 | + |
| 20 | + expect(shaderCodes).toMatchInlineSnapshot(` |
| 21 | + "struct mainVertex_Output_1 { |
| 22 | + @builtin(position) outPos: vec4f, |
| 23 | + @location(0) uv: vec2f, |
| 24 | + } |
| 25 | +
|
| 26 | + struct mainVertex_Input_2 { |
| 27 | + @builtin(vertex_index) vertexIndex: u32, |
| 28 | + } |
| 29 | +
|
| 30 | + @vertex fn mainVertex_0(_arg_0: mainVertex_Input_2) -> mainVertex_Output_1 { |
| 31 | + var pos = array<vec2f, 6>(vec2f(-1, 1), vec2f(-1, -1), vec2f(1, -1), vec2f(-1, 1), vec2f(1, -1), vec2f(1)); |
| 32 | + var uv = array<vec2f, 6>(vec2f(0, 1), vec2f(), vec2f(1, 0), vec2f(0, 1), vec2f(1, 0), vec2f(1)); |
| 33 | + return mainVertex_Output_1(vec4f(pos[_arg_0.vertexIndex], 0, 1), uv[_arg_0.vertexIndex]); |
| 34 | + } |
| 35 | +
|
| 36 | + @group(0) @binding(0) var<uniform> resolutionUniform_5: vec2f; |
| 37 | +
|
| 38 | + fn aspectCorrected_4(uv: vec2f) -> vec2f { |
| 39 | + var v = ((uv.xy - 0.5) * 2); |
| 40 | + var aspect = (resolutionUniform_5.x / resolutionUniform_5.y); |
| 41 | + if ((aspect > 1)) { |
| 42 | + v.x *= aspect; |
| 43 | + } |
| 44 | + else { |
| 45 | + v.y /= aspect; |
| 46 | + } |
| 47 | + return v; |
| 48 | + } |
| 49 | +
|
| 50 | + @group(0) @binding(1) var<uniform> time_6: f32; |
| 51 | +
|
| 52 | + fn palette_7(t: f32) -> vec3f { |
| 53 | + var a = vec3f(0.5, 0.5899999737739563, 0.8500000238418579); |
| 54 | + var b = vec3f(0.18000000715255737, 0.41999998688697815, 0.4000000059604645); |
| 55 | + var c = vec3f(0.18000000715255737, 0.47999998927116394, 0.4099999964237213); |
| 56 | + var e = vec3f(0.3499999940395355, 0.12999999523162842, 0.3199999928474426); |
| 57 | + var expr = cos((6.28318 * ((c * t) + e))); |
| 58 | + return (a + (b * expr)); |
| 59 | + } |
| 60 | +
|
| 61 | + fn accumulate_8(acc: vec3f, col: vec3f, weight: f32) -> vec3f { |
| 62 | + return (acc + (col * weight)); |
| 63 | + } |
| 64 | +
|
| 65 | + struct mainFragment_Input_9 { |
| 66 | + @location(0) uv: vec2f, |
| 67 | + } |
| 68 | +
|
| 69 | + @fragment fn mainFragment_3(_arg_0: mainFragment_Input_9) -> @location(0) vec4f { |
| 70 | + { |
| 71 | + var aspectUv = aspectCorrected_4(_arg_0.uv); |
| 72 | + var originalUv = aspectUv; |
| 73 | + var accumulatedColor = vec3f(); |
| 74 | + for (var iteration = 0; (iteration < 5); iteration++) { |
| 75 | + aspectUv = (fract((aspectUv * (1.3 * sin(time_6)))) - 0.5); |
| 76 | + var radialLength = (length(aspectUv) * exp((-length(originalUv) * 2))); |
| 77 | + var paletteColor = palette_7((length(originalUv) + (time_6 * 0.9))); |
| 78 | + radialLength = (sin(((radialLength * 8) + time_6)) / 8f); |
| 79 | + radialLength = abs(radialLength); |
| 80 | + radialLength = smoothstep(0, 0.1, radialLength); |
| 81 | + radialLength = (0.06f / radialLength); |
| 82 | + accumulatedColor = accumulate_8(accumulatedColor, paletteColor, radialLength); |
| 83 | + } |
| 84 | + return vec4f(accumulatedColor, 1); |
| 85 | + } |
| 86 | + }" |
| 87 | + `); |
| 88 | + }); |
| 89 | +}); |
0 commit comments