一點一點來,不要急功近利,因為那樣會適得其反,也不要被他人的口水搞亂內心和計畫,好不好?
-
Chapter 1. Introduction
Since you came here you probably want to learn the inner workings of computer graphics and do all the stuff the cool kids do by yourself. Doing things by yourself is extremely fun and resourceful and gives you a great understanding of graphics programming. However, there are a few items that need to be taken into consideration before starting your journey. Read it.
-
二、开始 • 认识 OpenGL
OpenGL 閱讀
-
Chapter 2. Getting-started • OpenGL
Before starting our journey we should first define what OpenGL actually is. OpenGL is mainly considered an API (an Application Programming Interface) that provides us with a large set of functions that we can use to manipulate graphics and images. However, OpenGL by itself is not an API, but merely a specification, developed and maintained by the Khronos Group. Read it.
-
三、开始 • 创建一个窗口
在我们开始创建令人惊叹的图形之前,首先需要做的事情是创建一个 OpenGL 上下文和一个应用窗口来进行绘制。然而,这些操作在不同的操作系统上是特定的,而 OpenGL 刻意地将自己与这些操作抽象开来。这意味着我们必须自己创建一个窗口、定义一个上下文,并处理用户输入。 閱讀
-
Chapter 3. Getting-started • Creating-a-window
The first thing we need to do before we start creating stunning graphics is to create an OpenGL context and an application window to draw in. However, those operations are specific per operating system and OpenGL purposefully tries to abstract itself from these operations. This means we have to create a window, define a context, and handle user input all by ourselves. Read it.
-
四、开始 • Hello, 窗口
讓我們看看是否可以啟動並運行 GLFW。首先,我們創建一個 .cpp 文件,然後在其頭部添加以下 includes。 閱讀
-
Chapter 4. Getting-started • Hello-Window
Let’s see if we can get GLFW up and running. First, create a .cpp file and add the following includes to the top of your newly created file. Read it.
-
五、开始 • Hello, 三角形
對於 OpenGL 來說,一切都發生在 3D 空間中,但螢幕或視窗其實是由二維像素所組成的陣列,因此 OpenGL 的主要工作之一就是將 3D 座標轉換為適合顯示在螢幕上的 2D 像素。這個從 3D 座標轉換為 2D 像素的過程是由 OpenGL 的圖形管線所處理的。圖形管線可以分為兩個主要部分:第一部分將 3D 座標轉換為 2D 座標,第二部分則將這些 2D 座標轉換為實際的彩色像素。本章將簡要介紹圖形管線的運作方式,並說明我們如何善用它來創造炫麗的像素效果。 閱讀
-
Chapter 5. Getting-started • Hello-Triangle
In OpenGL everything is in 3D space, but the screen or window is a 2D array of pixels so a large part of OpenGL’s work is about transforming all 3D coordinates to 2D pixels that fit on your screen. The process of transforming 3D coordinates to 2D pixels is managed by the graphics pipeline of OpenGL. The graphics pipeline can be divided into two large parts: the first transforms your 3D coordinates into 2D coordinates and the second part transforms the 2D coordinates into actual colored pixels. In this chapter we’ll briefly discuss the graphics pipeline and how we can use it to our advantage to create fancy pixels. Read it.
-
六、开始 • 著色器
上章提到,著色器是運行在 GPU 上的小程序。這些程序運行在圖形管線的各個部分。基本來講,著色器不過是將輸入轉換為輸出的程序。著色器同時也是彼此隔離的,它們之間不允許有通訊,唯一的通訊途徑是通過輸入和輸出。 閱讀
-
Chapter 6. Getting-started • Shaders
As mentioned in the Hello Triangle chapter, shaders are little programs that rest on the GPU. These programs are run for each specific section of the graphics pipeline. In a basic sense, shaders are nothing more than programs transforming inputs to outputs. Shaders are also very isolated programs in that they’re not allowed to communicate with each other; the only communication they have is via their inputs and outputs. Read it.
-
Chapter 7. Getting-started • Textures
We learned that to add more detail to our objects we can use colors for each vertex to create some interesting images. However, to get a fair bit of realism we’d have to have many vertices so we could specify a lot of colors. This takes up a considerable amount of extra overhead, since each model needs a lot more vertices and for each vertex a color attribute as well. Read it.
-
Chapter 8. Getting-started • Transformations
We now know how to create objects, color them and/or give them a detailed appearance using textures, but they’re still not that interesting since they’re all static objects. We could try and make them move by changing their vertices and re-configuring their buffers each frame, but that’s cumbersome and costs quite some processing power. There are much better ways to transform an object and that’s by using (multiple) matrix objects. This doesn’t mean we’re going to talk about Kung Fu and a large digital artificial world. Read it.
-
九、开始 • 座標系統
在上一章,我們知道了如何使用矩陣作為武器,來實現對頂點的轉換。對於那些你希望被渲染在屏幕上的頂點,OpenGL 要求它們在跑完 shader 代碼之後,全部落在標準設備座標(NDC)空間。也就是說,每個頂點的 x、y、z 座標都應該落在 -1.0 到 +1.0 之間;對於此範圍之外的點,它們將無法被看到。我們通常的做法是,在一個範圍(或者空間)裡指定一個座標系,這個座標系由我們自己來決定,然後在頂點著色器裡將頂點座標轉換為標準設備座標。接著這些 NDC 被交給光珊,以將它們轉換為屏幕 2D 座標/像素。 閱讀
-
Chapter 9. Getting-started • Coordinate-Systems
In the last chapter we learned how we can use matrices to our advantage by transforming all vertices with transformation matrices. OpenGL expects all the vertices, that we want to become visible, to be in normalized device coordinates after each vertex shader run. That is, the x, y and z coordinates of each vertex should be between -1.0 and 1.0; coordinates outside this range will not be visible. What we usually do, is specify the coordinates in a range (or space) we determine ourselves and in the vertex shader transform these coordinates to normalized device coordinates (NDC). These NDC are then given to the rasterizer to transform them to 2D coordinates/pixels on your screen. Read it.
-
十、开始 • 相機
譯者歸納:這篇講解了 3D 世界中相機的概念。這個概念是自然而然推進的,絕非胡亂製造的新概念。在 OpenGL 的渲染中,本身就已經有了相機的影子。相機是什麼?相機是一個設備,它讓世界萬物得以呈現,否則還能怎麼辦呢?閉著眼睛遐想嗎?在 3D 世界中,物件本身是客觀存在的,這是我們人類大腦的固有構造,它自然而然就是那個樣子的。我們根據這個固有的觀念去構建一個虛擬世界(由頂點、顏色、混合、遮擋、陰影等組成),將數據放置於特定空間中,然後使用「渲染 (render)」邏輯處理這個虛擬世界。透過鏡頭,我們看見它,這就是它的樣子,讓我們彷彿置身一個現實世界裡(為什麼?因為我們就是按照眼睛感知世界的方式去模仿的!)。 閱讀
-
Chapter 10. Getting-started • Camera
In the previous chapter we discussed the view matrix and how we can use the view matrix to move around the scene (we moved backwards a little). OpenGL by itself is not familiar with the concept of a camera, but we can try to simulate one by moving all objects in the scene in the reverse direction, giving the illusion that we are moving. Read it.
-
Chapter 11. Lighting • Colors
We briefly used and manipulated colors in the previous chapters, but never defined them properly. Here we’ll discuss what colors are and start building the scene for the upcoming Lighting chapters. Read it.
-
十二、光 • 基本光照
譯者總結:本文介紹了 Phong 光照模型!非常基礎,非常容易理解,是一篇極好的解釋圖形領域光照模型存在的現實理由及其實現辦法。Phong 模型裡,物件最終呈現出來的光是三種光的組合:1. 環境光;2. 散光(漫反射);3. 高光(反射光或者鏡面光)。文章分別對此三者進行的現實意義的解釋以及計算機層面的實現方案。結合最終程序運行,筆者將每一步實現的結果展現給讀者,讓讀者明白筆者說的到底“是什麼”。 閱讀
-
Chapter 12. Lighting • Basic-Lighting
Lighting in the real world is extremely complicated and depends on way too many factors, something we can’t afford to calculate on the limited processing power we have. Lighting in OpenGL is therefore based on approximations of reality using simplified models that are much easier to process and look relatively similar. These lighting models are based on the physics of light as we understand it. One of those models is called the Phong lighting model. The major building blocks of the Phong lighting model consist of 3 components: ambient, diffuse and specular lighting. Below you can see what these lighting components look like on their own and combined: Read it.
-
Chapter 13. Lighting • Materials
In the real world, each object has a different reaction to light. Steel objects are often shinier than a clay vase for example and a wooden container doesn’t react the same to light as a steel container. Some objects reflect the light without much scattering resulting in small specular highlights and others scatter a lot giving the highlight a larger radius. If we want to simulate several types of objects in OpenGL we have to define material properties specific to each surface. Read it.
-
十四、光 • 光照貼圖
貼圖,就是提供一張紋理圖(一般如此),紋理圖佈滿像素,像素值的一般格式為 RGBA,也就是顏色,爾顏色可用於著色器的 Fragment,這樣會讓物體看上去更逼真。紋理圖的存在在於提供一種可行的方式,以實現對物體表面的精確刻畫。 閱讀
-
Chapter 14. Lighting • Lighting-maps
In the previous chapter we discussed the possibility of each object having a unique material of its own that reacts differently to light. This is great for giving each object a unique look in comparison to other objects, but still doesn’t offer much flexibility on the visual output of an object. Read it.
-
Chapter 15. Lighting • Light-casters
All the lighting we’ve used so far came from a single source that is a single point in space. It gives good results, but in the real world we have several types of light that each act different. A light source that casts light upon objects is called a light caster. In this chapter we’ll discuss several different types of light casters. Learning to simulate different light sources is yet another tool in your toolbox to further enrich your environments. Read it.
-
十六、光 • 多重光源
承前章所學,吾人已悉 OpenGL 中之光照堂奧,舉凡 Phong 著色、材質、光照貼圖暨各類光源,皆已詳盡闡述。本章之旨,乃融會貫通前所學,以六光源齊發,營造一臻於完善之光照場景。吾人將模擬日暉,作定向光源;佐以四點光源,散佈於場景之中;復增一聚光燈,以擬手電之效。 閱讀
-
Chapter 16. Lighting • Multiple-lights
In the previous chapters we learned a lot about lighting in OpenGL. We learned about Phong shading, materials, lighting maps and different types of light casters. In this chapter we’re going to combine all the previously obtained knowledge by creating a fully lit scene with 6 active light sources. We are going to simulate a sun-like light as a directional light source, 4 point lights scattered throughout the scene and we’ll be adding a flashlight as well. Read it.
-
十七、模型載入 • Assimp
到目前為止,我們在所有場景中都大量地使用我們的小容器朋友,但隨著時間的推移,即使是我們最好的朋友也會變得有點無聊。在大型圖形應用程式中,通常有很多複雜而有趣的模型,它們比靜態容器更賞心悅目。然而,與容器物件不同,我們無法真正手動定義複雜形狀(例如房屋、車輛或類人角色)的所有頂點、法線和紋理座標。我們想要的是將這些模型匯入到應用程式中;這些模型是由 3D 藝術家在 Blender、3DS Max 或 Maya 等工具中精心設計的。 閱讀
-
Chapter 17. Model-Loading • Assimp
In all the scenes so far we’ve been extensively playing with our little container friend, but over time, even our best friends can get a little boring. In bigger graphics applications, there are usually lots of complicated and interesting models that are much prettier to look at than a static container. However, unlike the container object, we can’t really manually define all the vertices, normals, and texture coordinates of complicated shapes like houses, vehicles, or human-like characters. What we want instead, is to import these models into the application; models that were carefully designed by 3D artists in tools like Blender, 3DS Max or Maya. Read it.
-
十八、模型載入 • Mesh
使用 Assimp,我們可以將許多不同的模型載入應用程式,但一旦載入,它們都儲存在 Assimp 的資料結構中。我們最終想要的是將這些資料轉換為 OpenGL 可以理解的格式,以便我們可以彩現物件。我們從前一章了解到網格代表一個可繪製的實體,所以讓我們從定義我們自己的網格類別開始。 閱讀
-
Chapter 18. Model-Loading • Mesh
With Assimp we can load many different models into the application, but once loaded they’re all stored in Assimp’s data structures. What we eventually want is to transform that data to a format that OpenGL understands so that we can render the objects. We learned from the previous chapter that a mesh represents a single drawable entity, so let’s start by defining a mesh class of our own. Read it.
-
十九、模型載入 • Model
現在是時候動手使用 Assimp 並開始建立實際的載入和轉換程式碼了。本章的目標是建立另一個類別來完整表示一個模型,也就是說,一個包含多個網格(可能帶有多個紋理)的模型。一個包含木製陽台、塔樓,或許還有一個游泳池的房子,仍然可以作為單一模型載入。我們將透過 Assimp 載入模型,並將其轉換為我們在上一章中建立的多個 Mesh 物件。 閱讀
-
Chapter 19. Model-Loading • Model
Now it is time to get our hands dirty with Assimp and start creating the actual loading and translation code. The goal of this chapter is to create another class that represents a model in its entirety, that is, a model that contains multiple meshes, possibly with multiple textures. A house, that contains a wooden balcony, a tower, and perhaps a swimming pool, could still be loaded as a single model. We’ll load the model via Assimp and translate it to multiple Mesh objects we’ve created in the previous chapter. Read it.
-
二十、高級 OpenGL • 深度測試
在座標系統章節中,我們渲染了一個 3D 容器,並利用了 深度緩衝區 來防止三角形在應該位於其他三角形後面時卻渲染在前面。在本章中,我們將更詳細地闡述深度緩衝區(或稱 z-緩衝區)儲存的那些 深度值,以及它如何實際判斷一個片段是否在前面。 閱讀
-
Chapter 20. Advanced-OpenGL • Depth-testing
In the coordinate systems chapter we’ve rendered a 3D container and made use of a depth buffer to prevent triangles rendering in the front while they’re supposed to be behind other triangles. In this chapter we’re going to elaborate a bit more on those depth values the depth buffer (or z-buffer) stores and how it actually determines if a fragment is in front. Read it.
-
二十一、高級 OpenGL • 模板測試
一旦片元著色器處理完畢片元,就會執行一個所謂的「模板測試」(stencil test),它和深度測試一樣,可以選擇丟棄片元。之後,剩餘的片元會傳遞給深度測試,OpenGL 可能會在那裡丟棄更多片元。模板測試是基於另一個名為「模板緩衝」(stencil buffer)的內容,我們可以在渲染期間更新這個緩衝區以實現有趣的視覺效果。 閱讀
-
Chapter 21. Advanced-OpenGL • Stencil-testing
Once the fragment shader has processed the fragment a so called stencil test is executed that, just like the depth test, has the option to discard fragments. After that the remaining fragments are passed to the depth test where OpenGL could possibly discard even more fragments. The stencil test is based on the content of yet another buffer called the stencil buffer that we’re allowed to update during rendering to achieve interesting effects. Read it.
-
二十二、高級 OpenGL • 混合
OpenGL 中的「混合」(Blending)通常被稱為在物件中實現「透明度」(transparency)的技術。透明度的重點在於物件(或其部分)不具有實心顏色,而是由物件本身的顏色和其後方任何其他物件的顏色以不同強度組合而成。彩繪玻璃窗就是一個透明的物件;玻璃本身有顏色,但最終的顏色也包含了玻璃後方所有物件的顏色。這也是「混合」這個名稱的由來,因為我們將多個像素顏色(來自不同物件)「混合」成單一顏色。因此,透明度使我們能夠看穿物件。 閱讀
-
Chapter 22. Advanced-OpenGL • Blending
Blending in OpenGL is commonly known as the technique to implement transparency within objects. Transparency is all about objects (or parts of them) not having a solid color, but having a combination of colors from the object itself and any other object behind it with varying intensity. A colored glass window is a transparent object; the glass has a color of its own, but the resulting color contains the colors of all the objects behind the glass as well. This is also where the name blending comes from, since we blend several pixel colors (from different objects) to a single color. Transparency thus allows us to see through objects. Read it.
-
二十三、高級 OpenGL • 面剔除
試著在腦海中想像一個 3D 立方體,並數數從任何方向最多能看到幾個面。如果你的想像力不夠豐富,你可能最終會得出最多 3 個面。你可以從任何位置和/或方向觀察一個立方體,但你永遠無法看到超過 3 個面。那麼,我們為什麼要浪費精力繪製那些我們甚至看不到的其他 3 個面呢?如果我們能以某種方式丟棄它們,我們將可以節省超過 50% 這個立方體總共的片元著色器運行次數! 閱讀
-
Chapter 23. Advanced-OpenGL • Face-culling
Try mentally visualizing a 3D cube and count the maximum number of faces you’ll be able to see from any direction. If your imagination is not too creative you probably ended up with a maximum number of 3. You can view a cube from any position and/or direction, but you would never be able to see more than 3 faces. So why would we waste the effort of drawing those other 3 faces that we can’t even see. If we could discard those in some way we would save more than 50% of this cube’s total fragment shader runs! Read it.
-
二十四、高級 OpenGL • Framebuffers
So far we’ve used several types of screen buffers: a color buffer for writing color values, a depth buffer to write and test depth information, and finally a stencil buffer that allows us to discard certain fragments based on some condition. The combination of these buffers is stored somewhere in GPU memory and is called a framebuffer. OpenGL gives us the flexibility to define our own framebuffers and thus define our own color (and optionally a depth and stencil) buffer. 閱讀
-
Chapter 24. Advanced-OpenGL • Framebuffers
So far we’ve used several types of screen buffers: a color buffer for writing color values, a depth buffer to write and test depth information, and finally a stencil buffer that allows us to discard certain fragments based on some condition. The combination of these buffers is stored somewhere in GPU memory and is called a framebuffer. OpenGL gives us the flexibility to define our own framebuffers and thus define our own color (and optionally a depth and stencil) buffer. Read it.
-
二十五、高級 OpenGL • Cubemaps
我們已經使用 2D 紋理好一陣子了,但還有更多我們尚未探索的紋理類型。在本章中,我們將討論一種結合多個紋理為一體的紋理類型:立方體貼圖 (cube map)。 閱讀
-
Chapter 25. Advanced-OpenGL • Cubemaps
We’ve been using 2D textures for a while now, but there are more texture types we haven’t explored yet and in this chapter we’ll discuss a texture type that is a combination of multiple textures mapped into one: a cube map. Read it.
-
二十六、Advanced-OpenGL • Advanced-Data
Throughout most chapters we’ve been extensively using buffers in OpenGL to store data on the GPU. This chapter we’ll briefly discuss a few alternative approaches to managing buffers. 閱讀
-
Chapter 26. Advanced-OpenGL • Advanced-Data
Throughout most chapters we’ve been extensively using buffers in OpenGL to store data on the GPU. This chapter we’ll briefly discuss a few alternative approaches to managing buffers. Read it.
-
二十七、Advanced-OpenGL • Advanced-GLSL
This chapter won’t really show you super advanced cool new features that give an enormous boost to your scene’s visual quality. This chapter goes more or less into some interesting aspects of GLSL and some nice tricks that may help you in your future endeavors. Basically some good to knows and features that may make your life easier when creating OpenGL applications in combination with GLSL. 閱讀
-
Chapter 27. Advanced-OpenGL • Advanced-GLSL
This chapter won’t really show you super advanced cool new features that give an enormous boost to your scene’s visual quality. This chapter goes more or less into some interesting aspects of GLSL and some nice tricks that may help you in your future endeavors. Basically some good to knows and features that may make your life easier when creating OpenGL applications in combination with GLSL. Read it.
-
二十八、Advanced-OpenGL • Instancing
Say you have a scene where you’re drawing a lot of models where most of these models contain the same set of vertex data, but with different world transformations. Think of a scene filled with grass leaves: each grass leave is a small model that consists of only a few triangles. You’ll probably want to draw quite a few of them and your scene may end up with thousands or maybe tens of thousands of grass leaves that you need to render each frame. Because each leaf is only a few triangles, the leaf is rendered almost instantly. However, the thousands of render calls you’ll have to make will drastically reduce performance. 閱讀
-
Chapter 28. Advanced-OpenGL • Instancing
Say you have a scene where you’re drawing a lot of models where most of these models contain the same set of vertex data, but with different world transformations. Think of a scene filled with grass leaves: each grass leave is a small model that consists of only a few triangles. You’ll probably want to draw quite a few of them and your scene may end up with thousands or maybe tens of thousands of grass leaves that you need to render each frame. Because each leaf is only a few triangles, the leaf is rendered almost instantly. However, the thousands of render calls you’ll have to make will drastically reduce performance. Read it.
-
二十九、Advanced-OpenGL • Anti-Aliasing
Somewhere in your adventurous rendering journey you probably came across some jagged saw-like patterns along the edges of your models. The reason these jagged edges appear is due to how the rasterizer transforms the vertex data into actual fragments behind the scene. An example of what these jagged edges look like can already be seen when drawing a simple cube: 閱讀
-
Chapter 29. Advanced-OpenGL • Anti-Aliasing
Somewhere in your adventurous rendering journey you probably came across some jagged saw-like patterns along the edges of your models. The reason these jagged edges appear is due to how the rasterizer transforms the vertex data into actual fragments behind the scene. An example of what these jagged edges look like can already be seen when drawing a simple cube: Read it.
-
Chapter 30. Advanced-Lighting • Advanced-Lighting
In the lighting chapters we briefly introduced the Phong lighting model to bring a basic amount of realism into our scenes. The Phong model looks nice, but has a few nuances we’ll focus on in this chapter. Read it.
-
三十一、高級光照 • 伽馬矯正
一旦我們計算出場景的最終像素顏色,我們就必須將它們顯示在螢幕上。在數位成像的早期,大多數螢幕都是陰極射線管(CRT)螢幕。這些螢幕具有物理特性,即兩倍的輸入電壓並不會產生兩倍的亮度。將輸入電壓加倍會產生一個與指數關係約為 2.2(稱為螢幕的伽馬值)相等的亮度。這(巧合地)也與人類測量亮度的方式非常吻合,因為亮度也以類似的(反向)冪關係顯示。為了更好地理解這一切意味著什麼,請看下圖: 閱讀
-
Chapter 31. Advanced-Lighting • Gamma-Correction
As soon as we compute the final pixel colors of the scene we will have to display them on a monitor. In the old days of digital imaging most monitors were cathode-ray tube (CRT) monitors. These monitors had the physical property that twice the input voltage did not result in twice the amount of brightness. Doubling the input voltage resulted in a brightness equal to an exponential relationship of roughly 2.2 known as the gamma of a monitor. This happens to (coincidently) also closely match how human beings measure brightness as brightness is also displayed with a similar (inverse) power relationship. To better understand what this all means take a look at the following image: Read it.
-
三十二、高級光照 • Shadow-Mapping
陰影是光線被遮蔽而產生的。當一個光源的光線被其他物體遮擋而未能照射到某個物體時,該物體便處於陰影之中。陰影為光照場景增添了大量的真實感,並讓觀看者更容易觀察物體之間的空間關係。它們為我們的場景和物體提供了更強烈的深度感。例如,請看以下有陰影和無陰影的場景圖片: 閱讀
-
Chapter 32. Advanced-Lighting • Shadow-Mapping
Shadows are a result of the absence of light due to occlusion. When a light source’s light rays do not hit an object because it gets occluded by some other object, the object is in shadow. Shadows add a great deal of realism to a lit scene and make it easier for a viewer to observe spatial relationships between objects. They give a greater sense of depth to our scene and objects. For example, take a look at the following image of a scene with and without shadows: Read it.
-
三十三、Advanced-Lighting • Point-Shadows
In the last chapter we learned to create dynamic shadows with shadow mapping. It works great, but it’s mostly suited for directional (or spot) lights as the shadows are generated only in the direction of the light source. It is therefore also known as directional shadow mapping as the depth (or shadow) map is generated from only the direction the light is looking at. 閱讀
-
Chapter 33. Advanced-Lighting • Point-Shadows
In the last chapter we learned to create dynamic shadows with shadow mapping. It works great, but it’s mostly suited for directional (or spot) lights as the shadows are generated only in the direction of the light source. It is therefore also known as directional shadow mapping as the depth (or shadow) map is generated from only the direction the light is looking at. Read it.
-
三十四、高級光照 • 法線貼圖 (Normal Mapping)
我們的場景都塞滿了網格(Mesh),每個網格由數百或數千個三角形組成。我們透過將 2D 紋理包裹在這些平面三角形上,來提高真實感,隱藏了多邊形只是微小平面三角形的事實。紋理確實有幫助,但是當你仔細觀察網格時,仍然很容易看到底層的平面。然而,大多數現實生活中的表面都不是平坦的,並且會呈現出許多(凹凸不平的)細節。 閱讀
-
Chapter 34. Advanced-Lighting • Normal-Mapping
All of our scenes are filled with meshes, each consisting of hundreds or maybe thousands of triangles. We boosted the realism by wrapping 2D textures on these flat triangles, hiding the fact that the polygons are just tiny flat triangles. Textures help, but when you take a good close look at the meshes it is still quite easy to see the underlying flat surfaces. Most real-life surface aren’t flat however and exhibit a lot of (bumpy) details. Read it.
-
三十五、高級光照 • 視差貼圖(Parallax Mapping)
視差映射(Parallax Mapping) 是一種和法線映射(Normal Mapping)類似,但基於不同原理的技術。就像法線映射一樣,視差映射能顯著提升材質表面的細節感,並賦予其深度感。雖然這也是一種視覺幻象,但視差映射在表達深度感方面比法線映射更為出色,兩者結合時可以呈現出極為逼真的效果。視差映射不完全屬於(進階)光照技術,但它是法線映射的自然延伸,因此這裡還是會介紹它。值得注意的是,理解法線映射,特別是切線空間(tangent space)的概念,對學習視差映射非常重要。 閱讀
-
Chapter 35. Advanced-Lighting • Parallax-Mapping
Parallax mapping is a technique similar to normal mapping, but based on different principles. Just like normal mapping it is a technique that significantly boosts a textured surface’s detail and gives it a sense of depth. While also an illusion, parallax mapping is a lot better in conveying a sense of depth and together with normal mapping gives incredibly realistic results. While parallax mapping isn’t necessarily a technique directly related to (advanced) lighting, I’ll still discuss it here as the technique is a logical follow-up of normal mapping. Note that getting an understanding of normal mapping, specifically tangent space, is strongly advised before learning parallax mapping. Read it.
-
三十六、高級光照 • HDR
亮度與色彩值在預設情況下,當被儲存進 framebuffer(幀緩衝)時,會被限制在 0.0 到 1.0 之間。這看似無害的設定,導致我們總是必須在這個範圍內設定光源與顏色的數值,努力讓它們「剛好」地適配場景。這麼做雖然勉強能夠產生還不錯的結果,但如果我們走進一個非常明亮的區域,有多個強光源,總亮度加起來超過 1.0,那會發生什麼事呢?答案是,所有亮度或顏色總和超過 1.0 的片元都會被夾制(clamp)成 1.0,這樣的畫面看起來就會非常怪異: 閱讀
-
Chapter 36. Advanced-Lighting • HDR
Brightness and color values, by default, are clamped between 0.0 and 1.0 when stored into a framebuffer. This, at first seemingly innocent, statement caused us to always specify light and color values somewhere in this range, trying to make them fit into the scene. This works oké and gives decent results, but what happens if we walk in a really bright area with multiple bright light sources that as a total sum exceed 1.0? The answer is that all fragments that have a brightness or color sum over 1.0 get clamped to 1.0, which isn’t pretty to look at: Read it.
-
三十七、高級光照 • 輝光(Bloom)
明亮的光源以及被強光照射的區域,常常難以在顯示器上真實呈現,因為顯示器的亮度範圍有限。一種讓光源在螢幕上更顯著的方法是讓它發光(glow);光線會從光源周圍「溢出」(bleed),這樣能有效給觀眾一種光源非常明亮的視覺錯覺。 閱讀
-
Chapter 37. Advanced-Lighting • Bloom
Bright light sources and brightly lit regions are often difficult to convey to the viewer as the intensity range of a monitor is limited. One way to distinguish bright light sources on a monitor is by making them glow; the light then bleeds around the light source. This effectively gives the viewer the illusion these light sources or bright regions are intensely bright. Read it.
-
三十八、高級光照 • 延遲著色
我們目前使用的光照方法稱為「前向渲染」(forward rendering)或「前向著色」(forward shading)。這是一種直接的方法:我們對場景中的每個物體分別進行渲染,並根據所有光源為其計算光照。雖然這種方法易於理解和實現,但效能負擔較重,因為每個渲染的物體都要對每個光源對每個片元執行迭代,數量相當龐大!此外,在深度複雜度高(多個物體覆蓋同一像素)時,前向渲染也會浪費大量片元著色器的運算,因為片元輸出會被覆寫。 閱讀
-
Chapter 38. Advanced-Lighting • Deferred-Shading
The way we did lighting so far was called forward rendering or forward shading. A straightforward approach where we render an object and light it according to all light sources in a scene. We do this for every object individually for each object in the scene. While quite easy to understand and implement it is also quite heavy on performance as each rendered object has to iterate over each light source for every rendered fragment, which is a lot! Forward rendering also tends to waste a lot of fragment shader runs in scenes with a high depth complexity (multiple objects cover the same screen pixel) as fragment shader outputs are overwritten. Read it.
-
三十九、高級光照 • SSAO
我們在基礎光照章節中曾簡單提到過一個主題:環境光(ambient lighting)。環境光是一種固定的光照常數,我們將它加到場景的整體光照中,用以模擬光線的「散射」效果。現實中,光線會以各種方向、不同強度散射,因此場景中間接受光照的部分強度也會有所不同。其中一種間接光照的近似方法叫做「環境光遮蔽」(ambient occlusion),它試圖透過使折痕、孔洞以及彼此靠近的表面變暗來模擬間接光照。這些區域因為被周圍幾何體大部分遮擋,光線逃逸的路徑較少,因此看起來較暗。你可以觀察一下房間的角落和折痕,那裡的光線通常會稍微暗一些。 閱讀
-
Chapter 39. Advanced-Lighting • SSAO
We’ve briefly touched the topic in the basic lighting chapter: ambient lighting. Ambient lighting is a fixed light constant we add to the overall lighting of a scene to simulate the scattering of light. In reality, light scatters in all kinds of directions with varying intensities so the indirectly lit parts of a scene should also have varying intensities. One type of indirect lighting approximation is called ambient occlusion that tries to approximate indirect lighting by darkening creases, holes, and surfaces that are close to each other. These areas are largely occluded by surrounding geometry and thus light rays have fewer places to escape to, hence the areas appear darker. Take a look at the corners and creases of your room to see that the light there seems just a little darker. Read it.