glsl

OpenGL Implementing MultiPass

故事扮演 提交于 2019-12-01 22:52:12
I am having trouble porting some code I have successfully implemented in Shadertoy to desktop OpenGL, the problem is that I need to create a FrameBufferObject FBO so that I can do offscreen computations that will be later passed on to the main glsl fragment shader, the thing is that this buffer needs to reference itself as a texture to get the previous values for it to be able to run a simulation. I have successfully created the FBO: // Framebuffer configuration. unsigned int frameBufferOne; glGenFramebuffers(1, &frameBufferOne); glBindFramebuffer(GL_FRAMEBUFFER, frameBufferOne); // Create a

Can't set uniform value in OpenGL shader

一世执手 提交于 2019-12-01 22:38:52
I am currently learning OpenGL programming, and I have made some good progress, but I seem to be stuck now. Currently, I am trying to get simple shaders to work. To be more specific, I am trying to set a uniform value of the shader . The shaders compile successfully, and work correctly if I eliminate the uniform value. Here is the (vertex) shader code: #version 440 core layout(location = 0) in vec3 vertex; uniform mat4 mvp; void main() { gl_Position = mvp * vec4(vertex, 1); } And the code I use to set the value ( glGetUniformLocation returns 0 as expected): mvp = glm::mat4( glm::vec4(3.0f, 0

Access to 3D array in fragment shader

我的未来我决定 提交于 2019-12-01 22:31:32
I'm trying to provide access to a 3-dimensional array of scalar data to a fragment shader, from a Python program using PyOpenGL. In the fragment shader, I declare the a 3d sampler uniform uniform sampler3D vol; and in the Python program I have the following code to set up a scalar 3d texture vol = numpy.random.rand(3, 3, 3).astype(np.float32) texture = glGenTextures(1) glUniform1i(glGetUniformLocation(program, "vol"), 0) glActiveTexture(GL_TEXTURE0 + 0) glBindTexture(GL_TEXTURE_3D, texture) glTexImage3D(GL_TEXTURE_3D, 0, GL_RED, 3, 3, 3, 0, GL_RED, GL_FLOAT, vol) glEnable(GL_TEXTURE_3D)

Reading current framebuffer

流过昼夜 提交于 2019-12-01 20:35:21
Is there a way to read fragment from the framebuffer currently rendered? So, I'm looking for a way to read color information from the fragment that's on the place that current fragment will probably overwrite. So, exact position of the fragment that previously rendered. I found gl_FragData and gl_LastFragData to be added with certain EXT_ extensions to shaders, but if they are what I need, could somebody explain how to use those? I am looking either for a OpenGL or OpenGL ES 2.0 solution. EDIT: All the time I was searching for the solution that would allow me to have some kind of read&write

Export from Shadertoy to Three.js

假装没事ソ 提交于 2019-12-01 20:21:46
I am making my first steps coding. I made some courses on internet, then I played with some three.js experiments, and now I would like to continue learning experimenting with Shaders. I found Shadertoy.com and it's really amazing! There are a lot of difference experiments with incredible effects. I am trying to use one of these shaders in Three.js but is not so easy. The Shaders are already written, it's true. But I don't know what to do with that, I don't know how I can use it. Because it's not only copy and paste the code. There is a relation that I have to write to can apply some of these

Noise Algorithm fails in Samsung Galaxy SIII (GLES)

最后都变了- 提交于 2019-12-01 16:58:50
I am struggling to get the next simple algorithm working in the Samsung Galaxy SIII float rand(vec2 co) { return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } .... vec3 color = texture2D(u_texture, v_texcoord); gl_FragColor.rgb = color + vec3(rand(gl_FragCoord.xy + time / 1000.0)); .... The code generates perfectly the expected noise in Samsung Galaxy S1 and Google Nexus S. But it fails completely in the new smartphone which uses ARM's Mali-400/MP4. Anyone can spot anything wrong with this algorithm? Or maybe understand why could it fail? Your problem likely comes from taking

glVertexAttribPointer on built-in vertex attributes like gl_Vertex, gl_Normal

自闭症网瘾萝莉.ら 提交于 2019-12-01 16:51:57
I have to send vertex attributes using glVertexAttribPointer to shaders expecting them as built-in ( gl_Vertex , gl_Color , etc.). The glVertexAttribPointer function needs to specify the index (or location) of each built-in attribute. I can do it on NVidia implementations since the location of each attribute is fixed (see http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php at the section "Custom attributes), however i'm not sure about the locations in ATI implementation. Also, the function glGetAttribLocation will return -1 when trying to get the location of any attribute

Is it worth caching glsl uniform location in code?

对着背影说爱祢 提交于 2019-12-01 16:33:28
问题 I would like to have ability to set uniforms via their actual names in the shader myProgram.uniform3fv("uniformVector", 0.0f, 0.1f, 1.0f); do I have to cache locations in some form of a map? std::map<std::string, unsigned int> // or unordered_map or maybe OpenGL (on desktop) caches this anyway, so I would not have any performance difference? 回答1: The OpenGL specification defines functionality, not performance. So there's no way to know how any particular OpenGL implementation will store the

glVertexAttribPointer on built-in vertex attributes like gl_Vertex, gl_Normal

ぐ巨炮叔叔 提交于 2019-12-01 15:47:43
问题 I have to send vertex attributes using glVertexAttribPointer to shaders expecting them as built-in ( gl_Vertex , gl_Color , etc.). The glVertexAttribPointer function needs to specify the index (or location) of each built-in attribute. I can do it on NVidia implementations since the location of each attribute is fixed (see http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php at the section "Custom attributes), however i'm not sure about the locations in ATI implementation.

Speed of cos() and sin() function in GLSL shaders?

时光总嘲笑我的痴心妄想 提交于 2019-12-01 15:45:35
I'm interested in information about the speed of sin() and cos() in Open GL Shader Language . The GLSL Specification Document indicates that: The built-in functions basically fall into three categories: ... ... They represent an operation graphics hardware is likely to accelerate at some point. The trigonometry functions fall into this category. EDIT: As has been pointed out, counting clock cycles of individual operations like sin() and cos() doesn't really tell the whole performance story. So to clarify my question, what I'm really interested in is whether it's worthwhile to optimize away sin