UnityShader_GLSL书单

好吧,其实UnityShader和GLSL没啥关系的

(技术无界限,软硬件应该不分家,文理也不应该被人为分开)

纯粹的技术和初心是真的存在的

好吧,确实越老越胡思乱想,40岁而知天命,不是么?

会仔细看看,是不是真的好像书的概要那么内涵

(因为某人除了下面两个书,还分享了3,4,5本书,其实后面几本书是有点“浮"的,没必要细看)

那么,同一个作者推荐的前2本书会暴雷吗?

分别是:

1、Vulkan 应用开发指南

作者:[美] 格拉汉姆·塞勒斯(Graham Sellers)
译者:李晓波 等

  • 系统地介绍下一代OpenGL规范Vulkan
  • 揭示了Vulkan的独特性
  • 图形程序开发人员参考书

[外链图片转存失败(img-gxqEbDiH-1564562914717)(https://old.epubit.com/api/storage/getbykey/screenshow?key=1907075b21abe2d47873)]

本书系统地介绍下一代OpenGL规范Vulkan,揭示了Vulkan的独特性。本书主要内容包括:内存和资源、队列和命令、数据的移动、图像的展示、着色器和管线、图形管线对象、绘制命令、几何体的处理、片段的处理、同步、数据的回读以及多渲染通道等。 本书适合图形程序开发人员、熟悉图形和计算API的程序员阅读,也可供对Vulkan感兴趣的专业人士阅读。

2、Vulkan开发实战详解

作者:吴亚峰

[外链图片转存失败(img-L1s70yM2-1564562914721)(https://old.epubit.com/api/storage/getbykey/screenshow?key=1907f4fe5c7afaa74d45)]

  • Vulkan及三维图形学必知必会
  • Vulkan实现基本特效及高级特效
  • Vulkan完整游戏案例
  • 多平台完整源代码下载

书共分为19章,介绍了Vulkan的诞生、特点、开发环境的搭建以及运行机制、渲染管线和调试技术,着色器编程语言—GLSL、投影及各种变换、光照、纹理映射、3D模型的加载、混合与雾、两种测试及片元丢弃、顶点着色器的妙用、片元着色器的妙用、真实光学环境的模拟、阴影及高级光照、几种高级着色器特效、骨骼动画、Vulkan的性能优化等,后以一个休闲游戏—方块历险记的案例来展示Vulkan的功能与技术。本书按照必知必会的基础知识、基于Vulkan实现基本特效以及高级特效、完整游戏案例的顺序,循序渐进地进行详细讲解,适合不同需求、不同水平层次的各类读者。为了便于读者学习,随书提供了书中所有案例的完整源代码(书中所有案例都给出了安卓版和Windows版,后的大案例还进一步给出了macOS、iOS和Linux版),*限度地帮助读者快速地掌握各方面的开发技术。 本书适合游戏开发者、程序员学习,也可以作为大专院校相关专业的师生学习用书和培训学校的教材。

 

GLSL 各API

为什么对 GLSL 突然感兴趣呢,

无他,因为之前用了 RenderDoc 做 安卓手机得调试

没办法,必须得看,硬着头皮看,还不需要看Vulkan已经很不错了

UnityShader_GLSL书单_第1张图片

如上图,各API分别是:

glActiveTexture

glEnable

启用混合

glEnable(GL_BLEND)

glBlendFunctionSeperate

To get the blending result of our little two square example, we want to take the alpha of the source color vector for the source factor and 1−alpha of the same color vector for the destination factor. This translates to glBlendFunc as follows:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

It is also possible to set different options for the RGB and alpha channel individually using glBlendFuncSeparate:

glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);

This function sets the RGB components as we’ve set them previously, but only lets the resulting alpha component be influenced by the source’s alpha value.

看了也不知道说得啥

其实应该是同一个方法的重载,如:

GL_ONE  = 0.3, GL_Zero = 0.7 ,或者两者相加不需要==1,所以有第二个 glBlendFunctionSeperate()方法

glVertexAttribPointer

Batching vertex attributes Using glVertexAttribPointer we were able to specify the attribute layout of the vertex array buffer’s content. Within the vertex array buffer we interleaved the attributes; that is, we placed the position, normal and/or texture coordinates next to each other in memory for each vertex. Now that we know a bit more about buffers we can take a different approach.
What we could also do is batch all the vector data into large chunks per attribute type instead of interleaving them. Instead of an interleaved layout 123123123123 we take a batched approach “111122223333”.
When loading vertex data from file you generally retrieve an array of positions, an array of normals and/or an array of texture coordinates. It may cost some effort to combine these arrays into one large array of interleaved data. Taking the batching approach is then an easier solution that we can easily implement using glBufferSubData:

float positions[] = { ... };
 float normals[] = { ... }; 
float tex[] = { ... };
 // fill buffer 
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(positions), &positions); 

glBufferSubData(GL_ARRAY_BUFFER, sizeof(positions), sizeof(normals), &normals); glBufferSubData(GL_ARRAY_BUFFER, sizeof(positions) + sizeof(normals), sizeof(tex), &tex);
This way we can directly transfer the attribute arrays as a whole into the buffer without first having to process them. We could have also combined them in one large array and fill the buffer right away using glBufferData, but using glBufferSubData lends itself perfectly for tasks like these.
We’ll also have to update the vertex attribute pointers to reflect these changes:

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0); 
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)(sizeof(positions))); 
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)(sizeof(positions) + sizeof(normals)));

Note that the stride parameter is equal to the size of the vertex attribute, since the next vertex attribute vector can be found directly after its 3 (or 2) components.
This gives us yet another approach of setting and specifying vertex attributes. Using either approach is feasible, it is mostly a more organized way to set vertex attributes. However, the interleaved approach is still the recommended approach as the vertex attributes for each vertex shader run are then closely aligned in memory.

glUseProgram

A shader program object is the final linked version of multiple shaders combined. To use the recently compiled shaders we have to link them to a shader program object and then activate this shader program when rendering objects. The activated shader program’s shaders will be used when we issue render calls.

giUniform4fv

glDrawElements

All that’s left to do now is to bind the texture before calling glDrawElements and it will then automatically assign the texture to the fragment shader’s sampler:

glBindTexture(GL_TEXTURE_2D, texture);
glBindVertexArray(VAO); 
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);


 

 

参考

opengl 官方大全(book_pdf)

你可能感兴趣的:(每天一点u3d,ShaderShader学习)