Questions tagged [pixel-shader]

Pixel shaders, also known as fragment shaders, compute color and other attributes of each fragment. Pixel shaders range from always outputting the same color, to applying a lighting value, to doing bump mapping, shadows, specular highlights, translucency and other phenomena.

Pixel shaders, also known as fragment shaders, compute color and other attributes of each fragment. Pixel shaders range from always outputting the same color, to applying a lighting value, to doing bump mapping, shadows, specular highlights, translucency and other phenomena.

They can alter the depth of the fragment (for Z-buffering), or output more than one color if multiple render targets are active.

In 3D graphics, a pixel shader alone cannot produce very complex effects, because it operates only on a single fragment, without knowledge of a scene's geometry. However, pixel shaders do have knowledge of the screen coordinate being drawn, and can sample the screen and nearby pixels if the contents of the entire screen are passed as a texture to the shader. This technique can enable a wide variety of two-dimensional postprocessing effects, such as blur, or edge detection/enhancement for cartoon/cel shaders.

Pixel shaders may also be applied in intermediate stages to any two-dimensional images in the pipeline, whereas vertex shaders always require a 3D model. For instance, a pixel shader is the only kind of shader that can act as a postprocessor or filter for a video stream after it has been rasterized.

314 questions
59
votes
5 answers

WebGL/GLSL - How does a ShaderToy work?

I've been knocking around Shadertoy - https://www.shadertoy.com/ - recently, in an effort to learn more about OpenGL and GLSL in particular. From what I understand so far, the OpenGL user first has to prepare all the geometry to be used and…
Charlie
  • 3,852
  • 3
  • 36
  • 52
21
votes
2 answers

What is the relationship between gl_Color and gl_FrontColor in both vertex and fragment shaders

I have pass-through vertex and fragment shaders. vertex shader void main(void) { gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } fragment shader void main(void) { gl_FragColor =…
Thomas Vincent
  • 2,092
  • 4
  • 15
  • 24
14
votes
2 answers

Combining multiple pixel shaders efficiently

So I'm making a thing with XNA 3.1, and I have a lot of separate effects that are applied via pixel shaders. These come from all sorts of sources, such as special attacks, environment, and so forth. The issue I'm having is that I'm noticing a…
Hoeloe
  • 630
  • 3
  • 21
11
votes
1 answer

How much performance do conditionals and unused samplers/textures add to SM2/3 pixel shaders?

We've one pixel shader in HLSL which is used for slightly different things in a few places, and as such has several conditional blocks meaning that complex functionality is omitted in some cases. As well, this means we pass textures as sampler…
Mr. Boy
  • 52,885
  • 84
  • 282
  • 517
11
votes
2 answers

Floyd–Steinberg dithering alternatives for pixel shader

I know that Floyd–Steinberg dithering algorithm can't be implemented with pixel shader, because that algorithm is strictly sequential. But maybe there exist some higly parallel dithering algorithm which by it's visual output is similar to…
Agnius Vasiliauskas
  • 10,413
  • 5
  • 46
  • 66
11
votes
1 answer

Rendering to multiple textures with one pass in directx 11

I'm trying to render to two textures with one pass using C++ directx 11 SDK. I want one texture to contain the color of each pixel of the result image (what I normally see on the screen when rendering a 3D scene), and another texture to contain the…
l3utterfly
  • 1,656
  • 4
  • 28
  • 50
11
votes
1 answer

Pixel Shader model > 2.0 in FireMonkey

To start with my main question: Can I use pixel shader model 3, 4 or 5 in my FireMonkey applications? I want to be able to dynamically create pixel shaders in my FireMonkey program. To do that, I now compile a pixel shader using fxc.exe that comes…
Wouter van Nifterick
  • 22,500
  • 7
  • 72
  • 117
10
votes
1 answer

Color conversion from DXGI_FORMAT_B8G8R8A8_UNORM to NV12 in GPU using DirectX11 pixel shaders

I'm working on a code to capture the desktop using Desktop duplication and encode the same to h264 using Intel hardwareMFT. The encoder only accepts NV12 format as input. I have got a DXGI_FORMAT_B8G8R8A8_UNORM to NV12…
Ram
  • 1,218
  • 11
  • 30
10
votes
3 answers

Handling alpha channel in WPF pixel shader effect

Is there something unusual about how the alpha component is handled in a pixel shader? I have a WPF application for which my artist is giving me grayscale images to use as backgrounds, and the application colorizes those images according to the…
vanmelle
  • 1,465
  • 1
  • 12
  • 21
10
votes
2 answers

Pixel Shader Effect Examples

I've seen a number of pixel-shader effect examples, stuff like swirl on an image. But I'm wondering if anyone knows of any examples or tutorials for more practical uses of shader effects? I'm not saying that a swirl effect doesn't have it's uses,…
Chris Nicol
  • 9,726
  • 6
  • 35
  • 48
9
votes
1 answer

pow(0, 2.2) gives 1 in a hlsl pixel shader?

But pow(0, 2.0) gives 0 Seems that any float exponent gives 1 while integer exponents give 0. I am using DirectX 9 and hlsl compiler "D3DCompiler_43.dll". Confirmed that on Nvidia and Ati cards. I am confused! Is that some kind of known behaviour or…
Ole Dittmann
  • 1,654
  • 1
  • 12
  • 20
9
votes
1 answer

Should using a singleton PixelShader be a best practice?

In Microsoft's example for how to use the PixelShader they use a singleton. I've seen the same pattern in other places, and here they say The pixel shader is stored in a private static field _pixelShader. This field is static, because one instance…
shoren
  • 911
  • 8
  • 19
9
votes
4 answers

What kind of blurs can be implemented in pixel shaders?

Gaussian, box, radial, directional, motion blur, zoom blur, etc. I read that Gaussian blur can be broken down in passes that could be implemented in pixel shaders, but couldn't find any samples. Is it right to assume that any effect that concerns…
Joan Venge
  • 269,545
  • 201
  • 440
  • 653
8
votes
4 answers

Can I generate a random number inside a pixel shader?

I'm trying to write a very simple shader that adds random sparkle to applicable objects. The way I'd like to do this is by adding a random shade of white (R = G = B) to the pixel value within the pixel shader. It seems that noise() doesn't work the…
chaosTechnician
  • 1,522
  • 3
  • 16
  • 30
8
votes
3 answers

Efficient pixel shader sum of all pixels

How can I efficiently calculate the sum of all pixels in an image, by using a HSLS pixel shader? I'm interested in Pixel Shader 2.0, that I could invoke as a WPF shader effect.
luvieere
  • 35,580
  • 18
  • 120
  • 178
1
2 3
20 21