35
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, <...
25
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. ...
20
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. ...
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 ...
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 ...
10
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 ...
10
votes
Accepted
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 ...
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 ...
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 ...
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 ...
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 ...
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. ...
7
votes
Accepted
Correct form of the GGX geometry term
TL;DR: Your $G1$ formula is wrong.
Just to avoid confusion, I am assuming the isotropic version of the BRDF, the Smith microfacet model (as opposed to the V-cavity model), and the GGX microfacet ...
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 ...
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 ...
7
votes
Accepted
Where is the best place for Tangent-bitangent calculation, in shader or in C/CPP code?
Doing it in the CPU side during initialization is what I'd go for, this is assuming you are initialising that data once and passing it to the GPU.
On the GPU side, doing the calculations per fragment ...
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 ...
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 ...
7
votes
Accepted
Shader storage buffer indexing by 4 bytes instead of 3?
Does anyone ahve[sic] any idea of where to start looking
You fell victim to one of the classic blunders. Never use a vec3 in a UBO or SSBO.
While ...
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. ...
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 ...
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.
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 ...
6
votes
Accepted
Can (and how so) shaders paint screen pixels beyond those that occupied by the shaded mesh?
When you use linewidth or line antialiasing or pointwidth or pointsprites, OpenGL creates for you a small rectangle instead of the line or point, with texture coordinates. Nowadays you can even ...
6
votes
Accepted
SSAO artefacts on iPhone (OpenGL ES)
Resolved by adding precision highp sampler2D to my shaders.
About default precision settings on ES - https://www.khronos.org/files/opengles_shading_language.pdf ...
6
votes
Accepted
Open GL Shader Storage Buffer Objects to replace Vertex Attributes
The counter you want is built in the shader as gl_VertexID.
However you have 16 attributes of 4 components each to work with. Take 2 components for the texture ...
6
votes
I dont understand how a GPU computes and branches, could you please help me fix this shader preformance
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 ...
6
votes
Accepted
Colorblending shader recompilation scenarios
In GL's model of the GPU, the colour blending step is performed by special-purpose hardware. This idea dates back to the fixed-function origins of GL, before programmable shaders were even a thing.
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
shader × 262opengl × 96
glsl × 71
rendering × 28
texture × 27
fragment-shader × 22
hlsl × 20
lighting × 17
c++ × 13
gpu × 11
vulkan × 11
raytracing × 10
mathematics × 10
unity × 10
compute-shader × 9
3d × 8
performance × 8
uv-mapping × 8
transformations × 7
algorithm × 7
image-processing × 7
brdf × 7
webgl × 7
vertex-buffer-object × 7
directx × 7