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. ...
15
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
Accepted
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
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
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
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
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
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.
...
6
votes
GLSL. Can someone explain why gl_FragCoord.xy / screenSize is performed and for what reason?
Refer to narthex's excellent answer for details and example, but simply put,
If you want to map the pixel coordinate values to the range 0 to 1 , you divide by viewPortSize.
6
votes
What actually happens in frame buffer when an image or document is scrolled?
In the olden days of text-mode terminals, the "frame buffer" was a buffer of text, not an image. Scrolling worked in the way you described. The buffer was larger than would fit on the screen, and to "...
6
votes
How to access several textures from huge amount of textures in a shader?
Well, it's unlikely that 10,000 cubemaps could fit into memory at all (at 128x128x4-bytes-per-pixel, 10,000 cubemaps would require upwards of 4GB of RAM). But as far as the mechanism to use a large ...
6
votes
Accepted
Is a single shader and 1x1 pixel white sampler more efficient than frequent switching between shaders with and without samplers?
This is a really hardware-dependent question. But in general the best way to think about this is bottlenecks.
You mentioned:
one set of shaders, one slightly larger vertex struct and just uniform, ...
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 ...
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 ...
5
votes
Accepted
Derivative maps vs. Tangent Space Normal maps
After some researches and some answers from professionals here is my conclusion.
Pros
Don’t require tangents or binormals. Less interpolators.
Only need two channels. less texture memory.
Don’t ...
5
votes
Accepted
Strange behaviour in vertex shader with divisions
The vertex shader only runs per vertex, not for every point in the square. So the four vertices are mapped to (±2, ±2), and then the GPU draws a polygon between those vertices, which does cross the ...
5
votes
Accepted
Jagged texture's edge on perfectly straight UV of sphere mesh
It looks like distortion because the trapezoids are rendered as two triangles by the GPU. This leads to incorrect UV interpolation.
Try this: draw a horizontally symmetrical trapezoid with the top ...
5
votes
Is sub-texel shading possible?
The GPU hardware only supports nearest-neighbor, bilinear, trilinear, and anisotropic texture filtering. However, nothing stops you from implementing your own texture filtering in the pixel shader.
...
5
votes
Accepted
What is shader warming, and why does Direct3D seem to avoid it?
I hadn't heard the phrase 'shader warming' before, but from some googling around, it seems that some games/engines use this term for a method of forcing the shaders to be fully compiled during level ...
5
votes
Accepted
Why are oct trees so much more common than hash tables?
My 2 cents from writting the Chipmunk2D physics engine is that spatial hashing is great when you have a lot of objects that are all the same size. I had a demo 10 years ago that ran with 20k ...
5
votes
Accepted
Where should I learn shaders as a vulkan user?
Perhaps you should begin with classic opengl shaders in a more friendly enviroment. ShaderToy is a great community where you'll find tons of tutorials, code examples, masterpieces and great experts ...
5
votes
Why is OpenGL recompiling my depth map vertex shader based on the GL state?
This is an example of implementation details leaking through the abstraction. Parts of the GL state are often implemented via native GPU ISA instructions that the driver injects into user-defined ...
5
votes
How do I efficiently calculate the distance to the edge of a shape?
A texture that stores distance from the edge of the shape, like you described, is called a "distance field" (you'll find lots of results if you google that phrase). Distance fields can be ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
shader × 276opengl × 98
glsl × 71
rendering × 28
texture × 27
fragment-shader × 24
hlsl × 20
lighting × 17
c++ × 13
mathematics × 13
vulkan × 12
raytracing × 11
gpu × 11
compute-shader × 10
uv-mapping × 10
unity × 10
3d × 9
performance × 8
vertex-buffer-object × 8
transformations × 7
algorithm × 7
image-processing × 7
brdf × 7
color × 7
webgl × 7