New Terrain Early Shots

A place to show off your latest screenshots and for people to comment on them. Only start a new thread here if you have some nice images to show off!
Post Reply
User avatar
aguru
Goblin
Posts: 236
Joined: Tue Feb 26, 2008 5:48 pm
x 3

Re: New Terrain Early Shots

Post by aguru »

oki :) *crawls back into corner*
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Re: New Terrain Early Shots

Post by sinbad »

The lightmap isn't generated from dynamic lights because it's not dynamic. You need to call TerrainGlobalOptions::setLightMapDirection. This just looks like a simple case of having your dynamic directional facing one way and TerrainGlobalOptions::setLightMapDirection facing the other.

The dynamic lighting / shading on the terrain does pick up the light because it's a dynamic calculation at render time, the lightmap is not. They're separate so you can control them the way they actually get built.

And don't bother trying to use any other light than a directional light for the dynamic elements, only directional lights are supported right now. You're welcome to set up your own TerrainMaterialGenerator that does something else of course.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: New Terrain Early Shots

Post by jacmoe »

Yep. That's what I'm doing.
Until I figure out how to generate those texture maps, I'll just use the dual diffuse texture trick. :wink:
Or turn off all lights.

<edit>I know that its a diffuse map with specular in the alpha channel, and a normal map with heightmap in the alpha.
I guess I just need to read up on the nvDxt command-line syntax.</edit>
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Re: New Terrain Early Shots

Post by sinbad »

jacmoe wrote:Yep. That's what I'm doing.
Until I figure out how to generate those texture maps, I'll just use the dual diffuse texture trick. :wink:
Or turn off all lights.
Honestly I don't think you are setting the lightmap and dynamic dir light correctly. Or, maybe you're doing it at the wrong time (e.g. after you've created the terrain and didn't dirty the lightmap). I've played with lots of different directional setups and they're fine. I've also seen an effect like that and it's always when I change one without changing the other.
[edit]Unless by "that's what I'm doing" you were referring to making your own TerrainMaterialGenerator, in which case it's not my problem ;)

To make a diffuse/spec, normal/height image, use Image::loadTwoImagesAsRGBA or Image::combineTwoImagesAsRGBA and save the results for future use. That's how I created the textures for the demo.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: New Terrain Early Shots

Post by jacmoe »

This is what I am doing now:

Code: Select all

TerrainPage::TerrainPage(Ogre::SceneManager* sceneMgr)
{ 
	bool loadTerrain = false;

	Ogre::Vector3 lightdir(0, -0.3, 0.75);
	lightdir.normalise();
	Ogre::Light* l = sceneMgr->createLight("tstLight");
	l->setType(Ogre::Light::LT_DIRECTIONAL);
	l->setDirection(lightdir);
	l->setDiffuseColour(Ogre::ColourValue(1.0, 1.0, 1.0));
	l->setSpecularColour(Ogre::ColourValue(0.4, 0.4, 0.4));
	sceneMgr->setAmbientLight(Ogre::ColourValue(0.6, 0.6, 0.6));

	Ogre::TerrainGlobalOptions::setMaxPixelError(8);
	Ogre::TerrainGlobalOptions::setCompositeMapDistance(2000);
	Ogre::TerrainGlobalOptions::setLightMapDirection(lightdir);
	Ogre::TerrainGlobalOptions::setCompositeMapAmbient(sceneMgr->getAmbientLight());
	Ogre::TerrainGlobalOptions::setCompositeMapDiffuse(l->getDiffuseColour());

	mTerrain = OGRE_NEW Ogre::Terrain(sceneMgr);
	if(loadTerrain)
	{
		mTerrain->load("terrain.dat");
	}
	else
	{
		Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource("demoraw.raw", "General" );
		size_t size = stream.get()->size();
		if(size != 1025 * 1025 * 4)
		{
			OGRE_EXCEPT( Ogre::Exception::ERR_INTERNAL_ERROR, "Size of stream does not match terrainsize!", "TerrainPage" );
		}
		float* buffer = OGRE_ALLOC_T(float, size, Ogre::MEMCATEGORY_GENERAL);
		stream->read(buffer, size);

		Ogre::Terrain::ImportData imp;
		imp.terrainSize = 1025;
		imp.worldSize = 1024;
		imp.inputFloat = buffer;
		imp.minBatchSize = 33;
		imp.maxBatchSize = 65;

		// textures
		imp.layerList.resize(4);
		imp.layerList[0].textureNames.push_back("gras_diffuse_specular.tga");
		imp.layerList[0].textureNames.push_back("gras_normal_height.tga");
		imp.layerList[0].worldSize = 30;
		imp.layerList[1].textureNames.push_back("ground01.jpg");
		imp.layerList[1].textureNames.push_back("ground01.jpg");
		imp.layerList[1].worldSize = 30;
		imp.layerList[2].textureNames.push_back("schlamm_getrocknet2.jpg");
		imp.layerList[2].textureNames.push_back("schlamm_getrocknet2.jpg");
		imp.layerList[2].worldSize = 30;
		imp.layerList[3].textureNames.push_back("Boulder_Rocky_01_COL.dds");
		imp.layerList[3].textureNames.push_back("Boulder_Rocky_01_COL.dds");
		imp.layerList[3].worldSize = 20;

		mTerrain->prepare(imp);
		mTerrain->load();

		Ogre::String blendImages[4];
		blendImages[0] = "gras_00000_00000_000.PNG";
		blendImages[1] = "ground01_00000_00000_000.PNG";
		blendImages[2] = "schlamm_getrocknet2_00000_00000_000.PNG";
		blendImages[3] = "moos2_00000_00000_000.PNG";

		for(int j = 1;j < mTerrain->getLayerCount();j++)
		{
			Ogre::TerrainLayerBlendMap *blendmap = mTerrain->getLayerBlendMap(j);
			Ogre::Image img;
			img.load(blendImages[j],"General");
			int blendmapsize = mTerrain->getLayerBlendMapSize();
			if(img.getWidth() != blendmapsize)
				img.resize(blendmapsize, blendmapsize);

			float *ptr = blendmap->getBlendPointer();
			Ogre::uint8 *data = static_cast<Ogre::uint8*>(img.getPixelBox().data);

			for(int bp = 0;bp < blendmapsize * blendmapsize;bp++)
				ptr[bp] = static_cast<float>(data[bp]) / 255.0f;

			blendmap->dirty();
			blendmap->update();
		}

		mTerrain->freeTemporaryResources();

	}

	mTerrain->setPosition(Ogre::Vector3(512,0,512));
}
As you can probably see, I've converted the first texture to using a proper diffuse_specular, normal_heightmap, but the rest of the images are duplicated (because then the artifact doesn't show, but it obviously doesn't look good).

I create a new TerrainPage from the standard createScene function:

Code: Select all

	mSceneMgr->setSkyDome(true, "Examples/CloudySky");

	mCamera->setPosition(91.5022f, 49.8703f, 680.376f);

	if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(Ogre::RSC_INFINITE_FAR_PLANE))
    {
        mCamera->setFarClipDistance(0);   // enable infinite far clip distance if we can
    }

	mTerrainPage = new TerrainPage(mSceneMgr);
Setting a skydome, setting the position of the camera, adjusting the farclip distance and creating the terrain.
No additional stuff, no other lights than the directional.
I tried to copy the terrain sample as closely as I could. :wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Re: New Terrain Early Shots

Post by sinbad »

Code: Select all

   if(loadTerrain)
   {
      mTerrain->load("terrain.dat");
   }
There's your problem, probably. You're loading the terrain data if it exists, which includes a copy of the lightmap as calculated when it was saved. If you change the light direction from that, it'll be invalid and you'll need to tell it to regenerate the lightmap.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Re: New Terrain Early Shots

Post by sinbad »

I'm finding in the current version the lightmap calculation seems to be aborting early when generating terrain from an image and the dynamic update doesn't work anymore. I have no idea when this started happening, I'll look when I get time. Still, the bits that are updated are correct, including using your light direction.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: New Terrain Early Shots

Post by jacmoe »

<edit>I saw your in-between reply just now - the problem I had can be solved by providing the full set of textures. So I need to study texture tools, which I needed to study anyway, eventually.</edit>

What I discovered was: without light, everything's fine. With just the diffuse textures.
With light, the lightmap is barfed.
I can prevent it from barfing by providing a proper set of all four maps: diffuse, specular, normal and height.
Or I can just duplicate the diffuse, but then without the desired effect.
Diffuse maps alone won't cut it. At least not on my NVIDIA GeForce 8500 GT - not the best card around.
So, I need to look into that.
Then I can write a 'how-do-I-use-this-new-Ogre-terrain' tutorial. :wink:
So, I am deliberately trying to stay as close to a known good configuration here, obviously.
The saved terrain data file loads alright. It was just a separate test, which I probably should have edited out of my posted code to prevent any confusion.

The directional light doesn't change at all. It's copied directly from the sample. :)

I believed that any missing texture 'channels' would be handled by the terrain component, but it seems to be true only for unlit terrain.

<edit>But it seems that you're on the issue. No rush - I've found a work around</edit>
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: New Terrain Early Shots

Post by jacmoe »

Alright.
Here's one way to generate those textures:

1) Get ShaderMap CL from http://www.shadermap.renderingsystems.com/
2) Create a bat file with the following contents:

Code: Select all

CD "C:\Program Files\ShaderMap CL 1.2.2"

START /WAIT shadermap.exe cdiff "<texture_directory>\<texture_name>" -disp (60,100,12,xy) -norm (100,200,xy,0) -spec (100,-50,52,xy) -v 
Replace the directory and texture name with what you want to generate maps for.

3) Generate the maps by running the bat script, once for each texture.

4) Use the following code to combine the images:

Code: Select all

	Ogre::Image combined;

	combined.loadTwoImagesAsRGBA("moos1.jpg", "moos1_SPEC.bmp", 
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::PF_BYTE_RGBA);
	combined.save("moos1_diffusespecular.png");

	combined.loadTwoImagesAsRGBA("moos1_NORM.tga", "moos1_DISP.bmp", 
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::PF_BYTE_RGBA);
	combined.save("moos1_normalheight.png");
5) Get the nVidida texture tools (DDS Utilities) and convert the output textures to dds.

6) Done. :wink:

Thanks to Sinbad for leaving that image combine code in the playpen.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: New Terrain Early Shots

Post by jacmoe »

This is how it looks with proper textures:
screenshot01222010_124616722.jpg
screenshot01222010_124616722.jpg (147.01 KiB) Viewed 17381 times
If I had any artistic skill, it would look better.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: New Terrain Early Shots

Post by jacmoe »

Using the default material generator, we have a limit of 6 layers?
That's 6 textures we can blend? (if we're not using a global colour map, which we don't when splatting)
Or, am I missing anything?

Code: Select all

	uint8 TerrainMaterialGeneratorA::SM2Profile::getMaxLayers(const Terrain* terrain) const
	{
		// count the texture units free
		uint8 freeTextureUnits = 16;
		// lightmap
		--freeTextureUnits;
		// normalmap
		--freeTextureUnits;
		// colourmap
		if (terrain->getGlobalColourMapEnabled())
			--freeTextureUnits;
		// TODO shadowmaps

		// each layer needs 2.25 units (1xdiffusespec, 1xnormalheight, 0.25xblend)
		return static_cast<uint8>(freeTextureUnits / 2.25f);
}
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: New Terrain Early Shots

Post by jacmoe »

Is this per terrain page?
So you can actually have 6 different layers for a different page?
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Re: New Terrain Early Shots

Post by sinbad »

I use PixPlant to create my textures. It uses Ogre :)

The limit on the number of layers depends on what other features you use, but it's a base of 6. Adding a colour map and 3xPSSM can reduce this to 5.

And yes, those 5/6 can be different per page. Only the declaration is shared between pages, the textures that fill the slots can be different. (well, actually you can have different declarations & material generators per page if you want too, it's just simpler not to)
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: New Terrain Early Shots

Post by jacmoe »

Great, thanks! :)

So, if I wanted to overcome this limit, I'd have to create a new multi-pass material generator, right?
And suffer the performance hit, of course.

But, all in all: this new terrain component is far less of a head ache to setup and use than ye olde terrain scenemanager.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: New Terrain Early Shots

Post by jacmoe »

sinbad wrote:I'm finding in the current version the lightmap calculation seems to be aborting early when generating terrain from an image and the dynamic update doesn't work anymore. I have no idea when this started happening, I'll look when I get time. Still, the bits that are updated are correct, including using your light direction.
Oh, I see that too now, after updating to newest revision.
Could have spared myself the trouble of making those fancy textures - it looks flat as if I've used only diffuse maps.
At least I am ready for it when it's fixed. :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: New Terrain Early Shots

Post by jacmoe »

You're probably not interested, but here it is anyway:

Really quick screenshot from when the terrain is loaded:
screenshot01222010_214413145.jpg
screenshot01222010_214413145.jpg (102.78 KiB) Viewed 17268 times
Less than a second later:
screenshot01222010_214414645.jpg
screenshot01222010_214414645.jpg (65.7 KiB) Viewed 17268 times
First screenshot is with normal height and specular, but the second one is flat.
So, something happens. But it seems to bail out extremely quickly.

<edit>
Interestingly, when I save the terrain and load it, the terrain is lit and the diffuse_specular, normal_height textures are rendered correctly.
No lightmap, though. I think I can live with that for the time being. :wink:
</edit>
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Re: New Terrain Early Shots

Post by sinbad »

That's probably just the lightmap calculation failing for some reason and darkening everything. I will investigate why soon. My examples look fine, they just don't update the lightmap dynamically correctly, I don't know what broke this yet. I'm working on other issues for now but it's on my list.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Re: New Terrain Early Shots

Post by sinbad »

Lightmap generation is fixed now (bug was introduced in something as innocuous as fixing warnings, but the location of some casts was wrong).
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: New Terrain Early Shots

Post by jacmoe »

Yes, that fixed it! :D
Thanks a lot.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
stealth977
Gnoll
Posts: 638
Joined: Mon Dec 15, 2008 6:14 pm
Location: Istanbul, Turkey
x 42

Re: New Terrain Early Shots

Post by stealth977 »

Just a small complaint. When a Terrain Instance is unloaded and deleted, if i create another Terrain instance, it crashes due to a problem in OgreTerainQuadTreeNode::load(), couldnt really track what causes it.

using OGRE trunk ( 1.8 )

ismail,
Ismail TARIM
Ogitor - Ogre Scene Editor
WWW:http://www.ogitor.org
Repository: https://bitbucket.org/ogitor
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67
Contact:

Re: New Terrain Early Shots

Post by sinbad »

I'll need a repro case, TerrainGroup does exactly this when being used for paging and I don't get this problem. Make sure you updated to the latest too since I fixed some issues.
James Proctor
Orc
Posts: 406
Joined: Fri May 16, 2008 7:33 pm
x 5

Re: New Terrain Early Shots

Post by James Proctor »

Here are some screenshots from a Procedural Terrain Engine I am working on for a MMO Engine using the new Terrain system:
Attachments
Terrain1.jpg
Terrain1.jpg (151.26 KiB) Viewed 16618 times
Terrain6.jpg
Terrain6.jpg (203.24 KiB) Viewed 16618 times
Terrain7.jpg
Terrain7.jpg (157.17 KiB) Viewed 16618 times
Follow me on Twitter - https://twitter.com/EmpireGames
Follow my Blog on Blogger - http://empiredevelopment.blogspot.com/
rubasurex
Gnoblar
Posts: 15
Joined: Mon Aug 25, 2008 4:08 pm

Re: New Terrain Early Shots

Post by rubasurex »

I was just playing with the terrain sample and I moved the tudor houses around a bit. I noticed a couple of things.

Firstly, the colour shadows appear to project two sets of shadows in opposite directions. The each house has two shadows protruding opposite from one another.

Secondly, with the depth shadows, I noticed that the houses shadow the terrain, themselves and each other, however the terrain shadow never effects the houses. If I place a house in the shadow of a large hill, the house stays fully lit. I understand that the terrain is using a lightmap, which obviously only effects itself. However I was thinking that perhaps with depth shadows, the terrain could cast a shadow that could affect the houses? Is this possible or are there technical or performance limitations to this?
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: New Terrain Early Shots

Post by jacmoe »

rubasurex wrote:I was just playing with the terrain sample and I moved the tudor houses around a bit. I noticed a couple of things.

Firstly, the colour shadows appear to project two sets of shadows in opposite directions. The each house has two shadows protruding opposite from one another.
Unless you're working off the current Ogre 1.7 svn branch, chances are that it's fixed. :)
So update first.
rubasurex wrote:Secondly, with the depth shadows, I noticed that the houses shadow the terrain, themselves and each other, however the terrain shadow never effects the houses. If I place a house in the shadow of a large hill, the house stays fully lit. I understand that the terrain is using a lightmap, which obviously only effects itself. However I was thinking that perhaps with depth shadows, the terrain could cast a shadow that could affect the houses? Is this possible or are there technical or performance limitations to this?
The houses (anything) needs to be added to the shadow queue for pre-processing, as I understand it.
Check out the terrain sample, and the playpen.cpp in Ogre/tests.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
rubasurex
Gnoblar
Posts: 15
Joined: Mon Aug 25, 2008 4:08 pm

Re: New Terrain Early Shots

Post by rubasurex »

jacmoe wrote:Unless you're working off the current Ogre 1.7 svn branch, chances are that it's fixed. :)
So update first.
I tried it with the bleeding edge 1.7 svn... updated just before trying it.
jacmoe wrote:Check out the terrain sample, and the playpen.cpp in Ogre/tests.
I was trying it in the terrain sample. It appears as though the terrain sample only uses depth shadow mapping for the houses. The terrain itself still uses a lightmap by the looks of it (I could be wrong), which explains why the terrain shadow doesn't affect the houses. I'm just wondering if there is any reason why the terrain doesn't also use depth shadows to cast on to the houses?
Post Reply