glsl

What is the most efficient way to implement a convolution filter within a pixel shader?

血红的双手。 提交于 2019-11-30 10:48:49
问题 Implementing convolution in a pixel shader is somewhat costly as to the very high number of texture fetches. A direct way of implementing a convolution filter is to make N x N lookups per fragment using two for cycles per fragment. A simple calculation says that a 1024x1024 image blurred with a 4x4 Gaussian kernel would need 1024 x 1024 x 4 x 4 = 16M lookups. What can one do about this? Can one use some optimization that would need less lookups? I am not interested in kernel-specific

Parallax mapping glitch in OpenGL

拥有回忆 提交于 2019-11-30 10:14:11
And this is result when I invert the tangent vector right after transferring it to vertex shader: The "shadow" is in the wrong place. (And it works only when I rotate it through Y axis so the last image seem to present a good parallax mapped cube) IM SURE IT IS NOT A TANGENT VECTOR OR TEXTURE COORDINATES PROBLEM Because I used exactly the same tangent calculation functions and exactly the same cube position, normal and texture coordinate data as in working demo. After all, I exported arrays with position/texcoord/normal/tangent data into a .txt file and I saw what I exactly expected (and what

GLSL custom/no interpolation of triangles with vertex colors

风格不统一 提交于 2019-11-30 09:41:08
问题 The effect I want to achieve is vertex color with sharp contours. So inside the triangle the fragment shader should use the color of whatever vertex is closest to that fragment. Now when thinking about it, the only solution I can come up with is assigning tex coords 1,0,0 0,1,0 and 0,0,1 to the three vertices and have 2 (reoordered) duplicates of the vertex color array and then choose from the color aray of which the corresponding tex coord is highest. This method would at least add 9 more

How to project top and bottom area of openGL control

我只是一个虾纸丫 提交于 2019-11-30 09:33:57
问题 Using below code I can display an image in openGL control. Which is in rectangular shape. Now I want to project top and bottom area of this rectangular to a cylindrical shape.I mean need to perform a rectangular to cylidrical projection on openGL. How can I achieve this? private void CreateShaders() { /***********Vert Shader********************/ vertShader = GL.CreateShader(ShaderType.VertexShader); GL.ShaderSource(vertShader, @"attribute vec3 a_position; varying vec2 vTexCoord; void main() {

Why does barrier synchronize shared memory when memoryBarrier doesn't?

余生长醉 提交于 2019-11-30 08:49:17
The following GLSL compute shader simply copies inImage to outImage . It is derived from a more complex post-processing pass. In the first several lines of main() , a single thread loads 64 pixels of data into the shared array. Then, after synchronizing, each of the 64 threads writes one pixel to the output image. Depending on how I synchronize, I get different results. I originally thought memoryBarrierShared() would be the correct call, but it produces the following result: which is the same result as having no synchronization or using memoryBarrier() instead. If I use barrier() , I get the

How to define constant array in GLSL (OpenGL ES 2.0)?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 08:49:14
I just want to store an array of weights that needs to every fragment calculation. This: float weights[5] = float[5](3.4, 4.2, 5.0, 5.2, 1.1); Just throws this: ERROR: 0:30: ']' : syntax error syntax error ERROR: 0:30: ';' : syntax error syntax error Stefan Hanke From the OpenGL ES SL 1.0 spec , paragraph 4.1.9 Arrays (p. 24): There is no mechanism for initializing arrays at declaration time from within a shader. Note that this has been intentionally left out . According to this post , the OpenGL ES SL version for OpenGL ES 2 is based on OpenGL SL 1.2 . The same paragraph (p. 20) contains:

What kind of blurs can be implemented in pixel shaders?

巧了我就是萌 提交于 2019-11-30 08:34:38
问题 Gaussian, box, radial, directional, motion blur, zoom blur, etc. I read that Gaussian blur can be broken down in passes that could be implemented in pixel shaders, but couldn't find any samples. Is it right to assume that any effect that concerns itself with pixels other than itself, can't be implemented in pixel shaders? 回答1: You can implement everything, as long you are able to pass information to the shader. The trick, in this cases, is to perform a multiple pass rendering. The final

PowerVR SGX535 Shader Performance (OpenGL ES 2.0)

牧云@^-^@ 提交于 2019-11-30 06:48:15
问题 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

Do OpenGL GLSL samplers always return floats from 0.0 to 1.0?

元气小坏坏 提交于 2019-11-30 05:10:43
问题 I've created a couple of floating point RGBA texture... glBindTexture( GL_TEXTURE_2D, texid[k] ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_FLOAT, data); and then I double-buffer render/sample into

GLSL for simple water surface effects

限于喜欢 提交于 2019-11-30 05:04:36
I'm looking for some pointers on how to implement simple water surface effects in OpenGL ES 2.0. Nothing fancy like reflection or refraction, just a basic ripple/wave effect that modulates over time. Performance is critical. I'm assuming this will be best done in a shader. Any pointers on how to best handle this? There is an old trick to simulate water waves & ripples using minimum effort in terms of equations. It's used in many places, and I can't find the original, but you can grab it, for example, from here . You'll need 2 textures, each containing just height. Simulation is done by ping