- Home /
How do I render only a part of the cameras view?
How can I render only a part of the camera? Like camera.rect but it only render the visible areas, and doesn't squeeze the remaining.
I have tried rotating the camera while using camera.rect, but it deforms the image.
The camera renders everything is visible in its view angle (or fustrum, to be more precise). What exactly do you wanna do? Draw only selected objects? Zoom in some specific part of the screen?
You can set the camera to only render certain layers by unchecking the layers you don't want rendered in the "culling mask" field , but I'm unsure if that is what you are looking for.
Some more details would be nice.
No that's not what I needed, but thanks anyways for the comments.
Answer by Jayde · Jun 24, 2011 at 07:50 PM
It sounds like what you're looking for is a scissor rect instead of a viewport rect. You can simulate a scissor rect using a viewport rect by multiplying a scale and offset matrix into your projection matrix.
public static void SetScissorRect( Camera cam, Rect r )
{
if ( r.x < 0 )
{
r.width += r.x;
r.x = 0;
}
if ( r.y < 0 )
{
r.height += r.y;
r.y = 0;
}
r.width = Mathf.Min( 1 - r.x, r.width );
r.height = Mathf.Min( 1 - r.y, r.height );
cam.rect = new Rect (0,0,1,1);
cam.ResetProjectionMatrix ();
Matrix4x4 m = cam.projectionMatrix;
cam.rect = r;
Matrix4x4 m1 = Matrix4x4.TRS( new Vector3( r.x, r.y, 0 ), Quaternion.identity, new Vector3( r.width, r.height, 1 ) );
Matrix4x4 m2 = Matrix4x4.TRS (new Vector3 ( ( 1/r.width - 1), ( 1/r.height - 1 ), 0), Quaternion.identity, new Vector3 (1/r.width, 1/r.height, 1));
Matrix4x4 m3 = Matrix4x4.TRS( new Vector3( -r.x * 2 / r.width, -r.y * 2 / r.height, 0 ), Quaternion.identity, Vector3.one );
cam.projectionMatrix = m3 * m2 * m;
}
Answer by rohankad · Sep 15, 2015 at 05:36 AM
Ocullision Culling will help you out. It renders the objects which are available in the range of camera.
Occlusion culling is something different. He wants part of the screen to render is sounds.
Your answer
Follow this Question
Related Questions
Changing the Camera viewport rect results in resizing the objects rendered by the specific camera ? 1 Answer
Rendering players per camera 1 Answer
Render group of objects in front? 0 Answers
Can two cameras render at different speeds? 1 Answer
How do I force my cameras to render in a certain order in URP? 1 Answer