GAMES202-高质量实时渲染-闫令琪——Lecture 2:Recap of CG Basics 学习笔记

Lecture 2:Recap of CG Basics

Recap of CG Basics

  • Basic GPU hardware pipeline
  • OpenGL
  • OpenGL Shading Language (GLSL)
  • The Rendering Equation

一、Graphics (Hardware) Pipeline

image-20210323090334384

Input: vertices in 3D space:任何物体在3D空间中都会被表示成点以及点的连接关系

Vertices positioned in screen space:空间中的点经过一系列变换(MVP)变换到屏幕空间

Triangles positioned in screen space:经过变换后三角形的连接关系没有改变,也被投影到屏幕空间

Fragments (one per covered sample):光栅化,把一个个三角形离散成屏幕空间上的像素(片元)

Shaded fragments:确定了一个个片元以后就可以对其进行着色

Output: image (pixels):得到最后的图片

二、OPENGL

1、Summarize

​ --Is a set of APIs that call the GPU pipeline from CPU

​ --Cross platform

​ --Fragmented: lots of different versions

​ --C style, not easy to use

OPENGL在CPU端执行,负责调度GPU,可以跨平台运行,但是版本过度比较平滑,而且代码是C风格的,编程不易

2、OpenGL rendering process

Important analogy: oil painting

我们把OPENGL的渲染过程比作画油画

A. Place objects/models(把物体放在某个地方然后摆好姿势)

​ --Model specification

​ --Model transformation

规定一个模型然后进行变换

  • User specifies an object’s vertices, normals, texture coords and send them to GPU as a Vertex buffer object (VBO)

​ --Very similar to .obj files

VBO是GPU中间的一块区域,用来存储模型,存储方式与.obj文件的存储方式非常相似,存顶点的位置、法线、连接方式、纹理等。

  • Use OpenGL functions to obtain matrices

​ --e.g., glTranslate, glMultMatrix, etc.

​ --No need to write anything on your own

通过调用OPENGL的函数实现各种变换

B. Set up an easel(放置一个画架)

​ --View transformation

​ --Create / use a framebuffer

放置一个相机然后在OPENGL里建立“画架”framebuffer

  • Set camera (the viewing transformation matrix) by simply calling, e.g., gluPerspective

如:

image-20210323090817548

在OPENGL里只需要对相关的操作设置参数即可

C. Attach a canvas to the easel(固定一个画布)
  • Analogy of oil painting:
E. you can also paint multiple pictures using the same easel(用同一个画架画很多图)
  • One rendering pass in OpenGL

    –A framebuffer is specified to use

    –Specify one or more textures as output (shading, depth, etc.)

    –Render (fragment shader specifies the content on each texture)

用一个framebuffer可以输出很多不同的纹理,如shading的结果、深度图等,即光栅化一次可以得到很多信息图,由fragment shader来决定最后写到哪一个纹理中去。、

D. Paint to the canvas(在画布上画画)

​ --i.e., how to perform shading

​ --This is when vertex / fragment shaders will be used

用顶点着色器和片段着色器进行着色

  • For each vertex in parallel

    –OpenGL calls user-specified vertex shader:
    Transform vertex (ModelView, Projection), other ops

    我们在顶点着色器定义每个顶点进行MVP的操作及各种插值,然后将其送到片段着色器中,片段着色器得到的输入即为顶点着色器在每个顶点上输出的属性。

  • For each primitive, OpenGL rasterizes

    –Generates a fragment for each pixel the fragment covers

    OPENGL将一个个三角形打散成像素。

  • For each fragment in parallel

    –OpenGL calls user-specified fragment shader:Shading and lighting calculations

    –OpenGL handles z-buffer depth test unless overwritten

    对每一个片段进行着色,自己写片段着色器,OPENGL去调用然后进行每一个片段的着色等计算,也可以自己写OPENGL深度测试。

This is the “Real” action that we care about the most:user-defined vertex, fragment shaders

–Other operations are mostly encapsulated

–Even in the form of GUI-s

所以我们最关心的就是顶点着色器和片段着色器如何去写

F. Multiple passes!(多次渲染)

(Use your own previous paintings for reference)

shadow map的做法就是一个两趟渲染的方法,第一次先看到灯光能照到什么,第二次再看相机看到的物体能不能被光照到。

Summary: in each pass

–Specify objects, camera, MVP, etc.

–Specify framebuffer and input/output textures

–Specify vertex / fragment shaders

–(When you have everything specified on the GPU) Render!

OPENGL就是告诉GPU该做什么(状态机模型):

1.定义渲染的物体、使用的相机、MVP

2.告诉GPU选择什么framebuffer及输入输出的纹理都有哪些

3.告诉GPU怎么着色

三、OpenGL Shading Language (GLSL)

1、Shader Setup

Initializing (shader itself discussed later)

–Create shader (Vertex and Fragment)

–Compile shader

–Attach shader to program

–Link program

–Use program

创建→编译→集合→链接→使用

Shader source is just sequence of strings
Similar steps to compile a normal program

2、Phong Shader in Assignment 0

Vertex Shader

image-20210323090445542

Fragment Shader

image-20210323090525730 image-20210323090709825
3、Debugging Shaders
  • Years ago: NVIDIA Nsight with Visual Studio

    –Needed multiple GPUs for debugging GLSL

    –Had to run in software simulation mode in HLS

  • Now

    –Nsight Graphics (cross platform, NVIDIA GPUs only)

    –RenderDoc (cross platform, no limitations on GPUs)

    –Unfortunately I don’t know if they can be used for WebGL

四、The Rendering Equation

  • Most important equation in rendering

    –Describing light transport

image-20210323090859599
  • In real-time rendering (RTR)

    –Visibility is often explicitly considered

    –BRDF is often considered together with the cosine term

image-20210323090939700

在实时渲染中会引入visibility,人们考虑当前这个shading point是不是能够看到四面八方的光照,人们更多关注的是发出光线及着色的点能不能看到光源

Environment Lighting

  • Representing incident lighting from all directions

    –Usually represented as a cube map or a sphere map (texture)

    –We’ll introduce a new representation in this course

image-20210323091319638

Direct illumination

直接光照

image-20210124225509624

One-bounce global illumination

image-20210124225538348

间接光照加在直接光照上面形成全局光照(光线弹射两次)

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值