Is it correct to create a shader program for camera?

1k Views Asked by At

I want to create a separate class/prototype for camera object in my 3D application.

There is a Model-View matrix as I understood, which is used by developer for translating/rotating/using other Affine transformations for any 3D-object, which is added to scene.

But, my camera isn't a thing like some mesh. Camera doesn't need to have a color, so fragment shader is not needed (of course, if you don't want to visualize a camera as LINES, and switch between different cameras, just for example), so what do I really need for camera?

  • position in 3-dimensional vector ( x, y, z )
  • mat4 matrix, which describes position and some additional vector components, which I will use in vertex shader, and which will be used for camera's position translate
  • some controls for moving camera ( I don't want to describe big details about it, but just for example, let's say we will use only keyboard keys for moving and rotating it)

So, my question is... If viewport of our 3D-scene is represented by Model-View matrix on which any object is being processed by some Affine transformation. Is it correct to create a particular shader program for the camera object or maybe it's more correct to define such a shader program for scene object and just in some draw method/function translate camera position to Model-View matrix, which is hold in the property of Scene object?

I'm using WebGL library for my project, but I think some OpenGL developers may also answer to such a question, because these things are similar in both libraries.

1

There are 1 best solutions below

0
On BEST ANSWER

Is it correct to create a particular shader program for the camera object

No, because there is no camera in OpenGL. In fact there is not even a scene in OpenGL. OpenGL is a very simplicistic drawing API. All that OpenGL does is drawing points, lines or triangles to a pixel framebuffer, one point, line or triangle at a time and once it's drawn OpenGL already forgot about it.

Shaders are little programs that control how points, lines or triangles are turned into pixels on the screen. Shaders do not "control" scene objects. Why? Because there's no scene in OpenGL and there are no scene objects in OpenGL.

There is no camera. What you could think of a camera (but isn't) is some sub-transformation in the modelview that's moving the geometry on the screen around in a way, as if it were the result of moving a camera.

Note that this applies equally to WebGL and OpenGL-ES.