Could someone help me with a source code implementation?

Godot Version

4.7.2

Question

Hello everyone,

This is my first post here in the forum so please be nice. :slight_smile:

I hope this is the right place for this. I couldn’t find a dedicated source code category.

Question: Is there someone who would implement a source code fix and/or would point me into the right direction?

The TLDR part:

Usually when I need something I do it myself. Although I have a coding brain I never dared to delve into GIT Repositories or fundamentally changing elements of big projects like Godot. Only small things and only local on my machine. But while working on my Godot game I realized that I want something fixed and officially implemented, had the idea how to do it and … well. The basic principle works. But the bigger implementation destroys something in the render pipeline. Therefore I will not try to engage the GIT way and do it myself … yet. Also I would be more comfortable if this would be implemented by someone who knows what they do. :slight_smile:

The details part:

when having a light with a higher attenuation value (like 2) in a volumetric fog environment the fog starts to flicker. Yes, even with temporal reprojection. The reason is obvious: In the center of the light the energy injection rises way highter than 1 and the fog resolution does the rest. My solution: Cap the incection energy. So in volumetric_fog_process.glsl find the line

` ` `glsl
total_light += light * attenuation * shadow_attenuation * henyey_greenstein(dot(safe_normalize(light_pos - view_pos), safe_normalize(view_pos)), params.phase_g) * omni_lights.data[light_index].volumetric_fog_energy;
` ` `

and replace it with something like

` ` `glsl
if (cap > 0.0001) {
total_light += light * min(cap, attenuation * shadow_attenuation * henyey_greenstein(dot(safe_normalize(light_pos - view_pos), safe_normalize(view_pos)), params.phase_g)) * omni_lights.data[light_index].volumetric_fog_energy;
} else {
total_light += light * attenuation * shadow_attenuation * henyey_greenstein(dot(safe_normalize(light_pos - view_pos), safe_normalize(view_pos)), params.phase_g) * omni_lights.data[light_index].volumetric_fog_energy;
}
` ` `

Before that point define a cap value

` ` `glsl
float cap = omni_lights.data[light_index].volumetric_fog_cap;
` ` `

If I just set the value like

` ` `glsl
float cap = 1
` ` `

it works fine. But of course I want a per light custom value. So I injected an additional property to the light_3d.cpp, light_3d.h, rendering_server_enums.h and so on. But I realized that at this point I don’t EXACTLY know what I am doing. Godot is starting but the rendering of lights seems broken at this point. So maybe someone can point me in the right direction or tell me how stupid my idea is in the first place.

Welcome!

Could you please wrap your GDScript code inside a GDScript code block. There is an icon for that in the editor:
image

Will make your code nice and readable through highlighting.

Thank you. :slight_smile:

Ah thank you! I wanted to but I somehow did not see the icons. Thank you for pointing out.

Could you clarify what exactly you are doing? Are tinkering with Godot’s own code in C++ or are you writing a GLSL shader? If you don’t describe precisely enough what might have caused your problem it makes it hard for most people to find the right answer.

For GLSL you have to mark the code block with glsl, like so (but without the spaces between the backticks):

` ` `glsl
// your glsl code here.
` ` `

It also would be nice to see all your code for making it more readable.

Usually the important part gets marked as TLDR, not the other way around. :wink:

sorry for the late reply. I had some busy days.

Actually I believe that I put in all necessary details. But okay, I try to explain my problem again without too much convolution:

I tried to implement a fix into the source code of Godot to fix the flickering of volumetric fog on lights with higher attenuation by capping the energy intake value in the code for the volumetric fog. A part of my code works. But I wanted to implement additional customizability and that is an area where I was not exactly sure what I was doing. Also I am no expert in big C++ projects and GIT. So I am rather concerned of breaking something or doing it the wrong way. Therefore I was wondering if someone is willing to either help me step by step or quickly do it themself the right way.

edit: I can offer to make a video to explain the case. If it helps.

There’s https://chat.godotengine.org for contributor and channel/room for new contributors who’re not familiar with contribution workflow and new to godot codebase.

If you don’t want to contribute yourself, you can post the issue on github if you think it’s a bug: Issues · godotengine/godot · GitHub with potential fix (which you have posted here) for other contributor to implement/improve upon.

For a feature/improvement, you can submit a proposal also at github:

Ah, thank you very much. I was under the false impression that I could do it in this forum as well. Then I will try it on GIT directly or in the contributors channel. Thank you again. :slight_smile: