mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-17 05:49:30 -07:00
Renamed gpu-uniforms to gpu-buffer, and messed around with its API.
I believe all the align, size, stride and byteOffset values are now in the proper units, ie. bytes.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import uniforms from "/lib/gpu-uniforms.js";
|
||||
import { loadTexture, loadShader, makeUniformBuffer, makeBindGroup, makePassFBO, makePass } from "./utils.js";
|
||||
import { loadTexture, loadShader, makeBindGroup, makePassFBO, makePass } from "./utils.js";
|
||||
|
||||
// Multiplies the rendered rain and bloom by a loaded in image
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import uniforms from "/lib/gpu-uniforms.js";
|
||||
import { structs } from "/lib/gpu-buffer.js";
|
||||
import { getCanvasSize, makeUniformBuffer, makePipeline } from "./utils.js";
|
||||
|
||||
import makeRain from "./rainPass.js";
|
||||
@@ -38,7 +38,7 @@ export default async (canvas, config) => {
|
||||
GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST,
|
||||
};
|
||||
|
||||
const timeUniforms = uniforms.read(`[[block]] struct Time { seconds : f32; frames : i32; };`).Time;
|
||||
const timeUniforms = structs.from(`[[block]] struct Time { seconds : f32; frames : i32; };`).Time;
|
||||
const timeBuffer = makeUniformBuffer(device, timeUniforms);
|
||||
|
||||
const context = {
|
||||
@@ -68,7 +68,7 @@ export default async (canvas, config) => {
|
||||
pipeline.forEach((step) => step.setSize(...canvasSize));
|
||||
}
|
||||
|
||||
device.queue.writeBuffer(timeBuffer, 0, timeUniforms.write({ seconds: (now - start) / 1000, frames }));
|
||||
device.queue.writeBuffer(timeBuffer, 0, timeUniforms.toBuffer({ seconds: (now - start) / 1000, frames }));
|
||||
frames++;
|
||||
|
||||
const encoder = device.createCommandEncoder();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import uniforms from "/lib/gpu-uniforms.js";
|
||||
import { structs } from "/lib/gpu-buffer.js";
|
||||
import { loadShader, makeUniformBuffer, makeBindGroup, makePassFBO, makePass } from "./utils.js";
|
||||
|
||||
// Maps the brightness of the rendered rain and bloom to colors
|
||||
@@ -123,7 +123,7 @@ export default (context, getInputs) => {
|
||||
},
|
||||
});
|
||||
|
||||
const paletteShaderUniforms = uniforms.read(paletteShader.code);
|
||||
const paletteShaderUniforms = structs.from(paletteShader.code);
|
||||
const configUniforms = paletteShaderUniforms.Config;
|
||||
configBuffer = makeUniformBuffer(device, configUniforms, { ditherMagnitude: 0.05, backgroundColor: config.backgroundColor });
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import uniforms from "/lib/gpu-uniforms.js";
|
||||
import { structs, byteSizeOf } from "/lib/gpu-buffer.js";
|
||||
import { makePassFBO, loadTexture, loadShader, makeUniformBuffer, makeBindGroup, makePass } from "./utils.js";
|
||||
|
||||
const { mat4, vec3 } = glMatrix;
|
||||
@@ -47,7 +47,7 @@ export default (context, getInputs) => {
|
||||
const numQuads = config.volumetric ? numCells : 1;
|
||||
|
||||
const cellsBuffer = device.createBuffer({
|
||||
size: numCells * uniforms.byteSizeOf("vec4<f32>"),
|
||||
size: numCells * byteSizeOf("vec4<f32>"),
|
||||
usage: GPUBufferUsage.STORAGE,
|
||||
});
|
||||
|
||||
@@ -91,7 +91,7 @@ export default (context, getInputs) => {
|
||||
const ready = (async () => {
|
||||
const [msdfTexture, rainShader] = await Promise.all(assets);
|
||||
|
||||
const rainShaderUniforms = uniforms.read(rainShader.code);
|
||||
const rainShaderUniforms = structs.from(rainShader.code);
|
||||
configBuffer = makeConfigBuffer(device, rainShaderUniforms.Config, config, density, gridSize);
|
||||
|
||||
sceneUniforms = rainShaderUniforms.Scene;
|
||||
@@ -147,7 +147,7 @@ export default (context, getInputs) => {
|
||||
mat4.perspectiveZO(camera, (Math.PI / 180) * 90, aspectRatio, 0.0001, 1000);
|
||||
}
|
||||
const screenSize = aspectRatio > 1 ? [1, aspectRatio] : [1 / aspectRatio, 1];
|
||||
device.queue.writeBuffer(sceneBuffer, 0, sceneUniforms.write({ screenSize, camera, transform }));
|
||||
device.queue.writeBuffer(sceneBuffer, 0, sceneUniforms.toBuffer({ screenSize, camera, transform }));
|
||||
|
||||
// Update
|
||||
output?.destroy();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import uniforms from "/lib/gpu-uniforms.js";
|
||||
import { structs } from "/lib/gpu-buffer.js";
|
||||
import { loadShader, makeUniformBuffer, makePassFBO, makePass } from "./utils.js";
|
||||
|
||||
// Matrix Resurrections isn't in theaters yet,
|
||||
@@ -56,7 +56,7 @@ export default (context, getInputs) => {
|
||||
},
|
||||
});
|
||||
|
||||
const configUniforms = uniforms.read(resurrectionShader.code).Config;
|
||||
const configUniforms = structs.from(resurrectionShader.code).Config;
|
||||
configBuffer = makeUniformBuffer(device, configUniforms, { ditherMagnitude: 0.05, backgroundColor: config.backgroundColor });
|
||||
})();
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import uniforms from "/lib/gpu-uniforms.js";
|
||||
import { structs } from "/lib/gpu-buffer.js";
|
||||
import { loadShader, make1DTexture, makeUniformBuffer, makeBindGroup, makePassFBO, makePass } from "./utils.js";
|
||||
|
||||
// Multiplies the rendered rain and bloom by a 1D gradient texture
|
||||
@@ -91,7 +91,7 @@ export default (context, getInputs) => {
|
||||
},
|
||||
});
|
||||
|
||||
const configUniforms = uniforms.read(stripeShader.code).Config;
|
||||
const configUniforms = structs.from(stripeShader.code).Config;
|
||||
configBuffer = makeUniformBuffer(device, configUniforms, { ditherMagnitude: 0.05, backgroundColor: config.backgroundColor });
|
||||
})();
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ const makeUniformBuffer = (device, uniforms, data = null) => {
|
||||
mappedAtCreation: data != null,
|
||||
});
|
||||
if (data != null) {
|
||||
uniforms.write(data, buffer.getMappedRange());
|
||||
uniforms.toBuffer(data, buffer.getMappedRange());
|
||||
buffer.unmap();
|
||||
}
|
||||
return buffer;
|
||||
|
||||
Reference in New Issue
Block a user