Hi
I am playing around with some pixelshading and what I am expecting it to do is not what it is doing, or at least I think it is not doing what I want to acheive.
For the fun of it I am doing two render passes though this is not necessary.
This is my shader:
// FX parameter. Accessible from file
uniform extern float4x4 WorldViewProjMatrix;
// the output vertex structure
struct OutputVS
{
// POSITION0 tells that this member corresponds to the
// data member in the custom vertex structure with usage
// D3DDECLUSAGE_POSITION and index 0
float4 posH : POSITION0;
float4 col : COLOR0;
};
// VERTEX SHADER
// input: the current position of vertex and the specified color
// output: the transformed vertex
OutputVS VS1(float3 posL : POSITION0, float4 _col : COLOR0)
{
// initialize the output structure by zeroing it out
OutputVS outVS = (OutputVS)0;
// transform the vertex to homonegenous clip space
outVS.posH = mul(float4(posL,1.0f), WorldViewProjMatrix);
// pass the color
outVS.col = _col;
// return the vertex
return outVS;
}
// PIXEL SHADER
// input: a color vector
// output: color of the current pixel
float4 PS1(float4 _col : COLOR0) : COLOR
{
return float4(_col.rgb,_col.a*0.2f);
}
// PIXEL SHADER
// input: a color vector
// output: color of the current pixel
float4 PS2(float4 _col : COLOR0) : COLOR
{
return float4(_col.r*1.0f,_col.g*0.0f,_col.b*0.0f,_col.a);
}
// TECHNIQUE, (ie. the composition of shadering)
technique Technique1
{
pass P1
{
// which vertex and pixel shader is associated with the pass
//vertexShader = compile vs_2_0 VS1();
pixelShader = compile ps_2_0 PS1();
// set rendering states
FillMode = Solid;
}
pass P0
{
// which vertex and pixel shader is associated with the pass
vertexShader = compile vs_2_0 VS1();
pixelShader = compile ps_2_0 PS2();
// set rendering states
FillMode = Solid;
}
}
The first pass is P0 and here is the first question why?
Then I want the first PS to do somethings with the color red, this is not so important, and then in the scond pass P1 I'll do something with the alpha channel. Now is this the right way to think of it, if I want to do several passes? or have I misunderstood something? Isn't the color produced from the first pixelshader the input to the second? or is it necessary to extract it and then use it as input again? if so how is this done?
This is my c++ code wher I call the passes
// setting the number of passes the shader has
unsigned int numPasses = 2;
// beginning shader
HR(m_pEffect->Begin(&numPasses, 0));
for(unsigned int i = 0; i < numPasses; ++i)
{
HR(m_pEffect->BeginPass(i));
// drawing between passes will draw the geometry as
// specified in the shader
HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12));
// end pass
HR(m_pEffect->EndPass());
}
HR(m_pEffect->End());
regards
regards/thallishI don't care if I'm known, I'd rather people know me