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
5
votes
0 answers

Suggestions for HLSL 2D shader tutorials?

I am looking for some resources for writing 2D shaders (not 3D, so please no references to vertex shader code or anything like that). I'm using HLSL, but having a lot of trouble finding good tutorials. Any suggestions?
RCIX
  • 38,647
  • 50
  • 150
  • 207
5
votes
1 answer

How use pixel shader to achive smooth text?

I want to have smooth text in my game. I found that solution is pixel shader, so i do every thing like is described on github documentation . I've got font.vert and font.frag files and in this documentation is said that i should use const float…
peterSweter
  • 633
  • 6
  • 23
5
votes
2 answers

Are there DirectX guidelines for binding and unbinding resources between draw calls?

All DirectX books and tutorials strongly recommend reducing resource allocations between draw calls to a minimum – yet I can’t find any guidelines that get more into details. Reviewing a lot of sample code found in the web, I have concluded that…
5
votes
3 answers

Optimization of HLSL shader

I have the problem that the below pixel shader (HLSL) compiles to 68 instructions (with the below suggested optimizations). However, I would like to use it with shader model 2 and therefore unfortunately I can only use up to 64 instructions. Does…
ares_games
  • 1,019
  • 2
  • 15
  • 32
5
votes
1 answer

Creating WPF effects with different sized pixel shader samplers

I want to create an effect where I use a quite large image to produce a smaller image with HLSL through a WPF Effect. But it seems that WPF for some reason resizes all input images to the rendered size, which isn't what I want, since it will crop…
Markus
  • 1,614
  • 1
  • 22
  • 32
5
votes
1 answer

Calculating world space coordinates in the pixel shader

I have a pixel shader and I want to calculate the position of each pixel in terms of my world space coordinates. How would I do this? What would I need? I have a ps_input structure which has a float4 position : SV_POSITION. I'm assuming this is…
l3utterfly
  • 2,106
  • 4
  • 32
  • 58
5
votes
4 answers

Blurred picture after applying of shader effect

I've come across strange behavior of pixel shader in WPF. This problem is 100% reproducible, so I wrote small demo program. You can download source code here. The root of all evil is tiny class titled MyFrameworkElement: internal sealed class…
Alex Zhevzhik
  • 3,347
  • 19
  • 19
4
votes
1 answer

Variable Width Outline Effect Around a Texture in 2D

I am looking to create a glsl shader program that will give me a variable width outline around an arbitrary 2d texture as shown in the picture. Is this a reasonable job for the GPU? I've looked at edge-detection approaches but those would only…
Bret
  • 883
  • 1
  • 9
  • 18
4
votes
1 answer

OpenGL Pixel Shader: how to generate random matrix of 0s and 1s (on each pixel)?

So what I need is simple: each time we perform our shader (meaning on each pixel) I need to calculate random matrix of 1s and 0s with resolution == originalImageResolution. How to do such thing? As for now I have created one for shadertoy random…
Rella
  • 65,003
  • 109
  • 363
  • 636
4
votes
1 answer

Number of Geometry Shader Executions?

So a vertex shader is executed for each vertex and a fragment shader for each fragment (right?). How many times is a geometry shader executed?
clamp
  • 33,000
  • 75
  • 203
  • 299
4
votes
0 answers

Where is "Enable gather of GPU Disassembly" in visual studio 2017?

I need to debug a pixel shader, but I get the following message instead of disassembly: Enable GPU disassembly via View->Options->Graphics Diagnostics->Enable gather of GPU Disassembly. The vsglog must be re-opened for this change to take effect. I…
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
4
votes
2 answers

HLSL: problematic pixelshader code (alpha at zero when sampling)?

I have this strange problem with the sampler in the pixel shaders. When I sample from a sampler into an empty float4 variable I always get black/transparent color back. So if I use this I get a black screen: float4 PixelShaderFunction(float2…
Marino Šimić
  • 7,318
  • 1
  • 31
  • 61
4
votes
1 answer

Which texture slot should be used to start where I need 7th and 8th slot together among 0 to 8 index of 9 resources

I have total 9 texture resources among them I need 2 resources together for a pixel shader. In that case what should be the texture slot start index if I need the 7th and 8th texture resources only. (e.g. Texture2D foo1 : register(t7) and Texture2D…
4
votes
1 answer

Pure Depth SSAO flickering

I try to implement Pure Depth SSAO, using this tutorial, into an OpenGL ES 2.0 engine. Now I experience flickering, which looks like I read from somewhere, where I have no data. Can you see where I made a mistake or do you have an idea how to solve…
4
votes
2 answers

Recreating in a Pixel Shader/Other Method in WPF

Now that (amongst other effects) has been depreciated, I'm looking to see how I could re-create the exact same thing in a Shader Effect (including it's properties of BevelWidth, EdgeProfile, LightAngle, Relief and…
Todd Main
  • 28,951
  • 11
  • 82
  • 146
1 2
3
20 21