Skip to content

WebGPU: Sample environment#719

Merged
gkjohnson merged 13 commits intogkjohnson:webgpu-pathtracerfrom
TheBlek:webgpu-env
Feb 25, 2026
Merged

WebGPU: Sample environment#719
gkjohnson merged 13 commits intogkjohnson:webgpu-pathtracerfrom
TheBlek:webgpu-env

Conversation

@TheBlek
Copy link
Copy Markdown

@TheBlek TheBlek commented Feb 20, 2026

Adds support to sample environment texture by reusing EquirectHdrInfoUniform. This allows us to easily reuse code for weight calculation when implementing MIS

Copy link
Copy Markdown
Owner

@gkjohnson gkjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image Image

This is super cool to see 🤩

Comment on lines +63 to +77
// environment
envMap: texture_2d<f32>,
envMapSampler: sampler,
envMapRotation: mat3x3f,
envMapIntensity: f32,
envMapBlur: f32,

globalId: vec3u
) -> void {

let env = EnvironmentInfo(
envMapRotation,
envMapIntensity,
envMapBlur,
);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to pack these fields into a struct uniform rather than merging them into a struct after the fact?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to do that, but haven't managed to.
uniform( { ... } ), uniform( environmentInfoStruct( ... ) ), environmentInfoStruct( ... ) as values in paramters did not work for me. note: environmentInfoStruct = struct( { ... }, 'EnvironmentInfo' );

Maybe you know how to do that?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to not be supported 😅 According to here it should be possible. Might be time to make another three.js issue.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so it's clear - would you like to make the issue? Otherwise I can make one.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I was going to ask at the forum first if its truly impossible to do now. Maybe there is an example that I missed. You think its fine to make an issue at this point?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make an issue. I don't see structs used as uniforms in any example and the uniform node seems to imply it only takes math types and there are no other "uniform" nodes that seem to be applicable. If it turns out to be possible then it should be made more clear in the documentation.

Comment on lines +108 to +112
pathTracer.setEnvironment( environment,
scene.environment !== null ? ( scene.environmentIntensity ?? 1 ) : 0,
scene.environmentRotation,
scene.backgroundBlurriness ?? 0,
);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing that setting "backgroundBlurriness" seems to have no effect on the background appearance. Is there another setting I need to toggle?

Copy link
Copy Markdown
Author

@TheBlek TheBlek Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed that. It turns out that ndcToCameraRay generates non-normalized ray directions which lessened the impact of blurriness.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe that commit hasn't been pushed? I'm still seeing that blur doesn't work.

It turns out that ndcToCameraRay generates non-normalized ray directions

It's technically not needed in a lot of places but maybe it may make sense to just normalize the camera rays for convenience?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes. Megakernel version did not work because code moved and I forgot to move the fix. Pushed it.

And yeah, camera rays are just normalized after the generation. I figured modifying that in a library will limit people who do not actually need a normalized direction.

@gkjohnson gkjohnson merged commit 42ea8ff into gkjohnson:webgpu-pathtracer Feb 25, 2026
1 check passed
@gkjohnson
Copy link
Copy Markdown
Owner

🎉

image

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

Successfully merging this pull request may close these issues.

2 participants