glsl

textureGather() behavior at texel center coordinates

不打扰是莪最后的温柔 提交于 2019-12-12 09:17:00
问题 Suppose I have a 100x100 texture and I do the following: vec4 texelQuad = textureGather(sampler, vec2(50.5)/vec2(100.0)); The coordinate I am requesting is exactly at the center of texel (50, 50). So, will I get a quad of texels bounded by (49, 49) and (50, 50) or the one bounded by (50, 50) and (51, 51). The spec is evasive on the subject. It merely states the following: The rules for the LINEAR minification filter are applied to identify the four selected texels. The relevant section 8.14.2

OpenGL: Compute eye space coord from window space coord in GLSL?

▼魔方 西西 提交于 2019-12-12 08:56:21
问题 How do I compute an eye space coordinate from window space (pixel in the frame buffer) coordinates + pixel depth value in GLSL please (gluUnproject in GLSL so to speak)? 回答1: Looks to be duplicate of GLSL convert gl_FragCoord.z into eye-space z. Edit (complete answer): // input: x_coord, y_coord, samplerDepth vec2 xy = vec2(x_coord,y_coord); //in [0,1] range vec4 v_screen = vec4(xy, texture(samplerDepth,xy), 1.0 ); vec4 v_homo = inverse(gl_ProjectionMatrix) * 2.0*(v_screen-vec4(0.5)); vec3 v

Unable to use '%' in glsl

陌路散爱 提交于 2019-12-12 08:38:50
问题 While writing a shader program today, I encountered a situation where I have to use % to find the remainder. GLSL gave me an error saying that it is not available in the current version. I've tried several problems. GLSL doesn't support recursive function and while loops, which is needed if I want to create a function that can give me the result of (a % b) . So, I'm currently stuck. Can someone help me with this? Edit . I was trying to emulate a CRT screen using some shader code from this

GLSL per vertex fixed size array

人走茶凉 提交于 2019-12-12 08:27:26
问题 Is it possible in desktop GLSL to pass a fixed size array of floats to the vertex shader as an attribute? If yes, how? I want to have per vertex weights for character animation so I would like to have something like the following in my vertex shader: attribute float weights[25]; How would I fill the attribute array from my C++ & OpenGL program? I have seen in another question that I could get the attribute location of the array attribute and then just add the index to that location. Could

Why does GLSL's arithmetic functions yield so different results on the iPad than on the simulator?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 08:13:42
问题 I'm currently chasing some bugs in my OpenGL ES 2.0 fragment shader code which is running on iOS devices. The code runs fine in the simulator, but on the iPad it has huge problems and some of the calculations yield vastly different results, I had for example 0.0 on the iPad and 4013.17 on the simulator, so I'm not talking about small differences which could be the result of some rounding errors. One of the things I noticed is that, on the iPad, float1 = pow(float2, 2.0); can yield results

Passing data through tessellation shaders to the fragment shader

眉间皱痕 提交于 2019-12-12 07:37:03
问题 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

THREE.js - Billboard Vertex Shader

风流意气都作罢 提交于 2019-12-12 07:22:29
问题 I have the need to orientate an instance of THREE.Mesh to always face the camera. I know I could just use the [THREE.Mesh].lookAt() method, but I'm trying to work on my GLSL chops a bit more and want to be able to do this in a vertex shader. I've read through NeHe's Billboarding tutorial, and it makes sense to me. Well, all apart from the bit where one applies these orientation vectors to each vertex. I feel like I'm very close to getting this working, but as it stands at the moment, my

What versions of GLSL can I use in OpenGL ES 2.0?

风格不统一 提交于 2019-12-12 07:10:04
问题 I can't seem to find a clear answer on this, despite hours of googling. Can someone just tell me what's going on? I get errors saying things like, "version 140 is not supported." Is this my device (Kindle Fire) or GL ES 2.0? Do I need to add libraries or anything? 回答1: you actually don't have to add any libraries, 140 is far too new for Kindle Fire. Either remove the version specification or decrement it until the shader compiles. You may need to fix some other errors in the shader as the

glDrawElements gives EXC_BAD_ACCESS with VBO

↘锁芯ラ 提交于 2019-12-12 06:58:42
问题 I've just started learning opengl and I was trying to implement VBOs. this is what I'm doing: in the main method before I iterate, for each mesh I initialize its VBOs. The mesh->pos and mesh->norm contain the points and the normals of the triangles and the quads of the mesh. The mesh->triangle and mesh->quad contain the indices. for (auto mesh : scene->meshes) { mesh->vboPos = 0; glGenBuffers (1, &mesh->vboPos); glBindBuffer (GL_ARRAY_BUFFER, mesh->vboPos); glBufferData (GL_ARRAY_BUFFER, 3 *

glVertexAttribPointer vec2 but forward just one [closed]

眉间皱痕 提交于 2019-12-12 06:47:36
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . I have this, wich will read in vec2, is it possible to forward just one, so the vertex shader will recieve in each 0,1 then 1,2 2,3 and so on? float v[]{0,1,2,3,4...}; glVertexAttribPointer((GLuint)0, 2, GL_FLOAT, GL_FALSE, 0, 0); 回答1: This feels like a hack, but you could explicitely set the