Hot answers tagged

32 votes
Accepted

GLSL. Can someone explain why gl_FragCoord.xy / screenSize is performed and for what reason?

First, gl_FragCoord.xy are screen space coordinates of current pixel based on viewport size. So if viewport size is width=5, <...
user avatar
  • 2,037
23 votes
Accepted

Why are normal maps blue and purple in color?

Only tangent space normal maps are primarily blue. This is because the colour blue represents a normal of (0,0,1) which would be an unchanged normal when the triangle lies in the plane x and y, i.e. ...
user avatar
  • 541
22 votes
Accepted

Why is this conditional in my fragment shader so slow?

Pixels get grouped into little squares (how big depends on the hardware) and computed together in a single SIMD pipeline. (struct of arrays type of SIMD) This pipeline (which has several different ...
user avatar
19 votes
Accepted

How does Texture Cache work in Tile Based Rendering GPU

Whether it's a tile based GPU or not doesn't really affect the texture cache architecture. The memory layout of texture will look like some flavor of Morton order or Hilbert curve in all GPUs. As a ...
user avatar
17 votes
Accepted

How does Texture Cache work considering multiple shader units

At the top level, a GPU is subdivided into a number of shader cores. A small GPU in a notebook or tablet may have only a few cores while a high-end desktop GPU may have dozens. In addition to the ...
user avatar
  • 23.7k
17 votes
Accepted

Cause of shadow acne

Image 1: A bad case of shadow acne. (Synthetic and a bit exaggerated) Shadow acne is caused by the discrete nature of the shadow map. A shadow map is composed of samples, a surface is continuous. ...
user avatar
  • 8,159
16 votes
Accepted

Is using many texture maps bad for caching?

Just adding to imallett's answer, it is true that increasing the number of accesses to different texture data in a shader will increase pressure on the GPU cache(s), but there are several other ...
user avatar
  • 3,941
15 votes
Accepted

Efficient rendering with many light sources

Yes, but you need a paradigm shift. What you are accustomed is called forward rendering. You submit your geometry and then you proceed immediately with the shading pass. In the basic forward ...
user avatar
  • 2,468
14 votes

Why are normal maps blue and purple in color?

Because a normal map is covering vectors from -1 to 1 it makes sense to stretch this range into 0->1 so all of it can be fit inside the range of RGB. So usually we apply a transform on the normal to ...
user avatar
  • 2,234
13 votes
Accepted

Is a constant condition more costly than switching shaders?

On modern hardware if all invocations in a group follow the same path then the unused path doesn't get evaluated. in pseudo code: ...
user avatar
13 votes
Accepted

Double precision in shader

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 ...
user avatar
12 votes
Accepted

Do I need to rebind uniforms or attributes when changing shader programs?

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 ...
user avatar
  • 1,100
10 votes
Accepted

How does this small fractal shader work?

Here is a line by line breakdown of my shader: ...
user avatar
9 votes
Accepted

What algorithm is used in the animation of the uTorrent 's "About window"?

As you discovered and mentioned in your self-answer, the pattern in the background appears to be a sum of sinusoidal gradients. However, the example linked to in your answer is more complicated than ...
user avatar
  • 5,872
9 votes
Accepted

Modern way of light sources in OpenGL?

Why are they deprecated? Those functions are deprecated because the OpenGL API moved in favor of a programmable pipeline in contrast with the old fixed pipeline. The programmable pipeline allows the ...
user avatar
  • 516
9 votes
Accepted

How can I offset/shrink a triangular polygon in GLSL?

Given triangle ▲ABC, we bisect angle ∠BAC with line AD, derived with Angle Bisector Theorem: BA / BD = CA / CD Point E represents our objective refined position on the desired resulting inset ...
user avatar
  • 331
9 votes

Why are oct trees so much more common than hash tables?

Lots of things here. "When reading papers". What papers? If the topic of the paper is about something other than the spatial partitioning structure, it could be fair to use whatever knowing that the ...
user avatar
8 votes

Is using many texture maps bad for caching?

The answer depends on what you mean. Modern hardware (e.g. with bindless textures) really doesn't care too much how many textures are "bound". The real question is how many you use. Textures ...
user avatar
  • 1,790
8 votes

Cause of shadow acne

As an addition to the answer of joojaa: Using a bias to offset the shadow function does indeed solve the problem with shadow acne, but it can introduce an additional problem: Peter Panning As you see ...
user avatar
  • 1,750
8 votes
Accepted

Sine-based Tiled Procedural Bump

As you are taking the mean of a number of sine waves, your colour values will range from -1 to 1. From your example image, it looks like only the top half of this range of values (from 0 to 1) is ...
user avatar
  • 5,872
8 votes
Accepted

What are Jittering and Dithering

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. ...
user avatar
  • 6,440
7 votes

Flat shading for non-planar polygons

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 ...
user avatar
7 votes

What factors affect which shader language to learn?

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 ...
user avatar
7 votes
Accepted

Label Placing for thousands of objects with OpenGL

Since you are new to computer graphics, you may be better off avoiding the complications of SIMD and sticking with the traditional 'create a CPU thread + collect results' approach, or even run in the ...
user avatar
7 votes
Accepted

What's the difference between Sample and tex2D

They represent the same operation, but Sample is what it's called in D3D10 and newer versions of HLSL, while tex2D is what it's ...
user avatar
  • 23.7k
7 votes
Accepted

Can i compile my shaders to SPIR-V without using glslangValidator?

Typically compiling GLSL to SPIRV would be something you do as part of the build process, so that you end up distributing SPIRV instead of GLSL. Then you don't need to compile it at runtime. ...
user avatar
  • 501
6 votes
Accepted

Can the uniform id be changed from run to run on the same machine?

The uniform locations are set when the program is linked and are tied to the program. This means that when you create a new program then the uniform locations can change.
user avatar
6 votes

How to create a patterned object with variable pattern density in real-time?

In order to ensure that the pattern shapes are always either wholly present or absent, never cut off, it's necessary to ensure that the same p value is used for all ...
user avatar
  • 23.7k
6 votes

How to implement a realtime 2D light renderer with fog/colored light on the GPU?

If your wall geometry is vector graphics you can simply extrude the segment away from the light position. This means 2 triangles per draw call, all the extrusion offsets can can be handled in the ...
user avatar
  • 8,159
6 votes
Accepted

Loop performance in a shader

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 ...
user avatar

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