glsl

Cesium原理篇:6 Render模块(3: Shader)【转】

微笑、不失礼 提交于 2019-12-03 07:37:19
https://www.cnblogs.com/fuckgiser/p/5975274.html 在介绍Renderer的第一篇,我就提到WebGL1.0对应的是OpenGL ES2.0,也就是可编程渲染管线。之所以单独强调这一点,算是为本篇埋下一个伏笔。通过前两篇,我们介绍了VBO和Texture两个比较核心的WebGL概念。假设生产一辆汽车,VBO就相当于这个车的骨架,纹理相当这个车漆,但有了骨架和车漆还不够,还需要一台机器人来加工,最终才能成产出这辆汽车。而Shader模块就是负责这个生产的过程,加工参数(VBO,Texture),执行渲染任务。 这里假设大家对Shader有一个基本的了解,这一块内容也很多,不可能简单两句轻描淡写就豁然开朗,而且我也没有进行过系统的学习,所以就不班门弄斧了。进入主题,来看看Cesium对Shader的封装。 图1:ES2.0可编程渲染管线 上图是可编程渲染管线的一个大概流程,我们关注的两个橙色的圆角矩形部分,分别是顶点着色器和片源着色器。既然是可编程渲染管线,面向Shader的开发者提供了一种称为GLSL的语言,如果你懂C的话,两者语法是相当的,所以从语法层面学习成本不大。 ShaderSource创建 首先,Cesium提供了ShaderSource类来加载GLSL代码,我们来看一下它对应的拷贝构造函数: ShaderSource

Qt5 OpenGL GLSL version error

匿名 (未验证) 提交于 2019-12-03 07:36:14
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm starting out on using OpenGL with Qt, and with Shaders (I have OpenGL experience, but not with shaders yet) I'm following this tutorial: http://releases.qt-project.org/learning/developerguides/qtopengltutorial/OpenGLTutorial.pdf (the official Qt5 OpenGL tutorial). The problem is, that when I try to run my program, I get a black screen and the following error messages: QGLShader::compile(Vertex): ERROR: 0:1: '' : version '130' is not supported QGLShader::compile(Fragment): ERROR: 0:1: '' : version '130' is not supported My program is

Passing data through tessellation shaders to the fragment shader

一曲冷凌霜 提交于 2019-12-03 07:30:46
I'm a bit confused about how the shader pipeline works with regards to passing data through each stage. What I'm trying to do is pass color data that is loaded in the vertex stage using glVertexAttrib4fv() through the tessellation control shader, and then the tessellation evaluation shader, so that it can be used in the fragment shader. I'm not sure if I've made some sort of conceptual mistake (quite possible, since I'm still trying to get my head around this over fixed functions), but either way, as soon as I try and pass anything through the tessellation shaders, my primitives refuse to

Robust atan(y,x) on GLSL for converting XY coordinate to angle

僤鯓⒐⒋嵵緔 提交于 2019-12-03 07:25:12
问题 In GLSL (specifically 3.00 that I'm using), there are two versions of atan() : atan(y_over_x) can only return angles between -PI/2, PI/2, while atan(y/x) can take all 4 quadrants into account so the angle range covers everything from -PI, PI, much like atan2() in C++. I would like to use the second atan to convert XY coordinates to angle. However, atan() in GLSL, besides not able to handle when x = 0 , is not very stable. Especially where x is close to zero, the division can overflow

How to create multiple stop gradient fragment shader?

◇◆丶佛笑我妖孽 提交于 2019-12-03 07:19:42
I'm trying to create an OpenGL ES 2.0 fragment shader that outputs multiple stop gradient along one axis. It should interpolate between multiple colors at points defined in percents. I've achieved this by using if s the fragment shader, like this: float y = gl_FragCoord.y; float step1 = resolution.y * 0.20; float step2 = resolution.y * 0.50; if (y < step1) { color = white; } else if (y < step2) { float x = smoothstep(step1, step2, y); color = mix(white, red, x); } else { float x = smoothstep(step2, resolution.y, y); color = mix(red, green, x); } They say that branching in fragment shader can

Update an uniform variable in several shader programs at once

ⅰ亾dé卋堺 提交于 2019-12-03 06:53:13
I have several shaders with uniform variables, which have the same names in all shaders. What is the best way to update uniforms with same names in all shaders at once? I consider the following approaches: 1) Just store locations of that uniform for each program and update it just after the program is assigned as "used" program ( glUseProgram ). Disadvantages: All "shared" uniform variables will be updated after each glUseProgram call. Moreover, if a program is being used not for the first time during the current frame, all glUniform* calls will be redundant. Alternatively there should be a

How do I perform bit operations in glsl

不打扰是莪最后的温柔 提交于 2019-12-03 06:51:08
How do I perform bit operations in glsl? Using the regular C style bitwise operators | , & , ^ , or ! does not work. Aszarsha They have been introduced with GLSL 1.30 (OGL 3.0). Depending on what you want to do, you could eventually emulate them with floating point operations, x & (2^n)-1 = frac(x/(2^n))*(2^n) for example, but you'll have to take care of floating point errors. You need to put either #version 130 or #extension GL_EXT_gpu_shader4 : enable in the top of your shader to get access to the bit operators 来源: https://stackoverflow.com/questions/1700871/how-do-i-perform-bit-operations

GLSL: gl_FragCoord issues

孤人 提交于 2019-12-03 06:26:41
I am experimenting with GLSL for OpenGL ES 2.0. I have a quad and a texture I am rendering. I can successfully do it this way: //VERTEX SHADER attribute highp vec4 vertex; attribute mediump vec2 coord0; uniform mediump mat4 worldViewProjection; varying mediump vec2 tc0; void main() { // Transforming The Vertex gl_Position = worldViewProjection * vertex; // Passing The Texture Coordinate Of Texture Unit 0 To The Fragment Shader tc0 = vec2(coord0); } //FRAGMENT SHADER varying mediump vec2 tc0; uniform sampler2D my_color_texture; void main() { gl_FragColor = texture2D(my_color_texture, tc0); } So

What is the actual number of vertex uniform components for GLSL shader on ATI graphics card?

▼魔方 西西 提交于 2019-12-03 06:06:41
I'm writing a GLSL vertex shader for an iMac with a AMD Radeon HD 6970M 2048 MB graphics card: GL_MAX_VERTEX_ATTRIBS: 16 GL_MAX_VERTEX_UNIFORM_COMPONENTS: 4096 GL_VERSION: 2.1 ATI-7.12.9 GL_SHADING_LANGUAGE_VERSION: 1.20 In my shader I would like to have a large array of uniform mat4s: uniform mat4 T[65] but if I try to have 65 of these my shader (secretly) switches to Apple Software Renderer mode. If I instead use 64: uniform mat4 T[64] everything is fine. Seems to be a problem with exceeding the maximum number of uniforms. But as I wrote above I'm getting 4096 for GL_MAX_VERTEX_UNIFORM

Z-fighting solutions in depth test in OpenGL - how do they work?

佐手、 提交于 2019-12-03 06:02:47
Description I've had major problems with Z-Fighting in OpenGL and I've spent quite some time finding solutions for this problem. Some of the ones I've found and I understand and didn't like: Moving polygons away from each other ( like glPolygonOffset in OpenGL ) Dividing the scene according to Z coordinate and drawing parts of the scene with separate clean z-buffers. The ones I don't understand: Using Projection Matrix https://software.intel.com/en-us/articles/alternatives-to-using-z-bias-to-fix-z-fighting-issues Using "Logarithmic Depth Buffers" http://outerra.blogspot.com/2012/11/maximizing