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
2
votes
1 answer

Can a pixel shader run more than once per pixel per draw call in DirectX 9?

If I have multiple overlapping triangles in the same draw call, is my pixel shader entered for each pixel once per primitive that covers it? Or is the depth test performed first, and the shader is only entered exactly once per pixel, regardless of…
Justin R.
  • 23,435
  • 23
  • 108
  • 157
2
votes
1 answer

Reading from multiple render targets in DirectX

I have two render target views, my back buffer and a Texture2D that represents a specialized mask (I can't use the stencil buffer for what I need). My render method looks roughly like this: // clear the render target and depth stencil views, set…
Justin R.
  • 23,435
  • 23
  • 108
  • 157
2
votes
2 answers

HLSL Pixel shader lighting performance (XNA)

I have a simple enough shader that supports multiple point lights. Lights are stored as an array of Light structs (up to a max size) and I pass in the number of active lights when it changes. The problem is in the PixelShader function: It's basic…
DFreeman
  • 542
  • 6
  • 13
2
votes
1 answer

How to apply the perlin noise on a sphere?

I'm trying to create an animated sun in HLSL for an XNA project. I'm generating its texture in the pixel shader by using the Perlin Noise algorithm, which I learned from this site. This is the hlsl code I wrote for the pixel shader: sampler…
Omar
  • 16,329
  • 10
  • 48
  • 66
2
votes
1 answer

How to return a texture from pixel shader in Unity 3d shaderlab?

How to create a simple pixel color shader that say takes a texture, applyes something like masking: half4 color = tex2D(_Texture0, i.uv.xy); if(distance(color, mask) > _CutOff) { return color; } else { return static_color; } in and returns a…
myWallJSON
  • 9,110
  • 22
  • 78
  • 149
2
votes
0 answers

Seems like my Pixel Shader is not being called

I ve been messing around with DirectX and I ve been working on this weird idea of mine for some time now. It seems as if my pixel shader is not being invoked for some odd reason. I dont know if thats even possible or that its some stupid mistake of…
Safi
  • 21
  • 7
2
votes
0 answers

Managed DirectX: Applying HLSL Effect to Surface

First off, I am a complete DirectX noob. I'm loading a bitmap into a surface and need to apply an HLSL effect to it prior to display. The goal is to display real-time effects on the image. For whatever reason, the image displays but without the…
magnvs
  • 63
  • 1
  • 9
2
votes
1 answer

Where are the WPF effects defined?

I am wondering where the WPF effects such as Blur is defined? They are pixel shaders, right? Is there a way to peek into their implementation?
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
2
votes
2 answers

Bevel effect in HLSL

I'm trying to make a photoshop-like Bevel effect in HLSL. The hard part is finding the distance of a point from the closest edge (where alpha=0) Anyone have any ideas how to do this ? Best, SW
Shachar Weis
  • 936
  • 2
  • 20
  • 44
1
vote
1 answer

direct3d alphablend and pixel shaders

I have a 2D scene, 2 textures set as render targets, and a vertex buffer. first texture is filtered out by contrast/brightness pixel shader, the second acts as a menu, which I would not like to be processed by the same shader, but want it to be…
Ulterior
  • 2,786
  • 3
  • 30
  • 58
1
vote
1 answer

Use one vertex/fragment shader in multiple programs

In OpenGL ES 2.0, is it possible to use a compiled vertex/fragment shader in multiple linked programs? For example, let's say I have 1 compiled vertex shader and 5 compiled fragment shaders. Can I create 5 different programs(vsh1+fsh1, vsh1+fsh2,…
1
vote
1 answer

What does the pixel shader function tex1D do with a Texture2d

If I call tex1d from my pixel shader on a texture that has been initialized as a texture2d will it treat the data as a one dimensional array and then just take the element at whichever position you specify? For instance if you have a 10 x 10…
Mr Bell
  • 9,228
  • 18
  • 84
  • 134
1
vote
0 answers

whats wrong with using depth image for lighting

I want use a depth image to lighting a RawColor image but it not seems good i want know whats wrong with my code , or its all depth image can do :| the output image shape like Cone instead of circle and there are many noise on it , what i want to…
mX64
  • 388
  • 1
  • 7
  • 24
1
vote
1 answer

Set texture in effect file

I need to pass texture in shader file, but it is giving me error "Invalid call". Please help to tell where i am doing wrong ? Follow is code which is i have written. I am able to set all the parameter except Texture. float progress; float4…
Firoz
  • 7,224
  • 10
  • 41
  • 56
1
vote
1 answer

Is the render target view the only way to output data from pixel shader in DirectX?

Purpose: I want to render an image in the screen and save it in my disk. Description: I have a render target view. I have a input shader resource view with its texture (D3D11_USAGE_DYNAMIC). I have a output shader resource view with its texture…