How could this be done?
Is there some property to get shadow map coverage?
Or maybe create an additional camera from which to release rays to determine the average pixel color?
like this three.js webgl - read float pixels
How could this be done?
Is there some property to get shadow map coverage?
Or maybe create an additional camera from which to release rays to determine the average pixel color?
like this three.js webgl - read float pixels
Do you mind describing a bit why you want to make this kind of measurement? What do you want to achieve with an average luminosity value?
It is no big deal to extract values from the framebuffer like demonstrated in the above three.js
example. However, it is a real problem to detect the rendered 3D object in the framebuffer. Meaning you need a logic to determine whether an extracted color value belongs to a given 3D object or not. I’m not aware of an “easy” approach for implementing this task.
Yes, of course. take splinter cell as an example. there’s a light detector that tells how visible the character is. The output of the light detector is from 0 to 1, npcs react to this value.
In practice I think games would “fake it”, and measure some function of distance to lights vs. distance to enemies.
If you wanted to simulate it more accurately, sampling a low-resolution CubeCamera at the player’s location would be one option, as would be done when baking light probes:
https://threejs.org/examples/?q=lightprobe#webgl_lightprobe_cubecamera
To be honest, I don’t think I’m reading you correctly.
Tell me if this idea can serve as a solution.
We create a simple scene, with human body geometry centered. Phong material no att, perspective camera, point light source with no animation loop.
We need a subroutine to read the pixel value of scene. The next step will be to change light source intensity by notch and read the new pixel values.
Comparing the two data is the final step.
If you need some kind of light measuring from character position, I would go with @donmccurdy and render a CubeCamera. Since you don’t need actual color information (but mostly luma), you can make it really small (i.e. 16px each cube side) and leting the hardware to the bluring for you. Anyway this is going to be a fps killer if you put it in the main render loop, so do account for optimizations here (only render onchange, fixed framerate, based on space partitioning, etc).
On the other side, as you are refering to games as examples, I think that determining “how visible the character is” would be somehow more related to viewsheds estimation than luminosity /radiometric measurements. In that sense, the “visibility” seems an issue that can be re-framed as of line of sight calculations to/from player position.
Funny thing is that both light/shadows and line of sight calculations are rooted on almost the same principles and algoritms. This may lead you in a different direction, but If you are feeling to give this a chance, I would recommend start with reviewing basic reasoning around the problem before jumping into coding, this interactive article about visibility in 2d could be nice reading.