Skip to content
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

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

Open
gkjohnson opened this issue Apr 5, 2024 · 4 comments
Open
Milestone

Comments

@gkjohnson
Copy link
Owner

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

@gkjohnson gkjohnson added this to the v0.0.x milestone Apr 5, 2024
@JaimeTorrealba
Copy link

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
Copy link
Owner Author

gkjohnson commented May 24, 2024

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
Copy link

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
Copy link
Owner Author

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:

  • Add a field like ShapedAreaLight.visibleSurface to the ShapedAreaLight class.
  • The LightsInfoUniformStruct packs all light data into a texture so we'll need to add this new field to the class. Each light is allocated six pixels of data (6 * 4 float values) and you can see that the area light only uses up to 4 pixels. So if the surface is visible we can set the last value of pixel 6 (the alpha component) to "1". This value is unused by all light types so it's a good one to set.
  • The readLightInfo function in the lights_struct.glsl.js file reads the texture data and unpacks it for all lights and returns a struct with all the light information. We'll wan to add a new "surfaceVisible" field to the light struct so we can check this later.
  • Finally, if we're tracing the first ray then we'll want to find the first visible-surface light and return the color of the light as the result of the path trace. See this section here.

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!

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

No branches or pull requests

2 participants