glsl

OpenGL GLSL Binding Sampler for Fragment Shader

不想你离开。 提交于 2019-12-02 06:34:10
I am hoping to implement a shader on a 2D OpenGL application. My plan is to render a scene to a framebuffer object, and then render that framebuffer object to the screen using a shader. Here is the scene, which I have drawn to a framebuffer object, and then to the screen from there. Using the arrow keys makes the moon move around (I am quite proud of it!) However, when I try to render the framebuffer object to the screen using my shader program, I get this: It is very sad. This fragment shader is one which I got from a tutorial , and I'm sure the problem has to be with the Uniform Variables.

Resizable arrays in GLSL

霸气de小男生 提交于 2019-12-02 06:14:29
问题 For calculating multiple light sources it would be extremely handy to have resizable arrays in GLSL like the C++ std::vector . The size of the array has to be able to change all the time, without recompiling the shader. Is there some command, library etc. that can do this? 回答1: vector isn't magic; it works by allocating memory. There is no memory allocation in GLSL; a shader uses the resources it is given access to. Shaders aren't allowed to just create resources. The typical way this is

glMultiDraw functions and gl_InstanceID

杀马特。学长 韩版系。学妹 提交于 2019-12-02 05:45:08
问题 When I look at the documentation of glMultiDrawElementsIndirect (or in the Wiki) it says that a single call to glMultiDrawElementsIndirect is equivalent to repeatedly calling glDrawElementsIndirect (just with different parameters). Does that mean that gl_InstanceID will reset for each of these "internal" calls? And if so, how am I able to tell all these calls apart in my vertex shader? Background: I'm trying to draw all my different meshes all at once. But I need some way to known to which

How to implemen shadertoy code into three.js - clarifying the details

微笑、不失礼 提交于 2019-12-02 05:25:19
So here is a previous question: How to implement a ShaderToy shader in three.js Tried to implement the steps from the link above into this code unsucessfully: three.js/blob/master/examples/webgl_shader.html So I replaced the original vertex shader and the origianl fragment shader so I got this code: <script id="vertexShader" type="x-shader/x-vertex"> varying vec2 vUv; void main() { vUv = uv; vec4 mvPosition = modelViewMatrix * vec4(position, 1.0 ); gl_Position = projectionMatrix * mvPosition; } </script> <script id="fragmentShader" type="x-shader/x-fragment"> uniform float iGlobalTime; uniform

GLSL: pow vs multiplication for integer exponent

孤者浪人 提交于 2019-12-02 04:23:36
问题 Which is faster in GLSL: pow(x, 3.0f); or x*x*x; ? Does exponentiation performance depend on hardware vendor or exponent value? 回答1: While this can definitely be hardware/vendor/compiler dependent, advanced mathematical functions like pow() tend to be considerably more expensive than basic operations. The best approach is of course to try both, and benchmark. But if there is a simple replacement for an advanced mathematical functions, I don't think you can go very wrong by using it. If you

glMultiDraw functions and gl_InstanceID

百般思念 提交于 2019-12-02 01:32:28
When I look at the documentation of glMultiDrawElementsIndirect (or in the Wiki ) it says that a single call to glMultiDrawElementsIndirect is equivalent to repeatedly calling glDrawElementsIndirect (just with different parameters). Does that mean that gl_InstanceID will reset for each of these "internal" calls? And if so, how am I able to tell all these calls apart in my vertex shader? Background: I'm trying to draw all my different meshes all at once. But I need some way to known to which mesh the vertex, I'm processing in my vertex shader, belongs. Nicol Bolas The documentation says

GLSL: pow vs multiplication for integer exponent

孤街浪徒 提交于 2019-12-02 00:52:34
Which is faster in GLSL: pow(x, 3.0f); or x*x*x; ? Does exponentiation performance depend on hardware vendor or exponent value? While this can definitely be hardware/vendor/compiler dependent, advanced mathematical functions like pow() tend to be considerably more expensive than basic operations. The best approach is of course to try both, and benchmark. But if there is a simple replacement for an advanced mathematical functions, I don't think you can go very wrong by using it. If you write pow(x, 3.0) , the best you can probably hope for is that the compiler will recognize the special case,

Reading current framebuffer

折月煮酒 提交于 2019-12-02 00:31: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.

Is it ever reasonable to do computations outside of main in an OpenGL shader?

谁都会走 提交于 2019-12-02 00:17:37
I have some vertex shader code somewhat like the following (this is a bit of simplified example): attribute vec2 aPosition; attribute vec4 aColor; varying lowp vec4 vColor; uniform vec4 uViewport; mat4 viewportScale = mat4(2.0 / uViewport.z, 0, 0, 0, 0, -2.0 / uViewport.w, 0,0, 0, 0,1,0, -1,+1,0,1); void main() { vec2 pos = aPosition; gl_Position = viewportScale * vec4(pos, 0, 1); vColor = vec4(aColor.rgb*aColor.a, aColor.a); } In particular, the viewportScale matrix is calculated from the uViewport uniform outside of the main function . Using this from a browser (WebGL), it seems to work fine

Access to 3D array in fragment shader

自古美人都是妖i 提交于 2019-12-01 23:46:38
问题 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)