My setup is as follows:
Two layers with GameObjects in them: walls and shortWalls
Single camera, which is culling either walls or shortWalls
Single light, which is culling shortWalls
The effect I'm trying to create is a room where the walls can be fully rendered walls or only render the lowest part shortWalls (kind of like The Sims wall height).
The problem I am facing is that, when I change the camera culling mask to ignore walls, the light seems to ignore walls too. The culling mask of this light is constant, set to ignore shortWalls and to illuminate and cast shadows from walls.
I assume that, since the Unity Manual's layers page separates the use of layers by cameras and lights, the functionality is separated too. But it seems that the camera is ignoring the shadows cast by an object that is being culled.
Is there any way to allow the camera to render shadows casts by objects that are culled by the camera (but not the light)?
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 some objects I only want to render within a certain distance of the player. The objects don't have any colliders originally, so I am wondering what would be best for performance. Do I:
Check distance between object and player and render within a cerain distance
Add a trigger around my player, add colliders to all objects (using project->physics to make sure the layers only look for each other) and use OnTriggerEnter/Exit to determine when to render the object?
You can use cameras near/far clipping planes (Frustum Culling) to adjust the distance for rendering.
If you are looking for something more advanced use occlusion culling or combination of both:
Occlusion Culling is a feature that disables rendering of objects when they are not currently seen by the camera
because they are obscured (occluded) by other objects. This does not happen automatically in 3D computer graphics since most of the time objects farthest away from the camera are drawn first and closer objects are drawn over the top of them (this is called “overdraw”). Occlusion Culling is different from Frustum Culling. Frustum Culling only disables the renderers for objects that are outside the camera’s viewing area but does not disable anything hidden from view by overdraw. Note that when you use Occlusion Culling you will still benefit from Frustum Culling.
You can also use Camera.layerCullDistances if you want different camera cull distances for different objects:
Normally Camera skips rendering of objects that are further away than farClipPlane. You can set up some Layers to use smaller culling distances using layerCullDistances. This is very useful to cull small objects early on, if you put them into appropriate layers.
I'm looking for ways to clip an entire unity scene to a set of 4 planes. This is for an AR game, where I want to be able to zoom into a terrain, yet still have it only take up a given amount of space on a table (i.e: not extend over the edges of the table).
Thus far I've got clipping working as I want for the terrain and a water effect:
The above shows a much larger terrain being clipped to the size of the table. The other scene objects aren't clipped, since they use unmodifed standard shaders.
Here's a pic showing the terrain clipping in the editor.
You can see the clipping planes around the visible part of the terrain, and that other objects (trees etc) are not clipped and appear off the edge of the table.
The way I've done it involves adding parameters to each shader to define the clipping planes. This means customizing every shader I want to clip, which was fine when I was considering just terrain.
While this works, I'm not sure it's a great approach for hundreds of scene objects. I would need to modify whatever shaders I'm using, and then I'd have to be setting additional shader parameters every update for every object.
Not being an expert in Unity, I'm wondering if there are other approaches that are not "per shader" based that I might investigate?
The end goal is to render a scene within the bounds of some plane.
One easy way would be to use Box Colliders as triggers on each side of your plane. You could then turn off Renderers on objects staying in the trigger with OnTriggerEnter/OnTriggerStay and turn them on with OnTriggerExit.
You can also use Bounds.Contains.
Why seen cross-sections of objects? I have different meshes on objects with materials (with Standard Shader rendering mode = opaque)
http://prntscr.com/9vt7no
http://prntscr.com/9vt7px
It might be that the backface culling is set wrong (for your meshes). If it is culling front facing triangles while showing the backfacing ones, the effect would be about what you have shown on the pictures.
Either flip the cull mode of your shader, or flip the triangles in your mesh.
For a quick test your can just disable backface culling. If it looks right then, you know that your issue is about the culling.
I have a need for setting up clipping planes that aren't perpendicular to the camera. Doing that for the far plane was easy: I just added a shader that clears the background.
I just can't figure out how to do the same for the near clipping plane. I've tried to think of solutions dealing with multiple shaders and planes, a special cutting shader, having multiple cameras for this or somehow storing the view as a texture, but those ideas are mostly imperfect even if they were implementable. What I basically need is a shader that would say "don't render anything that's in front of me". Is that possible? Can I eg. make a shader to make the passed pixels "final"?