Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fragment Shader does not work if not using uniform #13

Open
dezmou opened this issue Jul 25, 2023 · 1 comment
Open

Fragment Shader does not work if not using uniform #13

dezmou opened this issue Jul 25, 2023 · 1 comment

Comments

@dezmou
Copy link

dezmou commented Jul 25, 2023

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.

@dezmou
Copy link
Author

dezmou commented Jul 26, 2023

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.

@dezmou dezmou changed the title Strange behavior of fragment shader Fragment Shader does not work if not using uniform Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant