Great tutorial works perfectly and very educational!
@matthewblank76912 жыл бұрын
A nice looking solution but due to the need of use of multiple cameras very performance heavy. I only did some profiling in Editor but it's hitting GPU pretty heavy. With 9 instances of this view cone - and even setting up the Render Texture to be 1/4th the size with depth buffer of only 4 it increases the render thread time from ~4ms to ~11ms.
@matthewblank76912 жыл бұрын
And I have 3080 so on a lower tier hardware will be very bad.
@dexter_hacks Жыл бұрын
@@matthewblank7691 Maybe use this only for enemies that are perched above and have to look down at objects of different heights and use the other normal raycasting for on-ground enemies?
@matthewblank7691 Жыл бұрын
@@dexter_hacks It was not the issue of the CPU and raycasting but the view cone rendering on the GPU caused by the amount of cameras that were rendering to the RenderTexture. I was able to speed it up a little by creating custom simple objects that were used for obstacles instead of the real ones and setting the cameras to only see thoseX lowering down the resolution of the RenderTexture way down and setting up the view cone to only render about 20 times per second. This improved things enough.
@dexter_hacks Жыл бұрын
@@matthewblank7691 Ok. In Desperados, it probably activates only those cameras in an area where the player is currently, and the rest is inactive (unless you manually activate it). But I wonder how they keep track of multiple players running in different directions and still detect the players. It starts with 30-40 enemies, but on an alert, you have additional enemies running out.
@matthewblank7691 Жыл бұрын
@@dexter_hacks Yeah, I'm doing this as well. It deactivates the View Cone if the mesh is not inside the Main Camera frustrum. The player detection is handled separately. I also had multiple characters on the map. Each NPC first calculates the distance squared, then does view angle and height calculations and only if both determine that the character can be seen I'm throwing raycast. This way i can have a lot of NPCs and only do full calculations for a few.
@advaita6643 Жыл бұрын
The camera in the ConeOfSight object renders this as per culling mask for the 'Obstacle' layer. How would one go about creating a block for the cone, along with this? So if there is an object (like a tall solid wall etc.) with a particular layer like 'OpaqueObstacle' or any layer that isn't an 'Obstacle' it should not be creating a shadow.
@thomasharvey29803 жыл бұрын
I was curious becomes I can't figure it out, is there a way to use this trick to create a fog of war like system? Something like what Zomboid does but in a full 3D setting like you have in this video
@EdenDev6 ай бұрын
How does this shader behave when the field of view height gets too close to the surface height? There, the depth comparison even with bias leads to oscillation in shape of teeth or sinus. Did you notice that?
@elmichiapologeta4 ай бұрын
How could i replicate this in unreal engine?
@telemaco98224 жыл бұрын
How can i implement It correctly in the Universal Render Pipeline? Apparently when i download the Universal RP package the cone no longer modifies itself if there are obstacles in front of the soldier.
@ssoltani4983 жыл бұрын
Is there any tutorial somewhere to make it using the Shader Graph?
@WelshGuitarDude Жыл бұрын
How does Unity know which camera to use when it gets the depth data? You have multiple cameras all writing to the same _CameraDepthTexture - how does it have the right camera? Also you have a _ViewDepthTexture as well... confusing me where these two come from. Why do you need two?
@GPUMan Жыл бұрын
_CameraDepthTexture is created by Unity and comes indeed from the main game camera (the player view). This is only used to check the object's intersection with the scene and to draw the cone as a decal. This is a global texture shared by all shaders. _ViewDepthTexture is used to render obstacle occlusion. It's created, rendered to, and passed into the material from ConeOfSightRenderer.Start() with ViewCamera.SetTargetBuffers and mMaterial.SetTexture (explained from 5:20). This means each soldier camera will write to its unique custom depth texture (and not the global _CameraDepthTexture) Each character has its own POV of the obstacles in front of them so it's necessary then that each camera (or soldier) renders to and samples from its own unique depth texture. Check the code here for a bit more context github.com/joscanper/unity_coneofsightfx/blob/master/Assets/Scripts/ConeOfSightRenderer.cs I hope that helps
@WelshGuitarDude Жыл бұрын
@@GPUMan your script you linked doesn't use the set target buffer method that unity provides? Is there a reason for that?
@GPUMan Жыл бұрын
@@WelshGuitarDude I don't recall exactly but probably just for simplification's sake. SetTargetBuffer allows you to specify multiple targets which wasn't necessary in this case
@WelshGuitarDude Жыл бұрын
@@GPUMan ah i see thats why you used target texture? Also do you know much about how Desperados changes the vision cone texture for crouching behind objects that are a certain height versus objects that fully clip the vision cone ?
@GPUMan Жыл бұрын
@@WelshGuitarDude hmm, that might not be possible with this method I'm afraid. Considering Desperados core tech is like 20 years old I wouldn't be surprised if they use regular ray tracing against simplified shapes at 3 different heights. Something a bit like this github.com/configithub/ray-tracer
@patek23852 жыл бұрын
Can You actually show or tell how did you add those shaders to the object?
@GPUMan2 жыл бұрын
The shader is applied to the material that is added to the cube. If you struggle with this, I would recommend following a tutorial about the basics of shaders first, since that's not the goal of this tutorial. Shaders 101 by "Makin' Stuff Look Good" is a great one.
@rodrigoguerra83724 жыл бұрын
Interesting effect, but you need a Phd to understand how to make this.