In the 2D game I have 2 orthographic cameras and two game objects, one behind another.
Near game objects have transparent sprites so we can see the back game object.
The near game object's depth is 0 and the other one's is -1. I want my first camera to render the near scene and another camera to render the back game object. The first camera follows the character so I want the second camera to follow him slowly and to show nice graphics.
The game object that you only want visible to one camera should be put in it's own layer. Then you can use its camera's culling mask to only see that layer (Or lets say that layer and the background layer).
Then for the camera that should never see the object, uncheck the object's layer.
Here is a video on the subject here from Pluralsite on Youtube.
Related
I am making a 3D isometric game, in my game, there is a lot of holes and the player can go into them, but the problem is when he goes into one of them he becomes invisible, I can,t move the camera it will change the concept I tried using shader like the one in this video but it makes the entire terrain transparent and glitchy (I am using unity terrain) so I am stuck and I need Idea how to make the layer visible inside the hole
What you're asking can be achieved in multiple ways, depending on your render pipeline and requirements.
If you're working with the Universal Render Pipeline (URP), you could create a Forward Renderer asset and create a custom render pass whenever your player is occluded by terrain.
You could assign a new Layer to the player, such as "Player", then select or deselect said mask from the Filters > Layer Mask properties of the Forward Render Data. Then assign the same or a custom material for when the player is occluded by terrain.
Alternatively, you could create either a cutout or a dither shader using Shader Graph, on which there are many tutorials
Camera GameObjects give you the option to select what layer you want them to "see" (render) using the culling mask. Think of layers as grouping GameObjects and giving that group a name.
You can have multiple cameras at the same time each one with a different name and different layer to render, or even change the viewing layer of a single camera depending on changes happening in the game.
Assign a layer tag in each of the terrain elements in your scene and have the camera render them accordingly and "cull" the rest.
Very helpful documentation on layers and camera culling mask.
I have two camera in the same position. I want to use the first camera's depth buffer to render the scene again on the second camera.
Use case:
I want to detect if a line that I draw on the 3d space is rendered behind an object or not. To do that, first I draw the scene normally on the first camera. Then I render the scene again on the second camera, which rendered unto a texture and set to culled all object except the line. The line is using a shader that will shows Red on the part that rendered behind an object, but to draw it correctly I need to render the second camera using the first camera's depth buffer. After that I just check if the texture has the red color.
Is it possible to do that on URP? Or do you guys have any other idea how to achieve what I want? !(https://i.stack.imgur.com/7hxDo.png)
hierarchy
2d sprite
panel UI
in game
Fist make sure your canvas' Render Mode is not set to Screen Space - Overlay.
If it is, then switch it to Screen Space - Camera and then change its Render Camera property to point to your main camera.
You can then use the following canvas' properties to control where it appears in relation to other sprites (which appears on top of which), the same way you control any other 2D Sprite:
Sorting Layer
Order in Layer
Also worth noting that 2D Sprites with same Sorting Layer and Order in Layer will use the distance to the camera to decide which one appears on top of which, and the same is true for the canvas:
If your canvas' Render Mode is set to Screen Space - Camera, it will always be positioned in front of your camera and you need to use its Plane Distance property in order to position it correctly.
If your canvas' Render Mode is set to World Space, you can position it freely in the world in the same way you position any other sprite.
First of all the hierarchy window in unity is completely irrelevant when its about positioning.
In Unity everything is 3D, even if you switch to 2D perspective.
So in your case you still have your camera, your sprite and your canvas in a 3D Dimension.
To set your sprite in front of the canvas you only need to increase the positioning stats (seen in your "panel UI" screenshot) at least slightly closer to your camera than the canvas is.
In Unity3d, I'm trying to make a simple metaball effect using multiple sprites of a blurred round, and those sprites move randomly.
Thus I'd like the shader to perform a pixel color change from the rendering of all the sprites all together and not one by one.
Here is an example :
The picture on the left shows four sprites with the blurred sprite ; the picture on the right is the result of the shader.
And I have no clue of how to do this.
If I understand your question correctly, what you can do is
Create a new RenderTexture
Move these sprites off-screen, out of the main camera's view.
Point a new orthographic camera at all of the sprites that you've moved off-screen and set this camera's Target Texture field (in the Inspector view) to the render texture. This will save whatever the camera is seeing to that texture.
From here you can render that texture onto the surface of another game object (maybe a Quad?)
Attach a custom shader material to that quad that takes the render texture as input.
Perform whatever operations you wish to the render texture within this shader
Position this quad object in front of your main camera so that the final result gets rendered to screen
Does this make sense?
I am using an orthographic camera view where the camera follows the player, but does not rotate. When the player goes behind other objects I need a way to still see it. I played with hiding the objects but the prefabs I am using from the asset store do not seem to work well unless they are rendered opaque.
How can I have the player show through other objects, or have an outline or 'ghost' of the player visible?
I would suggest you to use another camera which will have same behaviour (same position/rotation, movement) as your main camera but will only render the player's layer. so when player goes behind other objects, this camera can still see it and make sure it renders on top of everything else using Depth property of camera.
Hope it helps