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

Added support for visibility setting on Directional Lights #17788

Open
wants to merge 6 commits into
base: development
Choose a base branch
from

Conversation

lsemp3d
Copy link
Contributor

@lsemp3d lsemp3d commented Apr 21, 2024

Note: This is a Draft PR, feedback on the approach is welcome, I will have to apply the same paradigm to the other light types, so I want to make sure this is a good direction. Ideally, lights should've derived from the same base light data, but unfortunately it appears each light type was implemented independently, this means I will have to replicate this code accordingly.

What does this PR do?

Adds support to set Directional Lights visible through an editor setting and through script.

2024-04-20.17-46-41.mp4

image

Tested on Windows and Linux

Closes #17738

Signed-off-by: Luis Sempé <58790905+lsemp3d@users.noreply.github.com>
Signed-off-by: Luis Sempé <58790905+lsemp3d@users.noreply.github.com>
Copy link
Contributor

@moudgils moudgils left a comment

Choose a reason for hiding this comment

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

In the video why does it look like disabling GI also disables the light as well?

@@ -73,12 +73,11 @@ namespace AZ
AZStd::array<float, 3> m_direction = { { 1.0f, 0.0f, 0.0f } };
float m_angularRadius = 0.0f;
AZStd::array<float, 3> m_rgbIntensity = { { 0.0f, 0.0f, 0.0f } };
bool m_isVisible = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you may have missed uploading the shader file related to this.

@lsemp3d
Copy link
Contributor Author

lsemp3d commented Apr 22, 2024

In the video why does it look like disabling GI also disables the light as well?

It does, that's the behavior I noticed before these changes. Do you happen to know how to visualize the light when GI is off?

@lsemp3d lsemp3d self-assigned this Apr 23, 2024
@lsemp3d lsemp3d marked this pull request as ready for review April 23, 2024 02:12
@lsemp3d lsemp3d requested review from a team as code owners April 23, 2024 02:12
@lsemp3d
Copy link
Contributor Author

lsemp3d commented Apr 23, 2024

If this approach is acceptable I will begin adding support for the other light types

@moudgils
Copy link
Contributor

If this approach is acceptable I will begin adding support for the other light types

I dont see the shader changes related to this change. Where is m_isVisible added to the shader for directionalLight and how is it used?

@byrcolin byrcolin added feature/graphics This item is related to the Atom renderer or graphics. sig/graphics-audio Categorizes an issue or PR as relevant to SIG graphics-audio. and removed feature/graphics This item is related to the Atom renderer or graphics. labels Apr 23, 2024
@lsemp3d
Copy link
Contributor Author

lsemp3d commented Apr 24, 2024

If this approach is acceptable I will begin adding support for the other light types

I dont see the shader changes related to this change. Where is m_isVisible added to the shader for directionalLight and how is it used?

the visibility determination is done on the CPU and not in the shader, in order to propagate the component property m_isVisible it needed to be added to the LightData structure. m_isVisible will be available in the shader but it is unused. I would've preferred a more straightforward approach, however, given that lights are managed in the feature processor and accessed through handles, I needed to ensure the configuration got set on a per-light basis which meant I needed to follow the same paradigm used by the other properties like m_affectsGI

@akioCL
Copy link
Contributor

akioCL commented Apr 24, 2024

If this approach is acceptable I will begin adding support for the other light types

I dont see the shader changes related to this change. Where is m_isVisible added to the shader for directionalLight and how is it used?

the visibility determination is done on the CPU and not in the shader, in order to propagate the component property m_isVisible it needed to be added to the LightData structure. m_isVisible will be available in the shader but it is unused. I would've preferred a more straightforward approach, however, given that lights are managed in the feature processor and accessed through handles, I needed to ensure the configuration got set on a per-light basis which meant I needed to follow the same paradigm used by the other properties like m_affectsGI

There's no need to add the m_isVisible to the LightData structure. You can change the IndexedDataVector for a MultiIndexedDataVector, you can just add a new attribute. This attribute would be per light, and you can just access it with m_lightData.GetData<1>, where 1 would be the index of the new attribute. PointLights, DiskLights and SimpleSpotlights already use a MultiIndexedDataVector. DirectionalLights and SimplePointlights use IndexedDataVector that would need to be replaced.

Copy link
Contributor

@akioCL akioCL left a comment

Choose a reason for hiding this comment

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

This code is not really disabling any lights. What you are doing is just disabling the effect on GI, but the light is still being used. For disabling you have 2 options: either you remove the lightdata from the m_lightData (like calling ReleaseLight) so it's not in the lightdata vector or you add the m_isVisible attribute to the lightdata, and then modify the shaders to ignore the light if it has the m_isVisible = false. You have to keep in mind that we would need to modify the ray tracing shaders too, and I think those are saved as precompiled shaders (due to confidentiality issues).

@moudgils
Copy link
Contributor

This code is not really disabling any lights. What you are doing is just disabling the effect on GI, but the light is still being used. For disabling you have 2 options: either you remove the lightdata from the m_lightData (like calling ReleaseLight) so it's not in the lightdata vector or you add the m_isVisible attribute to the lightdata, and then modify the shaders to ignore the light if it has the m_isVisible = false. You have to keep in mind that we would need to modify the ray tracing shaders too, and I think those are saved as precompiled shaders (due to confidentiality issues).

Agreed. Btw modifying m_lightData via AcquireLight/ReleaseLight on the cpu is expensive and probably not recommended. I would go with option 2 and can help with RT shaders.

@moudgils
Copy link
Contributor

m_affectsGI

FYI - The reason why m_affectsGI is not searchable in the existing shaders as it is used within precompiled RT shaders. Basically in those shaders we use m_affectsGI as a boolean to skip gpu workload related to GI calculations.

@lsemp3d
Copy link
Contributor Author

lsemp3d commented Apr 24, 2024

Thanks for the feedback! It's exactly the guidance I needed! I'll update, and I agree, I'll avoid acquiring/releasing lights, will look at MultiIndexedDataVector first

Signed-off-by: Luis Sempé <58790905+lsemp3d@users.noreply.github.com>
Copy link
Contributor

@hosea1008 hosea1008 left a comment

Choose a reason for hiding this comment

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

There is already a way to disable the lighting for a light, if the lightingChannels are all 0, in the shader the apply lighting codes would be skipped.

So maybe you can try turning off all the lighting channels to achieve the same result? But it is not a good design to coupling lighting channel with lighting visibility, but you can refer to this PR for applying the shader changes? #17232

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/graphics-audio Categorizes an issue or PR as relevant to SIG graphics-audio.
Projects
Development

Successfully merging this pull request may close these issues.

Feature Request: Add ‘set/get visibility’ Script Canvas node for lights (like in Lumberyard)
6 participants