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 a debug draw mode for displaying UV2 (lightmap) texel density #62987

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

techiepriyansh
Copy link
Contributor

@techiepriyansh techiepriyansh commented Jul 13, 2022

Adds a debug draw mode for displaying UV2 texel density. It displays the UV2 texel density of all MeshInstance3Ds which have their GI_MODE set to GI_MODE_STATIC.

Partially addresses godotengine/godot-proposals#3213.

Todo

  • Port to mobile backend.
  • Figure out a better way to set DEBUG_UV2_TEXEL_DENSITY inside the scene shader instead of using a render mode define.
  • Use the fancy checkerboarding shader.

@techiepriyansh techiepriyansh requested review from a team as code owners July 13, 2022 18:55
@techiepriyansh techiepriyansh changed the title [WIP] Add a debug draw mode for display UV2 (lightmap) texel density [WIP] Add a debug draw mode for displaying UV2 (lightmap) texel density Jul 13, 2022
@techiepriyansh techiepriyansh force-pushed the debug-texel-density-draw-mode branch 2 times, most recently from fbca23f to 21df074 Compare July 13, 2022 19:54
@jcostello
Copy link
Contributor

So far is looking good

@fire
Copy link
Member

fire commented Jul 13, 2022

As the maintainer of the import pipeline giving more ways to determine this crucial detail to art budget and quality is important. 👍

Copy link
Contributor

@JFonS JFonS left a comment

Choose a reason for hiding this comment

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

Changes look good so far.

I wonder if it wouldn't be easier to put the checkerboard code in the Godot shader code (i.e. here), rather than in the internal scene shader.

The lightmap size would be an instance uniform then.

Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Looks amazing so far! I think this was definitely the general approach to take.

With a little bit of polish you should be able to finish this up pretty soon!

if (inst->data->base_type == RS::INSTANCE_MESH && inst->data->use_baked_light) {
Size2 lightmap_size = mesh_storage->mesh_get_lightmap_size_hint(inst->data->base) * inst->data->lightmap_scale;

if (inst->shader_parameters_offset == -1) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (inst->shader_parameters_offset == -1) {
if (inst->shader_parameters_offset == -1 && !inst->data->instance_allocated_shader_parameters && ) {

In my test project I get a spammed error because global_variables_instance_allocate() return -1 if the instance has already been allocated. Adding the check for instance_allocated_shader_parameters ensures that this doesn't happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added appropriate checks to mitigate the spammed error.

Copy link
Member

Choose a reason for hiding this comment

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

Did you test just adding && !inst->data->instance_allocated_shader_parameters? From my test it was able to remove the spammed error and it is much simpler code

@clayjohn
Copy link
Member

The CI build is failing because of missing documentation changes. When you add new features that are exposed, the docs need to be updated as well. You can update the docs by running the doctool command and then filling in the changed sections in the .XML documentation.

For example, here is how you run ``doctool` on 64 bit linux

./bin/godot.linuxbsd.tools.64 --doctool

For more information, we have a whole page on this in the docs: https://docs.godotengine.org/en/latest/community/contributing/updating_the_class_reference.html

@techiepriyansh techiepriyansh requested a review from a team as a code owner July 26, 2022 16:44
doc/classes/Viewport.xml Outdated Show resolved Hide resolved
doc/classes/RenderingServer.xml Outdated Show resolved Hide resolved
doc/classes/RenderingServer.xml Show resolved Hide resolved
@techiepriyansh techiepriyansh force-pushed the debug-texel-density-draw-mode branch 2 times, most recently from cba4f3a to 9a3940b Compare August 14, 2022 18:11
@clayjohn
Copy link
Member

I am still getting the instance buffer error when there are duplicate mesh resources in the scene:

servers/rendering/renderer_rd/storage_rd/material_storage.cpp:2173 - Condition "global_shader_uniforms.instance_buffer_pos.has(p_instance)" is true. Returning: -1

Otherwise it looks great! The new shader looks amazing.

I think to resolve the issue we need to add a function to material_storage to check if the global shader uniforms instance buffer contains the instance. Then we can make that check directly instead of relying on global_shader_uniforms_instance_allocate to return -1.

Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Looks great! I like the new approach. It is unfortunate to add more to the material storage API just for a debug feature. But it makes your actual debug code much more elegant.

@techiepriyansh techiepriyansh force-pushed the debug-texel-density-draw-mode branch from 662e080 to d214f4a Compare August 23, 2022 17:38
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

I've left one final style nitpick on the code comments (sorry). I am happy with the code as it is and have tested it extensively and it seems to work great! Good work, this required a lot more intrusive changes than any of us originally envisioned, but the results a pretty good.

Before merging @reduz and @JFonS should take a look as well.

drivers/gles3/storage/material_storage.cpp Outdated Show resolved Hide resolved
@clayjohn clayjohn requested a review from JFonS August 28, 2022 20:14
@clayjohn clayjohn requested a review from reduz August 28, 2022 20:14
@techiepriyansh techiepriyansh force-pushed the debug-texel-density-draw-mode branch from e881a48 to 4853932 Compare August 28, 2022 22:03
@techiepriyansh techiepriyansh changed the title [WIP] Add a debug draw mode for displaying UV2 (lightmap) texel density Add a debug draw mode for displaying UV2 (lightmap) texel density Aug 29, 2022
@akien-mga
Copy link
Member

@JFonS reduz was asking if this is intended to be merged before or after further changes you might have pending for UV2 layers?

@jcostello
Copy link
Contributor

@akien-mga @clayjohn should this be taking into consideration? #64908

@Calinou
Copy link
Member

Calinou commented Aug 30, 2022

@akien-mga @clayjohn should this be taking into consideration? #64908

You can have multiple LightmapGI nodes in a scene, so I don't think you can have a 1:1 mapping between meshes and the LightmapGI they're using. Some nodes may not be included in any LightmapGI yet either.

@atirut-w
Copy link
Contributor

You can have multiple LightmapGI nodes in a scene

Possibly off-topic, but why would someone do that? Tricks using layers?

Copy link
Contributor

@JFonS JFonS left a comment

Choose a reason for hiding this comment

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

The PR looks good to me.

I still haven't looked at moving UV2 to a custom layer, but it should be pretty straightforward. I would merge this PR, and then I will see if anything needs to be changed later on.

@akien-mga
Copy link
Member

Needs rebase, then should be good to merge if @clayjohn approves it too.

@akien-mga akien-mga requested a review from clayjohn September 8, 2022 13:24
@techiepriyansh techiepriyansh force-pushed the debug-texel-density-draw-mode branch from 4853932 to c5c8a52 Compare September 8, 2022 15:02
@techiepriyansh
Copy link
Contributor Author

Updated with master.

@clayjohn
Copy link
Member

clayjohn commented Sep 8, 2022

I'm happy with the changes. But it requires @reduz to take a quick look as well because of the additions to the MaterialStorage API.

@YuriSizov YuriSizov modified the milestones: 4.0, 4.1 Feb 10, 2023
@clayjohn clayjohn modified the milestones: 4.1, 4.x May 23, 2023
@jcostello
Copy link
Contributor

This PR is getting older. What can be done to merge it ASAP?

@Calinou
Copy link
Member

Calinou commented Sep 24, 2023

@techiepriyansh Could you look into rebasing this pull request if you have time? If you don't have time, let us know and we can mark this PR as salvageable 🙂

@techiepriyansh
Copy link
Contributor Author

Hi, as much as I'd like to get this PR merged myself, I'm afraid that I don't really have time right now. Please go ahead marking this PR as salvageable. When I get some time in the future, and it's still not taken up by anyone else, I'll do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

10 participants