Hello.
I am using sharpDX with effect framework and I want to render multipass effect, but faced with the issue that I could not apply second pass:
Here is my effect code:
Texture2D Texture;
SamplerState TextureSampler;
matrix OrthoMatrix;
struct VertexInputType
{
float4 position : SV_POSITION;
float4 color: COLOR;
float2 tex : TEXCOORD0;
};
struct PixelInputType
{
float4 position : SV_POSITION;
float4 color: COLOR;
float2 tex : TEXCOORD0;
};
PixelInputType SpriteVertexShader(VertexInputType input)
{
PixelInputType output;
output.color = float4(0, 0, 0, 0);
output.position = float4(0, 0, 0, 0);
// Change the position vector to be 4 units for proper matrix calculations.
input.position.w = 1.0f;
output.position = mul(input.position, OrthoMatrix);
// Store the texture coordinates for the pixel shader.
output.tex = input.tex;
output.color = input.color;
return output;
}
float4 SpritePixelShader(PixelInputType input) : SV_TARGET
{
return Texture.Sample(TextureSampler, input.tex)* input.color;
}
float4 SpritePixelShader2(PixelInputType input) : SV_TARGET
{
/*return Texture.Sample(TextureSampler, input.tex)+ input.color;*/
return float4(0,1,0,0);
}
technique10 SpriteBatch
{
pass P0
{
SetGeometryShader(0);
SetVertexShader(CompileShader(vs_4_0, SpriteVertexShader()));
SetPixelShader(CompileShader(ps_4_0, SpritePixelShader()));
}
pass P1
{
SetGeometryShader(0);
SetVertexShader(0);
SetPixelShader(CompileShader(ps_4_0, SpritePixelShader2()));
}
}
And here is how I use effect:
var effectByteCode = ShaderBytecode.CompileFromFile(@"Content\Effects\SpriteBatchEffect.fx", "fx_5_0");
effect = new Effect(this.graphicsDevice, effectByteCode);
int passesCount = effect.GetTechniqueByName("SpriteBatch").Description.PassCount;
var technique = effect.GetTechniqueByName("SpriteBatch");
graphicsDevice.SetVertexBuffers(0, vertexBufferBinding);
EffectPass localpass;
for (int i = 0; i < passesCount; i++)
{
localpass = technique.GetPassByIndex(i);
var passSignature = localpass.Description.Signature;
layout = new InputLayout(graphicsDevice, passSignature, inputElements);
graphicsDevice.InputLayout = layout;
localpass.Apply(graphicsDevice);
graphicsDevice.DrawIndexed(indexCount, 0, 0);
}
On this line var
passSignature = localpass.Description.Signature;
in the second pass I receive outofrange exception.
If I comment that line, There is no exception, but the second pass will never apply.
Could someone, please, say what I am doing wrong here?