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
  • 134k
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
  • 134k
5 votes

How do I wrap textures inside shader GLSL?

For people who come here from Google (like me), the shader version is: fract (tex_coord.st) this will loop coordinates in range 0.0 - 1.0
PiotrK's user avatar
  • 377
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
  • 134k
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

Super formula on shader

Instead of atan(sf.y/sf.x), use atan(sf.y,sf.x). This works because it takes the sign into consideration. Dividing the two ...
vero's user avatar
  • 155
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

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
  • 14.9k
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
  • 134k
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,634
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

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
  • 134k
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,632
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
  • 26.7k
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
  • 134k
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
3 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
  • 26.7k
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
Accepted

How do I draw individual pixels in the distance?

You can do this by constructing a custom Mesh and using the Points topology. This tells Unity to render every indexed vertex of the mesh as a single pixel. ...
DMGregory's user avatar
  • 134k
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
Accepted

Luminance 'y' value of surface texture

No, it will not. In GLSL vectors have three sets of swizzle masks: xyzw, rgba and stpq. The ...
kolrabi's user avatar
  • 891
2 votes
Accepted

OpenglGL Render two scenes with one draw call

http://chat.stackexchange.com/transcript/message/30419781#30419781 Bind more than one render target. Output two different colors from the fragment shader. You will of course need a second draw ...
Blue Bug's user avatar
  • 1,112

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