Phazorknight / Cogito

Immersive Sim Template Project for GODOT 4
MIT License
670 stars 72 forks source link

[Improvement/Suggestion] Stealth / Brightness Improvements #196

Closed Strongground closed 1 month ago

Strongground commented 1 month ago

Hi! I am currently building a prototype of a Thief-esque game in Godot. There is a lot in Cogito that I want to use but I noticed the Brightness component is - for my purposes - lacking. I would like to enhance it.

Currently, as far as I understood, it is using a simple approach using an area that emits signals if a body enters. This updates the brightness on the Player. Problems are currently:

I have two solutions for improving this:

  1. Dynamically create the Lightzones in the scene based on all light nodes, using their properties to calculate the brightness values for the player as well as size and position. Update position/orientation/size for dynamic lights. This is the simple approach, at least I think so. I can fully understand how this could (should?) work and I think I can implement it.

  2. Use Compute Shaders to take probe of the light in the scene and calculate the brightness for the player. This would be the more complex approach and I am not sure if it is feasible in Godot. I have no experience with Compute Shaders but I think I can learn it. It requires no changes to the scenes or Nodes and thus is more flexible.

I also read about how other projects tackled this, especially this forum post https://forums.thedarkmod.com/index.php?/topic/18882-how-does-the-light-awareness-system-las-work/ from "The Dark Mod" (which despite its name is a Thief-like game that started as a mod). Short explanation of their approach: Basically there is an invisible octahedron where the player is. Every time the player "litness" needs to be calculated a camera looks at that octahedron (from the top and bottom), checks the pixel brightness of that octahedron and uses that to determine how well lit the player is. I have seen it implemented in a Controller addon for Godot 3, maybe it can be ported over with little effort. Not sure how well it works with baked lights though.

I am open for discussion on this. :)

Phazorknight commented 1 month ago

Hi and welcome!

You're not the first one with this kind of suggestion. The naming might be a bit misleading (hinting more at it's purpose than it's function), but the VisibilityAttribute is meant to be "manual" set up, as more complex lights and geometry are making the intended visibility of a player at any location hard to control if created dynamically (think of just Lighting that's purely aesthetic, light bleed due to engine quirks etc). The whole idea is to have a system that works completely independent of Lights / Light nodes.

That being said, I totally see where you're coming from. I would welcome a player attribute that would work with the actual Lights within a scene, as you described. In fact, someone already attempted this in PR #124, though unfortunately they seem to have abandoned the PR.

Feel free to check out that PR (though it's quite old by now) and I'll also try to take a look if I can adapt whats there into a kind of LightMeterAttribute for the current Cogito version.

Phazorknight commented 1 month ago

Hey, please check out the new LightMeterAttribute that I just added in https://github.com/Phazorknight/Cogito/commit/9f4be7807297461340dcdbc4dc36d09a5f4723b0

It probably needs quite a bit of tweaking. If you want to have a shot at it yourself, feel free to use this new Attribute as the basis.

Strongground commented 1 month ago

Wow, I really didn't anticipate that fast of a response, let alone the complete feature already implemented just like that! :D Thanks a lot, I was prepared to spend the next week implementing this - you sped up my progress considerably. I will start build my test scenes and play around with wieldables, implementing arrows etc. and will absolutely do PRs if I create anything that looks like it might be useful in your framework. You made my day! :)

Phazorknight commented 1 month ago

You're very welcome, glad it provides the feature you're looking for. I do have to give user Nutcrawler the credit, they made the initial PR, I just plopped it into its own player attribute.

I assume this issue can be closed for now. Feel free to reopen if anything comes up.