Simple cloud layer SceneNode

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Post by Klunk »

very nice, work indeed, a couple things you could try adding. I couldn't really tell if your doing it already but we used to stretch the uvs as they get towards the horizon making the clouds smaller and looking more distant. Another thing you could try is using vertex alpha at the horizon of your object it blends the cloud into the horizon nicely and may solve the clouds looking out of scale when the pass in front of the mountains. This may involve adding an extra line of verts and custom shaders as I'm not that keyed up on irrlicht materials.

edit: if you do go down the custom shader path another trick, especially with those kind of cloud textures, is to use a fake "bloom" to the clouds using (if the cloud object origin is 0,0,0) dot(lightpos, vertpos) as the basis.
tbw
Posts: 59
Joined: Sat Jan 15, 2011 9:51 am
Location: Germany

Re: Simple cloud layer SceneNode

Post by tbw »

Thank you for your very useful tips.
Indeed in my project I combine the cloudscene node with a sun scene node, which produces a nice bloom effect if the whole scene is prepared with postprocessing. Regarding the blending of the clouds with the skybox I use ONE_TEXTURE_BLEND material:

Code: Select all

Material.MaterialType = video::EMT_ONETEXTURE_BLEND;
Material.MaterialTypeParam = video::pack_texureBlendFunc( 
                video::EBF_SRC_ALPHA, 
                video::EBF_ONE_MINUS_SRC_ALPHA,
                video::EMFN_MODULATE_1X, 
                video::EAS_TEXTURE | video::EAS_VERTEX_COLOR); 
This material comines the alpha channel of the texture with the vertex alpha. So you only have to place the cloudlayer in the right height by using the the method:

Code: Select all

setCloudHeight(f32 centerHeight, f32 innerHeight, f32 outerHeight) 
the vertex colors are set by

Code: Select all

setCloudColor(const video::SColor& centerColor, const video::SColor& innerColor, const video::SColor& outerColor)
Playing around with this two functions should lead to acceptable reults.

The stretching of the uvs is a really good idea! I will try this out!
Thanks again!
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Simple cloud layer SceneNode

Post by Granyte »

What could cause cloud layer not to show while the code still compile fine
jorgerosa
Competition winner
Posts: 117
Joined: Wed Jun 30, 2010 8:44 am
Location: Portugal
Contact:

Re: Simple cloud layer SceneNode

Post by jorgerosa »

Thanks for share this, this is really great stuff!

Everything works fine, but only if i comment these lines:

Code: Select all

// cloudLayer1->setTranslation(core::vector2d<f32>(0.008f, 0.0f));    // set translation (speed of the clouds)
// cloudLayer2->setTranslation(core::vector2d<f32>(0.006f, 0.003f));  // set translation (speed of the clouds)
// cloudLayer3->setTranslation(core::vector2d<f32>(0.006f, 0.003f));  // set translation (speed of the clouds)
Then, all the code runs ok, but the clouds layers have no movement, of course.

if I uncomment above lines, CODE::BLOCKS returns:
error: no matching function for call to 'irr::scene::CCloudSceneNode::setTranslation(irr::core::vector2d<float>)'

I cheched the class, there is:

Code: Select all

void CCloudSceneNode::setTranslation(core::vector2d<f32>& translation)
{
        // set the translation
        Translation = translation;
}
So... everything should work fine... what am i missing?.... (I´m using IRRLICHT V.1.7.2 and OpenGl 3.3.0, just in case...)
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Simple cloud layer SceneNode

Post by serengeor »

jorgerosa wrote:Thanks for share this, this is really great stuff!

Everything works fine, but only if i comment these lines:

Code: Select all

// cloudLayer1->setTranslation(core::vector2d<f32>(0.008f, 0.0f));    // set translation (speed of the clouds)
// cloudLayer2->setTranslation(core::vector2d<f32>(0.006f, 0.003f));  // set translation (speed of the clouds)
// cloudLayer3->setTranslation(core::vector2d<f32>(0.006f, 0.003f));  // set translation (speed of the clouds)
Then, all the code runs ok, but the clouds layers have no movement, of course.

if I uncomment above lines, CODE::BLOCKS returns:
error: no matching function for call to 'irr::scene::CCloudSceneNode::setTranslation(irr::core::vector2d<float>)'

I cheched the class, there is:

Code: Select all

void CCloudSceneNode::setTranslation(core::vector2d<f32>& translation)
{
        // set the translation
        Translation = translation;
}
So... everything should work fine... what am i missing?.... (I´m using IRRLICHT V.1.7.2 and OpenGl 3.3.0, just in case...)
Try defining the vector2d variable before function and pass it to it.
Working on game: Marrbles (Currently stopped).
jorgerosa
Competition winner
Posts: 117
Joined: Wed Jun 30, 2010 8:44 am
Location: Portugal
Contact:

Re: Simple cloud layer SceneNode

Post by jorgerosa »

serengeor wrote:Try defining the vector2d variable before function and pass it to it.
Worked like a charm! Thanks serengeor! Im still wondering why... but works!... :)
Here is the solution, might help someone else, too:

Code: Select all

cloudLayer1 = new scene::CCloudSceneNode(smgr->getRootSceneNode(), smgr);
core::vector2d<f32> xx = vector2d<f32>(0.008f, 0.0f);
cloudLayer1->setTranslation(xx); // set translation (speed of the clouds)
cobra
Posts: 371
Joined: Fri Jan 23, 2009 2:56 am
Location: United States
Contact:

Re: Simple cloud layer SceneNode

Post by cobra »

@jorgerosa

Changing:

Code: Select all

void CCloudSceneNode::setTranslation(core::vector2d<f32>& translation)
to:

Code: Select all

void CCloudSceneNode::setTranslation(const core::vector2d<f32>& translation)
Would be the best solution. It should be that way anyway.
Josiah Hartzell
Image
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Simple cloud layer SceneNode

Post by serengeor »

cobra wrote:@jorgerosa

Changing:

Code: Select all

void CCloudSceneNode::setTranslation(core::vector2d<f32>& translation)
to:

Code: Select all

void CCloudSceneNode::setTranslation(const core::vector2d<f32>& translation)
Would be the best solution. It should be that way anyway.
Yeah, I also wondered why it's not like that :)
Working on game: Marrbles (Currently stopped).
mecio
Posts: 9
Joined: Sun Aug 14, 2011 11:14 am

Re: Simple cloud layer SceneNode

Post by mecio »

What is wrong?

Code: Select all

#include "CloudSceneNode.h"
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
...
...
 
CCloudSceneNode* cloudLayer1 = new CCloudSceneNode(smgr->getRootSceneNode(), smgr);
core::vector2d<f32> xx = vector2d<f32>(0.008f, 0.0f);
cloudLayer1->setTranslation(xx);
cloudLayer1->getMaterial(0).setTexture(0, driver->getTexture("media/clouds/cloud01.png"));
cloudLayer1->setCloudHeight(0.5f, 0.1f, -0.05f);
I get this error.

Code: Select all

undefined reference to `irr::scene::CCloudSceneNode::CCloudSceneNode(irr::scene::ISceneNode*, irr::scene::ISceneManager*, int)'|
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Simple cloud layer SceneNode

Post by serengeor »

mecio wrote: I get this error.

Code: Select all

undefined reference to `irr::scene::CCloudSceneNode::CCloudSceneNode(irr::scene::ISceneNode*, irr::scene::ISceneManager*, int)'|
Add .cpp file into your project that contains the function.
Working on game: Marrbles (Currently stopped).
mecio
Posts: 9
Joined: Sun Aug 14, 2011 11:14 am

Re: Simple cloud layer SceneNode

Post by mecio »

I have it already but when i hanged

Code: Select all

    void CCloudSceneNode::setTranslation(core::vector2d<f32>& translation)
to

Code: Select all

    void CCloudSceneNode::setTranslation(const core::vector2d<f32>& translation)
message disappeared :shock:
tbw
Posts: 59
Joined: Sat Jan 15, 2011 9:51 am
Location: Germany

Re: Simple cloud layer SceneNode

Post by tbw »

Code: Select all

void CCloudSceneNode::setTranslation(const core::vector2d<f32>& translation)
is correct. (MS compiler does not care about it). I will change it a soon as possible and I will re-upload the source/example!

Thank you for the hint!
eagletree
Posts: 28
Joined: Mon Jul 26, 2010 11:55 pm

Re: Simple cloud layer SceneNode

Post by eagletree »

This scenenode is excellent. Thanks for the good work.

I loaded it on a couple of Macs now and it works as well there as on Windows, just needed the declaration of the vector2df as on Linux. No other scenenode I've tried has worked on the Mac out of the box (though I've only used a few from here so far).

Thanks again.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Simple cloud layer SceneNode

Post by randomMesh »

This is very nice indeed, thank you for sharing.

I got a few notes:
  • 1. The demo code linked in the first post still doesn't compile out of the box. You need to apply the changes cobra suggested.
    2. You got a memory leak in the demo. You don't drop the CCloudSceneNodes after usage.
    3. Every time a c++ programmer uses #define, God kills a kitten. Use a static const irr::u32 to save them!
    4. Fix your includes! Instead of including the complete Irrlicht library, only include the needed headers (to reduce compile time).
CloudSceneNode.h:

Code: Select all

 
#include <ISceneNode.h>
#include <S3DVertex.h>
 
CloudSceneNode.cpp:

Code: Select all

 
#include "CloudSceneNode.h"
#include <ISceneManager.h>
#include <ICameraSceneNode.h>
#include <IVideoDriver.h>
 
"Whoops..."
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Simple cloud layer SceneNode

Post by hendu »

@randomMesh

If you compile irr apps often, create a precompiled header for irrlicht.h; works much better than hand-tuning headers in every file ;)
Post Reply