Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Hot answers tagged

25

As far as I know there are no tools that allows you to steps through code in a shader (also, in that case you would have to be able to select just a pixel/vertex you want to "debug", the execution is likely to vary depending on that). What I personally do is a very hacky "colourful debugging". So I sprinkle a bunch of dynamic branches with #if DEBUG / #...


25

The interpolation looks fine. The main problem here is that the hash function you're using isn't very good. If I look at just one octave, and visualize the hash result by outputting hash(PT).x, I get something like this: This is supposed to be completely random per grid square, but you can see that it has a lot of diagonal line patterns in it (it almost ...


17

There's a bunch of a approaches, but none is perfect. It's possible to share code by using glAttachShader to combine shaders, but this doesn't make it possible to share things like struct declarations or #define-d constants. It does work for sharing functions. Some people like to use the array of strings passed to glShaderSource as a way to prepend common ...


15

First, gl_FragCoord.xy are screen space coordinates of current pixel based on viewport size. So if viewport size is width=5, height=4 then each fragment contains: Why are uvs needed? For example I rendered geometry to screen quad and then I need to apply some postprocessing on this quad in another rendering pass. To sample from that quad I need texture ...


13

Use cases are only limited by your imagination! noperspective means that the attribute is interpolated across the triangle as though the triangle was completely flat on the surface of the screen. You can do antialiased wireframe rendering with this: output a screen-space distance to the nearest edge as a noperspective varying and use that as coverage in the ...


13

The problem is, glVertexAttribPointer(0, 4, GL_DOUBLE... doesn't do what you think it does. Using actual double-precision vertex attributes and performing double precision computations is a very modern hardware feature (GL4/DX12) and is different from specifying the type GL_DOUBLE in the good old glVertexAttribPointer call. This always worked and does ...


12

You don't need to rebind the attributes, so long as you ensure that their location stays the same in both shaders. (Usually using the layout(location = X) syntax in GLSL, but can also be done with glBindAttribLocation if former is not available.) Uniforms, however, are part of the Shader Object state, and so will need to be set at least once for every ...


11

This issue looks like standard shadow map acne artifacts. Additionally your's lighting equation is incomplete or wrong. Light shouldn't influence faces with normals facing away from it. This also means that with a proper equation the "dark" side of the sphere shouldn't have any acne artifacts. There are three sources of acne artifacts: First acne source is ...


11

What you're talking about is commonly called "dependent texture reads" in the mobile development community. It's an implementation detail of certain hardware, and therefore it really depends on the GPU as to whether or not it has any performance implications. Typically it's something you see brought up for PowerVR GPU's in Apple hardware, since it was ...


10

DFG pops up in the family of microfacet based BRDFs. It is simply the product of three terms: D : The microfacet distribution. F : The fresnel coefficient. G : The geometric attenuation between microfacets. When someone says Cook-Torrance, they usually mean a microfacet BRDF where the distribution (D) is Beckmann, which I think is what the original Cook-...


9

There is also GLSL-Debugger. It is a debugger used to be known as "GLSL Devil". The Debugger itself is super handy not only for GLSL code, but for OpenGL itself as well. You have the ability to jump between draw calls and break on Shader switches. It also shows you error messages communicated by OpenGL back to the application itself.


9

I generally just use the fact that glShaderSource(...) accepts an array of strings as it's input. I use a json-based shader definition file, which specifies how a shader (or a program to be more correct) is composed, and there I specify the preprocessor defines I may need, the uniforms it uses, the vertex/fragment shaders file, and all the additional "...


9

Jittering and dithering are both techniques of adding noise to reduce visible artefacts (such as banding) in an image. They solve different kinds of artefacts so they are used in different situations. Jittering moves sample positions in space to reduce artefacts caused by regular sampling. Dithering changes the way colours are rounded (when reducing ...


9

This could be done that way: First condition is float val = 1.0-step(shouldY, ActualY); Then, the condition: state >= 20.0 && state < 40.0 can be changed to step(20.0, state) - step(40.0, state). This equals 0.0 if outside of range and 1.0 if inside. Let a = step(20.0, state) - step(40.0, state) Then we know that mix function: genType ...


8

I think the naming order is intuitive because it is in reading order (left to right), e.g., worldViewProjection means that your point/direction is first multiplied by the world matrix, then the view matrix, and then the projection matrix. In this manner, you know the correct multiplication order by just reading the variable name and you do not have to think ...


7

The shader language is bound to the APIs/engines that support it (glsl to openGL & WebGL and hlsl to D3D). There are tools to translate from one to the other but they aren't perfect. This means the main reason to pick one over the other is which platform you will be working on. However by the end of the year a new binary shader representation will come ...


7

There are several offerings by GPU vendors like AMD's CodeXL or NVIDIA's nSight/Linux GFX Debugger which allow stepping through shaders but are tied to the respective vendor's hardware. Let me note that, although they are available under Linux, I always had very little success with using them there. I can't comment on the situation under Windows. The ...


7

Without knowing the internals of Blender, I would say it uses shared normals for the quads, splitting the normals only on edges between the quads, not between the triangles. So your idea of uploading a normal per quad is probably close to the result you are looking for. If you load the mesh as quads, you are set. If you are using an old version of OpenGL ...


7

SOLUTION After a couple of days I realized that I was computing my projection matrix using a FOV angle in degrees and It should be in radians. I made the conversion and now everything works great. The interpolation among faces of my depth framebuffer's cubemap is now perfect. For this reason, It is important to handle every single trigonometric function's ...


7

Without seeing the error message I can't be sure but I think it's failing on the 1 being int instead of a float. float inv_coord = v_coord - 1.0; There is a simpler method, you can do 1.0 - v_coord and do away with the abs.


7

This is a common problem with very subtle gradients. The problem is that the image is displayed with 8 bits per component and this is not quite enough precision to make a gradient that is smooth to the eye under these conditions. However, the underlying calculations being done in the shader are at higher precision (e.g. float = 24 effective bits of mantissa)...


7

I don't think uniform arrays can be dynamically sized. In your case you should define the array as the maximum number of lights you will process and then use a uniform to control the number of iterations you do on this array. On the CPU side you can set a subset of the lights[] array according to the 'size' variable. e.g. #define MAX_LIGHTS 128 uniform ...


7

You can use a stencil instead, This allows the gpu to do an early out test before the fragment shader even starts. You only have to build the stencil once (possibly with a discard in a simple shader) and you can reuse the stencil in future draws.


6

Shader compilers are extremely aggressive about unrolling since early HW often didn't have flow control and the cost on more recent HW can vary. If you have a benchmark you are actively testing against and a range of relevant hardware, then try things to see what happens. Your dynamic loop is more amenable to developer intervention than a static loop - but ...


6

The order is arbitrary, but if you want to be compatible with physics textbooks then your notation is mostly set. The difference is that you seem to think that its more natural to observe the systen on the outside (and for graphics pipe devs its often so, not for modeler). For a mathematician it is more natural to think from local coordinates out. There are ...


6

Rather than trying to speed up your shader by fiddling with the code, can I suggest you make use of the GPU's inherent ability to rapidly fill polygons? This will allow it to eliminate the vast bulk of the cases where there is no need to even make a decision. What I suggest you try is something like the following: Create, say, a heptagon (i.e. the blue ...


6

Now this texture coordinates supposed to be updated for each vertex processed by vertex shader because i set the glVertexAttribDivisor() to 0 which means it should be. No, it doesn't. A divisor of 0 means that the texture coordinate work exactly as if you hadn't called glVertexAttribDivisor for that attribute at all. 0 is not a special case; it's the ...


6

The GLSL Specification in section 6.1.1 "Function Calling Conventions" states: The keyword in is used as a qualifier to denote a parameter is to be copied in, but not copied out. The keyword out is used as a qualifier to denote a parameter is to be copied out, but not copied in. This should be used whenever possible to avoid unnecessarily copying ...


6

There is no 100% consensus on what order matrix multiplication should model things, worse the industry is split along this. Some sources use row major and some sources use column major matrices. Great care should be taken to verify which is being used in your source and what is being used by your API! Some API's go as far as allowing one to multiply vectors ...


6

Not enough triangles. The situation is analogous to the sampling theorem that states that you can not reconstruct a signal if your sample frequency is below a certain threshold. Although in this, case you're not attempting to rebuild the signal with a higher order filter so the result is even more dramatic. And it results in interpolation errors. You can ...


Only top voted, non community-wiki answers of a minimum length are eligible