Caelum - [WARNING: Screenshot intensive]

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
User avatar
cdleonard
Goblin
Posts: 266
Joined: Thu May 31, 2007 9:45 am

Post by cdleonard »

Vectrex wrote:got a time problem with the latest svn.
Seems in the demo getJulianSecond doesn't ever change but getJulianSecondDifference works fine.
getJulianDayDifference and getJulianDay seem to work ok.
Am I missing something?
Julian second would be defined as the number of seconds since 4713 BC. I don't really think that number is useful to you. If you're using DirectX with fast floats you'll get precission issues as mentioned before. I switched precission inside getJulianSecond just like inside getJulianDay and it should work now; but the result is not useful.

I was not aware of these precission issues when I first tried adding astronomy code. It would probably be much better to keep time relative to J2000 instead; which gives much more manageable values. You would still get a precission hit with directx though.
User avatar
sjcomp
Gnome
Posts: 315
Joined: Sat Apr 23, 2005 2:35 pm
Location: Dover, NH
Contact:

Post by sjcomp »

Hello,

If a computer can not support cloud material, there is an exception thrown (Layered cloud material not supported). And caelum can not be used at all. Maybe it's a better to disable the cloud layer if it's not supported, but let the application continue?

Thanks.
Regards, Alexander. http://sjcomp.com
User avatar
cdleonard
Goblin
Posts: 266
Joined: Thu May 31, 2007 9:45 am

Post by cdleonard »

Big news: Caelum now has moon! Go "svn up" latest trunk and see how it looks like.

Features:
- Billboard for drawing.
- Phases using a cg shader.
- Mostly correct blending with other sky layers (stars, skydome and clouds).
- New moon will hide stars behind it
- Fades in and out at sunset and sunrise.
- Astronomically correct moon position.
- Fake phase calculations.
- Directional light source.

Implemented by Mihail Baesu (no forum account). We have a commercial project using Caelum which needed moon support; and here you go :)
User avatar
trilobite
Silver Sponsor
Silver Sponsor
Posts: 135
Joined: Thu Jul 13, 2006 9:16 pm
Location: San Juan Capistrano, CA, USA
x 1

Post by trilobite »

That sounds so cool.
I will be updating all my libraries this week... including the essential "Caelum." I can't wait to see what it looks like.

Thanks for all your creativity and hard work, cdleonard.
User avatar
triton
Greenskin
Posts: 138
Joined: Thu Mar 13, 2008 10:25 pm
Location: Portugal

Post by triton »

Screenshots please? :P
User avatar
cdleonard
Goblin
Posts: 266
Joined: Thu May 31, 2007 9:45 am

Post by cdleonard »

Ok; I solved several issues with the moon (mostly tiny bugs and compatibility issues). I also made the demo start at a time when the moon is visible (just rotate the camera, it should be there). Also, since the moon can sometimes be hard to spot I made the 'M' key direct the camera towards the moon.

Here are some screenshots (it's been a while):

Image Image
Image Image

Anyone know how I can make phpbb display multiple images per row?
[Edit by Kencho]Not using newlines after inserting them :)
Last edited by cdleonard on Mon May 05, 2008 4:29 pm, edited 2 times in total.
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

It's beautiful, thanks a lot for this contribution!
Image
Thor22
Kobold
Posts: 29
Joined: Tue Apr 10, 2007 12:31 pm

Post by Thor22 »

Woaw it's look very impressive, very nice contribution !
Image
Trosan
Greenskin
Posts: 101
Joined: Sun Jun 10, 2007 4:57 pm
x 1

Post by Trosan »

Out of curiosity. I have not taken a look at the code yet - but perhaps you can tell me if it is built in a modular way so that one could perhaps easily add a second moon as well? (for games set in a world with more than one moon)
User avatar
cdleonard
Goblin
Posts: 266
Joined: Thu May 31, 2007 9:45 am

Post by cdleonard »

Trosan wrote:Out of curiosity. I have not taken a look at the code yet - but perhaps you can tell me if it is built in a modular way so that one could perhaps easily add a second moon as well? (for games set in a world with more than one moon)
You can reuse the Moon class and the shader, but you'd have to write your own CaelumSystem class to wire everything up. The same goes for multiple suns. The astronomy code would be useless as well, and that part can't be generalized. There are lots of motion perturbations which are specific to the earth-sun-moon system.
User avatar
trilobite
Silver Sponsor
Silver Sponsor
Posts: 135
Joined: Thu Jul 13, 2006 9:16 pm
Location: San Juan Capistrano, CA, USA
x 1

Post by trilobite »

Stunning!
User avatar
trilobite
Silver Sponsor
Silver Sponsor
Posts: 135
Joined: Thu Jul 13, 2006 9:16 pm
Location: San Juan Capistrano, CA, USA
x 1

Post by trilobite »

A couple of problems with the current trunk:
1. Sun and stars rotating on different axes and in different angular directions.
Image

2. Moon not displaying. I can't find it. Resources seem to be present and loading as expected.

Code: Select all

void pbVoyageLegSurfaceScene::CreateCaelumSky()
{
	//	Pick components to create
	//	You can comment any of those and it should still work
	//	It makes little sense to comment the first three.
	caelum::CaelumSystem::CaelumComponent componentMask = 
		static_cast<caelum::CaelumSystem::CaelumComponent> (
		caelum::CaelumSystem::CAELUM_COMPONENT_SKY_COLOUR_MODEL |
		caelum::CaelumSystem::CAELUM_COMPONENT_SUN |				
		caelum::CaelumSystem::CAELUM_COMPONENT_SOLAR_SYSTEM_MODEL |
		caelum::CaelumSystem::CAELUM_COMPONENT_MOON |
		caelum::CaelumSystem::CAELUM_COMPONENT_SKY_DOME |
		caelum::CaelumSystem::CAELUM_COMPONENT_STARFIELD |
		caelum::CaelumSystem::CAELUM_COMPONENT_CLOUDS |
		0);

	// Initialise Caelum
	m_pCaelumSystem = new caelum::CaelumSystem (Ogre::Root::getSingletonPtr(), m_pSurfaceSceneMgr, componentMask);

	m_pCaelumSystem->setManageSceneFog(true);
	m_pCaelumSystem->setSceneFogDensityMultiplier(0.000015);

	// Setup sun options
	if (m_pCaelumSystem->getSun ()) 
	{
		m_pCaelumSystem->getSun ()->setAmbientMultiplier (Ogre::ColourValue(0.5, 0.5, 0.5));
		m_pCaelumSystem->getSun ()->setDiffuseMultiplier (Ogre::ColourValue(3, 3, 2.7));
		m_pCaelumSystem->getSun ()->setSpecularMultiplier (Ogre::ColourValue(5, 5, 5));
		m_pCaelumSystem->getSun ()->setManageAmbientLight (true);
	}

	// Setup fog options.
	if (m_pCaelumSystem->getGroundFog()) 
	{
		m_pCaelumSystem->getGroundFog()->findFogPassesByName();
	}

	//	Setup haze options (must be manually updated in framelistener)
	if (m_pCaelumSystem->getSkyDome ()) 
	{
		m_pCaelumSystem->getSkyDome ()->setHazeEnabled (true);
	}

	// Setup cloud options.
	// Tweak these settings to make the demo look pretty.
	if (m_pCaelumSystem->getClouds ()) 
	{
		m_pCaelumSystem->getClouds ()->setCloudSpeed(Ogre::Vector2(0.000005, -0.000009));
		m_pCaelumSystem->getClouds ()->setCloudBlendTime(3600 * 24);
		m_pCaelumSystem->getClouds ()->setCloudCover(0.3);
	}

	// Setup starfield options
	if (m_pCaelumSystem->getStarfield ()) 
	{
		m_pCaelumSystem->getStarfield ()->setInclination (Degree (13));
	}

	// Set time acceleration.
	m_pCaelumSystem->getUniversalClock ()->setTimeScale (512);

	m_pCaelumSystem->getUniversalClock ()->setGregorianDateTime (2007, 4, 9, 23, 33, 0);
	m_pCaelumSystem->getSolarSystemModel ()->setObserverLongitude (Ogre::Degree(45));
	m_pCaelumSystem->getSolarSystemModel ()->setObserverLatitude (Ogre::Degree(45));

	// Register caelum to the render target
	m_pWindow->addListener (m_pCaelumSystem);
	pb::pbOgreMgr::getSingleton().GetOgreRoot()->addFrameListener (m_pCaelumSystem);
}
Any ideas? Thanks.
User avatar
cdleonard
Goblin
Posts: 266
Joined: Thu May 31, 2007 9:45 am

Post by cdleonard »

trilobite wrote:A couple of problems with the current trunk:
1. Sun and stars rotating on different axes and in different angular directions.
I think you can change the axis on which the stars are rotating; but they're far from astronomically correct. The right way to implement stars would be as a billboardset with azimtuh/altitude and aparent magnitude for each star. Oh well.
trilobite wrote:2. Moon not displaying. I can't find it. Resources seem to be present and loading as expected.
Does it should up in the demo (press M to focus the camera on it). The moon is supposed to be invisible during the day; and a new moon is basically a black circle over the stars and which can be hard to spot.
User avatar
trilobite
Silver Sponsor
Silver Sponsor
Posts: 135
Joined: Thu Jul 13, 2006 9:16 pm
Location: San Juan Capistrano, CA, USA
x 1

Post by trilobite »

So are you saying that the rotation of the starfield dome is not included in the sun movement calcs?

I was able to see the moon in the sample and in my app. Very cool. Incidentally, the moon should be visible during daytime.

I'll take a look at these problems and report back if I find out anything useful.
Cobra8472
Halfling
Posts: 83
Joined: Thu Jun 02, 2005 4:44 pm

Post by Cobra8472 »

I still cant figure out how I could get the proper position of the sun in Vector3 format.


Anyone?
User avatar
Xavyiy
OGRE Expert User
OGRE Expert User
Posts: 847
Joined: Tue Apr 12, 2005 2:35 pm
Location: Albacete - Spain
x 87

Post by Xavyiy »

Cobra8472 wrote:I still cant figure out how I could get the proper position of the sun in Vector3 format.


Anyone?
Ogre::Vector3 SunPosition = CameraPosition - CaelumLightDirection*CaelumSunRadius;

Doesn't work it?

Xavi
User avatar
trilobite
Silver Sponsor
Silver Sponsor
Posts: 135
Joined: Thu Jul 13, 2006 9:16 pm
Location: San Juan Capistrano, CA, USA
x 1

Post by trilobite »

Try these two hacks to get the starfield movement to closely match the sun/moon movement:
1. in Starfield.cpp
in void Starfield::update (const float time)
modified code as follows:

Code: Select all

// commented out by trilobite	orientation = orientation * Ogre::Quaternion (Ogre::Radian (time * 2 * Ogre::Math::PI), Ogre::Vector3::UNIT_Y);
//	revised by trilobite. modified code by placing minus sign in front of time var
	orientation = orientation * Ogre::Quaternion (Ogre::Radian (-time * 2 * Ogre::Math::PI), Ogre::Vector3::UNIT_Y);
2. In CaelumTest1.h
in CaelumSampleFrameListener(RenderWindow* win, Camera* cam): ExampleFrameListener(win, cam)
modified code to set inclination to match Earth's axial tilt. Notice the value is negative.

Code: Select all

        // Setup starfield options
        if (mCaelumSystem->getStarfield ()) {
		//	commented out by trilobite   mCaelumSystem->getStarfield ()->setInclination (Degree (13));
	    //	revised by trilobite    
			mCaelumSystem->getStarfield ()->setInclination (Degree (-23.4));
		//	end revised by trilobite
As I said, these are hacks and may not produce useful results if the observer lat. and long. change or at different times of the orbital year. If not, then perhaps these hacks will give clues leading to a permanent fix. :)
User avatar
Eugene
OGRE Team Member
OGRE Team Member
Posts: 185
Joined: Mon Mar 24, 2008 4:54 pm
Location: Kraków, Poland
x 41

Post by Eugene »

Moon must be visible on day sky, and probably share render queue with sun, as it is expensive resource.
User avatar
trilobite
Silver Sponsor
Silver Sponsor
Posts: 135
Joined: Thu Jul 13, 2006 9:16 pm
Location: San Juan Capistrano, CA, USA
x 1

Post by trilobite »

Eugene wrote:Moon must be visible on day sky, and probably share render queue with sun, as it is expensive resource.
Yes, the moon should be visible day and night. And it should be a source of light as well. cdleonard? Kencho? What do you think about this?

I'll fiddle with it today and see what I can come up with...
User avatar
cdleonard
Goblin
Posts: 266
Joined: Thu May 31, 2007 9:45 am

Post by cdleonard »

trilobite wrote:
Eugene wrote:Moon must be visible on day sky, and probably share render queue with sun, as it is expensive resource.
Yes, the moon should be visible day and night. And it should be a source of light as well. cdleonard? Kencho? What do you think about this?
The moon is already a faint, directional lightsource with constant intensity. Moonlight intensity should depend on the phase of the moon. It should also probably be brighter at night to account for a different dynamic range in the scene. Right now a full moon at night has the same intensity as a new moon at noon; which is probably bad.

Blending is a bit more complicated. The skydome (the blue thing which accounts for sunlight scattering) is alpha-blended with the background. It has a low alpha in the dark parts and a high alpha in the bright parts. This is how stars fade in and out in the evening/morning; the alpha of the skydome drops from 1 to 0.

The moon fades in and out just like the stars do; using the skydome's alpha. This works a lot better that expected and looks very pretty, but does not account for the fact that the moon is much brighter than the stars. The moon and stars always fade in and out together. I'm not exactly sure how to fix this. Maybe alpha in the framebuffer could be used as some sort of "additional brightness"?

There's nothing wrong with drawing the skydome after the moon; in real-life atmospheric scattering is indeed "in front" of the moon. It is also "in front" of the sun. The physically correct draw order would be stars, sun, moon, and skydome; with additive blending for the skydome. Unfortunately this requires HDR and has to be faked with alpha-blending instead.
trilobite wrote:I'll fiddle with it today and see what I can come up with...
All ideas and improvements are welcome.
Vectrex
Ogre Magi
Posts: 1266
Joined: Tue Aug 12, 2003 1:53 am
Location: Melbourne, Australia
x 1
Contact:

Post by Vectrex »

do the sun and moon's light sources turn off when they go beyond the horizon?
User avatar
cdleonard
Goblin
Posts: 266
Joined: Thu May 31, 2007 9:45 am

Post by cdleonard »

Vectrex wrote:do the sun and moon's light sources turn off when they go beyond the horizon?
No; but they should. The sun goes really really dark though :D. It would be nice to implement it automatically inside BaseSkyLight by turning off the light if it's too dark anyway.
User avatar
trilobite
Silver Sponsor
Silver Sponsor
Posts: 135
Joined: Thu Jul 13, 2006 9:16 pm
Location: San Juan Capistrano, CA, USA
x 1

Post by trilobite »

cdleonard wrote:
Vectrex wrote:do the sun and moon's light sources turn off when they go beyond the horizon?
No; but they should. The sun goes really really dark though :D. It would be nice to implement it automatically inside BaseSkyLight by turning off the light if it's too dark anyway.
I happen to be working on that very feature right now... along with a bunch of other things. One of the main reasons to turn off the sun or the moon is that they still throw shadows and illuminate the scene even if they are below the horizon.

I will be proposing many new "control and customization" variables and functions in the next day or so. I am really drilling down into Caelum, trying to make it as customizable as possible -- for my needs. Hopefully, these proposed additions will be acceptable to others as well. Not touching ANY of the hard calcs.

One of the things I am doing is replacing existing literal constant values (like 2.0, or 1.5) that exist here and there in the code, with variables that can be adjusted by the user through new APIs.

Should I just post changes here? Or is there a better way to do it?
User avatar
cdleonard
Goblin
Posts: 266
Joined: Thu May 31, 2007 9:45 am

Post by cdleonard »

trilobite wrote:One of the things I am doing is replacing existing literal constant values (like 2.0, or 1.5) that exist here and there in the code, with variables that can be adjusted by the user through new APIs.

Should I just post changes here? Or is there a better way to do it?
Posting (unified) diffs here is just fine.
User avatar
trilobite
Silver Sponsor
Silver Sponsor
Posts: 135
Joined: Thu Jul 13, 2006 9:16 pm
Location: San Juan Capistrano, CA, USA
x 1

Post by trilobite »

OK, here we go. Lots of PROPOSED changes. I will be submitting these proposed changes in several sequential posts here.

First, the biggest change has to do with moving ambient light management off of the SkyLight ant into CaelumSystem. The reason is that when there is a sun and a moon, BOTH are setting ambient light levels -- without regard to the other.

As a result, calls to the sun or moon to manage ambient light no longer exist (in these proposals), but must be made to CaelumSystem.

These changes all came about as I was trying to get better control over shadows and ambient light settings.

SKYLIGHT.H
in the Attributes "protected" section

Code: Select all

//	begin commenting out by trilobite 5-5-08	
//	NOTE: ambient light management has been moved to CaelumSystem
		/// If true then this class also manages ambient lighting.
//		bool mManageAmbientLight;
//	end commenting out by trilobite

//	begin added by trilobite 5-5-08

		/** Factor to establish minimum sunlight/moonlight light levels.
		 *	In "setMainLightColour(...)," this factor is used to compare against the sum of the R G and B channels
		 *	of the main light colour. If this sum is less than mSkyLightShutoffMinimum,
		 *	then this Skylight is set to invisible -- which eliminates its influence
		 *	in the scene.
         */
		Ogre::Real		mSkyLightShutoffMinimum;
//	end adds by trilobite
in Methods "public:"

Code: Select all

//	begin commenting out by trilobite 5-5-08
//	NOTE: ambient light management has been shifted to CaelumSystem
//	There, it manages transitions between bright/dark/sunny/moony ambient regimes.
//	This new system replaces the existing method in which each skylight (sun and moon)
//	independently sets scene ambient light -- without regard to each other.
//		/// This can make this class manage the ambient light of the scene.
//		void setManageAmbientLight (bool manage);
//
//		/// If the class is managing the scene's ambient light.
//		bool isManagingAmbientLight () const;
//
//	end commenting out by trilobite
and

Code: Select all

//	begin added by trilobite 5-5-08
	
		/**	Sets an initial value with which to compare the main light's current
		  *	diffuse colour composite (r+g+b). In setMainLightColour(...), if
		  *	the composite value is < this shutoff minimum, then the light is 
		  * set to invisible -- removing its influence on the scene.
		  */
		void	setInitialSkyLightShutoffMinimum(const Ogre::Real rMinimum);
		
		/**	gets the initial skylight shutoff minimum value
		*/		
		Ogre::Real	getInitialSkyLightShutoffMinimum();

//	end add by trilobite
SKYLIGHT.CPP in BaseSkyLight::BaseSkyLight (...) constructor

Code: Select all

//	begin commenting out by trilobite 5-5-08
//	mManageAmbientLight = false;
//	end commenting out by trilobite

	//	begin add by trilobite 5-5-08
	mSkyLightShutoffMinimum = 0.09;
	//	end adds by trilobite
a new void BaseSkyLight::setMainLightColour (...)

Code: Select all

/* commented out by trilobite 5-5-08
void BaseSkyLight::setMainLightColour (const Ogre::ColourValue &colour) {
	// Set light colours.
	mMainLight->setDiffuseColour (colour * mDiffuseMultiplier);
	mMainLight->setSpecularColour (colour * mSpecularMultiplier);
	if (isManagingAmbientLight()) {
		mScene->setAmbientLight(colour * mAmbientMultiplier);
	}
}
*/	
//	end commented out by trilobite

//	revised by trilobite 5-5-08
void BaseSkyLight::setMainLightColour (const Ogre::ColourValue &colour) 
{
	// first, set light colours.
	mMainLight->setDiffuseColour (colour * mDiffuseMultiplier);
	mMainLight->setSpecularColour (colour * mSpecularMultiplier);

	//	second, adjust ambient light settings if necessary
	//	get numbers we can use for testing ambient light intensity

	//	get a composite light intensity value
	Ogre::ColourValue	tempColour(colour);
	Ogre::Real	rColourSum = tempColour.r + tempColour.g + tempColour.b;

	//	avoid divide-by-zero errors
	if (rColourSum <= 0.0)
	{
		tempColour.r = tempColour.g = tempColour.b = 0.001;
		rColourSum = tempColour.r + tempColour.g + tempColour.b;
	}

	//	third, shutoff this light if really dim
	//	update to find the ultimate minimum value for this skylight
	if (rColourSum < (mSkyLightShutoffMinimum))
		mSkyLightShutoffMinimum = rColourSum;
	
	//	turn this light off if it is within 10 percent of its minimum
	if (rColourSum < (mSkyLightShutoffMinimum * 1.10))
		mMainLight->setVisible(false);
	else
		mMainLight->setVisible(true);
}
//	end revised by trilobite
commenting out two functions

Code: Select all

//	begin comment out by trilobite 5-5-08
//	NOTE: ambient light management has moved to CaelumSystem
//	void BaseSkyLight::setManageAmbientLight (bool manage) {
//	mManageAmbientLight = manage;
//	}
//
//bool BaseSkyLight::isManagingAmbientLight () const {
//	return mManageAmbientLight;
//}
//	end comment out by trilobite
added two new functions

Code: Select all

//	begin added by trilobite 5-5-08
void	BaseSkyLight::setInitialSkyLightShutoffMinimum(const Ogre::Real rMinimum)
{
	mSkyLightShutoffMinimum = rMinimum;
}


Ogre::Real	BaseSkyLight::getInitialSkyLightShutoffMinimum()
{
	return mSkyLightShutoffMinimum;
}

//	end add by trilobite
}
More to follow... CaelumSystem and Starfield
Post Reply