2022 Developer Survey is open! Take survey.
29 votes
Accepted

How do I write a shader that lights up when objects are near a surface?

A general outline: Create a depth map of your scene without the shield. You can get this effectively for free, since transparent objects are often rendered in a later pass anyway. Otherwise, you can ...
user avatar
25 votes

Why is H (blinn) used instead of R (phong) in specular shading?

For perfectly reflective surfaces Phong-model makes sense. However, where does the n in (R.V)^n of Phong-model for approximating rougher surfaces come from? Where is the theory that you have to raise ...
user avatar
  • 870
11 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 ...
user avatar
10 votes
Accepted

How to implement color changing fragment shader?

Here's how I would do this. First, make sure you have the object's UVs or world coords (which you can pass through from your vertex shader) available to you. If it's just a background, you could also ...
user avatar
8 votes

GLSL - one-pass gaussian blur

The trick for rapid Gaussian blurring with GLSL is to take advantage of the fact that the GPU provides linear interpolation in hardware. Therefore, you can effectively sample four 2D pixels with a ...
user avatar
7 votes
Accepted

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

Set the filterMode of your textures to FilterMode.Point. This will use nearest-neighbor interpolation, which will result in ...
user avatar
7 votes
Accepted

How to pass a big (60+) amount of variables to an HLSL pixel shader?

Use several constant buffers and group variables together based on how often they change. If your variables are fairly static ( or just huge ) you may be better off converting values into a texture ...
user avatar
  • 246
6 votes

Why is H (blinn) used instead of R (phong) in specular shading?

Actually, I think you yourself listed the reasons why Blinn is the default over Phong. Each reason you listed there is, in fact, an area where Blinn proves superior to Phong. Taken as a whole, all ...
user avatar
  • 161
6 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 ...
user avatar
  • 112k
5 votes

How do I write a shader that lights up when objects are near a surface?

It's just using the depth map. It renders the world then renders the shield and takes a difference between the shield's rendered z value and the depth buffer z value to tint the pixel more white.
user avatar
  • 584
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 ...
user avatar
  • 112k
4 votes
Accepted

How does OpenGL determine different outputs with shaders?

By default the output variable (outputColor) is bound to location 0. For a fragment shader this specifies the color value to be used for that fragment for the framebuffer object in position 0. You ...
user avatar
  • 1,001
4 votes
Accepted

Calling Shader Functions Inside Other Shaders

When uploading shader source, you may provide more than one string. The lines of the strings are concatenated into the full text source for the shader compiler. You can thus emulate an include system ...
user avatar
  • 4,064
4 votes
Accepted

2D day night mapping

What you need is to retroproject the point on your map, from the inverse Mercator into 3d space, then place the sun as a directional light (not point like your ...
user avatar
  • 2,343
4 votes
Accepted

Best way of writing pixel manipuliting-intensive applications with OpenGL/Direct3D

I understand that you are at a loss. I also liked to hack pixels when I was young, and did some games on calculator devices, or dos era this way. This can still be done today, but, because of various ...
user avatar
  • 2,343
4 votes

How do I wrap textures inside shader GLSL?

You don't set these values in the shader. You set them in your program, generally when first creating the texture (though it can be set or changed whenever). If you've already uploaded your texture ...
user avatar
  • 484
4 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
user avatar
  • 347
4 votes
Accepted

Pixelation shader explanation?

This is a pixelation shader, it seems. What it does is, it divides the screen into tiny rectangles, the side of each rectangle is determined by the values dx and dy. The smaller the value of ...
user avatar
4 votes
Accepted

Is there a way to get what pixel is being processed within the fragment shader?

There is, in the fragment shader, a variable called gl_FragCoord. This contains the coordinates of the currently executing fragment shader. Note that (by default) a pixel at pixel coordinates (x,y) ...
user avatar
  • 3,203
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 3,989
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 ...
user avatar
  • 14.5k
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 ...
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 ...
user avatar
  • 112k
3 votes

Best way of writing pixel manipuliting-intensive applications with OpenGL/Direct3D

I'm also from a pixel-banging background. PEEK and POKE anyone? Using a GPU is a different mind-set entirely. (Well, it's still code, so just "more of the same...) The GPU is really good at certain ...
user avatar
3 votes
Accepted

Unity: cg fragment shader processing array of points

As discussed in the comments above, it may be easier to get this effect (and scale better to large values of N) by flipping the request around. Rather than the shader for the scene geometry checking -...
user avatar
  • 112k
3 votes

Shadertoy getting help moving to glsl

You have two options: Use gl_FragCoord and pass a uniform variable for iResolution. Everything else will work exactly like in ...
user avatar
  • 451
3 votes
Accepted

Fragment shader, tint color problem

The problem was there gl_FragColor = (1.0, 0 , 0 ,1.0);//vec4(texVal.rgb, texVal.a)*(1.0, 0 , 0 ,1.0); it miss the vec4 name ...
user avatar
  • 293
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 ...
user avatar
  • 1,604

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