|
|
I use the pixel fog in fixed pipeline and the result is correct.(the code as below)
- // Enable fog blending.
- m_pD3DDevice->SetRenderState(D3DRS_FOGENABLE, TRUE);
- // Set the fog color.
- m_pD3DDevice->SetRenderState(D3DRS_FOGCOLOR, pFog->GetColor());
- m_pD3DDevice->SetRenderState(D3DRS_FOGTABLEMODE, (DWORD)pFog->GetMode());
- float fStart=(float)pFog->GetStart();
- float fEnd=(float)pFog->GetEnd();
- float fDensity=(float)pFog->GetDensity();
- // Set fog parameters.
- if( pFog->GetMode() == ENUM_FOG_MODE_LINEAR )
- {
- m_pD3DDevice->SetRenderState(D3DRS_FOGSTART, *(DWORD *)(&fStart));
- m_pD3DDevice->SetRenderState(D3DRS_FOGEND, *(DWORD *)(&fEnd));
- }
- else
- {
- m_pD3DDevice->SetRenderState(D3DRS_FOGDENSITY, *(DWORD *)(&fDensity));
- }
复制代码
But when I apply the pixel fog code into a model with shader(partial submeshes have effect instance), the result is incorrect. So I render the model with shader(include the submeshes without effect instance, I use a default effect file to render them). I define the effect state(pixel fog) into the technique as below:
- technique tech01
- {
- pass pass01
- {
- VertexShader=compile vs_2_0 VS();
- FogEnable=true;
- FogTableMode=UIConst_FogType;//int
- FogStart=UIConst_FogStart;//float
- FogEnd=UIConst_FogEnd;//float
- FogDensity=UIConst_FogDensity;//float
- FogColor=0xFF0000FF;
- PixelShader=compile ps_3_0 PS();
- }
- }
复制代码
But the result still the same with the previous result only using fixed pipeline.
How do I define the effect state to get the correct result of pixel fog?
or I must use the vertex and pixel shader to calculate each pixel with fog? |
|