游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1583|回复: 0

pixel fog in shader code (DirectX 9)

[复制链接]

414

主题

611

帖子

621

积分

高级会员

Rank: 4

积分
621
发表于 2009-2-11 16:57:00 | 显示全部楼层 |阅读模式
I use the pixel fog in fixed pipeline and the result is correct.(the code as below)


  1.                 // Enable fog blending.
  2.                 m_pD3DDevice->SetRenderState(D3DRS_FOGENABLE, TRUE);

  3.                 // Set the fog color.
  4.                 m_pD3DDevice->SetRenderState(D3DRS_FOGCOLOR, pFog->GetColor());

  5.                 m_pD3DDevice->SetRenderState(D3DRS_FOGTABLEMODE, (DWORD)pFog->GetMode());

  6.                 float fStart=(float)pFog->GetStart();
  7.                 float fEnd=(float)pFog->GetEnd();
  8.                 float fDensity=(float)pFog->GetDensity();

  9.                 // Set fog parameters.
  10.                 if( pFog->GetMode() == ENUM_FOG_MODE_LINEAR )
  11.                 {
  12.                         m_pD3DDevice->SetRenderState(D3DRS_FOGSTART, *(DWORD *)(&fStart));
  13.                         m_pD3DDevice->SetRenderState(D3DRS_FOGEND,   *(DWORD *)(&fEnd));
  14.                 }
  15.                 else
  16.                 {
  17.                         m_pD3DDevice->SetRenderState(D3DRS_FOGDENSITY, *(DWORD *)(&fDensity));
  18.                 }
复制代码


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:


  1. technique tech01
  2. {
  3.     pass pass01
  4.     {
  5.         VertexShader=compile vs_2_0 VS();

  6.         FogEnable=true;
  7.         FogTableMode=UIConst_FogType;//int
  8.         FogStart=UIConst_FogStart;//float
  9.         FogEnd=UIConst_FogEnd;//float
  10.         FogDensity=UIConst_FogDensity;//float
  11.         FogColor=0xFF0000FF;

  12.         PixelShader=compile ps_3_0 PS();
  13.     }
  14. }
复制代码


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?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-20 08:42

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表