Refactor
This commit is contained in:
parent
de7fcc15d0
commit
9e582110ea
27 changed files with 248 additions and 123 deletions
|
|
@ -1,8 +1,13 @@
|
|||
import { setUpFullScreenQuad } from '../../utils/full-screen-quad';
|
||||
import { CommonParameters } from '../common-parameters';
|
||||
import { RenderSettings } from './render-settings';
|
||||
import shader from './render.wgsl';
|
||||
|
||||
export class RenderPipeline {
|
||||
private static readonly UNIFORM_COUNT = 4;
|
||||
|
||||
private readonly pipeline: GPURenderPipeline;
|
||||
private readonly uniforms: GPUBuffer;
|
||||
private readonly quadVertexBuffer: GPUBuffer;
|
||||
|
||||
private bindGroup?: GPUBindGroup;
|
||||
|
|
@ -34,6 +39,23 @@ export class RenderPipeline {
|
|||
topology: 'triangle-strip',
|
||||
},
|
||||
});
|
||||
|
||||
this.uniforms = this.device.createBuffer({
|
||||
size: RenderPipeline.UNIFORM_COUNT * Float32Array.BYTES_PER_ELEMENT,
|
||||
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
|
||||
});
|
||||
}
|
||||
|
||||
public setParameters({
|
||||
canvasSize,
|
||||
deltaTime,
|
||||
time,
|
||||
}: CommonParameters & RenderSettings) {
|
||||
this.device.queue.writeBuffer(
|
||||
this.uniforms,
|
||||
0,
|
||||
new Float32Array([canvasSize[0], canvasSize[1], deltaTime, time])
|
||||
);
|
||||
}
|
||||
|
||||
public execute(commandEncoder: GPUCommandEncoder, colorTexture: GPUTexture) {
|
||||
|
|
@ -64,13 +86,19 @@ export class RenderPipeline {
|
|||
entries: [
|
||||
{
|
||||
binding: 0,
|
||||
resource: {
|
||||
buffer: this.uniforms,
|
||||
},
|
||||
},
|
||||
{
|
||||
binding: 1,
|
||||
resource: this.device.createSampler({
|
||||
magFilter: 'linear',
|
||||
minFilter: 'linear',
|
||||
}),
|
||||
},
|
||||
{
|
||||
binding: 1,
|
||||
binding: 2,
|
||||
resource: colorTexture.createView(),
|
||||
},
|
||||
],
|
||||
|
|
|
|||
1
src/pipelines/render/render-settings.ts
Normal file
1
src/pipelines/render/render-settings.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export interface RenderSettings {}
|
||||
|
|
@ -1,8 +1,14 @@
|
|||
@group(0) @binding(0) var mySampler: sampler;
|
||||
@group(0) @binding(1) var TargetTexture : texture_2d<f32>;
|
||||
struct Settings {
|
||||
size : vec2<f32>,
|
||||
deltaTime : f32,
|
||||
time : f32,
|
||||
};
|
||||
|
||||
@group(0) @binding(0) var<uniform> settings : Settings;
|
||||
@group(0) @binding(1) var mySampler: sampler;
|
||||
@group(0) @binding(2) var TargetTexture : texture_2d<f32>;
|
||||
|
||||
@fragment
|
||||
fn fragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
|
||||
return vec4(textureSample(TargetTexture, mySampler, uv).rgb * 1.0, 1);
|
||||
return vec4(textureSample(TargetTexture, mySampler, uv).r * 1.0, settings.deltaTime * 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue