-
-
Notifications
You must be signed in to change notification settings - Fork 208
Open
Description
There are a few lygia WebGPU files calling for conditional compilation in lygia. e.g. rbg2xyz. They're in comments now of course, since wgsl doesn't support conditional compilation. I'll bet there are more conditions in the glsl that haven't been ported to WebGPU yet too.
Here's the rgb2xyz example:
// #ifdef CIE_D50
// const mat3 RGB2XYZ = mat3(
// 0.4360747, 0.2225045, 0.0139322,
// 0.3850649, 0.7168786, 0.0971045,
// 0.1430804, 0.0606169, 0.7141733);
// #else
const RGB2XYZ = mat3x3<f32>(
0.4124564, 0.2126729, 0.0193339,
0.3575761, 0.7151522, 0.1191920,
0.1804375, 0.0721750, 0.9503041 );
// #endif
// #endif
fn rgb2xyz(rgb: vec3f) -> vec3f { return RGB2XYZ * rgb; }With WESL, we can support that now like this:
@if(CIE_D50)
const mat3 RGB2XYZ = mat3(
0.4360747, 0.2225045, 0.0139322,
0.3850649, 0.7168786, 0.0971045,
0.1430804, 0.0606169, 0.7141733);
@if(!CIE_D50)
const RGB2XYZ = mat3x3<f32>(
0.4124564, 0.2126729, 0.0193339,
0.3575761, 0.7151522, 0.1191920,
0.1804375, 0.0721750, 0.9503041 );
fn rgb2xyz(rgb: vec3f) -> vec3f { return RGB2XYZ * rgb; }
I can send a PR to do that for some of the existing cases. That'll work for typical users.
Later, there's more to do on the WESL side to make it nicer, but I don't think we need wait. e.g. in the future we should probably support @else as well as @if. And we should define a way to set condition values from shaders not just JavaScript..
Metadata
Metadata
Assignees
Labels
No labels