Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions buffers/GeometryBuffer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ GeometryBuffer.prototype.init = function(geometries) {
// even though their data didnt got uploaded yet
let container = device.createRayTracingAccelerationContainer({
level: "bottom",
flags: GPURayTracingAccelerationContainerFlag.PREFER_FAST_TRACE,
flags: GPURayTracingAccelerationContainerUsage.PREFER_FAST_TRACE,
geometries: [
{
flags: GPURayTracingAccelerationGeometryFlag.OPAQUE,
flags: GPURayTracingAccelerationGeometryUsage.OPAQUE,
type: "triangles",
index: {
buffer: faceBuffer,
Expand Down
4 changes: 2 additions & 2 deletions buffers/InstanceBuffer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ InstanceBuffer.prototype.init = function(instances, materials, textures, lights)
let {accelerationContainer} = geometry;
let {material, transform} = instance.data;
let instanceEntry = {};
instanceEntry.flags = GPURayTracingAccelerationInstanceFlag.FORCE_OPAQUE;
instanceEntry.flags = GPURayTracingAccelerationInstanceUsage.FORCE_OPAQUE;
instanceEntry.mask = 0xFF;
instanceEntry.instanceId = ii;
instanceEntry.instanceOffset = 0x0;
Expand All @@ -226,7 +226,7 @@ InstanceBuffer.prototype.init = function(instances, materials, textures, lights)

let accelerationContainer = device.createRayTracingAccelerationContainer({
level: "top",
flags: GPURayTracingAccelerationContainerFlag.ALLOW_UPDATE | GPURayTracingAccelerationContainerFlag.PREFER_FAST_TRACE,
flags: GPURayTracingAccelerationContainerUsage.ALLOW_UPDATE | GPURayTracingAccelerationContainerUsage.PREFER_FAST_TRACE,
instances: geometryInstances
});

Expand Down
13 changes: 9 additions & 4 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ Object.assign(global, glMatrix);
});
global["window"] = window;

let adapter = await GPU.requestAdapter({
window,
preferredBackend: "Vulkan"
});
let adapterOptions = {
window
}
if (process.argv.includes("--vulkan")) {
adapterOptions.preferredBackend = "Vulkan"
}
let adapter = await GPU.requestAdapter(adapterOptions);
console.log("adapter:", adapter.name);
console.log(" extensions:", adapter.extensions);

let device = await adapter.requestDevice({
extensions: ["ray_tracing"]
Expand Down
3 changes: 2 additions & 1 deletion passes/RayPickingPass.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ RayPickingPass.prototype.init = function(instanceContainer) {
}),
rayTracingState: {
shaderBindingTable,
maxRecursionDepth: 1
maxRecursionDepth: 1,
maxPayloadSize: 2 * 4 * Float32Array.BYTES_PER_ELEMENT + 4, // size of glsl struct RayPayload?
}
});

Expand Down
5 changes: 3 additions & 2 deletions passes/RayTracingPass.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ RayTracingPass.prototype.init = function(scene) {
let rayShadowCHitShaderModule = device.createShaderModule({ code: loadShaderFile(`shaders/shading/shadow-ray-closest-hit.rchit`) });
let rayShadowMissShaderModule = device.createShaderModule({ code: loadShaderFile(`shaders/shading/shadow-ray-miss.rmiss`) });

let shaderBindingTable = device.createRayTracingShaderBindingTable({
let shaderBindingTable = device.createRayTracingShaderBindingTable({
stages: [
{ module: rayGenShaderModule, stage: GPUShaderStage.RAY_GENERATION },
{ module: rayCHitModule, stage: GPUShaderStage.RAY_CLOSEST_HIT },
Expand Down Expand Up @@ -149,7 +149,8 @@ RayTracingPass.prototype.init = function(scene) {
}),
rayTracingState: {
shaderBindingTable,
maxRecursionDepth: 2
maxRecursionDepth: 2,
maxPayloadSize: 5 * 4 * Float32Array.BYTES_PER_ELEMENT + 8, // size of glsl struct RayPayload?
}
});

Expand Down
28 changes: 28 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@cwasm/[email protected]":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@cwasm/jpeg-turbo/-/jpeg-turbo-0.1.0.tgz#3672ee45e8622de3575ddfd948bca6f4215506ff"
integrity sha512-20rDDG0NpoDDMG7bjeV15tzk5ayL2mT3lG7IXbfkmosJMI3GsdWDRyyyRkE64hZmQSVzTADtYtj3qMzDwrw/hQ==

"@cwasm/[email protected]":
version "0.1.1"
resolved "https://registry.yarnpkg.com/@cwasm/lodepng/-/lodepng-0.1.1.tgz#2ce1bb6dead53f043741395b4efdf8a8fb9d454b"
integrity sha512-i2aa5ILUfPsPrWhJdJTjIWZTSVWwoDCwBBnjErDhxBdcZNQywkcAc+xtHuLibQ++chS5bLQNvBNaeP0sYS5n5A==

gl-matrix@^3.1.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/gl-matrix/-/gl-matrix-3.3.0.tgz#232eef60b1c8b30a28cbbe75b2caf6c48fd6358b"
integrity sha512-COb7LDz+SXaHtl/h4LeaFcNdJdAQSDeVqjiIihSXNrkWObZLhDI4hIkZC11Aeqp7bcE72clzB0BnDXr2SmslRA==

tolw@^0.1.8:
version "0.1.8"
resolved "https://registry.yarnpkg.com/tolw/-/tolw-0.1.8.tgz#c19095c0a28dc1387c48db82a95ed08b5dda4abc"
integrity sha512-olxkOErscYps+5LaBCEOpYbR9MuK3NiUNz2eojPVu6CCxOmZXvf07O405au/Cd2HdevnRCPS6mWo8tlIbTxbVQ==

webgpu@latest:
version "0.1.16"
resolved "https://registry.yarnpkg.com/webgpu/-/webgpu-0.1.16.tgz#dec416373e308181b28864b58c8a914461d7ceee"
integrity sha512-KAXn/f8lnL8o4B718zzdfi1l0nEWQpuoWlC1L5WM/svAbeHjShCEI0l5ZcZBEEUm9FF3ZTgRjWk8iwbJfnGKTA==