Jump to content
  • Advertisement
Sign in to follow this  
newtechnology

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

This topic is 1222 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Edited by newtechnology

Share this post


Link to post
Share on other sites
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:
 
}

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Edited by Migi0027 (????)

Share this post


Link to post
Share on other sites

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.

Edited by newtechnology

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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)?

Share this post


Link to post
Share on other sites

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.

Edited by newtechnology

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!