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.

310 questions
22
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,214
  • 4
  • 17
  • 25
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
  • 650
  • 4
  • 21
13
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,935
  • 5
  • 50
  • 70
13
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
  • 2,106
  • 4
  • 32
  • 58
12
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
  • 60,845
  • 93
  • 320
  • 589
11
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,764
  • 1
  • 14
  • 22
11
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,605
  • 1
  • 14
  • 22
11
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
  • 315,713
  • 212
  • 479
  • 689
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
  • 23,603
  • 7
  • 78
  • 122
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…
iamrameshkumar
  • 1,328
  • 1
  • 14
  • 34
10
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,640
  • 4
  • 18
  • 31
10
votes
2 answers

DirectX 11 Pixel Shader What Is SV_POSITION?

I am learning HLSL for DirectX 11, and I was wondering what exactly is the SV_POSITION that is the output for a Vertex Shader, and the input for a Pixel Shader. 1: Is this x,y,z of every pixel on your screen, or of the object? 2: Why is it 4 32bit…
Mike5050
  • 625
  • 1
  • 7
  • 22
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
  • 10,256
  • 7
  • 39
  • 49
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
  • 931
  • 8
  • 20
8
votes
2 answers

WebGL/GLSL time variable similar to ShaderToy

Here is my vertex shader attribute vec4 a_position; varying vec4 v_color; void main() { gl_Position = vec4(a_position.xy, 0.0, 1.0); v_color = gl_Position * 0.5 + 0.5; } Here is my fragment shader precision mediump float; varying vec4…
Mudassir Ali
  • 7,913
  • 4
  • 32
  • 60
1
2 3
20 21