glsl

CESIUM内置shader变量和函数[转]

徘徊边缘 提交于 2019-11-29 01:58:43
cesium中内置了一些常量、变量和函数,在vs和fs中可直接使用。 内置uniform 内置uniform主要置于AutomaticUniforms类里面,该类私有未开放文档。 czm_backgroundColor An automatic GLSL uniform representing the current scene background color. Example: // GLSL declaration uniform vec4 czm_backgroundColor; // Example: If the given color's RGB matches the background color, invert it. vec4 adjustColorForContrast(vec4 color) { if (czm_backgroundColor.rgb == color.rgb) { color.rgb = vec3(1.0) - color.rgb; } return color; } czm_brdfLut An automatic GLSL uniform containing the BRDF look up texture used for image-based lighting computations. Example: // GLSL

Render water-paint in iOS

感情迁移 提交于 2019-11-29 01:22:09
问题 I have been working with OpenGL in iOS, and setting the colors with glColor4f(r,g,b,a) and then drawing my own color on a white UIImageView . I basically have a brush, which is then moved around my user's touch, and then it paints the color onto the canvas. But this color needs to be water paint (like smudged color) Does anyone understand/knows how to get a water color like this app does, and how the background UIImageView has a texture on it? https://itunes.apple.com/us/app/hello-watercolor

Why does my translation matrix needs to be transposed?

我的未来我决定 提交于 2019-11-29 01:09:05
I'm working on a small graphics engine using OpenGL and I'm having some issues with my translation matrix. I'm using OpenGL 3.3, GLSL and C++. The situation is this: I have defined a small cube which I want to render on screen. The cube uses it's own coordinate system, so I created a model matrix to be able to transform the cube. To make it myself a bit easier I started out with just a translation matrix as the cube's model matrix and after a bit of coding I've managed to make everything work and the cube appears on the screen. Nothing all to special, but there is one thing about my

What does (gl_FragCoord.z / gl_FragCoord.w) represent?

 ̄綄美尐妖づ 提交于 2019-11-29 00:10:08
问题 I want actual world space distance, and I get the feeling from experimentation that (gl_FragCoord.z / gl_FragCoord.w) is the depth in world space? But I'm not too sure. EDIT I've just found where I had originally located this snippet of code. Apparently it is the actual depth from the camera? 回答1: This was asked (by the same person) and answered elsewhere. I'm paraphrasing and embellishing the answer here: As stated in section 15.2.2 of the OpenGL 4.3 core profile specification (PDF), gl

PowerVR SGX535 Shader Performance (OpenGL ES 2.0)

允我心安 提交于 2019-11-28 21:33:19
I'm currently working on a couple of shaders for an iPad game and it seems as if Apple's GLSL compiler isn't doing any optimizations (or very few). I can move a single line in a shader and drop my FPS from 30 to 24 but I really have no idea why this is happening. Does anyone have any references for the following: what PowerVR instructions are generated from GLSL instructions? what are the timings of the PowerVR instructions? what sort of parallel processing units are in the PowerVR535 and how can they be exploited? Thanks, Tristan http://www.imgtec.net/factsheets/SDK/POWERVR%20SGX.OpenGL%20ES

Shader position vec4 or vec3

梦想的初衷 提交于 2019-11-28 21:27:20
I have read some tutorials about GLSL. In certain position attribute is a vec4 in some vec3. I know that the matrix operations need a vec4, but is it worth to send an additional element? Isn't it better to send vec3 and later cast in the shader vec4(position, 1.0)? Less data in memory - it will be faster? Or we should pack an extra element to avoid casting? Any tips what should be better? layout(location = 0) in vec4 position; MVP*position; or layout(location = 0) in vec3 position; MVP*vec4(position,1.0); For vertex attributes, this will not matter. The 4th component is automatically expanded

GLSL, Array of textures of differing size

走远了吗. 提交于 2019-11-28 19:43:02
When doing multitexturing in GLSL, is there anyway to have an indexable array of samplers where each texture is a different size? This syntax isn't valid: uniform sampler2D texArray[5]; Right now it seems like the only option is to individually create the samplers: uniform sampler2D tex1; uniform sampler2D tex2; uniform sampler2D tex3; uniform sampler2D tex4; uniform sampler2D tex5; But then I can't iterate through them, which is a real pain in the ass. Is there a solution? This syntax isn't valid: Says who? Arrays of samplers most certainly are valid (depending on the version). How you use

Should I calculate matrices on the GPU or on the CPU?

爷,独闯天下 提交于 2019-11-28 18:35:30
Should I prefer to calculate matrices on the CPU or GPU? Let's say I have the following matrices P * V * M , should I calculate them on the CPU so that I can send the final matrix to the GPU (GLSL) or should I send those three matrices separately to the GPU so that GLSL can calculate the final matrix? I mean in this case GLSL would have to calculate the MVP matrix for every vertex, so it is probably faster to precompute it on the CPU. But let's say that GLSL only has to calculate he MVP matrix once, would the GPU calculate the final matrix faster than the CPU? General rule: If you can pass it

What can cause glDrawArrays to generate a GL_INVALID_OPERATION error?

纵然是瞬间 提交于 2019-11-28 18:08:32
I've been attempting to write a two-pass GPU implementation of the Marching Cubes algorithm, similar to the one detailed in the first chapter of GPU Gems 3, using OpenGL and GLSL. However, the call to glDrawArrays in my first pass consistently fails with a GL_INVALID_OPERATION . I've looked up all the documentation I can find, and found these conditions under which glDrawArrays can throw that error: GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to an enabled array or to the GL_DRAW_INDIRECT_BUFFER binding and the buffer object's data store is currently mapped. GL

How can I improve this WebGL / GLSL image downsampling shader

强颜欢笑 提交于 2019-11-28 18:02:42
I am using WebGL to resize images clientside very quickly within an app I am working on. I have written a GLSL shader that performs simple bilinear filtering on the images that I am downsizing. It works fine for the most part but there are many occasions where the resize is huge e.g. from a 2048x2048 image down to 110x110 in order to generate a thumbnail. In these instances the quality is poor and far too blurry. My current GLSL shader is as follows: uniform float textureSizeWidth;\ uniform float textureSizeHeight;\ uniform float texelSizeX;\ uniform float texelSizeY;\ varying mediump vec2