What semantic(s) to use in order to rendre in multiple targets ?

Started by
1 comment, last by theScore 10 years, 10 months ago

Hi !

I compile my pixel shader with the version : ps_5_0 as a parameter in the instruction :


if(FAILED(D3DX11CompileFromFileA("./Shaders/GBuffer.hlsl",NULL, NULL, "pixel_main", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &blobPixelGBuffer, &errorBlob, NULL )))

But at the compilation, I get these errors if I put the semantics COLOR0, COLOR1, and COLOR2 or SV_Target0, SV_Target1, SV_Target2,

both generates compilation errors.

The shader is here :


struct psIn
{
	float4 color		: COLOR0 ;
	float4 RTposition	: POSITION1 ;
	float2 texCoord		: TEXCOORD0 ;
	float3 normal		: NORMAL ;
	float4 posInLightSpace	 : TEXCOORD1 ;
};

struct psOut
{
	float4 color		: SV_Target ;
	float4 RTposition	: SV_Target1 ;
	float4 RTnormal		: SV_Target2 ;
};

SamplerState colorMap : register( s[0] ) ;
SamplerState specularMap : register( s[1] ) ;
SamplerState shadowMap  : register( s[2] );

cbuffer GBufferConstants
{
	bool texturedMesh ;
	bool isSpecular ;
	float epsilon ;
}
Texture2D texObj2D ;


float4 getColor(psIn IN)
{
   if(texturedMesh == true)
   {

	return texObj2D.Sample(colorMap, IN.texCoord) ;
   }
	else
	   return IN.color ;
}



/* pixel shader */
psOut pixel_main(psIn IN, psOut OUT )
{
    OUT.color = getColor(IN) ; ;
    OUT.RTposition = IN.RTposition ;
    OUT.RTnormal = float4(IN.normal, 1.0) ;
    return OUT ;
}

Do you have an idea ? I looked in the directx documantation and it seems that it is SV_Target but it don't work unsure.png

Advertisement

In the future it would be helpful if you post the compilation errors, since it would help people to quickly figure out what's wrong with your code.

Your problem is that you're taking your "psOut" structure as an input parameter to your pixel shader, and SV_Target is an invalid input semantic for a pixel shader. Just remove it as a parameter, and declare it locally to your function:


psOut pixel_main(psIn IN)
{
    psOut OUT;
    OUT.color = getColor(IN) ; ;
    OUT.RTposition = IN.RTposition ;
    OUT.RTnormal = float4(IN.normal, 1.0) ;
    return OUT ;
}

Thanks it works ! Alright, next time I put errors from compiler. smile.png

This topic is closed to new replies.

Advertisement