Skip to main content
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 ...
DMGregory's user avatar
  • 136k
12 votes
Accepted

How to make a 2D neon-like trail effect in Unity

To achieve this effect my friend has created a custom sprite, we played around with all sorts of sprites and you can customize this part to your liking. The shader I've written for this effect, takes ...
John Hamilton's user avatar
7 votes
Accepted

How do I calculate UV space from world space in the fragment shader?

Do I understand correctly that you want an effect somewhat like this? (If I'm way off, you may need to edit your question to include more description of what you're trying to do and why) Here I have ...
DMGregory's user avatar
  • 136k
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 ...
DMGregory's user avatar
  • 136k
4 votes
Accepted

HLSL texture sampler always returns white

The problem is this: the compiler optimizes the effect file. So in your code only ONE sampler is created. However in reality you are using TWO textures. The first one, being the Texture provided as ...
Felsir's user avatar
  • 4,067
4 votes
Accepted

GLSL: Issue replacing ternary operator with mix

The main issue is that (ONE3-b)/a may cause a division by zero. This causes the result to be NaN (Not A Number). In that case mix will also return NaN because ...
Stephane Hockenhull's user avatar
4 votes
Accepted

How to make far block graphically better?

What you see is there because the textures are in a higher resolution than what they get drawn in. This results in a very pixelated look. To "fix" this you can generate mipmaps. Mipmaps are the ...
Bálint's user avatar
  • 15k
4 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. ...
Krupip's user avatar
  • 1,763
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 ...
jhoffman0x's user avatar
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 ...
DMGregory's user avatar
  • 136k
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 ...
Theraot's user avatar
  • 27.3k
3 votes

GLSL - skewed parallax occlusion mapping

normalMapping should use TBN, Parallax Mapping should use transpose(TBN), and viewDirection should mul transpose(TBN).
玩雪明's user avatar
3 votes

GLSL Fragment Shader compiles fine on certain computers

Remove the 'f' on your float constants. It's not part of the GLSL language. Source: GLSL Specification If you do not put a #version NNN pragma at the top of your ...
Stephane Hockenhull's user avatar
3 votes
Accepted

Procedural Hatching

Yes, in fact I'm not sure of any other way you'd do it other than in the fragment shader. Here's some examples I found: This ShaderToy uses a noise texture and another function to generate the ...
Cobertos's user avatar
  • 1,644
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. :) ...
DMGregory's user avatar
  • 136k
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 ...
user1118321's user avatar
  • 2,642
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 ...
Ocelot's user avatar
  • 1,433
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 ...
Felsir's user avatar
  • 4,067
3 votes
Accepted

How to decorate the floor with a grid?

One way to do a square pattern in glsl is with mod: ...
Theraot's user avatar
  • 27.3k
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 ...
DMGregory's user avatar
  • 136k
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 ...
Maximus Minimus's user avatar
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 ...
NCoolgamer's user avatar
2 votes

How to prevent intepolated texture in fragment shader (Unity CG)

If you want to do this without a script, simply in the Project Window: Select your image in the Assets folder The Import Settings will now be visible in the Inspector Window In Import Settings, Find "...
nathanfranke's user avatar
2 votes

Difference in Shading Using Eye Space or Model Space Coordinates

First, you are misunderstanding the point of the article; these are not two different kinds of fragment shading. This is just an illustration two different coordinate systems. Which one you use will ...
Trevor Powell's user avatar
2 votes

Metaballs created through raycasting in fragment shader - billboards are still recognizable

I solved it and it was a rather stupid mistake on my part. I post this though because it might help others using raycasts to create surfaces, even though the answer "should" be obvious: When ...
Grougal's user avatar
  • 31
2 votes
Accepted

Does GLSL support multitexturing?

"Multitexturing" is an OpenGL feature from before programmable shaders; shaders pretty much made the concept obsolete, and it was quickly deprecated. Any websites you read which talk about "...
Trevor Powell's user avatar
2 votes

Ashikhmin-Shirley model implementation: ugly result

vec4 Fr(float u, vec4 specular) { return specular + (1.0-specular) * pow(1.0 - u, 5.0); } what's the specular in this function ? I think you specular is wrong,...
liujiapeng's user avatar
2 votes

Has anyone ever made a shader that produces something similar to pixel art?

To get a look very close to pixel art, simply use a cel shader and upscale the result without interpolation. This will give you proper results for still images, but the illusion will fall apart as ...
Philipp's user avatar
  • 121k
2 votes

DirectX11 - Color Interpolation Along Quad Diagonal

You need per-fragment color interpolation rather than per vertex color interpolation. If you write the interpolation yourself in the fragment shader, you can make it work any way you'd like. ...
user1118321's user avatar
  • 2,642

Only top scored, non community-wiki answers of a minimum length are eligible