Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0e01d2d
mix and math merging
Dec 2, 2025
825f443
math fix, removing unnecessary files for math & mix
Dec 2, 2025
952ae74
fixes for mix
Dec 2, 2025
ce3b9b2
organization
Dec 2, 2025
dc849e2
more cleanup
Dec 2, 2025
f880063
format
Dec 2, 2025
3736de2
transform node generates stuff in the wrong pipeline atm
Dec 4, 2025
1164142
need to fix terrain renderer
Dec 4, 2025
767ecd2
I think it works??
Dec 4, 2025
9e5d28e
format fixes
Dec 4, 2025
4378c75
mask float ported over to code
Dec 5, 2025
45bd83d
code gen
Dec 5, 2025
07a18ea
format
Dec 5, 2025
00b4291
added identity if transform is undefined
Dec 5, 2025
a65ec48
create bitmap from image texture
sgmq0 Dec 5, 2025
48b0678
adding useEffect to scatter
Dec 5, 2025
e79ed20
adding useEffect to scatter
Dec 5, 2025
18a024b
undoing changes in this branch
Dec 5, 2025
859ccaa
load a single texture
sgmq0 Dec 5, 2025
bff9f19
Merge branch 'main' into neha/merge-nodes
Dec 5, 2025
059b4f0
format
Dec 5, 2025
e150a62
Merge branch 'main' into ray/texture-loading
sgmq0 Dec 5, 2025
1e1e664
gltf models that have material color and no texture
sgmq0 Dec 5, 2025
2fcff3d
Merge branch 'main' into ray/texture-loading
sgmq0 Dec 6, 2025
405802f
default texture color that works with objs
sgmq0 Dec 6, 2025
97cc9e3
avocado :)
sgmq0 Dec 6, 2025
78596ce
fixing to be y up
Dec 6, 2025
432e227
format
Dec 6, 2025
ce4b370
fix gltf loading
sgmq0 Dec 7, 2025
56b5719
format issues
sgmq0 Dec 7, 2025
19b0db9
Merge branch 'neha/merge-nodes' into ray/texture-loading
sgmq0 Dec 7, 2025
6d7184d
make textures mandatory
sgmq0 Dec 7, 2025
7eadef0
support for multiple textures
sgmq0 Dec 7, 2025
7b62801
Merge branch 'ray/texture-loading' into neha/scatter-mask-fix
sgmq0 Dec 7, 2025
4d46766
Merge branch 'main' into ray/texture-loading
sgmq0 Dec 7, 2025
a113f52
Update terrain-renderer.ts
sgmq0 Dec 7, 2025
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
2 changes: 1 addition & 1 deletion src/lib/renderers/pipelines/instancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export class IndirectInstancer {
// create buffers for the image bitmaps
const firstSource = imageBitmaps![0];
this.textureArray = this.device.createTexture({
label: 'FAT FUCKING TEXTURE!!!!',
label: 'material texture',
format: 'rgba8unorm',
size: {
width: firstSource.width,
Expand Down
9 changes: 9 additions & 0 deletions src/lib/renderers/terrain-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,15 @@ export class TerrainRenderer implements IRenderer {
return;
}

// unused for now
/*
const customInstanceShader = jit.generateInstanceShaderCode(
config,
instanceComputeShaderTemplate,
);
console.log('custom instance shader:', customInstanceShader);
*/

// Create buffers for mesh
const instanceVertexBuffer = this.device.createBuffer({
size: mesh.vertices.byteLength,
Expand Down
58 changes: 56 additions & 2 deletions src/lib/scene/mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,64 @@ export class OBJ extends Mesh {
}
}

// load textures here...
for (const gltfMaterial of gltf.materials!) {
// base color
if (gltfMaterial.pbrMetallicRoughness?.baseColorTexture) {
const texInfo = gltfMaterial.pbrMetallicRoughness?.baseColorTexture;
const gltfTexture = gltf.textures![texInfo.index];

const imageIndex = gltfTexture.source!;
const imageDef = gltf.images![imageIndex];

const view = gltf.bufferViews![imageDef.bufferView!];
const buffer = gltfWithBuffers.buffers[view.buffer];

const byteOffset = (view.byteOffset ?? 0) + buffer.byteOffset;
const byteLength = view.byteLength;

const imageBytes = new Uint8Array(buffer.arrayBuffer, byteOffset, byteLength);

// create image (sus)
const imageBitmap = await createImageBitmap(
new Blob([imageBytes], { type: imageDef.mimeType ?? 'image/png' }),
);

finalBitmaps.push(imageBitmap);
} else {
// if there is no texture for base color, create a base color bitmap
let baseColor: number[] = [0.5, 0.5, 0.5, 1.0];

if (
gltfMaterial.pbrMetallicRoughness &&
gltfMaterial.pbrMetallicRoughness.baseColorFactor
) {
baseColor = gltfMaterial.pbrMetallicRoughness.baseColorFactor;
}

const [r, g, b, a] = baseColor.map((v) => Math.round(v * 255));

const canvas = document.createElement('canvas');
canvas.width = canvas.height = 1;

const ctx = canvas.getContext('2d')!;
ctx.fillStyle = `rgba(${r},${g},${b},${a})`;
ctx.fillRect(0, 0, 1, 1);

const blob = await new Promise<Blob>((resolve, reject) => {
canvas.toBlob((blob) => {
if (blob) resolve(blob);
else reject(new Error('Canvas toBlob() returned null'));
}, 'image/png');
});
const imageBitmap = await createImageBitmap(blob);

finalBitmaps.push(imageBitmap);
}
}

this.vertices = new Float32Array(finalVertices);
this.indices = new Uint32Array(finalIndices);
this.textures = finalBitmaps;

console.log('textures', finalBitmaps);
}
}
3 changes: 1 addition & 2 deletions src/lib/shaders/instancing.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ var<storage, read> indices: array<u32>;
@group(2) @binding(1) var ourTexture: texture_2d_array<f32>;

@group(3) @binding(0)

var<uniform> transform_matrix: mat4x4<f32>;

struct VertexIn {
Expand Down Expand Up @@ -105,7 +104,7 @@ fn fs_main(in: VertexOut) -> @location(0) vec4f

if (color.a < 0.5) {
discard;
}
}

return color;

Expand Down