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.

Filter by
Sorted by
Tagged with
19
votes
1answer
2k views

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 ...
14
votes
1answer
670 views

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 ...
11
votes
2answers
3k views

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?
11
votes
1answer
3k views

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.
11
votes
1answer
2k views

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 ...
11
votes
1answer
3k views

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 ...
11
votes
2answers
2k views

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 ...
10
votes
2answers
907 views

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?
10
votes
1answer
2k views

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 ...
9
votes
1answer
1k views

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 ...
9
votes
2answers
4k views

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?
9
votes
1answer
3k views

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 ...
9
votes
1answer
155 views

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 ...
8
votes
3answers
223 views

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

In a recent version of uTorrent , if you open the About Window, you will see an animated background , which is kind of waves that go on forever. How can this be achieved? Is this kind of a well-known ...
8
votes
2answers
781 views

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

I need to offset all (blue) triangles, each independently of the others, using the vertex-shader. In order to manipulate the triangle as a whole, I've created custom (vec3) attributes for each vertex (...
8
votes
2answers
536 views

Can (and how so) shaders paint screen pixels beyond those that occupied by the shaded mesh?

I have some experience programming geometry and compute shaders - but never adventured myself in really playing with the fragment shaders. Currently, I am trying to better understand how they work and ...
8
votes
2answers
166 views

Encode two R11G11B10F buffers into one using Y'CbCr?

We are trying to optimize Lighting in fillrate. Integrated graphics chips are very slow in memory access. There are two Light Buffers: one for Diffuse and one for Specular. Both use format R11G11B10F....
8
votes
2answers
232 views

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

Assume there is some value p, calculated per-frame, that varies continuously over the surface of an object. The value of p ...
8
votes
1answer
161 views

There are many shading languages built on top of GLSL or HLSL - what problems do they typically solve, and what worthwhile advancements do they make?

Whew, that was a long title. Either way, I'm asking this question, since I like to think about various things, and it occurred to me that there isn't really any simple, open source layers on top of ...
8
votes
1answer
490 views

Shader uniform performance

I'd like to know if there's any performance impact based on how I struct my shader uniforms. For instance, is passing 4 floats worse than passing a single vec4?
7
votes
1answer
8k views

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: ...
7
votes
1answer
200 views

How does this small fractal shader work?

I would like to know the magic behind this tiny fractal shader; I didn't really understand the code and the mentioned thread... Is there an accessible explaination? https://www.shadertoy.com/view/...
7
votes
2answers
848 views

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 ...
7
votes
1answer
551 views

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

Since long ago I wanted to implement a 2D lightning algorithm based on an idea I saw on YouTube. The video is realtime, but it runs on the CPU and the resolution is pretty low. I'm curious if anyone ...
7
votes
1answer
813 views

Constant screen-space-width rim shading

As of lately I've been studying a bit of shaders (in Unity), and am trying to recreate the "light-based inline" that can be observed in the latest Legend of Zelda. But maybe the task is a bit above my ...
7
votes
2answers
873 views

Multiple Lights Shading - One Pass vs Multiple Passes

I was looking into ways to implement multiple lights shading and I've noticed Unity uses multiple passes to achieve it. It performs a base pass to apply the brightest directional pixel light + 4 ...
7
votes
1answer
363 views

Explicit vs Automatic Attribute Binding

I'm a beginner in OpenGL and I've been doing some research on the topic of shaders and attributes. Most places I go say that explicit attribute binding (whether it be in the shader itself with ...
7
votes
2answers
804 views

Eye Parallax Refraction

I am trying to implement the Parallax Refraction effect explained by Jorge Jimenez on this presentation: http://www.iryoku.com/downloads/Next-Generation-Character-Rendering-v6.pptx and I am facing ...
6
votes
1answer
3k views

Double precision in shader

for better accuracy, instead of GLfloat, I bound double data and tried to use the data in shader as follow: (I just tested to draw single triangle.) cpp. ...
6
votes
2answers
307 views

What factors affect which shader language to learn?

I don't know any shader languages. I've heard of GLSL and HLSL, and I'm interested in learning one or both. Are there significant differences between them that would make one or other better in ...
6
votes
2answers
3k views

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

I want to recreate this smoke/cloud effect which is used in the Arrival (2016) movie end credits. I uploaded a sped up version of the credits to see the smoke dynamics. http://streamable.com/n3309 ...
6
votes
1answer
549 views

Flat shading for non-planar polygons

I'm trying to figure out how to properly implement flat shading for meshes containing non-planar polygons (using OpenGL/GLSL). The aim is to obtain something similar to the result Blender gives (all ...
6
votes
1answer
1k views

What's the difference between Sample and tex2D

I am mainly using Unity but I think that it's not related to this engine, and I am wondering what's the difference between using tex2D and ...
6
votes
1answer
490 views

Open GL Shader Storage Buffer Objects to replace Vertex Attributes

At first: I already posted this on the stackoverflow community. I'm new and didn't know about this community here. I apologize. I basically got the same question as the guy who asked here: https://...
6
votes
1answer
493 views

SSAO artefacts on iPhone (OpenGL ES)

I've never written shaders before, and now I'm trying to implement SSAO with SceneKit on OS X and iOS. I'm trying different SSAO shaders that I find, e.g. from Three.js, this one, and this one. On OS ...
6
votes
2answers
517 views

Best technique to draw overlapping colored line segments that follow the same route

I'm not too versed in computer graphics so my question may be vague. I'm given a sequence of GPS coordinates which I draw on an iOS map, and they define bus routes. Some of the bus routes happen to ...
6
votes
1answer
659 views

Label Placing for thousands of objects with OpenGL

Question How to manage data (GPU,CPU) for dynamic label placement in 3d for thousands of objects (OpenGL)? Details objects: count: 2k-10k type: points/quads labels: bilboarding data: text and ...
6
votes
1answer
201 views

Mix shader looks wrong on my path tracer

I apologize if my methods seem way off because this is my first time trying to build a path tracer and I'm struggling quite a bit. Currently, I am trying to mimic the "mix shader" node in Blender 3D ...
6
votes
1answer
706 views

Why are tessellation shaders disliked?

I often hear that tessellation shaders aren't great for performance reasons. Something along the lines that if you try to use a tessellation shader, you'll find that the data you get out isn't ...
6
votes
1answer
732 views

HLSL Deferred Rendering

I've recently made the switch to Visual 2015 and the .fx files have been depreciated. My project contained .fx files for the shaders so I've been switching over. Only during the switch have I changed ...
6
votes
1answer
286 views

B-Spline patches on the tessellation shader. How to get the control points

I have a polygonal mesh with ngons in it. I want to make a tessellation shader to which I send only the regular quads in such a way that it can construct a B-Spline surfaces across it. I came across ...
6
votes
0answers
185 views

Avoiding Mach band effect when using multiple lights

I wrote a simple Phong shader with two directional lights for a project, and noticed an unpleasant artifact in the lighting. Where both lights are illuminating the same region, dark bands appear at ...
6
votes
0answers
172 views

Dual paraboloid shadow texture edge seams

I implemented dual paraboloid shadows for point lights. The goal was to reduce the number of shadow passes. Also the target is GLES3.0 so no layered rendering is available. The shadows work, and ...
5
votes
1answer
2k views

Modern way of light sources in OpenGL?

In older versions of OpenGL there were things like: glLight(...) gl_LightSourceParameters The modern way of doing lighting is passing light source parameters manually to the shader in vao-s? Or ...
5
votes
2answers
964 views

Is there a way to draw spherical objects without triangles?

It seems that in all existing graphics libraries, 3D objects are always described in terms of triangles. Drawing triangles can be implemented very efficiently on video hardware and since any 3D object ...
5
votes
2answers
173 views

What is the correct way to put different textures on different parts of an object?

I tried passing a variable from the vertex shader to tell the fragment shader whether or not I wanted part of an object textured. That way I could write another shader for the other parts of the ...
5
votes
1answer
200 views

Sine-based Tiled Procedural Bump

I am trying to implement this formula to generate bump but I am facing some issue. The result doesn't look the same it's much darker. Here is my result (without same parameters) but it is much darker ...
5
votes
2answers
913 views

Screenspace Normals - Creation, Normal Maps, and Unpacking

I'm trying to condense my Deferred Rendering G-Buffer. So I have some questions about getting 2-component Screenspace Normals. I know Frostbite and Killzone (the only two AAA company's G-Buffers I ...
5
votes
1answer
187 views

What actually happens in frame buffer when an image or document is scrolled?

What actually happens inside computer when the text, pdf, jpeg, ms-word or any other document(file) is scrolled? Does it generate a new bitmap image sufficient for the screen to display even for tiny ...
5
votes
1answer
2k views

Fragment shader's output variables

EDIT: This is a duplicate of a question from stack overflow: https://stackoverflow.com/questions/9222217/how-does-the-fragment-shader-know-what-variable-to-use-for-the-color-of-a-pixel If you want to ...