EKsumic's Blog

let today = new Beginning();

Click the left button to use the catalog.

OR

Shader入门基础(一)

Shader入门基础(一)

图形渲染程序

显卡在设计之初,主要是为了解决实时渲染3D图像的问题,

实时即以很快的速度生成图像,而不是播放已经录好的图像——播放视频。

实时渲染对任何一个游戏都至关重要,

因为计算机在屏幕上生成的图像,都是对玩家操作的即时反馈。

CPU中非常常见的if-else语句,在GPU中效率并不高,

这就是为什么我们要学习Shader编程。


首先,需要知道,应当尽量避免if-else语句在Shader编程中出现。

其次,对显卡的编程大致分为两种

① 并行计算(Parallel Computing)

例如CUDA\OpenCL\OpenACC,使用它们我们可以对图形图像进行处理,

或者进行高效、密集的数学运算,制作实时电影特效,或训练深度学习网络。

② 图形编程(Graphic Programming)

显卡设计之初最主要的功能,没有之一;

它利用显卡来生成实时的三维图像。


在屏幕中显示的3D物体其实是由三角形构成的。

移动3D视角的反馈,实际上是坐标变换的结果。

三角形作为最基本的图元之一,可以构造出很多复杂的图形。

任何图形在计算机中,都可以由许多三角形构成。


在确定完所有三角形的空间位置之后,显卡开始并行运算。

第一件事,显卡会对三角形进行坐标变换。

第二件事,显卡就会对三角形覆盖区域,进行逐点绘制。

对场景中成千上万个三角形并行运算后,产生了最终我们观察到的画面。


对显卡的编程,其实就是向显卡下达指令来告诉它去做什么。


说到对显卡的图形编程,就不得不提OpenGL\DirectX\Vulkan三大API。

当你使用这些API的时候,这些指令会经过一个叫做驱动程序的东西,

它会将你下达的指令翻译成显卡硬件能直接运行的机器码,也就是0和1。

说到显卡编程就不得不提Shader程序,

Shader中文翻译为 着色器 ,但这样翻译其实并不准确,

Shader程序主要是用来绘制光照和阴影的,而Shade就是阴影的意思。

不过绘制光照和阴影只是Shader的基本作用之一。


Shader的编程语言有GLSL、Cg/HLSL、SPIR-V,它们分别来自OpenGL、DirectX、Vulkan。


对今天Shader程序的编写,我们在Unity中完成,

之所以选择Unity,是因为真正的图形编程,

大多都是在游戏引擎中直接完成。

游戏引擎通常会提供一个方便的编辑器,

可以快速测试你编写的Shader程序,并且提供UI界面让你调节复杂的参数。

 

下一篇:创建并编写你的第一个Shader程序
 

This article was last edited at 2020-03-31 07:28:01

Quinton Gorham

We Tech From Zero team is ensuring that technology is one of the most significant aspects of our daily lifestyle and have designed this techfromzero.com website. Especially, this is an informative platform for useful tech tips and news. The techfromzero.com broadly consists of a few categories. Those are Windows, Linux, Mobile, Chrome, Firefox and other browsers. Moreover, we really admire your engagement with us to improve our website. Hence, you can send us ideas and suggestions for future development as we are dedicated to offering the best information. It is very reliable to follow the guides. Even, the details can be easily referred by a person with an average understanding capacity. So, this is an ideal solution for people in different classes of education, age and profession. Our customer service will help you to clarify the doubts in your mind regarding our website content. Therefore, we invite you to share your concerns with the ”Contact Us” details mentioned here.

reply

2021-10-21 21:43:42

David Bote

Hello, I hope you are doing well, and business is Great! However, if you need working capital to further grow and expand your business, we may be a perfect fit for you and here’s why. Our loans are NOT based on your personal credit, and NO collateral is required. We are a Direct Lender who can approve your loan today, and fund as early as Tomorrow. We offer loans from 5k to 500k with flexible payments and great terms. Just click on the link to INSTANTLY see how much you qualify for www.topdogcapital.xyz Applying does NOT affect your credit! Warm Regards, David Bote Top Dog Capital www.topdogcapital.xyz This is an Advertisement. To unsubscribe, click here www.topdogcapital.xyz/unsubscribe or write to: Top Dog Capital 9169 W State St #3242 Garden City, ID 83714

reply

2021-11-06 04:03:28

* *