Thread: About rendering in a far point

  1. #1
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291

    About rendering in a far point

    Hello, I have a question about the glance's reach in a terrain rendering. I'm using DevC++-MingW and dx4devcpp libraries (from www.gamecoding.co.uk, it's DirectX 8).
    I have seen that on rendering a big terrain the objects rendered farest from the view point are not displayed (or maybe the objects rendered farest that x pixels from the view point are not diplayed); also I can see that when I move away the view point from the object it is 'undisplayed' gradually, so finally it disappears (it happens moving away over any of the axes).
    Let me attach some images to ilustrate that: on the first it's all right, on the second the 'terrace' starts to disappear on the left side, on the third is disappearing from both sides, and in the last one is only a 'triangle'.

    The display mode is set to 800x600, format D3DFMT_X8R8G8B8, RefreshRate 75; the backbuffer SwapEffect=D3DSWAPEFFECT_DISCARD, EnableAutoDepthStencil true, AutoDepthStencilFormat=D3DFMT_D16. The terrain is a 50x50 quadrants, each of 40x40, and it is rendered using an index buffer.

    My question is: what is that effect? or ¿where can I find info about it and solve that problem? I have downloaded de DirectX9 documentation, done an 'overlook', but I can't find anything about it (I'm not an usually english speaker/reader/writer, so maybe I missed something while reading the documentation).

    Thank's in advance
    Niara

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    look up D3DXMatrixPerspectiveFovLH(...), the last param is the far distance, e.g. everything after that point will be clipped (disappear), just set it higher

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    Hello X PaYnE X, thank's for your time and your help, that was exactly the thing. Now it seems for me a banal question (5 minutes ago it was a big problem); can see that I must read better the dx manual before do so basic questions in those usual functions (I think that is a usual function because I have used D3DXMatrixPerspectiveFovLH since the first triangle on the 'very beguiner's tutorial chapter 0' , and I never stopped to think about it).
    ending: thank's for your time and your help
    Niara

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    To eliminate those artifacts at the far clip plane, use pixel fog, range fog, or vertex fog.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    Hello Bubba, thank's for your time and help; I have already taked a look at the fog technique, but let me fight with it some days, I'll try to set it up in the terrain far borders.
    Does the fog spend more capacity than a far view? (althought using fog I can make more elegant terrains, I think).
    jbosch(vosk)

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Here is the fog technique in action.

    Here is the code that gets it done.

    Code:
    g_pDevice->SetRenderState(D3DRS_FOGENABLE,true);
      
      SkyColor=D3DCOLOR_XRGB(64,230,255);
      
      g_pDevice->SetRenderState(D3DRS_FOGCOLOR,SkyColor);
      g_pDevice->SetRenderState(D3DRS_FOGTABLEMODE,D3DFOG_LINEAR);
      
      float Start=700.0f;
      float End=800.0f;
    
      g_pDevice->SetRenderState(D3DRS_FOGSTART, *(DWORD *)(&Start));
      g_pDevice->SetRenderState(D3DRS_FOGEND,   *(DWORD *)(&End));
    Where Skycolor is a simple DWORD. Notice this effect really doesn't work well with my huge textured quads. It would work much better if I had a tiled set of quads because then the triangles would be smaller and thus the artifacts from the vertex shading would be much smaller.

    However Direct3D works much better with large quads than tons of small ones so I use them whenever possible. The only other solution to this is to use pixel shaders or vertex shaders to get the desired effect.

    I also have some code for volumetric fog and height fog - think of fog as in a mountain valley early in the morning.

    The fog in this screenshot is simple range-based pixel fog based on Direct3D's simple vertex lighting scheme.

    To change the interpolation factor to something that looks better change the distance between the start fog distance and the ending fog distance. The ending fog distance is the point at which the render will only show the fog color and nothing else. So think of it as the 'invisible point'. The start fog distance is when you begin to notice the fog.

    If you set the start fog distance to 1.0f and the end fog distance to 1000.0f, this would look like a really foggy day.

    I will post more screenies of fog if you need help.

    Set the type of fog with SetRenderState().
    Last edited by VirtualAce; 05-25-2005 at 04:15 PM.

  7. #7
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Here is another example:

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    And here is the same shot with fog start and fog end indicated.

  9. #9
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    Hello Bubba, nice shots. I had already setted up the fog effect and it works fine, but I have find a derived effect: on writing text with the DX DrawText() function it sets the text color to the fog color (only if D3DRS_FOGENABLE is TRUE). I haven't find any reference to that secondary effect on the DirectX Programer's Reference, so for the moment to avoid it I disable the fog effect (also works if I set the fog color to the text color), draw the text, and re-set the fog to it's original. A second way could be drawing 2D sprites from a charset map, but I think that maybe it would be slower (althought for the moment the game speed isn't the problem). Let me append two images: in the first I set up the linear fog (start 1.0f, end 2000.0f, red) and draw green text without disabling the fog; the result is that the text is auto setted to the fog color. On the second I set up the fog, disable before draw the text, and re-set the fog effect. The code I used to do it:
    Code:
    //setting up the fog
    float inici=1.0f;
    float final=2000.0f;
    g_pd3ddevice->SetRenderState(D3DRS_FOGENABLE,TRUE);
    g_pd3ddevice->SetRenderState(D3DRS_FOGCOLOR,D3DCOLOR_XRGB(255,0,0));
    g_pd3ddevice->SetRenderState(D3DRS_FOGVERTEXMODE,D3DFOG_LINEAR);
    g_pd3ddevice->SetRenderState(D3DRS_FOGSTART,*(DWORD*)(&inici));
    g_pd3ddevice->SetRenderState(D3DRS_FOGEND,*(DWORD*)(&final));
    Code:
    //creating the font
    LOGFONT LogFont={16,0,0,0,FW_NORMAL,false,false,false,DEFAULT_CHARSET,OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,PROOF_QUALITY,DEFAULT_PITCH,"Verdana"};
    D3DXCreateFontIndirect(g_pd3ddevice,&LogFont,&g_Font);
    //g_Font is a LPD3DXFONT
    Code:
    /*
    The draw text function from a call such like
    m_pTipog1->mostraTexte("the text",10,10,D3DCOLOR_XRGB(0,255,0));
    where m_pTipog1 is an object created with an HFONT created with the CreateFont() Win32 API standard function, and D3DXCreateFont(device,HFONT_last_created,LPD3DXFONT);
    That LPD3DXFONT is wich I'll use to draw the text
    */
    void CTipografia::mostraTexte(LPSTR tx,int x,int y,D3DCOLOR color)
    {
    RECT area;
    area.left=x;
    area.top=y;
    area.right=0;
    area.bottom=0;
    
    m_pTipog->Begin();
    g_pd3ddevice->SetRenderState(D3DRS_FOGENABLE,FALSE);
    m_pTipog->DrawTextA(tx,-1,&area,DT_CALCRECT,0);
    m_pTipog->DrawTextA(tx,-1,&area,DT_LEFT,color);
    g_pd3ddevice->SetRenderState(D3DRS_FOGENABLE,TRUE);
    m_pTipog->End();
    /*
    where m_pTipog is the LPD3DXFONT previously created
    */
    }
    I think I haven't forgot anything.
    Is that secondary fog effect normal and the disabling the fog before draw text a right solution?
    Thank's

    Niara

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why not use an = Operator instead of a Copy Constructor?
    By thetinman in forum C++ Programming
    Replies: 48
    Last Post: 10-15-2007, 03:58 PM
  2. trouble with overloaded operator
    By kkurz in forum C++ Programming
    Replies: 2
    Last Post: 10-31-2003, 12:59 PM
  3. floating point operators
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 10-22-2003, 07:53 PM
  4. fixed point / floating point
    By confuted in forum Game Programming
    Replies: 4
    Last Post: 08-13-2002, 01:25 PM