Is it possible to output integer from pixel shader?

Jan 21, 2015 at 9:33 PM
sorry if this question does not make much sense. But in my case, I use multiple pass pixels shaders to do some processing. The result from previous pixel shader (not float but integer type for example) will be used as input for the next.
So, is there a way to set this up? What's the pixel shader look like? I'm constantly puzzled by signature such as:
float4 PSMAIN( in VS_OUTPUT input ) : SV_Target
the return type is float4, but what's the use of SV_Target here?
Coordinator
Jan 24, 2015 at 12:13 PM
SV_Target is what they call a "SEMANTIC", and it is basically a keyword that identifies what the main output of the pixel shader is. If it is just outputting to a color render target, then the float4 type makes sense.

As to your chaining of pixel shaders, if each subsequent processing stage is dependent on the prior stage (i.e. you sample multiple pixels/texels from the previous stage) then you need to do separate passes. Since a pixel shader can only work on one pixel at a time, you wouldn't be able to access the intermediate values from the neighboring pixels.

If you don't sample neighboring pixels at all, then you can just do all the calculations within one pixel shader and there is no need for chaining them. In this case, if you want to have reusable sections of code, then HLSL lets you define functions in much the same way you would for C or C++. If you want to get my opinion on a particular case, them please post the shaders or link to them in your GitHub repo and I can take a look.
Jan 29, 2015 at 2:51 PM
MSDN states that pixel shader can only output float. However, I've seen code like this:
struct PS_OUTPUT {
   uint4 result    : SV_Target0;
};
I tried creating a render target with unsigned integer format for the above shader output. But got the error message that the pixel shader output is float and does not match the resource format. It works if I change resource format to float, does that means the result is implicitly converted to float?