How do I go about rendering objects outside of the camera’s field of view?
The shader I am using can slightly change the shape / position of objects visually, but the gameobject is obviously unmoved and so Unity sometimes thinks (correctly) that the object is outside the camera’s field of view, but because of the shader they are in view and not being rendered. This also causes objects to disappear just before going off camera.
It would be pretty ugly to put a border round the edge of the screen so how would I go about doing this?
Basically I want to make the culling frustum a little larger than the view frustum of the camera. Is this possible?
If you could, at least, give the code of the shader, it could be helpfull.
You will have to make some research about Frustum culling. This is the method used to not render objects which are outside the cameras’ view frustum.
From the doc, it is said that :
Unity ensures that when rendering your objects those which are completely outside of this frustum are not displayed. This is called Frustum Culling. Frustum Culling happens irrespective of whether you use Occlusion Culling in your game.
See : Unity - Manual: Camera component
EDIT : it is possible to modifiy the culling distance for specific layers (near and far plane distance)
I think it will be difficult to find a way to tell your cameras to render an object if it is outside the view frustum.
Oops, my bad, see this blog post :
The author simply moves the bounds of the gameobject inside the view frustum (but set the transform position back), so that the cameras render it.
// boundsTarget is the center of the camera's frustum, in world coordinates:
Vector3 camPosition = camera.transform.position;
Vector3 normCamForward = Vector3.Normalize(camera.transform.forward);
float boundsDistance = (camera.farClipPlane - camera.nearClipPlane) / 2 + camera.nearClipPlane;
Vector3 boundsTarget = camPosition + (normCamForward * boundsDistance);
// The game object's transform will be applied to the mesh's bounds for frustum culling checking.
// We need to "undo" this transform by making the boundsTarget relative to the game object's transform:
Vector3 realtiveBoundsTarget = this.transform.InverseTransformPoint(boundsTarget);
// Set the bounds of the mesh to be a 1x1x1 cube (actually doesn't matter what the size is)
Mesh mesh = GetComponent().mesh;
mesh.bounds = new Bounds(realtiveBoundsTarget, Vector3.one);
Credits : Allen Pestaluky
private Vector3 GetRectPoints(Vector3 center, Vector3 right, Vector3 Up, float width, float height)
Vector3 upDif = Up * height / 2f;
Vector3 rightDif = right * width / 2f;
Vector3 ar = new Vector3;
ar = center - upDif - rightDif;
ar = center + upDif - rightDif;
ar = center + upDif + rightDif;
ar = center - upDif + rightDif;
private bool IsIntoFrustum(Vector3 point, float radius) // Point is Object center, Radius is sphere radius of the target object
var frustumHeight = Mathf.Tan(camera.fieldOfView * 0.5f * Mathf.Deg2Rad);
var frustumWidth = frustumHeight * camera.aspect;
Vector3 pointToCam = point - camera.transform.position;
Vector3 cubeRectPoints = GetRectPoints(camera.transform.position + camera.transform.forward * pointToCam.magnitude,
camera.transform.right, camera.transform.up, pointToCam.magnitude * frustumHeight,
pointToCam.magnitude * frustumWidth);
for (int i = 0; i < cubeRectPoints.Length; i++)
Vector3 center = camera.transform.position + camera.transform.forward * pointToCam.magnitude;
if (Vector3.Distance(point, center) > Vector3.Distance(cubeRectPoints*, center) + radius)*