# Fog Question

This topic is 4813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I created a linear fog in my application that doesn't work rigth...i implemented it so: device.SetRenderState(RenderStates.FogEnable, True) device.SetRenderState(RenderStates.FogColor, Color.ToArgb) If Mode = FogMode.Linear Then device.SetRenderState(RenderStates.FogTableMode, Mode) device.SetRenderState(RenderStates.FogStart, FogStart) device.SetRenderState(RenderStates.FogEnd, FogEnd) End If this actuly colors all the things i draw before in the fog color.Are any other PresenationParameters,..or device parameters that should be set before calling this?I tryed manny values for FogStart, and FogEnd but i see the same effect. Do i need to use Ligths in order this to work? P.S I understand c code :)) [Edited by - Zmax on September 12, 2005 7:04:04 AM]

##### Share on other sites
From what you've posted, it looks okay to me... although, your start/end values aren't included - which could be your issue [smile]

What sort of ranges are you using for your start/end values? The correct range depends on what type of fog you're using.

Have a read of Fog Parameters in the MSDN documentation if you haven't already. Make sure that what you're configuring matches up with what you're trying to achieve.

hth
Jack

##### Share on other sites
I used 0.5F for FogStart and 0.8F fog end,...tryed other valtues too.I think i have to set other parameters or i don't know. Al what i paint is painted in one single color(fog color) ...i don't know why.

##### Share on other sites
hi,

Be carefull about the fogstart and fogend. It's not between 0 and 1, it depends on you scene. If you have a terrain of 1000 unit width, you would use 500, 800 as fogstart and end.

Your problem seems to be that. Because with your values, everything farther than 0.8 units will be completely colored with the fog color.

##### Share on other sites
Quote:
 I used 0.5F for FogStart and 0.8F fog end,...tryed other valtues too

Quote:
 Original post by paicBe carefull about the fogstart and fogend. It's not between 0 and 1, it depends on you scene. If you have a terrain of 1000 unit width, you would use 500, 800 as fogstart and end.

If, for the mode you're using, fog is defined in world-coordinates then your 0.5-0.8 would fog pretty much all of the scene [smile] Maybe try increasing it to 50-80 or 500-800 (as appropriate for your draw distance).

hth
Jack

##### Share on other sites
Haha, i used those values too, 40..80,...anyway i tryed lots of start,end parameters.
How could i post a printscreen of the app, here on the forum?

This is the complete sub i'm using:

Private Sub CreatePixelFog(ByVal Clr As Color, ByVal Mode As FogMode)
Const FogStart = 80
Const FogEnd = 500
Const Density = 0.66F

device.SetRenderState(RenderStates.FogEnable, True)
device.SetRenderState(RenderStates.FogColor, Clr.ToArgb)
If Mode = FogMode.Linear Then
device.SetRenderState(RenderStates.FogTableMode, Mode)
device.SetRenderState(RenderStates.FogStart, FogStart)
device.SetRenderState(RenderStates.FogEnd, FogEnd)
Else
device.SetRenderState(RenderStates.FogTableMode, Mode)
device.SetRenderState(RenderStates.FogDensity, Density)
End If
End Sub
I'm using this rigth before the device.endscene,..and before i have the scene drawing,sets...i thought that i have to set something else...funky ligths? :))

##### Share on other sites
Quote:
 How could i post a printscreen of the app, here on the forum?

You have to find somewhere to host it, I forget the name of it - but theres one that a lot of people use (devimg?). Then you simply use the HTML <img src=".."> tags.

Anyway, back on topic...

I've got a feeling you might be hitting some type issues with your code. I used to do a lot of work with VB6, but no recent stuff with VB.Net (you're using MDX/.Net, right?).

Back in the good 'ol VB6 days we had to use a hack to feed in the correct value for the fog start/end - the native interfaces took a DWORD but it was assumed to be a float, so some binary magic was required to pack the 32bit float into a 32bit int. VB6 did it using a D3DXBuffer object iirc.

Maybe you need to check this angle out - make sure that the datatypes match up and so on (your FogStart and FogEnd are ambiguous). The native DX documentation has the correct cast/conversion fragment in the SetRenderState() documentation, maybe the MDX one has a similar fragment??

hth
Jack

##### Share on other sites
I'm having the opposite problem with my fog... If I specify the start/end from the range 0.0f - 1.0f, it works, but I get terrible resolution (if I want it out in the distance, I have to do start: 0.99f, end: 1.0f... I don't get much control over it).

When I try to enter the start/end in world coordinates, I simply get no fog at all. Does anyone know how to get the world coordinate fog working? I've tried literally everything =\ My perspective matrix IS Eye-W compliant (or whatever) as I'm using the D3DX function to generate it.

Are there some presentation parameters or SOMETHING that I could be missing?
Here's the code I'm using:

pd3dDevice->SetRenderState( D3DRS_FOGTABLEMODE, D3DFOG_LINEAR );pd3dDevice->SetRenderState( D3DRS_FOGSTART, FtoDW( 0.99f ) );pd3dDevice->SetRenderState( D3DRS_FOGEND, FtoDW( 1.0f ) );pd3dDevice->SetRenderState( D3DRS_FOGENABLE, true );

Thanks

##### Share on other sites
Look i succeded solving my problem(at the end of the day as usual :))
Here's the code that works excellent for me:

Private Sub CreatePixelFog(ByVal Clr As Color, ByVal Mode As FogMode)
Const FogStart = 0.0F
Const FogEnd = 800.0F
Const Density = 0.005F

device.RenderState.FogEnable = True
device.RenderState.FogColor = Clr
If Mode = FogMode.Linear Then

device.RenderState.FogVertexMode = Mode
device.RenderState.FogStart = FogStart
device.RenderState.FogEnd = FogEnd
Else
device.RenderState.FogVertexMode = Mode
device.RenderState.FogDensity = Density
End If
End Sub
hope you understand vb.net code :) if you want me to give a c code please ask :)

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
633346
• Total Posts
3011451
• ### Who's Online (See full list)

There are no registered users currently online

×