Skip to main content
19 votes
Accepted

Performance of Compute Shaders vs. Fragment Shaders for Deferred Rendering

After more analysis, the TL;DR here is that, yes, the slowdown is due to memory locality, and yes the pixel order is to blame. More interestingly, by writing the shader differently, we can greatly ...
geometrian's user avatar
  • 1,990
9 votes

Using a LUT to speed up a trig heavy shader for mobile devices

It has been suggested in comments repeatedly, but noone felt the need to give a proper answer, so for the sake of completeness, a straight-forward and common solution to this problem might be to use a ...
Christian Rau's user avatar
7 votes
Accepted

Fragment shader's output variables

It works almost exactly the same way as vertex shader inputs. In vertex shaders, you have inputs. And these inputs represent vertex attribute indices, the numbers you pass to ...
Nicol Bolas's user avatar
  • 9,842
7 votes
Accepted

Why does substracting -1 in shader fail for a float data type?

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 ...
ratchet freak's user avatar
6 votes
Accepted

How to ensure a fragment shader only runs once

I don't think your approach is viable for a variety of reasons. a GPU is heavily cache-dependent for performance. Pulling the same pixels over and over will just measure how fast a cache hit is. ...
ratchet freak's user avatar
5 votes
Accepted

Understanding fragment shader coordinate system

Everything in this code functions as intended, until I try to translate the entire grid (grid lines) to the center of the screen by adding v_Resolution.x / 2 to uv.x. Not sure what your intention is ...
wychmaster's user avatar
  • 1,251
5 votes

Advice on how to create GLSL 2D soft smoke/cloud shader

There is good glsl source of noise (simplex noise) online to make real time noise. In addition to this, to make effect of moving fog/smoke like in this video you can make 3D FBM function. This is my ...
mdkdy's user avatar
  • 2,169
5 votes
Accepted

Advice on how to create GLSL 2D soft smoke/cloud shader

Noise functions are definitely your friend here—FBM would be one good candidate. You’re right that it can look too uniform on its own, but if you blend multiple layers of it together, using different ...
Noah Witherspoon's user avatar
4 votes
Accepted

Ray tracing - partial derivatives for texture lookup

Yes, ray differentials are the way to go. The Paper by Igehy introduces them for the use case of filtered texture lookups. When generating the primary rays, you initialise the differentials to reflect ...
Stefan Werner's user avatar
4 votes
Accepted

Z buffer working in OpenGL

When depth testing is enabled, the testing occurs after the fragment shader executes. The procedure is relatively simple (and spelled out pretty well here): Get depth of fragment Test against depth ...
aces's user avatar
  • 1,353
4 votes
Accepted

Curve rotation in GLSL fragment shader

You are doing completely different things in Matlab than in your Fragment Shaders. In Matlab you are generating bunch of points that can be drawn anywhere on the screen and then you are transforming ...
revers's user avatar
  • 56
4 votes

Will the gaussian kernels in this fragment shader be computed for every fragment?

It depends. On a desktop, if the Gaussian function is always called with the same arguments, the shader compiler will probably optimize it so it's evaluated only ...
Julien Guertault's user avatar
4 votes
Accepted

Help me understand the voronoi shader

1) Scale the texture coordinates from [0,1]x[0,1] -> [0,3]x[0,3]. It works with higher integer scales as well. This creates an imaginary 3x3 tiles grid. st *= 3.; ...
Isolin's user avatar
  • 438
4 votes
Accepted

SDF rendering for large world

You tile idea seems to be a good one to cut down on local complexity. You can't reasonably evaluate every primitive everywhere. Not if you want good performance anyway. So you need a simplified ...
Olivier's user avatar
  • 1,585
3 votes

gl_FragCoord and glViewport

since that is the case for window-space coordinates in the vertex stage. There are no "window-space coordinates in the vertex stage". Or at least, not in the vertex shader. Window-space is ...
Nicol Bolas's user avatar
  • 9,842
3 votes
Accepted

Count number of green fragments that are within a given distance from each screen fragment

You're getting a cross shape in the output because in your loop, you're counting pixels on the center row and column multiple times. For example the pixel at (0, 0) offset will be counted on every ...
Nathan Reed's user avatar
  • 25.1k
3 votes
Accepted

OpenGL ES Frag Shader - Branching

I think the most efficient way might be either return float(shadowValue > shadowTexZ); or ...
Detheroc's user avatar
  • 1,436
3 votes

Anti-Aliasing simple circle fragment shader

Probably the simplest way is to use smoothstep to make a transition from white to black: ...
lisyarus's user avatar
  • 225
3 votes
Accepted

How to avoid declaring sampler outside of statement?

Background In order to support mipmapping, the texture sampling system needs to know what scale the texture is being displayed at. In order to determine that scale automatically, the derivatives (or “...
Kevin Reid's user avatar
  • 1,196
3 votes
Accepted

Is it possible to fill in Stencil Buffer programmatically via fragment shader?

There are a few confusing statements in your question. However, I'll still assume you're largely aware of how the stencil buffer and the stencil test actually work. I'll also talk about OpenGL, based ...
Christian Rau's user avatar
3 votes
Accepted

Why is the z coordinate simply set to 1 for setting up direction of a ray in ray marching

It depends on your setup. Of course you can normalize the direction to have length 1, but it is usually unnecessary. The following figure depicts the differences: Round frustum end face Flat frustum ...
Enigmatisms's user avatar
2 votes

Will the gaussian kernels in this fragment shader be computed for every fragment?

The shader compiler will very likely perform common-subexpression consolidation, and compute that function once, and reuse it each time it appears in the shader. You might think that, since ...
GroverManheim's user avatar
2 votes
Accepted

How to correctly implement Lambertian BRDF with point light

It doesn’t matter that it’s a point light; the 1/π normalization factor is what’s causing your surface to be 1/π as bright as you’d like it to be. You can either up your light intensity so the maximum ...
Noah Witherspoon's user avatar
2 votes

Is it possible to override or disable blending per pixel

You seem to be using additive blending against its purpose. Additive blending is supposed to represent light from multiple sources being combined. It is not physically possible for one source of light ...
Nicol Bolas's user avatar
  • 9,842
2 votes
Accepted

Alpha component in color buffer affects RGB components?

It looks like you're drawing with pre-multiplied alpha. This means that the red, green, and blue channels have been multiplied by the alpha channel. So your shader should look more like this: ...
user1118321's user avatar
  • 3,421
2 votes

Interpolation in Graphics Pipeline

The rasterizer determines, which pixel is rendered depending on vertex positions that come out of the vertex shader. For each rasterized pixel, the rasterizer knows where it lies inside the triangle ...
wychmaster's user avatar
  • 1,251
2 votes
Accepted

Are stencil buffer dimensions required to match render target dimensions?

When the framebuffer attachment sizes differ, rendering will only happen to the smallest size supported by all attachments (i.e. a rectangle of minimal width & height among all the attachments). ...
lisyarus's user avatar
  • 225
1 vote

Is fragment shader run on fragments that are outside of rasterized geometry?

Broadly speaking, the way to deal with this is to check the depth value for that position on the screen. If the value is the value you cleared the depth buffer to, then you didn't write anything to ...
Nicol Bolas's user avatar
  • 9,842
1 vote
Accepted

gl_ClipDistance vs gl_CullDistance

The two are different because they do different things. Clipping and culling aren't the same thing at all. If an edge crosses a clip plane, the primitive has to be clipped to be within that plane. ...
Nicol Bolas's user avatar
  • 9,842
1 vote

Can I write histogram equalization, blurring, sharpening grayscale image etc.. as shader programs with openGL?

Yes you can. There are basically two approaches: You draw everything to a framebuffer object. Then you apply image processing fragment shaders to resulting texture of the previous draw call, where ...
Kaan E.'s user avatar
  • 461

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