glsl

Picking triangles in OpenGL core profile when using glDrawElements

时间秒杀一切 提交于 2019-12-07 08:47:30
问题 I am drawing a mesh of triangles using glDrawElements and would like to be able to pick/select a triangle using the mouse click. The mesh of triangles can be very big. In fixed-function OpenGL there is the possibility of using GL_SELECT: http://content.gpwiki.org/index.php/OpenGL:Tutorials:Picking .. However I am only interested in using OpenGL core profile. Another possibility would be to use 'color coding': http://www.lighthouse3d.com/opengl/picking/index.php?color1 http://www.opengl.org

GLSL integration function

可紊 提交于 2019-12-07 06:36:24
问题 Any recommendation on how to implement efficient integral functions, like SumX and SumY, in GLSL shaders? SumX(u) = Integration with respect to x = I(u0,y) + I(u1,y) +... + I(uN,y); u=normalized x coordinate SumY(v) = Integration with respect to y = I(x,v0) + I(x,v1) +... + I(x,vN); v=normalized y coordinate For instance the 5th pixel of the first line would be the sum of all five pixels on the first line. And the last pixel would be the sum of all previous pixels including the last pixel

GLSL: Can't get uniforms location

白昼怎懂夜的黑 提交于 2019-12-07 06:27:24
问题 My problem is fact that I can't get some uniforms location, when location of others I get without problems. For example I have in VS uniforms called "MVP" and "Model" and I have "MVP" location without problems, but I don't have "Model" location which I use symmetrically. In the same manner I can't get location of fields from Light structure in FS. Its code passing data into shader: bool Shader::SetShaderParameters(mat4 MVPMatrix,mat4 Model,GLint textureUnit) { GLuint matrixLocation =

OpenGL GLSL uniform branching vs. Multiple shaders

狂风中的少年 提交于 2019-12-07 06:24:37
问题 I've been reading many articles on uniform if statements that deal with branching to change the behavior of large shaders "uber shaders". I started on an uber shader (opengl lwjgl) but then I realized, the simple act of adding an if statement set by a uniform in the fragment shader that does simple calculations decreased my fps by 5 compared to seperate shaders without uniform if statements. I haven't set any cap to my fps limit, it's just refreshing as fast as possible. I'm about to add

Recolor sprites on the fly

帅比萌擦擦* 提交于 2019-12-07 06:12:18
问题 I need to replace colors of the sprite. Some example founded in google Here is I've found a looks like working solution for Unity - [How to Use a Shader to Dynamically Swap a Sprite's Colors][2] How to port it to cocos2d-x? Can someone please help with code examples? I'm looking for cocos2d-x v3 code snippet. Really looking forward for some help. 回答1: The algorithm in the article How to Use a Shader to Dynamically Swap a Sprite's Colors is very simple. It is based on a one dimensional lookup

Disable GLSL compiler optimization

こ雲淡風輕ζ 提交于 2019-12-07 06:04:36
问题 I am using OpenGL 4.2 with GLSL 420 .I need to prevent the GLSL compiler from optimizing out unused uniforms as those serve for occasional tests. I have tried to put: #version 420 #pragma optimize (off) ... ...... But it seems to have no effect.The compiler still cleans all the unused uniforms.I am running on NVidia drivers v319 on Linux with GeForce 680GTX 回答1: Inactive uniform determination is not an optimization. It is a consequence of how unextended GLSL programs work, they are compiled

GLSL boolean evaluation wackiness

落爺英雄遲暮 提交于 2019-12-07 05:48:52
问题 I am having quite a time with a simple on/off switch in my fragment shader. I want to compare the output of a motion-blur pass with the unprocessed output, so I have added a boolean uniform to the fragment shader like such: uniform boolean blur; I activate it (based on keyboard input and a global int called blur) like such: if ( key == 'b' ) blur = !blur; glUseProgram( program ); glUniform1i( blur_loc, blur ); and then in the shader it is declared with all my other uniforms like this: uniform

GLSL 4.1 with gl_ModelViewProjectionMatrix

吃可爱长大的小学妹 提交于 2019-12-07 05:47:41
问题 I am working on a glsl shader program as part of a plugin that runs inside a "closed source" application. The application (maya) is written using opengl 2.1, but our graphics cards support opengl/glsl 4.1 and I want to use tessellation and geometry shaders in my program. The application sets up the opengl viewport and the traditional model/view matrix stack and I do not have control over that part of the code. My pass-through vertex shader uses GLSL 1.2 and works fine: // GLSL VERTEX SHADER

Wide lines in geometry shader behaves oddly

▼魔方 西西 提交于 2019-12-07 05:25:05
问题 I'm trying to render arbitrary wide lines (in screen space) using a geometry shader. At first it seems all good, but on certain view position the lines are rendered incorrectly: The image on the left present the correct rendering (three lines on positive X, Y and Z axes, 2 pixel wide). When the camera moves near the origin (and indeed near the lines), the lines are rendered like the right image. The shader seems straightforward, and I don't understand what's going on my GPU: --- Vertex Shader

Can you pass a fixed-size array as a GLSL function parameter?

无人久伴 提交于 2019-12-07 03:08:27
问题 In a GLSL shader, I want to create a function that looks a bit like this : void MyFunction(out float results[9]) { float value0 = 3.1546; float value1 = 42; // whatever value /* ... long, complicated code ... */ results[0] = value0; results[1] = value1; results[2] = value2; ... } Can such a function signature be used and compiled in GLSL ? If no, are there any alternatives ? 回答1: Yes, this is legal GLSL code. That doesn't mean it will certainly compile, but it is legal code. That being said,