2
\$\begingroup\$

What is the concept of a "camera" in game development? It seems that OpenGL and Vulkan don't explicitly have a concept of a camera.

However, engines like Unity, Unreal Engine, Godot, Flutter Flame, and Three.js do incorporate the concept of a camera. It's also frequently mentioned in computer graphics textbooks.

I came across this resource: https://learn.unity.com/mission/creative-core-cameras?uv=2022.3&pathwayId=61a65568edbc2a00206076dd

Can the camera be understood as the entity that determines the visible area in a scene?

Given that OpenGL and Vulkan don't explicitly include a camera, does this imply that the implementation of cameras is arbitrary and specific to each game engine, requiring developers to learn the differences between each engine's camera system?

The camera does not appear in the general iOS app, Android app, or Flutter app. It is instantly needed in game development and I am struggling to understand it.

I also watched the video: https://www.youtube.com/watch?v=eq8L1fozxto&list=PLiZZKL9HLmWPBK7P8gb2XZRnbwBbFuvqS&index=4

The specifications of Flame's camera are constantly changing, which means that much of the information available online becomes outdated quickly (though the video above is very recent). This makes it difficult to learn and understand the camera system without getting distracted by these frequent changes.

Since I am working on 2D game, 2D games are easier for me to understand (although I don't mind if the answer pertain to 3D games).

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Imagine you use a LIVE camera to broadcast LIVE a football game to an audience. So, whatever your camera sees is exactly what the users can see in REAL TIME. That is basically the concept a camera in a Unity game. In a game, users can also rotate a camera in any angle, and move the camera any distance in any direction to see objects in a game. Users can also put the camera at a fixed location to view objects moving around in a game. Each Unity game must have at least 1 camera. Otherwise, Unity won't let you test-play the game on the editor, and users won't be able to see anything. \$\endgroup\$ Commented Aug 24 at 9:34

1 Answer 1

2
\$\begingroup\$

Camera Concept Primer

In the case of 2D graphics, you normally define an area where you draw your shapes and lines etc. This is the canvas. Its coordinate center is at (0,0) at the top-left corner and you define a width and a height for it in pixels. You can draw inside the canvas, but you can also draw a shape that is bigger or only partially inside the frame, which is clipped automatically at the borders of the canvas. This would be the "scene" to be built and rendered, but being visible only partially.

You can think of all those properties as being defined by the "camera" in the 3D case. Because of those similarities some 2D engines may provide a camera concept to tweak all those settings as well.

Your strategy when rendering a 2D image will be to paint the background first, then the middleground and the foreground last. This is the painter's algorithm. For a 3D scene you need to determine those layers in a similar fashion. Therefore you have a "camera" which defines via its view-axis which elements to draw first and last.

To understand the concept of a "camera" in (3D) computer graphics, you need to understand coordinate systems (and transformation matrices). There are several of them involved in building and rendering a scene.

I sacrifice some details in the following, for clarity of the example, but the general direction is valid:

  • Imagine a 3D model in local coordinate space, with (0,0,0) at its center
  • Imagine a scene containing that model at the position (100,100,100)
  • Imagine a camera in the scene at (500,500,500) looking towards the model
  • Imagine a canvas on which the image the camera "sees" is drawn.

All those stages are part of the OpenGL rendering pipeline and occur in all 3D engines as well (more generally named Graphics Pipeline).

If the image of the scene needs to be rendered, OpenGL will take the vertex information of all models in the scene and transform them into the coordinate system of the camera. This is done by a series of matrix multiplications.

The resulting coordinate space has the camera always at the origin (0,0,0). Its negative Z-axis points forward (in case of OpenGL) and there is a vector which defines what is "up", usually the Y-axis is used for that, so vec3(0,1,0). The camera defines the maximum render distance beyond which all vertices are not rendered anymore. The camera also defines the "viewport" (having the origin at the center) and the "canvas"/"image" in width and height in pixels (and origin at the top left). This will be the final rendered image to be displayed on screen.

Here is a tutorial that explains the steps in terms of OpenGL commands. You will notice that all the vectors to define a camera coordinate system are assembled first and used as input for the glLookAt(). That is how OpenGL defines the transformation matrix of the camera.

Because the camera has a 3D position, it is almost always visualized as an entity of the scene graph in game engines like Unity for example. This allows easy manipulation of the camera's properties. However, this does not make clear that the camera is in fact a very special entity which defines the whole camera coordinate system needed during the render process. Thus, defines the cut-out of the scene that will be visible as the final image.

Sidenote: A scene can have more than one camera setup in the scene, but only one of them can be the active one, whose image is being rendered. Strictly speaking, there has to be one active camera per viewport, because you can have multiple viewports on a screen for example. This and more is covered under the topics of "Multi target rendering" and "Render to texture".

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .