alelievr / HDRP-UI-Camera-Stacking

Optimized implementation of camera stacking for UI only in HDRP.
MIT License
173 stars 22 forks source link

[Question] Is Lit support even possible in the future? #12

Closed StepanMynarik closed 2 years ago

StepanMynarik commented 2 years ago

Hi,

I'm making a stealth game. For AI vision I had to solve light level measurement (so that NPCs don't see the player and/or other NPCs when they're hiding in the dark).

I tried reproducing GPU lighting on CPU (for just one point in space). I managed to reproduce attenuation from HDRP source code, but that still doesn't produce complete results. I wasn't able to fully account for the final light falloff like this. Maybe I missed something, I thought Attenuation functions are everything I need for direct real-time lighting.

So I abandoned that solution and added second camera that only renders octahedron placed inside the player chest and/or other NPCs. For example on frame 1 I render octahedron (A) from the top facing downward, on frame 2 I then render the same octahedron from the bottom facing upward. Then I do the same on frames 3 and 4 for octahedron (B) etc. This ends up in a render texture that I then sample.

But dayum... the performance is terrible, even when the second camera has insanely small frustum. The technique presented in this repository seems amazing, but doesn't support lit geometry. Plus I will still need a second camera anyway, right?

Sorry if this question is a bit unrelated, but I'm a bit desperate here.

Any better ideas how to handle what I'm doing? Any tips? Please <3

alelievr commented 2 years ago

I think for your case a custom pass would be more appropriate since you want to reuse the same lighting as your main camera and the performance hit is negligible too. You can check my other repro for examples about custom passes: https://github.com/alelievr/HDRP-custom-passes

StepanMynarik commented 2 years ago

I think for your case a custom pass would be more appropriate since you want to reuse the same lighting as your main camera and the performance hit is negligible too. You can check my other repro for examples about custom passes: https://github.com/alelievr/HDRP-custom-passes

At the time of writing this question I had a very weird idea about custom passes. I didn't realize Custom Passes can't help when measuring lighting from AI POV. Not from player's POV but from AI POV. Hence there is no way to avoid using an actual second camera it seems.

I tried calculating lightness manually from a script, but that proved impossibly complex. HDRP has too many light types and shapes plus many more properties and volumes that affect resulting lightness.

So I'm left with hyper expensive second camera :(

alelievr commented 2 years ago

Indeed if your AI can't use the same information that you have on-screen or is outside of the main view it won't work. With 2 cameras, you can lower the CPU and GPU cost by disabling as many frame settings as you can from the camera, also reducing the resolution to minimum value will help.