Fog

Problems building or running the engine, queries about how to use features etc.
Post Reply
CrosRoad95
Kobold
Posts: 27
Joined: Fri Mar 27, 2020 5:32 pm

Fog

Post by CrosRoad95 »

Ogre Version: : 2.3
Operating System: : Windows
Render System: : Directx11

How can i add fog? tested method "setFog" with different arguments
Tried to use it https://github.com/cryham/ogre23demo/co ... 0b7581e20b but it doesn't calculate distance properly so fog is always same color.

Checkout ogre-next source code for examples and only ones were with "setFog" method,

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Fog

Post by dark_sylinc »

Hi!

Fog was added very recently (literally a month ago) in Ogre-Next 3.0 (currently 'master' branch).

There were various community solutions for earlier versions.

Note that Ogre-Next 2.3 & 3.0 are currently highly compatible (as long as you were using C++11 or newer) so you can easily switch to master if you have to.

Note: Due to being brand new, only Y-up convention has been tested. Although the API supports other conventions, they're likely not working correctly yet.

CrosRoad95
Kobold
Posts: 27
Joined: Fri Mar 27, 2020 5:32 pm

Re: Fog

Post by CrosRoad95 »

So i can safely switch to ogre 3.0? i use c++17

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Fog

Post by dark_sylinc »

In theory yes.

We are focusing more on stability and quality of life improvements rather than adding new features for this next release.

But of course make a backup first and try to port to the new version. Required changes should be minimal (off the top of my head, Ogre::Root added a new argument on creation to make it easier to detect common developer mistakes; fixing that compile error takes 3 minutes).

CrosRoad95
Kobold
Posts: 27
Joined: Fri Mar 27, 2020 5:32 pm

Re: Fog

Post by CrosRoad95 »

Can't see 3.0.0 release/tag, i have to download latest master branch instead?

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Fog

Post by dark_sylinc »

Yes. You'll have to build it yourself.

You can use the scripts for that which do it automatically for you.

CrosRoad95
Kobold
Posts: 27
Joined: Fri Mar 27, 2020 5:32 pm

Re: Fog

Post by CrosRoad95 »

Okey, i updated ogre to newest branch ( commit 60f890aa3fc055832caba35235a811a424f6eaed https://github.com/OGRECave/ogre-next/c ... a424f6eaed )

Copied ogre-next-master/Samples/Media folder and set ogre to use it.

Based on sample Samples/2.0/ApiUsage/Atmosphere i added:
m_pHlmsPbs->_setProperty(HlmsBaseProp::Fog, 1);
and
Ogre::ColourValue fadeColour(0.9, 0, 0);
m_pSceneManager->setFog(Ogre::FOG_EXP, fadeColour, 0.1, 1, 2);
( tried linear too )

And fog is completly not visible, not from even 1000 meters while it should be visible from very close
What am i missing?

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Fog

Post by dark_sylinc »

No. None of that.

Just do what the samples are doing:

Code: Select all

Ogre::AtmosphereNpr *atmosphere = OGRE_NEW Ogre::AtmosphereNpr( vaoManager );
Ogre::AtmosphereNpr::Preset preset = atmosphere->getPreset();
preset.fogDensity = fogDensity;
// These two I'll have to explain what they do; but basically it controls how much fog
// affects bright pixels. Because usually bright lights manage to get "through" fog
// This is more useful in HDR, but can also be used in LDR
// I recommend you 1st leave the defaults untouched; then start playing with it once you get fog working
preset.fogBreakMinBrightness = ...;
preset.fogBreakFalloff = ...;
atmosphere->setPreset( preset );

// Start optional
atmosphere->setSunDir(
    sunLight->getDirection(),
    std::asin( Ogre::Math::Clamp( -sunLight->getDirection().y, -1.0f, 1.0f ) ) /
        Ogre::Math::PI );
atmosphere->setLight( sunLight );
// End optional
atmosphere->setSky( mSceneManager, true );
CrosRoad95
Kobold
Posts: 27
Joined: Fri Mar 27, 2020 5:32 pm

Re: Fog

Post by CrosRoad95 »

I don't have idea how it works.
Added:

m_pAtmosphere = new AtmosphereNpr(m_pRenderSystem->getVaoManager());
AtmosphereNpr::Preset preset = m_pAtmosphere->getPreset();
preset.fogBreakMinBrightness = 0.05f;
preset.densityCoeff = 0.5f;
preset.fogDensity = 0.5f;
preset.time = 0.5f;
preset.skyColour = Vector3(1, 0, 0);

And i can't see any effect of that code. ( tested different properties, added only these you suggested and they did not work as well)

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Fog

Post by dark_sylinc »

Don't forget to call atmosphere->setSky( mSceneManager, true ); at the end.

CrosRoad95
Kobold
Posts: 27
Joined: Fri Mar 27, 2020 5:32 pm

Re: Fog

Post by CrosRoad95 »

@property( !hlms_shadowcaster || alpha_test )
@property( !hlms_shadowcaster )
@insertpiece( PassStructDecl )
@end
@insertpiece( MaterialStructDecl )
@insertpiece( InstanceStructDecl )
@insertpiece( AtmosphereNprSkyStructDecl ) // <= THIS LINE
@end

It almost working, issue i found is that AtmosphereNprSkyStructDecl isn't added.
I'm getting error: 100000001PixelShader_ps.hlsl(1193,42-53): error X3004: undeclared identifier 'atmoSettings'

Don't want to hack it by removing "hlms_shadowcaster" condition, so i'm asking, how can i make this check pass?

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Fog

Post by dark_sylinc »

Can you upload the generated shader dump so I can take a look? (i.e. 100000001VertexShader_vs & 100000001PixelShader_ps)
Thanks.

CrosRoad95
Kobold
Posts: 27
Joined: Fri Mar 27, 2020 5:32 pm

Re: Fog

Post by CrosRoad95 »

here's link to 100000001PixelShader_ps.hlsl

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Fog

Post by dark_sylinc »

It sounds like it's the wrong file? atmoSettings couldn't be found anywhere in it.

CrosRoad95
Kobold
Posts: 27
Joined: Fri Mar 27, 2020 5:32 pm

Re: Fog

Post by CrosRoad95 »

I'm using excact same media files as in newest main branch. added following locations and initialized them:
/Media/2.0/scripts/materials/Common/HLSL
/Media/2.0/scripts/materials/Common/Any
/Media/2.0/scripts/materials/Common
/Media/Hlms/Pbs/Any/Atmosphere

Here are all generated shaders:
heres ogre.log ( output from console ):

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Fog

Post by dark_sylinc »

The generated shaders suggests one or more of the following happened:

  • The files from Samples/Media/Hlms/Pbs/Any/Atmosphere were not copied over to your data folder

  • Ogre was compiled without OGRE_BUILD_COMPONENT_ATMOSPHERE (it should be on by default)

  • After calling HlmsPbs::getDefaultPaths, Hlms/Pbs/Any/Atmosphere is not part of the values in outLibraryFoldersPaths, for some reason

  • atmosphere->setSky( mSceneManager, true ); was not called

  • You're still directly calling m_pHlmsPbs->_setProperty(HlmsBaseProp::Fog, 1); which you shouldn't do.

Cheers

CrosRoad95
Kobold
Posts: 27
Joined: Fri Mar 27, 2020 5:32 pm

Re: Fog

Post by CrosRoad95 »

I was missing OGRE_BUILD_COMPONENT_ATMOSPHERE macro, now it's working! THANKS!

Post Reply