41
votes
Accepted
How to do color post processing in WebGL, when you can not read the color of the current pixel?
This is not a WebGL 2 restriction. This is fundamentally how GPUs and their 3D rendering APIs all work.
Because they're designed to render many triangles and fragments in parallel, they structurally ...
5
votes
Accepted
Does it make sense to do more calculations in the fragment shader if there are more vertices than pixels?
The calculation falls apart like so:
If every one of those 3 million polygons rasterizes to at least one pixel on average, then doing the operation in the fragment shader still results in it being ...
5
votes
Shader FloodFill Alogrithm
The above method was not only outdated for 2017, but extra-ordinarily slow. There are dedicated algorithms to do what you're talking about on the GPU that take maximal advantage of GPU parallelism.
...
4
votes
Accepted
Depth Intersection Shader
This issue exists with the original shader as well, but is less apparent with the sphere mesh.
Notice how it looks alright when the model's vertices are close to the intersecting object.
But as they ...
4
votes
Accepted
Is linear filtering possible on depth textures in OpenGL?
Shadow maps, the way you're using them, don't filter well. The linear filtering does what it's supposed to, it's just not the thing you actually want for this context.
Take a sample point halfway ...
4
votes
How would I mask the player node out of a canvas shader?
You will setup a SubViewport (you would not need a container for it, since - I presume - it would not be shown), make sure its render mode and its clear mode are ...
4
votes
Accepted
Recreating a 3D pixel art water effect
Since you are asking for "insights", I will describe my understanding of how this shader works, rather than provide an actual production-ready solution.
Besides, I'm not well-versed in ...
3
votes
Accepted
Shader vs Working with Pixels
There are a few benefits when using a shader:
Speed
The GPU is faster in manipulating pixels. Ofcourse you can 'preprocess' the texture and that will be fine. It is under the assumption that you ...
3
votes
Accepted
My Single Pass Gaussian Blur Looks Awful
Your sampling points are most likely messed up because you are not taking into account that texture texel size is in range [0; 1]. You need to divide offset coordinates by texture resolution. We can ...
3
votes
Accepted
How to implement multicolored flashing sprite effect like in Contra and the Messenger?
I think you could achieve this effect by using a rotating color palette. You can do this in GLSL by passing in a grayscale image and a 1D texture containing the color palette. You'd sample the ...
3
votes
Shader FloodFill Alogrithm
As Bálint noted in a previous answer, shaders are designed to be highly parallel, which makes them an awkward fit for flood-filling.
In parallel execution, the GPU's many cores are making decisions ...
3
votes
Accepted
How can I create an outline shader for a plane?
If all we need is an outline around a rectangle, we can compute this analytically with the math of signed distance fields. :)
...
3
votes
Accepted
How to decorate the floor with a grid?
One way to do a square pattern in glsl is with mod:
...
3
votes
Accepted
Unity mesh shader for outlining colour changes
What you're finding here is that drawing the line based on your height above/below the boundary gives inconsistent results: in places where the height changes quickly (steep slopes), the outline ends ...
3
votes
Accepted
Sending light data from Vertex Shader to Pixel Shader?
It's valid, but you have a limited number of interpolators between the two shader stages, and depending how much data you're sending you may bump into that limit. You'll almost certainly need to split ...
3
votes
Accepted
Unity Shader w Color Bar for Fragment Color Manipulation
To sample _ColorBar based on the 0-1 value of the _MainTex's red channel, you can just use the sampled value's red channel as UV ...
3
votes
Accepted
What is the proper way to write a pixel shader that only outputs depth?
You don't need to return anything. This is a valid pixel shader:
struct VS_OUTPUT
{
float4 position: SV_POSITION;
};
void main(VS_OUTPUT input)
{
}
2
votes
How can you pass a large amount of textures or equivalent to the fragment shader in OpenGL?
I would use a Cube Map Texture Array for this. You can query the maximum array texture layers with:
...
2
votes
How to create a depth-recording shader for shadow mapping?
One of the things you need to understand that the red component is actually visually correct. The Z Depth is being embedded in values close to 1.
If you want to just see a colour change to see ...
2
votes
Phantom objects in ray tracing
The issue was not testing that the intersection needs to happen between the object and the light position. i.e I was raytracing past the light.
i.e the check: ...
2
votes
How can I Fade Paint over time?
frag is declared as returning a Vector (float4). What you are actually returning is a Scalar (...
2
votes
Algorithm for a rain effect (Shaders)
Changing the colour of the snowflakes isn't very hard, here's what you need to do:
...
2
votes
Accepted
2
votes
Combining several passes in shader in Unity
You should think of a single pass of a shader as a complete render of the object:
first, the vertex shader decides where the vertices should go within the camera's projection
then, the rasterizer/...
2
votes
OpenGL Outlining Cubes in a Greedy Meshed Mesh
Ok, I finally got it to work using this annoying-looking method:
...
2
votes
OpenGL Texture Zig-Zag Artifacts Over Time
To me it actually looks and sounds like bad video memory or core issue.
Sometimes video cards can start to corrupt their outputs as the silicon degrades.
If other cards do not show this artifact, then ...
2
votes
Accepted
Raymarching signed distance function resulting in holes on surface - step size required?
After messing with the Shadertoy link (thank you for that, by the way), I have discovered that most of your problem comes from the line ...
2
votes
Accepted
OpenGL Fragment shader: not all fragments showing colors
This is definitely Z-Buffer problem, artifacts seem to resolve at a distance closer to the viewer, where precision is supposed to be higher.
It is worth knowing, that exactly this problem has been ...
2
votes
Creating Blender-like cavity shader
Closest I've seen to recreating this effect as a shader
https://youtu.be/JMMy-xqrwdw
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
fragment-shader × 326shaders × 160
glsl × 87
opengl × 86
hlsl × 52
unity × 47
directx × 24
xna × 19
directx11 × 18
textures × 15
opengl-es2 × 15
vertex-shader × 14
graphics × 12
cg × 12
c++ × 10
xna-4.0 × 10
shadows × 10
2d × 9
opengl-es × 9
optimization × 9
shadow-mapping × 9
c# × 8
android × 8
webgl × 8
libgdx × 7