<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      怎么在3D場景中加入Fog

      [摘要]在3D場景中加入Fog(霧化效果)能增加真實感,產生縱深感和距離感,也可以用來營造氣氛;或者使景物產生朦朧的感覺。Direct3D支持兩種霧化模式——pixel fog 和 vertex fog 。...
          在3D場景中加入Fog(霧化效果)能增加真實感,產生縱深感和距離感,也可以用來營造氣氛;或者使景物產生朦朧的感覺。Direct3D支持兩種霧化模式——pixel fog 和 vertex fog 。

          Fog的使用相當簡單。只需要設置好幾個參數就可以。

      首先設置是否啟用Fog效果:
          g_pDevice->SetRenderState(D3DRS_FOGENABLE, TRUE);
      接著判斷Fog的顏色:
          g_pDevice->SetRenderState(D3DRS_FOGCOLOR, 0x0f0f0f);

      然后判斷要使用的Fog的公式模式,Fog的公式模式有三種——D3DFOG_LINEAR 、D3DFOG_EXP、D3DFOG_EXP2

      1.如果使用D3DFOG_LINEAR模式,就要設置起用Fog的深度的開始值D3DRS_FOGSTART和結束值D3DRS_FOGEND
          pd3dDevice8->SetRenderState(D3DRS_FOGSTART, *((DWORD*) (&fFogStart)));
          pd3dDevice8->SetRenderState(D3DRS_FOGEND, *((DWORD*) (&fFogEnd)));

      2.如果使用非D3DFOG_LINEAR模式,就要設置Fog的濃度
          g_pDevice->SetRenderState(D3DRS_FOGDENSITY, *(DWORD *)(&Density));

      個人感覺Pixel Fog更容易實現和控制一些
      下面給出一個Pixel Fog的例子

      float Start = 0.5f, // For linear mode
      End = 0.8f,
      Density = 0.66; // For exponential modes
      DWORD Mode = D3DFOG_EXP;//你也可嘗試著設置 Mode = D3DFOG_LINEAR;

      // Enable fog blending.
      g_pDevice->SetRenderState(D3DRS_FOGENABLE, TRUE);

      // Set the fog color.
      g_pDevice->SetRenderState(D3DRS_FOGCOLOR, 0x0f0fff);

      // Set fog parameters.
      if(D3DFOG_LINEAR == Mode)
      {
          g_pDevice->SetRenderState(D3DRS_FOGTABLEMODE, Mode);
          g_pDevice->SetRenderState(D3DRS_FOGSTART, *(DWORD *)(&Start));
          g_pDevice->SetRenderState(D3DRS_FOGEND, *(DWORD *)(&End));
      }
      else
      {
          g_pDevice->SetRenderState(D3DRS_FOGTABLEMODE, Mode);
          g_pDevice->SetRenderState(D3DRS_FOGDENSITY, *(DWORD *)(&Density));
      }


      日韩精品一区二区三区高清