Herramientas de usuario

Herramientas del sitio


fw:ogl:graphics

¡Esta es una revisión vieja del documento!


Gráficos con OpenGL y GLSL

Conceptos

Graphics pipeline

Se refiere a los pasos que sigue la tarjeta gráfica para dibujar por pantalla.

En sí es la manipulación de los vértices y los modelos que acaban siendo una porción del framebuffer, este concretamente corresponde a lo que se acaba mostrando por pantalla.

  1. Operaciones Per-Vertex: los vértices son almacenados por OpenGL mediante la proyección de las matrices modelo-vista y convertidos a coordenadas de ventana. También es justo en esta en la que los shaders son calculados (controlados por GLSL), se colocan pues las luces, los reflejos y propiedades de superficies.
  2. Clipping y culling: Se calcula el clipping (porción de las primitivas que va a dibujarse) y qué caras son marcadas por culling (selección de caras que se han de ver) se han de preparar para la rasterización.
  3. Transformaciones de proyección de de vista: se aplica la transformación por perspectiva, los objetos que están lejos de la cámara se hacen más pequeños.
  4. Rasterización: Los vértices que forman las primitivas se unen y se rasterizan (se rellenan). Esta fase es compleja y contiene el conjunto de sub-pasos denominado pixel pipeline.
  5. Operaciones per-fragment: Esta fase también puede ser manipulada por GLSL, esta vez utilizando los fragment-shaders. Aquí se calculan los colores finales de los pixels en la pantalla.
  6. Framebuffer: En esta última fase los píxels ya forman parte de la porción de memoria llamada framebuffer. Por defecto este es pasado a pantalla cuando hay un intercambio (swap) de buffers. OpenGL permite varios objetos framebuffer (FBO) para crear una animación más fluida. A la vez, esto FBO también pueden ser aplicados como texturas o primitivas.

Matrices de OpenGL

Shaders

Los shaders son programas que se ejecutan sobre el procesador gráfico y son utilizados para modificar los efectos de luz, sombras y producir efectos de postprocesado especiales. Proporcionan gran flexibilidad a la hora de programar la GPU.

Tipos de shaders

  • Vertex shaders

Vertex shaders are run once for each vertex given to the graphics processor. The purpose is to transform each vertex's 3D position in virtual space to the 2D coordinate at which it appears on the screen (as well as a depth value for the Z-buffer). Vertex shaders can manipulate properties such as position, color, and texture coordinate, but cannot create new vertices. The output of the vertex shader goes to the next stage in the pipeline, which is either a geometry shader if present, or the pixel shader and rasterizer otherwise. Vertex shaders can enable powerful control over the details of position, movement, lighting, and color in any scene involving 3D models.

  • Geometry shaders

Geometry shaders are a relatively new type of shader, introduced in Direct3D 10 and OpenGL 3.2; formerly available in OpenGL 2.0+ with the use of extensions.[2] This type of shader can generate new graphics primitives, such as points, lines, and triangles, from those primitives that were sent to the beginning of the graphics pipeline.[3] Geometry shader programs are executed after vertex shaders. They take as input a whole primitive, possibly with adjacency information. For example, when operating on triangles, the three vertices are the geometry shader's input. The shader can then emit zero or more primitives, which are rasterized and their fragments ultimately passed to a pixel shader. Typical uses of a geometry shader include point sprite generation, geometry tessellation, shadow volume extrusion, and single pass rendering to a cube map. A typical real world example of the benefits of geometry shaders would be automatic mesh complexity modification. A series of line strips representing control points for a curve are passed to the geometry shader and depending on the complexity required the shader can automatically generate extra lines each of which provides a better approximation of a curve.

  • Pixel shaders

Pixel shaders, also known as fragment shaders, compute color and other attributes of each fragment. Pixel shaders range from always outputting the same color, to applying a lighting value, to doing bump mapping, shadows, specular highlights, translucency and other phenomena. They can alter the depth of the fragment (for Z-buffering), or output more than one color if multiple render targets are active. In 3D graphics, a pixel shader alone cannot produce very complex effects, because it operates only on a single fragment, without knowledge of a scene's geometry. However, pixel shaders do have knowledge of the screen coordinate being drawn, and can sample the screen and nearby pixels if the contents of the entire screen are passed as a texture to the shader. This technique can enable a wide variety of two-dimensional postprocessing effects, such as blur, or edge detection/enhancement for cartoon/cel shaders. Pixel shaders may also be applied in intermediate stages to any two-dimensional images in the pipeline, whereas vertex shaders always require a 3D model. For instance, a pixel shader is the only kind of shader that can act as a postprocessor or filter for a video stream after it has been rasterized.

Algoritmos de shading

Técnicas de interpolación:

  • Flat shading
  • Gouraud shading
  • Phong shading

Modelos de iluminación (pueden ser combinados con técnicas de interpolación):

  • Blinn–Phong
  • Cook–Torrance (microfacets)
  • Lambert
  • Minnaert
  • Oren–Nayar (Rough opaque diffuse surfaces)
  • Phong
  • Ward anisotropic
  • Cel shading

Lenguajes para programar shaders

  • GLSL: Oficial de OpenGL (OpenGL Shading Language).
  • HLSL: Oficial de Direct3d (High Level Shading Language).
  • Cg: Propio de nVidia.

GLSL

fw/ogl/graphics.1360520642.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)