Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to enable Exponential Pixel Fog in DirectX 8.1

Status
Not open for further replies.

monzy

Programmer
Oct 1, 2002
2
IN
Background: To create a mini-solar system with the earth being orbited by satellites. This is the way I approached the problem:
(1) Used Shape Creation Function for Meshes namely D3DXCreateSphere to create the mesh containing a sphere
(2) Used D3DXCloneMeshFVF function to create a duplicate of the mesh with a new vertex format which contains elements for storing texture coordinates
(3) Applied a texture to the sphere

Problem: I wanted to use Exponential Pixel fog to create a foggy effect but I am unable to do so. I used the same code and followed the steps as provided in the SDK C++ Help. . All I get now is the sphere of the same color as I set in the D3DRS_FOGCOLOR and the bitmap is nowhere to be seen.

My doubts: (1) Should I enable pixel fog before or after the DrawSubset() function call to draw the mesh subset when I render the scene? (Both seem to produce the same effect. But what is the logically correct thing to do?)
(2) Why is the textured bitmap that I attached to the spherical mesh not visible when I use Exponential pixel fog?
(3) Could a possible reason for the fog effects not coming out as intended be : If the projection matrix isn't compliant with this requirement, fog effects are not applied properly. (MSDN) If so, how do I make a W-Friendly Projection Matrix??
I am quite unclear about how to do that and can’t seem to find any relevant information on the web.

Please tell me where I could be going wrong. Thanks in advance for your time.

Monzy
 
Hi there!
I am adding this bit of information to the background of the problem that I have provided above.
--I have used a Flexible Vertex Format or FVF for describing attributes of a vertex.
--Later, I set the vertex shader to our FVF by invoking the function SetVertexShader()

Just adding to the above list of doubts and perhaps rephrasing my question a little bit:
(a) MSDN states that <I> Pixel fog is not supported when using a vertex shader</I>
So does this mean that when we use our FVF we cannot use pixel fog and instead have to use vertex fog? If so, is there anyway we can in fact use pixel fog with a vertex shader or not?
(I know its stupid to ask such a question because I should be able to draw a conclusion from what is stated in black and white, but I ask because I want to reinforce my understanding.. that’s all :))
(b) I used vertex fog instead of pixel fog. Now, I am able to see the foggy effect on the the earth :) BUT :( the problem now is that I also see a small black sphere of about ¼ the radius of the original sphere object right in the middle as well as another black sphere of about 3/4th the radius of the original sphere also beneath the texture that I have attached as something like a shadow appearing in the view. The contours of the smaller sphere that appears does not have well-defined contours while the larger on does and appear to be black (D3DXCreateSphere creates a sphere of black color) and rotates in exactly the same way as the mesh that I have created.
 
Can you post your code?
I think maybe you fog density is too strong.
I've tried like this. And it works. Try to move you camera to and fro from the screen. And you'll see the effect.
According to my understanding, the &quot;start&quot; and &quot;end&quot; only have effect on linear fog while the &quot;density&quot; is only active on exp fog.

float Start = 10.0f, // Linear fog distances
End = 50.0f;

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

// Set the fog color.
g_pd3dDevice->SetRenderState(D3DRS_FOGCOLOR, 0x00000000);

// Set fog parameters.
int Mode = D3DFOG_LINEAR;
float Density = 0.02f;
if(D3DFOG_LINEAR == Mode)
{
g_pd3dDevice->SetRenderState(D3DRS_FOGVERTEXMODE, Mode);
g_pd3dDevice->SetRenderState(D3DRS_FOGSTART, *(DWORD *)(&Start));
g_pd3dDevice->SetRenderState(D3DRS_FOGEND, *(DWORD *)(&End));
}
else
{
g_pd3dDevice->SetRenderState(D3DRS_FOGVERTEXMODE, Mode);
g_pd3dDevice->SetRenderState(D3DRS_FOGDENSITY, *(DWORD *)(&Density));
}

// Enable range-based fog if desired (only supported for
// vertex fog). For this example, it is assumed that UseRange
// is set to a nonzero value only if the driver exposes the
// D3DPRASTERCAPS_FOGRANGE capability.
// Note: This is slightly more performance intensive
// than non-range-based fog.
if(1)
g_pd3dDevice->SetRenderState(
D3DRS_RANGEFOGENABLE,
TRUE);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top