OGRE clipmaps terrain sample

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!
User avatar
Falagard
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2060
Joined: Thu Feb 26, 2004 12:11 am
Location: Toronto, Canada
x 3

Post by Falagard »

Thanks!
Lord LoriK
Goblin
Posts: 254
Joined: Tue Feb 13, 2007 5:33 am

Post by Lord LoriK »

Great! Just tested it... 523k triangles @ 105fps IS something nice...

I've seen something strange, though. Some triangles seem to 'pop' for a frame, giving a noticeable noise. Some images with the triangles marked:
Image
Image
Image
I ran it under Windows XP, both OpenGL and D3D performed equally. I have an NVidia 7300 card.

Somebody else has the same issue?
rotalever
Gnoblar
Posts: 21
Joined: Sun May 06, 2007 9:08 pm

Post by rotalever »

I've read the post and it looks like that only the algorithm for the terrain itself was made. No texturing, no compression. I've done the same, not in ogre, but in C and with a Cg-Vertex-Shader (only for geomorphing) some months ago. I was really fast (around 200fps with a 4097² terrain on a Geforce 6800GS).

I am very interested in having a version for ogre with texturing and the suggested compression scheme.

Is there anything going on right now, or is the project dead?
I would be interested in doing a plugin but I am not an expert in compression and have problems in understanding the paper of malvar. If someone makes a C++ function/class available which uses the PTC-Image Coder would be a great help. Another possibility would be to tile the terrain in blocks and use jpg to compress each of the blocks.

The other thing that must be done is applying textures. What would be a good technique? Texture Splatting through shaders? The Alpha maps must be as large as the terrain, how to store them? I want to store the whole terrain in memory because it's very small due to compression, but can the alpha maps be compressed in a similar way?
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

I found a directX implementation (with source) that I didn't know about of "GPU Geometry Clipmaps" on this site: http://filougk.blogspot.com/2007/03/gpu ... ource.html

Get the demo from here: http://www.box.net/shared/6kpclevjmo
And the latest code from here: http://www.box.net/shared/5tjxj2oq3i

There are some directX parts of it that I don't know how to translate to OGRE, it uses functions like "SetStreamSourceFreq" that the OGRE dx render system doesn't use – so it is not that easy to convert the project to OGRE.
Watch out for my OGRE related tweets here.
User avatar
Falagard
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2060
Joined: Thu Feb 26, 2004 12:11 am
Location: Toronto, Canada
x 3

Post by Falagard »

Hrm, SetStreamSourceFrequency I've seen used for shader instancing - the true instancing version that only requires you to have one mesh loaded instead of multiple in the same VB.

I'm guessing that this is used for the clipmaps because it's always the same quad with same number of verts, just repeated within the scene a whole bunch of times, so it could probably be done the old fashioned way by creating separate copies of the mesh in question.

Oh yeah, I've seen that demo before. Under the Cecil license, some french license that I think is more restricted than LGPL - closer to GPL.

And I'm sorry, but those controls are so awkward... wow.
User avatar
nonifier
Gnoblar
Posts: 13
Joined: Mon Jul 21, 2008 9:17 am
Location: Athis-Mons France

Post by nonifier »

Hi everybody !



Assaf & Tuan, what's a greate work you have done !!

It's been a while since the last post, so I'm wondering if your projects are still in progress ?

I'm also working on the Gpu implementation of the Geometry Clipmap, so I'm very intresting in your projects :)




Cheers !
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

Well, I only converted someone else's project to OGRE here.
I didn't continue on this.
You should look at the NVIDIA sdk for a newer code sample of this idea using DX10.
Watch out for my OGRE related tweets here.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Post by jacmoe »

Interestingly, someone put a clipmapterrain folder in my ogreaddons.. :)
/* 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 66

Post by sinbad »

Yep, hellcatv and shirsoft from Stanford have a project they're actively working on,so wanted an addon spot for it. I rarely say no to that kind of offer ;)
User avatar
bishopnator
Goblin
Posts: 299
Joined: Thu Apr 26, 2007 11:43 am
Location: Slovakia / Switzerland
x 11

Post by bishopnator »

There are some directX parts of it that I don't know how to translate to OGRE, it uses functions like "SetStreamSourceFreq" that the OGRE dx render system doesn't use – so it is not that easy to convert the project to OGRE.
I know that it is pretty old message from Assaf .. I am using SetStreamSourceFreq with DX render system in ogre for HW instancing - it's pretty easy to add support for that feature - I don't know if you need this.

You only need to modify ogre in 3 files:
1) OgreRenderOperation.h
add

Code: Select all

size_t				instancesCount; ///< use 0 for turn off instancing
and init it to 0 in c-tor

2) OgreSceneManager.cpp
in method SceneManager::renderSingleObject reset ro.instancesCount to 0 before calling const_cast<Renderable*>(rend)->getRenderOperation(ro); (little hack - better solution will be setup instancesCount in every getRenderOperation method)

3) OgreD3D9RenderSystem.cpp
turn-on HW instancing:

Code: Select all

		if(op.instancesCount > 0) {
			hr = mpD3DDevice->SetStreamSourceFreq(0, D3DSTREAMSOURCE_INDEXEDDATA | op.instancesCount);
			if(SUCCEEDED(hr)) {
				mpD3DDevice->SetStreamSourceFreq(1, D3DSTREAMSOURCE_INSTANCEDATA | 1);
			}
			if (FAILED(hr))
			{
				OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to setup geometry instancing", "D3D9RenderSystem::_render" );
			}
		}
turn-off HW instancing:

Code: Select all

		if(op.instancesCount > 0) {
			// finish instancing
			hr = mpD3DDevice->SetStreamSourceFreq(0, 1);
			if( SUCCEEDED( hr ) ) {
				mpD3DDevice->SetStreamSourceFreq(1, 1);
			}
			if (FAILED(hr))
			{
				OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to unbind geometry instancing", "D3D9RenderSystem::_render" );
			}
		}
Whole method:

Code: Select all

    //---------------------------------------------------------------------
    void D3D9RenderSystem::_render(const RenderOperation& op)
	{
        // Exit immediately if there is nothing to render
        // This caused a problem on FireGL 8800
        if (op.vertexData->vertexCount == 0)
            return;

        // Call super class
		RenderSystem::_render(op);

        // To think about: possibly remove setVertexDeclaration and 
        // setVertexBufferBinding from RenderSystem since the sequence is
        // a bit too D3D9-specific?
		setVertexDeclaration(op.vertexData->vertexDeclaration);
        setVertexBufferBinding(op.vertexData->vertexBufferBinding);

		// Determine rendering operation
		D3DPRIMITIVETYPE primType = D3DPT_TRIANGLELIST;
		DWORD primCount = 0;
        switch( op.operationType )
		{
        case RenderOperation::OT_POINT_LIST:
			primType = D3DPT_POINTLIST;
			primCount = (DWORD)(op.useIndexes ? op.indexData->indexCount : op.vertexData->vertexCount);
			break;

		case RenderOperation::OT_LINE_LIST:
			primType = D3DPT_LINELIST;
			primCount = (DWORD)(op.useIndexes ? op.indexData->indexCount : op.vertexData->vertexCount) / 2;
			break;

		case RenderOperation::OT_LINE_STRIP:
			primType = D3DPT_LINESTRIP;
			primCount = (DWORD)(op.useIndexes ? op.indexData->indexCount : op.vertexData->vertexCount) - 1;
			break;

		case RenderOperation::OT_TRIANGLE_LIST:
			primType = D3DPT_TRIANGLELIST;
			primCount = (DWORD)(op.useIndexes ? op.indexData->indexCount : op.vertexData->vertexCount) / 3;
			break;

		case RenderOperation::OT_TRIANGLE_STRIP:
			primType = D3DPT_TRIANGLESTRIP;
			primCount = (DWORD)(op.useIndexes ? op.indexData->indexCount : op.vertexData->vertexCount) - 2;
			break;

		case RenderOperation::OT_TRIANGLE_FAN:
			primType = D3DPT_TRIANGLEFAN;
			primCount = (DWORD)(op.useIndexes ? op.indexData->indexCount : op.vertexData->vertexCount) - 2;
			break;
		}

        if (!primCount)
			return;

		HRESULT hr;
		if(op.instancesCount > 0) {
			hr = mpD3DDevice->SetStreamSourceFreq(0, D3DSTREAMSOURCE_INDEXEDDATA | op.instancesCount);
			if(SUCCEEDED(hr)) {
				mpD3DDevice->SetStreamSourceFreq(1, D3DSTREAMSOURCE_INSTANCEDATA | 1);
			}
			if (FAILED(hr))
			{
				OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to setup geometry instancing", "D3D9RenderSystem::_render" );
			}
		}

		// Issue the op
		if( op.useIndexes )
		{
            D3D9HardwareIndexBuffer* d3dIdxBuf = 
                static_cast<D3D9HardwareIndexBuffer*>(op.indexData->indexBuffer.get());
			hr = mpD3DDevice->SetIndices( d3dIdxBuf->getD3DIndexBuffer() );
			if (FAILED(hr))
            {
				OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Failed to set index buffer", "D3D9RenderSystem::_render" );
            }

            do
            {
                // do indexed draw operation
			    hr = mpD3DDevice->DrawIndexedPrimitive(
                    primType, 
                    static_cast<INT>(op.vertexData->vertexStart), 
                    0, // Min vertex index - assume we can go right down to 0 
                    static_cast<UINT>(op.vertexData->vertexCount), 
                    static_cast<UINT>(op.indexData->indexStart), 
                    static_cast<UINT>(primCount)
                    );

            } while (updatePassIterationRenderState());
		}
		else
        {
            // nfz: gpu_iterate
            do
            {
                // Unindexed, a little simpler!
			    hr = mpD3DDevice->DrawPrimitive(
                    primType, 
                    static_cast<UINT>(op.vertexData->vertexStart), 
                    static_cast<UINT>(primCount)
                    ); 

            } while (updatePassIterationRenderState());
        } 

		if(op.instancesCount > 0) {
			// finish instancing
			hr = mpD3DDevice->SetStreamSourceFreq(0, 1);
			if( SUCCEEDED( hr ) ) {
				mpD3DDevice->SetStreamSourceFreq(1, 1);
			}
			if (FAILED(hr))
			{
				OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to unbind geometry instancing", "D3D9RenderSystem::_render" );
			}
		}

		if( FAILED( hr ) )
		{
			String msg = DXGetErrorDescription9(hr);
			OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Failed to DrawPrimitive : " + msg, "D3D9RenderSystem::_render" );
		}
        
	}
How to use HW instancing, just look into DX API - I studied it from this documetation (how to setup vertex buffers) - Efficiently Drawing Multiple Instances of Geometry
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re:

Post by jacmoe »

sinbad wrote:Yep, hellcatv and shirsoft from Stanford have a project they're actively working on,so wanted an addon spot for it. I rarely say no to that kind of offer ;)
What license is it under? BSD/MIT/LGPL? :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
shirsoft
Gnoblar
Posts: 1
Joined: Mon Jan 05, 2009 12:15 am

Re: OGRE clipmaps terrain sample

Post by shirsoft »

Somehow I landed up on this page. Its BSD license.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: OGRE clipmaps terrain sample

Post by jacmoe »

shirsoft wrote:Somehow I landed up on this page. Its BSD license.
I am following you with great interest! :D
/* 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: OGRE clipmaps terrain sample

Post by stealth977 »

Last year i worked on a little DirectX project using some kind of clipmapping. What i did was to create a static indexbuffer containing tristrip operations for all detail levels of clipmaps (usually 5 - 6 detail levels), then creating vertex buffers for patches (64 is ok, 128 gives much better detail but high poly count) and updating them when necessary, then its just 1 render call for every detail level of clipmap ( 5 - 6) (each detail level has twice the size of patch so 6 levels with 64 patch size means 4096x4096 terrain, or 5 levels with 128 patch size gives the same terrain size, of course you can decrease the detail to limit the actual rendering area (you can make 3 levels with 128 patch size, meaning the rendering rectangle contains 1024x1024 vertices - though it is reduced to 32768 tris for 0 level, 8192 tris for 1st level, 2048 for 2nd and 512 tris for 3rd level ) to render all terrain.

The application uses some kind of splatting (though its not perfect since it doesnt use alpha maps for layers, the alpha values for layers are contained in vertex data currently 4 layers used). Also i packed 4 terrain textures in 3 textures like ground_r, ground_g,ground_b each containing only 1 channel of every terrain texture so ground_r.r = 1st textures red, ground_r.g = 2nd textures red etc. which makes it only one multiplication with the vector containing layer alphas.

Anyway, on my laptop (2.0Ghz single core, Ati X600 128 MB) it gives around 150 FPS with splating and 4097x4097 16bit map.
Although there is an implementation in code it doesnt use vertex morphing at the moment.For anyone who wants to check how it works, the windows binaries and the full source with textures and data are at:

http://www.bafragroup.com/ogrefiles/clipmap.rar (25MB)
Ismail TARIM
Ogitor - Ogre Scene Editor
WWW:http://www.ogitor.org
Repository: https://bitbucket.org/ogitor
xiaohe771
Gnoblar
Posts: 1
Joined: Sat Apr 18, 2009 7:09 am

Re: OGRE clipmaps terrain sample

Post by xiaohe771 »

Help me!
I got source code from svn, there is "Path=../../../bhm/bhm" in the terrain.txt. But Where are the folder "bhm" and the files "bhm*.*"? Help me!!
The_Andreyp
Gnoblar
Posts: 9
Joined: Fri Apr 20, 2007 9:14 am

Re: OGRE clipmaps terrain sample

Post by The_Andreyp »

Hey Assaf . Mega respect. Can you help me ? I do not understand how to got it working:

1) i use clipmaps like you..
2) i use 6 box planes like you
3) i do not know what is next:

how to find that one shared 6 clipmaps center

i saw your function that tells faceID and coords in (0,1) range inside of this face.. and ?......... what is next ?

thanks
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: OGRE clipmaps terrain sample

Post by Assaf Raman »

Man, I created this thread years ago, I just tried to convert a sample I found, I can't really help you, I don't remember what is going on with this sample.
Watch out for my OGRE related tweets here.
The_Andreyp
Gnoblar
Posts: 9
Joined: Fri Apr 20, 2007 9:14 am

Re: OGRE clipmaps terrain sample

Post by The_Andreyp »

hm... can you point me onto that sample ?
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: OGRE clipmaps terrain sample

Post by Assaf Raman »

What do you mean? All my work on this topic is on the first few posts on this thread.
Watch out for my OGRE related tweets here.
The_Andreyp
Gnoblar
Posts: 9
Joined: Fri Apr 20, 2007 9:14 am

Re: OGRE clipmaps terrain sample

Post by The_Andreyp »

you mentioned you used other sample..

i guess you took heightmapped clipmaps (in 2d)

and you made em as spherical self ? but you just do not remember how does it work ?
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: OGRE clipmaps terrain sample

Post by Assaf Raman »

heightmapped, I don't remember the spherical version of it, but - look for "clipmaps" on this page (not OGRE - but source code).
Watch out for my OGRE related tweets here.
The_Andreyp
Gnoblar
Posts: 9
Joined: Fri Apr 20, 2007 9:14 am

Re: OGRE clipmaps terrain sample

Post by The_Andreyp »

thx