Error: pixel shader must minimally write all four components of SV_Target0

Started by
7 comments, last by Hodgman 8 years, 9 months ago

I am writing shader for shadow map by reading Frank D. Luna's Direct3D11 book. In shadow map, in order to skip writing transparent pixels into shadow map, he uses this pixel shader:

http://pastebin.com/ed8EVJXg

But since I do not use effects11, I use this.

http://pastebin.com/zykr04tu (Pixel shader code separately)

^ But that doesn't work. I get this error:

Error 1 error X4530: pixel shader must minimally write all four components of SV_Target0 K:\Visual Studio Projects\NT Engine\NT Engine\FXC
Advertisement
What do you expect to happen with that shader? You have to actually write a pixel out, i.e:

struct VS_OUT
{
        float4 PosH : SV_POSITION;
        float2 Tex  : TEXCOORD;
};
 
SamplerState Sampler : register(s0);
 
Texture2D DiffuseMap;
float4 main(VS_OUT pin) : SV_TARGET
{
        float4 Diffuse = DiffuseMap.Sample(Sampler, pin.Tex);
 
        //clip pixels having alpha value < 0.15 (nearly transparent)
        clip(Diffuse.a - 0.15f);
        return Diffuse:
 
}
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

What do you expect to happen with that shader? You have to actually write a pixel out, i.e:

Wrong. If you are rendering to a depth buffer with no render targets bound you still need the pixel shader for alpha testing, but there is no need for any return value.

Ignore this post, read Mona2000's post wrong. I'm very sorry.

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

What do you expect to happen with that shader? You have to actually write a pixel out, i.e:


struct VS_OUT
{
        float4 PosH : SV_POSITION;
        float2 Tex  : TEXCOORD;
};
 
SamplerState Sampler : register(s0);
 
Texture2D DiffuseMap;
float4 main(VS_OUT pin) : SV_TARGET
{
        float4 Diffuse = DiffuseMap.Sample(Sampler, pin.Tex);
 
        //clip pixels having alpha value < 0.15 (nearly transparent)
        clip(Diffuse.a - 0.15f);
        return Diffuse:
 
}

I am just rendering depth for shadow mapping. I just wanna clip transparent pixels from being rendered in that. I do not want to return a color at all cause renderTarget is null.

EDIT: Changing pixel shader and vertex shader version fixed the issue biggrin.png (ps_4_0_level_9_1 to ps_4_0)
Thanks for all your help.

What do you expect to happen with that shader? You have to actually write a pixel out, i.e:


Wrong. If you are rendering to a depth buffer with no render targets bound you still need the pixel shader for alpha testing, but there is no need for any return value.
Well then, how about you tell us the correct way to fix his issue?

I'm on mobile so I can't research his exact issue, but what I'm gathering from the error is that regardless that you have no color buffer bound, the api still expects him to output something, which is likely discarded when no colorbuffer is bound.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.
Well then, how about you tell us the correct way to fix his issue?

I would if I could, but there is no issue in the code he posted; it compiles perfectly fine for me. Perhaps he is compiling it with the wrong target (D3D9on11 or however that thing is called)?

I just told it was a version issue. After changing version from ps_4_0_9_1 to just ps_4_0, it compiled perfectly.

@Slicer: No, it is perfectly fine to not return a color (by using void pixel shader) when no renderTarget is bound.

In my portability header, i have some code like this for handling depth-only shaders:

#if SHADER_MODEL > 3
#define DUMMY_RETURN_TYPE void
#define DUMMY_RETURN 
#define DUMMY_RETURN_SEMANTIC
#else
#define DUMMY_RETURN_TYPE float4
#define DUMMY_RETURN return (float4)0
#define DUMMY_RETURN_SEMANTIC: SV_TARGET0
#endif
(and define SHADER_MODEL when compiling the code)

This topic is closed to new replies.

Advertisement