Jump to content
  • Advertisement
Sign in to follow this  
huaner

.fx fog && pixed piple fog

This topic is 3656 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

hi: i disable fog state in the effect pass;and want to enable fog when i push 'F'. but, i found it didn't work. my .fx is:
technique Fog
{
    pass P0
    {
        pixelshader      = null;
        vertexshader     = null;
        FogVertexMode = LINEAR; 
        FogStart      = 50.0f; 
        FogEnd        = 300.0f; 
        FogColor      = 0x00CCCCCC; 
        FogEnable     = false;       
    }
}
and the c++ code is:
Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00CCCCCC, 1.0f, 0);
		Device->BeginScene();

		// set the technique to use
		FogEffect->SetTechnique( FogTechHandle );

		UINT numPasses = 0;
    	FogEffect->Begin(&numPasses, 0);

		D3DXMATRIX I;
		D3DXMatrixIdentity(&I);
		for(int i = 0; i < numPasses; i++)
		{
			FogEffect->BeginPass(i);

			if( TheTerrain )
				TheTerrain->draw(&I, false);
		}
		FogEffect->End();

		if( ::GetAsyncKeyState('F') & 0x8000f )
		{
			Device->SetRenderState(D3DRS_FOGENABLE, true);

			Device->SetRenderState( D3DRS_FOGSTART, 50.0f );
			Device->SetRenderState( D3DRS_FOGEND, 300.0f );
			Device->SetRenderState( D3DRS_FOGCOLOR, 0x00ffCCCC );
			Device->SetRenderState( D3DRS_FOGTABLEMODE ,  D3DFOG_LINEAR);
		}

		Device->EndScene();

		Device->Present(0, 0, 0, 0);
so, why it doesn't work. thanks a lot

Share this post


Link to post
Share on other sites
Advertisement
When you call FogEffect->BeginPass(0), the ID3DXEffect interface calls IDirect3DDevice9::SetRenderState and sets the fog states according to what you have in the effect file. This means it will override the render states you're setting later, after you've drawn everything.

You'll have to either...

a) Set the render state after you call BeginPass and before you render your terrain. You'll also have to do it every frame, since every time you call BeginPass the effect will set things as they are in the technique

b) Make 2 techniques, one with fog and one without. Then pick the technique you want based on user input. This, IMO, is more ideal than a).

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
When you call FogEffect->BeginPass(0), the ID3DXEffect interface calls IDirect3DDevice9::SetRenderState and sets the fog states according to what you have in the effect file. This means it will override the render states you're setting later, after you've drawn everything.

You'll have to either...

a) Set the render state after you call BeginPass and before you render your terrain. You'll also have to do it every frame, since every time you call BeginPass the effect will set things as they are in the technique

b) Make 2 techniques, one with fog and one without. Then pick the technique you want based on user input. This, IMO, is more ideal than a).


if i beginpass at first, will it override the render states later? i found if i disable the fog in the pass, later i enable it by SetRenderState, the somethings i draw out shader is effected by fog.

Share this post


Link to post
Share on other sites
Quote:
Original post by huaner
Quote:
Original post by MJP
When you call FogEffect->BeginPass(0), the ID3DXEffect interface calls IDirect3DDevice9::SetRenderState and sets the fog states according to what you have in the effect file. This means it will override the render states you're setting later, after you've drawn everything.

You'll have to either...

a) Set the render state after you call BeginPass and before you render your terrain. You'll also have to do it every frame, since every time you call BeginPass the effect will set things as they are in the technique

b) Make 2 techniques, one with fog and one without. Then pick the technique you want based on user input. This, IMO, is more ideal than a).


if i beginpass at first, will it override the render states later? i found if i disable the fog in the pass, later i enable it by SetRenderState, the somethings i draw out shader is effected by fog.


ID3DXEffect will always set render states in BeginPass. If you're confused about the order in which things are occurring, go ahead and capture a frame in PIX and look at the order in which SetRenderState calls occur.

Share this post


Link to post
Share on other sites
Some people don't know, but you can use parameters to set render states in the fx file:


bool g_enableFog = false;

technique MyTec {
pass P0
{
pixelshader = null;
vertexshader = null;
FogVertexMode = LINEAR;
FogStart = 50.0f;
FogEnd = 300.0f;
FogColor = 0x00CCCCCC;
FogEnable = g_enableFog; // assign value of parameter
}
}


In your app you can now control the render state by setting the parameter:


// grab a handle to the parameter
D3DXHANDLE enableFogHandle = fx->GetParameterByName("g_enableFog");

// to enable fog
fx->SetBool(enableFogHandle, true);
// to disable fog
fx->SetBool(enableFogHandle, false);


I really like this method of setting render states as it fits perfectly in the way I handle other parameters. No need to create a different technique or pass render states to the device directly!

You can control all render states and sampler state settings with parameters (makes it easy to e.g. control texture filtering from the app).

Regards,
Andre

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
Quote:
Original post by huaner
Quote:
Original post by MJP
When you call FogEffect->BeginPass(0), the ID3DXEffect interface calls IDirect3DDevice9::SetRenderState and sets the fog states according to what you have in the effect file. This means it will override the render states you're setting later, after you've drawn everything.

You'll have to either...

a) Set the render state after you call BeginPass and before you render your terrain. You'll also have to do it every frame, since every time you call BeginPass the effect will set things as they are in the technique

b) Make 2 techniques, one with fog and one without. Then pick the technique you want based on user input. This, IMO, is more ideal than a).


if i beginpass at first, will it override the render states later? i found if i disable the fog in the pass, later i enable it by SetRenderState, the somethings i draw out shader is effected by fog.


ID3DXEffect will always set render states in BeginPass. If you're confused about the order in which things are occurring, go ahead and capture a frame in PIX and look at the order in which SetRenderState calls occur.


thank your for your reply. i also confused that i enable the fog in pass 0; after endpass(0), i just use SetRenderState to enable fog, my intention just next rendering is effected by fog and not rendering by pass(0).
the renderstate can be changed by different pass; so, i think, why i end a pass,
its also effected by later?
thanks a lot!

Share this post


Link to post
Share on other sites
Quote:

You can control all render states and sampler state settings with parameters (makes it easy to e.g. control texture filtering from the app).

At first, thanks for your reply. i try this method befor, but failed. my pass is:
Quote:

pass P0
{
Sampler[0] = (LayerMap0Sampler);
Sampler[1] = (BlendMapSampler);
vertexShader = compile vs_2_0 Terrain_MultiTexVS();
pixelShader = compile ps_2_0 Terrain_MultiTexPS1();


FogEnable = bEnableFog;
FogStart = g_FogStart;
FogEnd = g_FogEnd;
FogColor = g_FogColor;
}

and transforming fog parameter by:
Quote:

//set fog start
D3DXHANDLE FogStartHandle = g_pEffect->GetParameterByName(0, "g_FogStart");
g_pEffect->SetFloat(FogStartHandle, 300.0f);

//set fog end
D3DXHANDLE FogEndHandle = g_pEffect->GetParameterByName(0, "g_FogEnd");
g_pEffect->SetFloat(FogEndHandle, 3000.0f);

//set fog color
D3DXVECTOR4 colorfog = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
D3DXHANDLE FogColorHandle = g_pEffect->GetParameterByName(0, "g_FogColor");
g_pEffect->SetVector(FogColorHandle, &colorfog);

it can't work:(

Share this post


Link to post
Share on other sites
Quote:

// grab a handle to the parameter
D3DXHANDLE enableFogHandle = fx->GetParameterByName("g_enableFog");
// to enable fog
fx->SetBool(enableFogHandle, true);
// to disable fog
fx->SetBool(enableFogHandle, false);


i just hava another question that confused. i just used SetValue as follow:

bool fogenable = true;
g_pEffect->SetValue("bEnableFog", &fogenable, sizeof(bool));

this also didn't work. why?

Share this post


Link to post
Share on other sites
Quote:
Original post by huaner
pass P0
{
Sampler[0] = (LayerMap0Sampler);
Sampler[1] = (BlendMapSampler);
vertexShader = compile vs_2_0 Terrain_MultiTexVS();
pixelShader = compile ps_2_0 Terrain_MultiTexPS1();


FogEnable = bEnableFog;
FogStart = g_FogStart;
FogEnd = g_FogEnd;
FogColor = g_FogColor;
}

Try:
FogEnable = (bEnableFog);
FogStart = (g_FogStart);
FogEnd = (g_FogEnd);
FogColor = (g_FogColor);

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!