taichi.js
taichi.js copied to clipboard
Fragment Shader does not work if not using uniform
Hello,
I try to fool around with the game of Life playground.
If we take this piece of code
let render = ti.kernel(() => {
ti.clearColor(renderTarget, [0.0, 0.0, 0.0, 1.0]);
for (let v of ti.inputVertices(vertices)) {
ti.outputPosition([v.x, v.y, 0.0, 1.0]);
ti.outputVertex(v);
}
for (let f of ti.inputFragments()) {
let coord = (f + 1) / 2.0;
let cellIndex = ti.i32(coord * (liveness.dimensions - 1));
let live = ti.f32(liveness[cellIndex]);
ti.outputColor(renderTarget, [live, live, live, 1.0]);
}
});
And let's say I don't want game of life but I want to fill the canvas with red pixel.
let render = ti.kernel(() => {
ti.clearColor(renderTarget, [0.0, 0.0, 0.0, 1.0]);
for (let v of ti.inputVertices(vertices)) {
ti.outputPosition([v.x, v.y, 0.0, 1.0]);
ti.outputVertex(v);
}
for (let f of ti.inputFragments()) {
// let coord = (f + 1) / 2.0;
// let cellIndex = ti.i32(coord * (liveness.dimensions - 1));
// let live = ti.f32(liveness[cellIndex]);
ti.outputColor(renderTarget, [1.0, 0.0, 0.0, 1.0]);
}
});
I get black canvas and in the console :
Bind group layout index (0) doesn't correspond to a bind group for this pipeline.
- While Validating GetBindGroupLayout (0) on [RenderPipeline]
If i uncomment the lines and keep my red pixel, then it work
let render = ti.kernel(() => {
ti.clearColor(renderTarget, [0.0, 0.0, 0.0, 1.0]);
for (let v of ti.inputVertices(vertices)) {
ti.outputPosition([v.x, v.y, 0.0, 1.0]);
ti.outputVertex(v);
}
for (let f of ti.inputFragments()) {
let coord = (f + 1) / 2.0;
let cellIndex = ti.i32(coord * (liveness.dimensions - 1));
let live = ti.f32(liveness[cellIndex]);
ti.outputColor(renderTarget, [1.0, 0.0, 0.0, 1.0]);
}
});
I've also attempted with removing the lines instead of commenting it.
Look like it work only if we are "using" some uniform even if we are not using it : Those are two example that work :
for (let f of ti.inputFragments()) {
let foo = liveness[[0, 0]];
ti.outputColor(renderTarget, [1.0, 0.0, 0.0, 1.0]);
}
for (let f of ti.inputFragments()) {
let foo = numNeighbors[[0, 0]];
ti.outputColor(renderTarget, [1.0, 0.0, 0.0, 1.0]);
}
So maybe that is a niche bug that occure only when we want a fragment shader that does not use uniforms.