Skip to content

Shader pre-processor: Improve parsing + fix WGSL #16474

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

Merged
merged 4 commits into from
Apr 10, 2025

Conversation

Popov72
Copy link
Contributor

@Popov72 Popov72 commented Apr 10, 2025

I have improved the shader pre-processor so that constructions of this type are analyzed correctly:

#define BRDF_DIFFUSE_ROUGHNESS_EON 0
#define BRDF_DIFFUSE_ROUGHNESS_BURLEY 1

#if BASE_DIFFUSE_ROUGHNESS_MODEL == BRDF_DIFFUSE_ROUGHNESS_EON
    diffuseRoughnessTerm = diffuseBRDF_EON(vec3(1.0), diffuseRoughness, NoL, NoV, LoV) * PI;
#elif BASE_DIFFUSE_ROUGHNESS_MODEL == BRDF_DIFFUSE_ROUGHNESS_BURLEY
    diffuseRoughnessTerm = vec3(diffuseBRDF_Burley(NoL, NoV, VoH, diffuseRoughness) * PI);
#endif

Before the PR, you couldn't test against a name, you had to use immediate values (0 instead of BRDF_DIFFUSE_ROUGHNESS_EON and 1 instead of BRDF_DIFFUSE_ROUGHNESS_BURLEY in the example above).

I have also reworked the way we handle preprocessing in WGSL, as it was causing some problems before. I have tried to add a number of comments in the code to explain why things are done in that way.

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 10, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 10, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 10, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 10, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 10, 2025

@RaananW RaananW merged commit 7c6a2c6 into BabylonJS:master Apr 10, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants