TEMA 2.4.1 ETAPA DE TESELACIÓN EJEMPLOS CON OPENGL Curso 2013 / 14 Procesadores Gráficos y Aplicaciones en Tiempo Real Profesores: David Miraut y Óscar D. Robles GMRV 2005-2014 Febrero 2014 Procesadores Gráficos -- Máster en Informática Gráfica, Juegos y Realidad Virtual -- ETAPA TESELACIÓN 13/14 1/20
Índice Curva de Bézier Superficie de Bézier Subdivisión de toda una esfera Teselación Phong Ejemplos tomados de la asignatura Advanced Topics in Graphics del Dr. Burton -- CSE4431 (Univ. York) 2/20
Bezier Curve Example 3/20
Bezier Curve Example use the tesselation shader to subdivide the curve into line segments that can be rendered possible to control the number of vertices based on curvature, screen area, etc. 4/20
Bezier Curve Example 5/20
Bezier Curve Example tesselation control shader #version 400 #extension GL_ARB_tessellation_shader: enable uniform float uouter1; layout(vertices = 4) out; // number of vertices in output patch void main() { } index of the vertex being processed by this invocation of the shader gl_out[gl_invocationid].gl_position = gl_in[gl_invocationid].gl_position; gl_tesslevelouter[0] = 1.; gl_tesslevelouter[1] = uouter1; runs once for each input patch vertex output patch vertex position = input patch vertex position 6/20
Bezier Curve Example tesselation evaluation shader #version 400 #extension GL_ARB_tessellation_shader: enable runs once for each output patch vertex generated by the TPG layout(isolines, equal_spacing) in; void main() { vec4 p0 = gl_in[0].gl_position; vec4 p1 = gl_in[1].gl_position; vec4 p2 = gl_in[2].gl_position; vec4 p3 = gl_in[3].gl_position; assign incoming vertex positions to separate variables for readability number of vertices in the input patch is stored in gl_patchverticesin 7/20
Bezier Curve Example tesselation evaluation shader (cont) float u = gl_tesscoord.x; 3-component floating-point vector holding the (u, v, w) coordinate of the vertex being processed by the TES float b0 = (1. u) * (1. u) * (1. u); float b1 = 3. * u * (1. u) * (1. u); float b2 = 3. * u * u * (1. u); float b3 = u * u * u; } gl_position = b0 * p0 + b1 * p1 + b2 * p2 + b3 * p3; 8/20
Bezier Surface similar to Bezier curve, except need two parameters u and v 16 control points instead of 4 parametric matrix equation see Dr. Bailey s tessellation shader slides 27-35 9/20
Whole-Sphere Subdivision a tessellation shader can easily be used to create a sphere given only its location and radius a sphere can be parameterized using two angles just use a quad 0 v 1 π θ π 0 u 1 π π φ 2 2 10/20
Whole-Sphere Subdivision the outer tessellation levels are useful here low tessellation on the two outer edges at the poles high tessellation on the two outer edges that are meridians see Dr. Bailey s tessellation shader slides 36-40 0 v 1 π θ π 0 u 1 π π φ 2 2 11/20
Adapting to Screen Coverage so far we have been using inner and outer tessellation levels that are passed in as uniform variables this is somewhat inflexible it would be useful if the tessellation shader could determine an optimal level of tessellation one idea adjust tessellation based on the area of the screen covered TCS needs to be able to compute or guess what the final patch will look like on the screen for this to work 12/20
Adapting to Screen Coverage for the whole-sphere example this is straightforward compute the extents of the three axes of the sphere in NDC or screen coordinates use the extents to set the number of outer tessellation levels for the meridian edges see Dr. Bailey s tessellation shader slides 41-44 13/20
Adapting to Screen Coverage 14/20
Adapting to Screen Coverage 15/20
Adapting to Screen Coverage 16/20
Adapting to Screen Coverage 17/20
PN Triangles a method of tessellating objects made up of triangles where the per-vertex normal vectors are known (or can be calculated) useful when your models are made up of triangles instead of smooth patches (like Bezier or B spline surfaces) basic idea use the vertices and normal vectors of the input triangle to compute a displacement field that produces a Bezier triangle see Dr. Bailey s tessellation shader slides 45-51 see jdupuy s blog posting 18/20
Phong Tessellation essentially a geometric version of Phong normal interpolation where the vertex positions are interpolated (instead of the normal vectors) http://perso.telecom-paristech.fr/~boubek/papers/phongtessellation/ 19/20
Phong Tessellation simpler than PN triangles and produces similar results see jdupuy s blog posting for a shader see original paper for full details http://perso.telecom-paristech.fr/~boubek/papers/phongtessellation/ 20/20