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
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
  • 35,702
  • 48
  • 141
  • 204
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
  • 494
  • 4
  • 18
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
  • 945
  • 2
  • 14
  • 31
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
  • 1,656
  • 4
  • 28
  • 50
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,267
  • 16
  • 18
4
votes
1 answer

Writing a HLSL4 pixel shader to perform a lookup from a 2Dtexture

I'm a beginner pixel shader writer and I'm running into some trouble. I want to take a 256x256, 16-bit input (DXGI_FORMAT_R16_UINT) image, and pass it through a 256x256 look-up texture (DXGI_FORMAT_R8_UNORM) to convert it to a 256x256 8-bit…
SJoshi
  • 1,559
  • 18
  • 43
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
  • 59,216
  • 102
  • 341
  • 614
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
  • 30,396
  • 73
  • 193
  • 291
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,178
  • 1
  • 26
  • 56
4
votes
1 answer

Why "Warning X4000: use of potentially uninitialized variable" shows for more than one usage of common method?

I have a common method in hlsli /// RendererShaderTypes.hlsli /// static inline float4 OverlayColor(float2 texOverlay, float4 videoColor) { float4 texColor = float4(imageMixTexture[4].Sample(imageMixSampler[4], texOverlay)); if…
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

Using shaders from Shadertoy in Interface Builder (Xcode)

I'm attempting to see what shaders look like in Interface Builder using sprite kit, and would like to use some of the shaders at ShaderToy. To do it, I created a "shader.fsh" file, a scene file, and added a color sprite to the scene, giving it a…
BadPirate
  • 24,683
  • 10
  • 85
  • 118
4
votes
1 answer

How do you access a previously shaded texture in a Pixel Shader?

In WPF, I want to use a pixel shader to modify a composite image i.e. a new image overlaid on top of a previously shaded image. The new image comes in as a largely transparent image except where there is data (think mathematical functions - sine…
Keith Hill
  • 173,872
  • 36
  • 316
  • 347
4
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…
1 2
3
20 21