implementing random function for strands#8730
implementing random function for strands#8730perminder-17 wants to merge 4 commits intoprocessing:dev-2.0from
Conversation
|
Hi @davepagurek and @ksen0 , sorry for the delay, its open for the review, Can you please check once? |
davepagurek
left a comment
There was a problem hiding this comment.
Thanks for taking this on, the structure is looking good! I left one thing about possibly making the call index a runtime thing instead of compile time to better support for loops, and maybe we could add a test case for vertex + fragment shaders too?
|
|
||
| const callIndex = strandsContext._randomCallCount++; | ||
|
|
||
| const nodeArgs = [seedNode, callIndex]; |
There was a problem hiding this comment.
I think that means that if you were to call random() in a for loop, e.g.:
let data = uniformStorage(someStorage)
for (let i = 0; i < 5; i++) {
data[i] += random()
}...then they'd all get the same random value added to them because random here is just one AST node and would have one fixed call index, translating into something like:
for (var i = 0; i < 5; i++) {
data[i] += random(seed, 0);
}Do we have the option of making the call index be a global variable in the shader code so that it's not fixed? e.g something like:
var<private> invocation: i32 = 0;
fn random(seed: f32) -> f32 {
let val = ...; // Do random gen here, using `invocation`
invocation++;
return val;
}
// So then the call site is just:
for (var i = 0; i < 5; i++) {
data[i] += random(seed);
}| if (shaderType === 'vertex') { | ||
| if (!main.match(/\@builtin\s*\(\s*instance_index\s*\)/)) { | ||
| main = main.replace(/\)\s*(->|\{)/, ', @builtin(instance_index) instanceID: u32) $1'); | ||
| const ensuredInstance = ensureBuiltinParam(main, 'instance_index', 'instanceID', 'u32'); |
There was a problem hiding this comment.
nice work generalizing this!
No description provided.