Yes something like this sounds expensive, but I’m trying to make a screenshot analyzer, a player can take a photo(screenshot) and i need to know exactly whats in shot.
I need raycasts for things like checking object distances.
I have tried checking what renderers are in scene and which are visible, however this does not detect wether an object is completely obscured by another so that was out of the question.
Can’t seem to find any reference online to anyone actually doing this, this will only happen once (not in update for obvious reasons)
so unless any other suggestions pop up, I want to raycast every pixel(can skip some for efficiency eg every 10, but let’s see if it’s possible first) in the CAMERAS FOV, as the field of view will likely change each time.
I have attempted a different method using multiple arcs of raycasts see post below.
Noone responded to the issue i had, i could limit the horizontal arcs to the FOV but i couldn’t work out the math to limit them to the vertical so I’m here asking for other suggestions.
While surely possible with raycasts, I’d like to present another angle to tackle this problem:
You could render the whole scene into an offscreen buffer and use a distinct color code for every object in your scene. You could then use a compute shader create a map of all visible colors and from there deduct which objects where drawn.
this might be way faster than raycasts, could work nicely with a custom render feature and would also respect the visual shape of your objects, not the physical collider representation.
I appreciate the reply but that sounds a little out of my skillset. I have never worked with shaders before, plus i would still need a way to check the distance of objects etc which is why i thought raycasts would be easiest with just checking the hits. If i can find absolutly no way to use raycasts for this i will look into this option thanks
Just for completeness sake: you can also have a depth map rendered and find the distance of the object by averaging those out.
btw I remembered this method:
Given a point between (0,0) and (1,1) this method returns a ray going from the cameras near plane through the given point. Might simplify the math needed
Well, I did this in 1999 in DirectX 7 without any shaders to speak of, so you just need the render texture, then to read it. You can look up the distance later once you know the object’s colour ID and where you captured.
So it’s not a technical thing really, more of a how do I look at this problem thing.