HLSL Multiple passes issue

Started by
1 comment, last by thallish 17 years, 5 months ago
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
Advertisement
Hi,

if you want to do several passes with pixel shaders, you normally render to a texture in the first pass, then render a textured quad (and use the result of the first pass as a texture), and use the second pixel shader. Then, you can do this through multiple passes is you want.
Don;t ask how to do this using the effects framework, I've never used it because I do it by hand :)

If you want to output to the color channel and the alpha channel, feel free to emit both in the same pixel shader if nothing is against it.

If you need some clarification, feel free to ask more!

To visually see the results of passes, and some real multipass effects, download RenderMonkey from the Ati website, and play with it a little bit! It helps a lot!

kp
------------------------------------------------------------Neo, the Matrix should be 16-byte aligned for better performance!
Hi

Ill check out rendermonkey for a while.

Anyways is there anybody who know where I can read some more about using multiple passes? or can explain the intrinsic workings of the whole tomato:)

regards

regards/thallishI don't care if I'm known, I'd rather people know me

This topic is closed to new replies.

Advertisement