程序代写CS代考 data structure GPU c++ Computer Graphics

Computer Graphics
COMP3421/9415 2021 Term 3 Lecture 2

What are we covering today
How do Computers make Graphics?
¡ñ Hardware – Monitors and GPUs
¡ñ What’s in the screen? Pixels and colours
¡ñ What’s the GPU? A computer inside your computer
¡ñ What is “rendering” (Polygon Rendering)?
¡ñ What is OpenGL?
¡ñ What are Shaders?
¡ñ How are we coding in this subject?

Graphics Hardware – Monitors
A two dimensional array of lights
¡ñ A panel with an array of light sources . . . ¡ð LCD, LED, OLED etc etc . . . Cathode Ray Tube 😛
¡ñ Each little light (called a pixel) has separate red, green and blue capability
¡ñ The image on screen can refresh multiple times a second
¡ñ Current standard is around 1920 x 1080 at 16-24bits per pixel and 60hz
A cathode ray tube monitor from the 1990s Image credit:

Monitors – Illusions of Reality
None of this is real
¡ñ The illusion of colour
¡ñ The illusion of complete objects
¡ñ The illusion of movement
1mm of pixels in different formats Image credit: Wikipedia user Pengo

Graphics Hardware – Graphics Cards
Specialised hardware
¡ñ A computer in your computer
¡ñ Has a processor . . .
¡ñ . . . and its own memory
¡ñ Receives data through the
motherboard
¡ñ Only outputs video to the monitor
(we’re disregarding GPGPU for the moment)
Image credit: Nvidia

Graphics Cards – Historical Perspective
Why is this a separate piece of hardware?
¡ñ From a bandwidth perspective:
¡ð A sample monitor has 1920 x 1080 pixels in 24bits of colours = approx 6MB
¡ð Refreshing 60 times a second = approx 365MB a second
¡ð PCI Express bus bandwidth is approx 266MB a second
¡ñ Without a graphics card, we lack the bandwidth to refresh a monitor
¡ñ Historically, this was one of the first reasons why separate graphics
hardware was created (back when the numbers were more like 640 x 480)
¡ñ However, it’s not just a bandwidth issue!

Graphics Hardware vs the Computer’s CPU
A massively parallel floating point calculator
Regular CPU (Intel Core i9)
GPU (Nvidia 3090)
8 processing cores @ 3.6GHz
10,496 processing cores @ 1755MHz
Each core runs different processes independently
Every core is running the same code at the same time
Large range of possible instructions
Limited set of calculations available
A funny take on this from an Nvidia conference: https://youtu.be/-P28LKWTzrI

Polygon Rendering (an introduction)

Polygons
Taking a concept of a scene and turning it into an image
¡ñ This is a huge concept . . . we’ll start simple
¡ñ A polygon is a shape, made up of vertices (corners) and edges (lines)
A vertex

Polygons into Meshes
A complex object can be made up of many vertices and edges
¡ñ Pieced together, we call this a “mesh”
¡ñ A series of polygons where some of them
share vertices
¡ñ This creates a “surface”
Image credit: School of Computing, University of Utah

Vertices and Coordinates
Keeping track of vertices
¡ñ Vertices have coordinates, like x,y,z
¡ñ A group of floating point numbers
¡ñ Data Structures!
¡ñ Vectors of vertices
¡ñ Coordinates also allow us to apply techniques from linear algebra (transform matrices)
Image credit: Wikipedia user §¡§ß§Õ§â§Ö§Û §±§Ö§â§è§Ö§Ó

View Projection
How do we “look” at a virtual scene?
Image credit:

Virtual to Real
Projection to Pixels
¡ñ Imagine every pixel being in the virtual world
¡ñ Imagine a line drawn from the virtual camera through a pixel
¡ñ That line meets an object in the world
¡ñ Whatever colour that object is . . .
¡ñ Is the colour the pixel ends up

3D Projection
Mapping coordinates
¡ñ We’re mapping 3D coordinates onto our 2D monitor
¡ñ If we have a viewpoint in the same coordinate system (the camera)
¡ñ We can tell what that camera should see using maths
¡ñ More detail in future lectures!
Image credit: learnopengl.com

Break Time
5 minute break
¡ñ Graphics can be excessively technical
¡ñ It can also involve a LOT of maths
¡ñ We’re going to use a lot without necessarily
knowing it in extreme detail
¡ñ But we will still definitely want to understand
how things work at a theoretical level

Coding Graphics

What is OpenGL?
The Open Graphics Library
¡ñ A big API/Library
¡ñ Gives us access to the Graphics Card
¡ñ Also provides a lot of functionality so that we can do graphics without low
level programming
¡ñ Is not a language itself!

Shaders
Code that runs on the GPU
¡ñ C++ runs on the CPU (once compiled)
¡ñ GLSL (OpenGL Shader Language) runs on the GPU
¡ñ Vertex Shader
¡ð Runs once per vertex
¡ð Can manipulate vertices (and more later!)
¡ñ Fragment Shader
¡ð Runs once per pixel
¡ð Can manipulate the colour of the pixel
¡ð Usually receives information from the vertex shader

C++ Features in this Course
A specific subset of C++ for Graphics Purposes
¡ñ A compromise between needing a prior C++ course
¡ñ and being able to get involved with Graphics quickly
¡ñ Want a primer? We got you fam: https://youtu.be/3DStoqQnUxc
¡ñ Want a reference project?
https://gitlab.cse.unsw.edu.au/COMP3421/21T3/cpp101

Our Code Setup
C++ with OpenGL
¡ñ Cmake project works in different operating systems
¡ñ We’re supporting Windows, Linux and MacOS
¡ñ Not IDE specific, CLion and VSCode recommended
¡ñ You don’t need to buy a RTX 3090 to learn how to code Graphics!
¡ñ Want help getting set up?
https://gitlab.cse.unsw.edu.au/COMP3421/21T3/opengl_cmake_setup

What did we learn today?
Our first step into the details
¡ñ Graphics Hardware – monitors and graphics cards
¡ñ Polygon Rendering – an overview
¡ñ Graphics Development in this course ¡ð OpenGL
¡ð Shaders ¡ð C++
¡ð Cmake