gkjohnson / three-gpu-pathtracer

Path tracing renderer and utilities for three.js built on top of three-mesh-bvh.
https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/index.html
MIT License
1.27k stars 125 forks source link

Add support for rendering area light helper as area light surface #618

Open gkjohnson opened 2 months ago

gkjohnson commented 2 months ago

Would require special handling since the material is set to a mesh basic material. Perhaps this project can export one?

JaimeTorrealba commented 1 month ago

Hi, I would like to take this one :)

Have you thought in something?

We can create a new folder just for "Helper" (this could work for the PhysicalCamera, and other components in the future), and create our own helper. If we do so, let me tried to add some "emissive" value or something to make them feel like a helper

--/src ----/helper

The other option might be to traverse the scene in searching for any basicMaterial to override them?

Which want you prefer? (any other alternative is accepted)

gkjohnson commented 1 month ago

Hey Jaime! This would be great!

Sorry for the slow response - I was thinking about the best way to implement this. Thinking about it more I'm not sure if adding geometry via something like RectAreaLightHelper is the best way to add support for rendering the light surface. They will doubly contribute to the lighting of the scene because the geometry will be considered emissive to get the right brightness.

I'm thinking adding an extra optional field like renderLightSurface to the light objects that defaults to false would be the best place to start. This would involve modifying the light info uniform texture to add a new field for rendering it and then finding the closest visible light on the first ray to check for collisions.

How does that sound?

JaimeTorrealba commented 1 month ago

That's sound a good idea, but I have doubts where to start and what should be the final render "helper"

sorry if my questions are too basic, I'm new here, and I would like to contribute this project (who looks amazing)

Checking the code, I see that you have

src/uniforms/LightsInfoUniformStruct.js and src/shader/structs/lights_struct.glsl.js where changes have to be made in order to add this new field.

What I'm not sure if changes have to be made in something like src/shader/sampling/light_sampling_functions.glsl.js in order to check the collision?

I don't know if you're in discord, but maybe a more fluid communication could help BboyJT#2838

gkjohnson commented 4 weeks ago

Here's a breakdown of what I see as needing to change in order to add this feature. Lets start with the Area Lights and then we can consider adding the option for other light surface (like spot lights with a radius) if we want:

Let me know if that all makes sense. And feel free to make a preliminary PR if you'd like me to take a look. Appreciate you digging into this!