Questions tagged [shader]

For all questions related to shaders, i.e. the programmable part of the GPU pipeline. For language-specific shader questions, see also the [glsl] and [hlsl] tags.

Shaders are programs which are written to customise a programmable GPU pipeline.

The most common shader languages are GLSL and HLSL.

248 questions
25
votes
2 answers

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

I'm new to shaders and know that you can color pixels with gl_FragColor but sometimes there is this thing: vec2 uv = gl_FragCoord.xy / screenSize; // or resolution or smthn depends on the implementation If gl_FragCoord is like pixel coordinates,…
idchlife
  • 353
  • 1
  • 3
  • 6
22
votes
1 answer

Why is this conditional in my fragment shader so slow?

I have set up some FPS-measuring code in WebGL (based on this SO answer) and have discovered some oddities with the performance of my fragment shader. The code just renders a single quad (or rather two triangles) over a 1024x1024 canvas, so all the…
Martin Ender
  • 2,700
  • 4
  • 22
  • 45
18
votes
2 answers

Why are normal maps blue and purple in color?

I am learning about normal mapping. I understood that RGB values are converted into XYZ, but my question is how is it converted and why is the normal map blue and purple in color?
Abhinay Singh Negi
  • 303
  • 1
  • 2
  • 5
16
votes
1 answer

Is a constant condition more costly than switching shaders?

In general, branching in shaders is not a good idea. But now I have a shader with a condition that is constant with respect to the entire draw call. So the branch that is executed is always the same for one draw call. Is such kind of branching still…
nikitablack
  • 711
  • 4
  • 15
15
votes
2 answers

Cause of shadow acne

I know how shadow mapping works but I am not getting the cause of shadow acne! Can anyone tell me cause of shadow acne in a simple way and how is it related to depth map resolution?
13
votes
2 answers

Derivative maps vs. Tangent Space Normal maps

I discovered that some engines use derivative maps instead of tangent space normal maps. After some reading, it seems to be a really awesome way to replace tangent space normals but are there some disadvantage using them ? Why still continue using…
MaT
  • 1,219
  • 10
  • 21
13
votes
1 answer

How does Texture Cache work considering multiple shader units

Modern GPUs have many parallel shading units. I'd like to know how texture cache is managed in that scenario.
Felipe Lira
  • 1,236
  • 1
  • 11
  • 16
13
votes
1 answer

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

Rendering the scene usually involves more than one shader program which, in my case, all use the same attributes and share at least some of the uniforms. To have them working properly, I currently play safe, meaning I rebind the attributes and get…
Nero
  • 1,310
  • 3
  • 15
  • 31
13
votes
1 answer

Loop performance in a shader

I am wondering what's the best way to integrate a dynamic loop function in a shader? First, it seems that dynamic arrays are not possible. So, is it better to create a maximum size array and only fill a part of it or define arrays with predefined…
MaT
  • 1,219
  • 10
  • 21
12
votes
1 answer

Correct form of the GGX geometry term

I'm trying to implement a microfacet BRDF in my raytracer but I'm running into some issues. A lot of the papers and articles I've read define the partial geometry term as a function of the view and half vectors: G1(v, h). However, when implementing…
Erwin
  • 123
  • 1
  • 6
11
votes
2 answers

Is using many texture maps bad for caching?

If I have many textures (say 5+ maps) bound to the same texture unit, does it work worse for cache than if I had only 2 or 3 textures?
Felipe Lira
  • 1,236
  • 1
  • 11
  • 16
11
votes
1 answer

Efficient rendering with many light sources

To render a scene with a single light source using phong shading, one can calculate the final color of each fragment passed into the fragment shader based on the ambient/diffuse/specular components of both the material and the light source. This can…
es1024
  • 433
  • 5
  • 12
10
votes
1 answer

How does Texture Cache work in Tile Based Rendering GPU

How does cache work with tile based rendering? Are there any tips on how to improve cache hit ratio for it? (for instance, if tiles are processed horizontally and I have vertical segments of triangles with the same texture, does it work worse for…
Felipe Lira
  • 1,236
  • 1
  • 11
  • 16
10
votes
1 answer

Per Vertex Computation in OpenGL Tesselation

I try to implement a position based cloth simulation using hardware tesselation. This means I want to just upload a control quad to the graphics card and then use tesselation and geometry shading to create the nodes in the cloth. This idea follows…
Dragonseel
  • 1,790
  • 1
  • 10
  • 23
9
votes
2 answers

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

When reading papers I commonly find Oct tree implementations of geometry representations to sort the data. However whenever I think about the problem hash tables seem better overall. Hash tables have a better average and worse case scenarios for…
Makogan
  • 1,584
  • 8
  • 27
1
2 3
16 17