| 741 | } |
| 742 | |
| 743 | class Viscous extends ShaderPass { |
| 744 | constructor(simProps: any) { |
| 745 | super({ |
| 746 | material: { |
| 747 | vertexShader: face_vert, |
| 748 | fragmentShader: viscous_frag, |
| 749 | uniforms: { |
| 750 | boundarySpace: { value: simProps.boundarySpace }, |
| 751 | velocity: { value: simProps.src.texture }, |
| 752 | velocity_new: { value: simProps.dst_.texture }, |
| 753 | v: { value: simProps.viscous }, |
| 754 | px: { value: simProps.cellScale }, |
| 755 | dt: { value: simProps.dt }, |
| 756 | }, |
| 757 | }, |
| 758 | output: simProps.dst, |
| 759 | output0: simProps.dst_, |
| 760 | output1: simProps.dst, |
| 761 | }); |
| 762 | this.init(); |
| 763 | } |
| 764 | update(...args: any[]) { |
| 765 | const { viscous, iterations, dt } = (args[0] || {}) as { |
| 766 | viscous?: number; |
| 767 | iterations?: number; |
| 768 | dt?: number; |
| 769 | }; |
| 770 | if (!this.uniforms) return; |
| 771 | let fbo_in: any, fbo_out: any; |
| 772 | if (typeof viscous === "number") this.uniforms.v.value = viscous; |
| 773 | const iter = iterations ?? 0; |
| 774 | for (let i = 0; i < iter; i++) { |
| 775 | if (i % 2 === 0) { |
| 776 | fbo_in = this.props.output0; |
| 777 | fbo_out = this.props.output1; |
| 778 | } else { |
| 779 | fbo_in = this.props.output1; |
| 780 | fbo_out = this.props.output0; |
| 781 | } |
| 782 | this.uniforms.velocity_new.value = fbo_in.texture; |
| 783 | this.props.output = fbo_out; |
| 784 | if (typeof dt === "number") this.uniforms.dt.value = dt; |
| 785 | super.update(); |
| 786 | } |
| 787 | return fbo_out; |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | class Divergence extends ShaderPass { |
| 792 | constructor(simProps: any) { |
nothing calls this directly
no outgoing calls
no test coverage detected