CG Class 28, Thurs 2018-12-06

CG Class 27, Mon 2018-12-03

1   OpenGL in Guha vs WebGL in Angel

  1. Guha, the text I used before Angel, uses OpenGL. Angel uses WebGL.

  2. OpenGL has a C API; WebGL uses Javascript.

  3. That OpenGL is the obsolete version 2; WebGL is based on the current OpenGL 3.

  4. OpenGL 2 has an immediate mode design: you draw things and they are forgotten.

    In WebGL you send buffers to the GPU and then draw them.

  5. OpenGL has compute shaders and geometry shaders. They fill in points along Bezier curves and draw trimmed NURBS.

  6. A NURBS surface is a 2D parametric surface in 3D (or 4D if homogeneous).

    A trim line is a 1D parametric curve in the the 2D parameter space of the surface.

    The trim lines cut around the outside of the desired region and also cut out holes.

    This is a powerful technique.

2   Chapter 15 slides

  1. You do not need to learn most of those slides. Later I'll summarize what you need.
  2. 15_1 Global rendering.
  3. 15_2 Ray tracing.
  4. 15_3 What's next?.

CG Class 26, Thurs 2018-11-29

2   Old OpenGL in C and with NURBS

Before Angel, I used another book, Guha. It used old OpenGL in C. However therefore it could show NURBS. Some sample programs are in

https://wrf.ecse.rpi.edu/wiki/ComputerGraphicsFall2013/guha/Code

Look at bezierCurves, which shows moving control points.

trimmedBicubicSplineSurface shows NURBS.

3   WebGL query

Victor Calvert writes,

The WebGL report shows current-environment specifics, including the maximum number of textures, maximum framebuffer resolution, and other information, retrieved via the WebGL API.

CG Homework 11, due Mon 2018-12-03 2359

  1. (2 pts) Computing the effect of light reflecting off of one diffuse surface onto the other surfaces in the scene is called:

    1. Bitblt
    2. Bump mapping
    3. Environment mapping
    4. Radiosity
    5. Texture mapping
  2. (2 pts) Painting a image onto a face to simulate fine detail is called:

    1. Bitblt
    2. Bump mapping
    3. Environment mapping
    4. Radiosity
    5. Texture mapping
  3. (2 pts) Pretending to alter the normal vectors to the surface during rendering is called:

    1. Bitblt
    2. Bump mapping
    3. Environment mapping
    4. Radiosity
    5. Texture mapping
  4. (2 pts) Quickly copying blocks of pixels from one buffer to another is called:

    1. Bitblt
    2. Bump mapping
    3. Environment mapping
    4. Radiosity
    5. Texture mapping
  5. (2 pts) Reflecting the objects around a shiny object onto its surface is called:

    1. Bitblt
    2. Bump mapping
    3. Environment mapping
    4. Radiosity
    5. Texture mapping

    Answer: slides 9_3.

  6. (2 pts) Several coordinate systems are typically used in texture mapping. Which one may be used to model curves and surfaces?

    1. Lagrangian coordinates
    2. Object or World Coordinates
    3. Parametric coordinates
    4. Texture coordinates
    5. Window Coordinates
  7. (2 pts) Which one is used to identify points in the image to be mapped?

    1. Lagrangian coordinates
    2. Object or World Coordinates
    3. Parametric coordinates
    4. Texture coordinates
    5. Window Coordinates
  8. (2 pts) Which one is conceptually, where the mapping takes place?

    1. Lagrangian coordinates
    2. Object or World Coordinates
    3. Parametric coordinates
    4. Texture coordinates
    5. Window Coordinates
  9. (2 pts) Which one is where the final image is really produced?

    1. Lagrangian coordinates
    2. Object or World Coordinates
    3. Parametric coordinates
    4. Texture coordinates
    5. Window Coordinates

    Answers: slide 9_4_5.

  10. (2 pts) Mathematically, the aliasing problem in CG

    1. happens when high frequency signals are not sampled often enough.
    2. happens when low frequency signals are sampled too often.
    3. is a new problem that did not occur with the old displays.
    4. can be reduced by subsampling and averaging
    5. both 1 and 4.
  11. (2 pts) When you add many images together to blend them, there may be problems: (10_3)

    1. Loss of accuracy if each color has only 8 bits.
    2. You can't do this at all in WebGL.
    3. This requires using a color buffer of at least 4096x4096.
    4. This requires a stencil buffer.
    5. This requires that the A component be set to 0.0.
  12. (2 pts) Fog has been removed from OpenGL, and is not in WebGL, because: (10_3)

    1. The several possible fog factors (linear, exponential, gaussian) were too confusing.
    2. With cleaner air, we no longer want to model smog.
    3. It executed too slowly.
    4. Removing it simplified the standard, and anyway you can implement it yourself.
    5. It wasn't removed; it's still part of WebGL.
  13. (2 pts) What does sampler2D do? (10_4)

    1. Return a sample random variable from a probability distribution.
    2. Return one specific texel from a texture map.
    3. Return a point on a bezier curve by interpolating control points.
    4. Interpoint a texture value from nearby texels.
    5. Compute a phong-shaded color.
  14. (2 pts) Rendering a scene by computing which pixels are colored by each object is called (12_5)

    1. Image space approach
    2. Modelview space approach
    3. Object space approach
    4. Pixel space approach
    5. Viewport space approach
  15. (2 pts) Rendering a scene by computing which objects are behind each pixel is called (12_5)

    1. Image space approach
    2. Modelview space approach
    3. Object space approach
    4. Pixel space approach
    5. Viewport space approach
  16. (2 pts) Cohen-Sutherland clipping (13_1)

    1. Clips faces fast by doing concave faces properly.
    2. Clips faces fast by normalizing the projection first.
    3. Clips lines fast by eliminating many simple cases quickly.
    4. Clips lines fast by using the fact the current CPUs do division fast.
    5. Clips textures fast with a mipmap.
  17. (2 pts) View normalization (13_1)

    1. Makes the clip region into a cube but changes object cubes into parallelepipeds.
    2. Preserves angles and distances.
    3. Preserves angles but not distances.
    4. Preserves distances but not angles.
    5. Was obsoleted by fast CPUs.
  18. (2 pts) About polygon clipping: (13_2)

    1. A polygon might gain vertices.
    2. A polygon might gain area.
    3. If a polygon's vertices are all outside the clip region, then it may be deleted.
    4. Using a 6-stage pipeline keeps the latency the same.
    5. Concave polygons become convex.
  19. (2 pts) From his profits from SGI, Netscape, and other startups, Jim Clark bought the world's XXX largest yacht.

    1. 1st
    2. 2nd
    3. 3rd
    4. 4th
    5. 5th
  20. (2 pts) Which hidden surface algorithm sorts objects back-to-front? (13_2)

    1. BSP tree
    2. depth (Z) buffer
    3. image space
    4. painter's
    5. scan line
  21. (2 pts) Which hidden surface algorithm preprocesses objects into a tree so that you can change the viewpoint and then render by traversing the tree in a different order? (13_2)

    1. BSP tree
    2. depth (Z) buffer
    3. image space
    4. painter's
    5. scan line
  22. (2 pts) Which hidden surface algorithm might send its output straight to a display like a CRT w/o ever storing the whole image? (13_2)

    1. BSP tree
    2. depth (Z) buffer
    3. image space
    4. painter's
    5. scan line
  23. (2 pts) Some colors that you can see on your display cannot be printed, and vv. Why? (13_4)

    1. Purple is not a pure spectral color.
    2. The UV emitted by the display fades the printer paper.
    3. The display and printer's gamuts don't match.
    4. The printer has 4 inks but the display only 3 primaries.
    5. There's no such thing as a standard display - different manufacturers have different notions of red.
  24. (2 pts) What is happening in the following code that is part of a picking program that we saw (11_4):

    if(i==0) gl_FragColor = c[0];
      else if(i==1) gl_FragColor = c[1];
      else if(i==2) gl_FragColor = c[2];
      else if(i==3) gl_FragColor = c[3];
      else if(i==4) gl_FragColor = c[4];
      else if(i==5) gl_FragColor = c[5];
      else if(i==6) gl_FragColor = c[6];
    
    1. This assigns to each pixel the number that we'd like returned if the user clicks on that pixel.
    2. This assigns to each pixel the true color of that polygon.
    3. This keeps track of how many times the user clicked on that pixel.
    4. This notes how many vertices that polygon has.
    5. This notes the shininess exponent for that face.
  25. (2 pts) Radiosity is better than ray tracing when the scene is all

    1. diffuse objects
    2. objects outside the viewing region
    3. objects that are very close to the viewpoint
    4. specular objects
    5. very small objects
  26. (2 pts) Ray tracing is better than radiosity when the scene is all

    1. diffuse objects
    2. objects outside the viewing region
    3. objects that are very close to the viewpoint
    4. specular objects
    5. very small objects
  27. (2 pts) Firing multiple rays through each pixel handles the problem of

    1. diffuse objects
    2. objects outside the viewing region
    3. objects that are very close to the viewpoint
    4. specular objects
    5. very small objects
  28. (2 pts) Consider a 2D Cartesian cubic Bezier curve with these control points: (0,0), (0,1), (1,1), (1,0). What is the point at t=0? OK to look up the formula.

    1. (0,0)
    2. (0,1)
    3. (1,0)
    4. (1/2, 3/4)
    5. (1/2,1)
  29. (2 pts) What is the point at t=1/2?

    1. (0,0)
    2. (0,1)
    3. (1,0)
    4. (1/2, 3/4)
    5. (1/2,1)
  30. (2 pts) What is the point at t=1?

    1. (0,0)
    2. (0,1)
    3. (1,0)
    4. (1/2, 3/4)
    5. (1/2,1)
  31. (2 pts) If you interpolate a curve through a list of control points instead of approximating a curve near the points, then what happens?

    1. It will not be possible to join two curves and match the radii of curvature.
    2. The calculations to compute the curve will take impossibly long.
    3. The curve will stay within the convex hull of the control points.
    4. The curve will swing outside the convex hull of the control points.
    5. This isn't possible for curves of odd degree.
  32. (2 pts) If you use quadratic Bezier curves, then what happens?

    1. It will not be possible to join two curves and match the radii of curvature.
    2. The calculations to compute the curve will take impossibly long.
    3. The curve will stay within the convex hull of the control points.
    4. The curve will swing outside the convex hull of the control points.
    5. This isn't possible for curves of even degree.

(Total: 64 points.)

CG Class 25, Mon 2018-11-26

1   ACM SIGSPATIAL GIS Cup 1st place

Here.

In 2016, we won 2nd. We also won 2nd in 2015.

3   Chapter 14

  1. Curves are the next chapter of Angel. WebGL does this worse than full OpenGL. Here is a summary. Big questions:

    1. What math to use?
    2. How should the designer design a curve?
    3. My notes on Bezier curves.
  2. Partial summary:

    1. To represent curves, use parametric (not explicit or implicit) equations.

    2. Use connected strings or segments of low-degree curves, not one hi-degree curve.

    3. If the adjacent segments match tangents and curvatures at their common joint, then the joint is invisible.

    4. That requires at least cubic equations.

    5. Higher degree equations are rarely used because they have bad properties such as:

      1. less local control. Changing one control point of a hi-degree curve changes the whole curve. Parts of the curve distant from that point may move a lot. This makes designing a desired curve impossible.
      2. numerical instability. Small changes in coefficients cause large changes in the curve, even if computations are exact.
      3. roundoff error. Computations are not exact.
    6. See my note on Hi Degree Polynomials.

    7. One 2D cartesian parametric cubic curve segment has 8 d.f. in 2D (12 in 3D).

      \(x(t) = \sum_{i=0}^3 a_i t^i\),

      \(y(t) = \sum_{i=0}^3 b_i t^i\), for \(0\le t\le1\).

    8. Requiring the graphic designer to enter those coefficients would be unpopular, so other APIs are common.

    9. Most common is the Bezier formulation, where the segment is specified by 4 control points, which also total 8 d.f.: P0, P1, P2, and P3.

    10. The generated curve starts at P0, goes near P1 and P2, and ends at P3.

    11. The curve stays inside the control polygon, the convex hull of the control points. A flatter control polygon means a flatter curve. Designers like this.

    12. A choice not taken would be to have the generated curve also go thru P2 and P3. That's called a Catmull-Rom-Oberhauser curve. However that would force the curve to go outside the control polygon by a nonintuitive amount. That is considered undesirable.

    13. Instead of 4 control points, a parametric cubic curve can also be specified by a starting point and tangent, and an ending point and tangent. That also has 8 d.f. It's called a Hermite curve.

    14. The three methods (polynomial, Bezier, Hermite) are easily interconvertible.

    15. Remember that we're using connected strings or segments of cubic curves, and if the adjacent segments match tangents and curvatures at their common joint, then the joint is invisible.

    16. Matching tangents (called \(G^1\) or geometric continuity) is sufficient, and is weaker than matching the 1st derivative (\(C^1\) or parametric continuity), since the 1st derivative has a direction (tangent) and a length. Most people do \(C^1\) because it's easier and good enough. However \(G^1\) gives you another degree of freedom to use in your design.

    17. Similarly, matching the radius of curvature (\(G^2\) or geometric continuity) is weaker than matching the 2nd derivative (\(C^2\) or parametric continuity), but most people do parametric continuity.

    18. Parametric continuity reduces each successive segment from 8 d.f. down to 2 d.f.

    19. This is called a B-spline.

    20. From a sequence of control points we generate a B-spline curve that is piecewise cubic and goes near, but probably not thru, any control point (except perhaps the ends).

    21. Moving one control point moves the adjacent few spline pieces. That is called local control. Designers like it.

    22. One spline segment can be replaced by two spline segments that, together, exactly draw the same curve. However they, together, have more control points for the graphic designer to move individually. So now the designer can edit smaller pieces of the total spline.

    23. Extending this from 2D to 3D curves is obvious.

    24. Extending to homogeneous coordinates is obvious. Increasing a control point's weight attracts the nearby part of the spline. This is called a rational spline.

    25. Making two control points coincide means that the curvature will not be continuous at the adjacent joint.

      Making three control points coincide means that the tangent will not be continuous at the adjacent joint.

      Making four control points coincide means that the curve will not be continuous at the adjacent joint.

      Doing this is called making the curve (actually the knot sequence) Non-uniform. (The knots are the values of the parameter for the joints.)

    26. Putting all this together gives a non-uniform rational B-spline, or a NURBS.

    27. A B-spline surface is a grid of patches, each a bi-cubic parametric polynomial.

    28. Each patch is controlled by a 4x4 grid of control points.

    29. When adjacent patches match tangents and curvatures, the joint edge is invisible.

    30. The surface math is an obvious extension of the curve math.

      1. \(x(u,v) = \sum_{i=0}^3\sum_{j=0}^3 a_{ij} u^i v^j\)
      2. \(y, z\) are similar.
      3. One patch has 48 d.f. for Cartesian points, or 64 d.f. for homogeneous points, although most of those are used to establish continuity with adjacent patches.
  3. My extra enrichment info on Splines.

  4. The program I showed earlier is robotArm is Chapter 9.

  5. To run program figure there, you may first need to fix an error in figure.html. Change InitShaders to initShaders.

    Many of the textbook programs have errors that prevent them from running. You can see them in the console log.

CG Class 24, Mon 2018-11-19

1   Thanksgiving trivia questions

  1. When the native American Squanto greeted the Pilgrims in March 1621, what language did he use?
  2. Where had he learned it?

2   Nice site on visualizing quaternions

Lessons by Grant Sanderson, Technology by Ben Eater.

here

3   Chapter 13 slides ctd

  1. 13_2 Polygon rendering. Includes clipping polygons, hidden surface algorithms.
  2. 13_3 Rasterization.

4   My commentaries

4.1   Clipping

  1. Many of these algorithms were developed for HW w/o floating point, where even integer multiplication was expensive.
  2. Efficiency is now less important in most cases (unless you're implementing in HW).
  3. The idea of clipping with a 6-stage pipeline is important.
  4. Jim Clark, a prof at Stanford, made a 12-stage pipeline using 12 copies of the same chip, and then left Stanford to found SGI.
    1. Later he bankrolled Netscape and 2 other companies.
    2. More recently he had the world's 4th largest yacht.

4.2   Polygon rendering

  1. My note on Bresenham Line and Circle Drawing. Jack Bresenham, then at IBM invented these very fast ways to draw lines and circles with only integer addition and subtraction. My note gives step-by-step derivations by transforming slow and clear programs to fast and obscure programs.
  2. My note on Two polygon filling algorithms.

4.3   Visibility methods

Here's my summary of problems with the main methods:

  1. Painters:
    1. The painter's algorithm is tricky when faces are close in Z.
    2. Sorting the faces is hard and maybe impossible. Then you must split some faces.
    3. However sometimes some objects are always in front of some other objects. Then you can render the background before the foreground.
  2. Z-buffer:
    1. Subpixel objects randomly appear and disappear (aliasing).
    2. Artifacts occur when objects are closer than their Z-extent across one pixel.
    3. This happens on the edge where two faces meet.
  3. BSP tree:
    1. In 3D, many faces must be split to build the tree.
  4. The scanline algorithm can feed data straight to the video D/A. That was popular decades ago before frame buffers existed. It became popular again when frame buffers are the slowest part of the pipeline.
  5. A real implementation, with a moving foreground and fixed background, might combine techniques.
  6. References: wikipedia.

5   Textbook programs

  1. Chapter 10 Mandlebrot showing serious computation in the fragment shader.

CG Class 23, Mon 2018-11-12

1   Upcoming classes

  1. No class Wed 11/14.
  2. No class Thurs 11/15 because Pres Jackson scheduled a faculty meeting then.
  3. Next class Mon 11/19

2   Chapter 12 slides ctd

  1. 12_3 Graphical Objects and Scene Graphs.

  2. 12_4 Graphical Objects and Scene Graphs 2.

  3. 12_5 Rendering overview.

    At this point we've learned enough WebGL. The course now switches to learn the fundamental graphics algorithms used in the rasterizer stage of the pipeline.

3   Chapter 13 slides

  1. 13_1 Clipping.

    A lot of the material in the clipping slides is obsolete because machines are faster now. However perhaps the rendering is being done on a small coprocessor.

    Big idea (first mentioned on Oct 20): Given any orthogonal projection and clip volume, we transform the object so that we can view the new object with projection (x,y,z) -> (x,y,0) and clip volume (-1,-1,-1) to (1,1,1) and get the same image. That's a normalization transformation'.

4   Textbook programs

  1. Chapter 10 Mandlebrot showing serious computation in the fragment shader.