UnityShader_GLSL书单

2021年补充,无聊逛书城,碰到一个好老师了

没有拍照或者视频,有些可惜了

一个中年大叔(老师),买了一个超市推车大小的书,都是html5+css;十几本,整座山高,怀疑他是否能推动

(目测在做教案,能做这样老师的学生应该是比较幸运)

我们又有什么理由不努力呢

(书很多,居多,但100本里选一本看就够了)

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

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

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

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

现在的我会仔细看看,是不是真的好像看了很多书,又好像什么都没看,书的作者(个人|群)和概要都很关键

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

一个作者写的,然后下面一堆人推荐,这种书真的不要看,一个老师看了几十本,然后推给你的,要珍惜,真的,不要毕业之后,才想起要珍惜

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

分别是:

(哥没推荐,不能保证不暴雷,第二本2021年在书城看了,几乎每个章节介绍一个特性,共有19章,实际工作中所有这些特性都有涉猎,很实在的一本书,不过貌似现在vulkan的商业项目还是偏少,市场上估计都在消化和做向前兼容)

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已经很不错了

如上图,各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)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

avi9111

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值