Help with shadows and speed

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
joey.watts.96
Posts: 5
Joined: Sun Jun 10, 2012 12:11 am

Help with shadows and speed

Post by joey.watts.96 »

Hey everybody,
I am trying to make a minecraft clone (sorry, I know lots of people do this), and I've been using polyvox to manage my terrain data. This is what I've been able to come up with:
http://s11.postimage.org/3wwax7ryr/image.jpg

I'm actually looking to create something along the lines of this:

Image

That's from the Accidental Noise library's entry about minecraft terrain generation on their website.

The BasicExample from the PolyVox examples also features something like this.

The shadows in my code look really weird. Do I have odd color parameters that create this weird look, or did I do something else? I'll try to post relevant code:

Code: Select all

 
    E_DRIVER_TYPE driver;
 
    if (render == "Direct3D 8")
        driver = EDT_DIRECT3D8;
    else if (render == "Direct3D 9")
        driver = EDT_DIRECT3D9;
    else if (render == "OpenGL")
        driver = EDT_OPENGL;
    else
        driver = EDT_SOFTWARE;
    IrrlichtDevice* device = createDevice(driver, dimension2d<u32>(resx,resy), 32, fullscreen, true, false, 0);
 
    ISceneManager* smgr = device->getSceneManager();
    IVideoDriver* vdri = device->getVideoDriver();
    IGUIEnvironment* gui = device->getGUIEnvironment();
 
    ILightSceneNode* light = smgr->addLightSceneNode(0, core::vector3df(0,256,0),
                    video::SColorf(1.0f, 0.6f, 0.7f, 1.0f), 800.0f);
 

Code: Select all

 
smgr->setShadowColor(SColor(150,0,0,0)); 
for (int x = 32*-2; x < 32*2; x+=32)
        for (int y = 64; y < 128+32; y+=32)
            for (int z = 32*-2; z < 32*2; z+=32)
            {
                SMesh* mesh = worldman->generateMesh(Region(x,y,z,x+32,y+32,z+32));
                IMeshSceneNode* node = smgr->addMeshSceneNode(mesh);
                node->setMaterialFlag(video::EMF_LIGHTING, true);
                node->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
                node->setPosition(vector3df(x,y,z));
                
 
            }
 
My other issue is speed. In my picture, you can see its at 12 fps. My chunk size is 32x32x32 and I'm using PolyVox's CubicSurfaceExtractorWithNormals... Can anyone give me hints to make this faster?

I use a nested-for loop to generate the chunks, and I get about 30-40 fps with this, but its still only a few chunks:

Code: Select all

 
for (int x = 32*-2; x < 32*2; x+=32)
        for (int y = 64; y < 64+32; y+=32)
            for (int z = 32*-2; z < 32*2; z+=32)
 
joey.watts.96
Posts: 5
Joined: Sun Jun 10, 2012 12:11 am

Re: Help with shadows and speed

Post by joey.watts.96 »

I feel retarded. My color in the ILightSceneNode constructor was wrong. Changing it to 1.f,1.f,1.f,1.f gives decent results, definitely needs adjusting though...

I still need help with speed though.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Help with shadows and speed

Post by mongoose7 »

Use fewer meshes. For example, the picture you give could be made with just one mesh. I don't know how you do shadows, but that may have to be taken into account.
joey.watts.96
Posts: 5
Joined: Sun Jun 10, 2012 12:11 am

Re: Help with shadows and speed

Post by joey.watts.96 »

mongoose7 wrote:Use fewer meshes. For example, the picture you give could be made with just one mesh. I don't know how you do shadows, but that may have to be taken into account.
Okay, but the meshes will have to be regenerated. Will one Mesh w/ multiple MeshBuffers help?

EDIT: Multiple mesh buffers puts the vertices on top of each other (there's no easy way to apply an offset to the vertices of the MeshBuffer.) I'm not even sure the multiple buffers would really do anything for me...
joey.watts.96
Posts: 5
Joined: Sun Jun 10, 2012 12:11 am

Re: Help with shadows and speed

Post by joey.watts.96 »

I use one SMesh per chunk... I have been playing with the size of chunks to see if I see a speed increase. How many vertices per SMesh is optimal? Are there other ways to increase speed?
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Help with shadows and speed

Post by REDDemon »

only profiling can tall that to you. If bottleneck is number of drawcalls, increase size of chunks. If updating time for chunks is bottleneck reduce size of chunks. (or split updating to several frames)

If geometry is still a bottleneck...
Are you drawing also invisible cubes? For example if you have a cube wich is surrounded by other 6 cubes (1 for each face) there is no need for draw that cube.

A smaller volume can contain a insane amount of cubes, removing invisible ones (or just invisible faces of 2 adiacent cubes) can be complex but will give nice boost.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
joey.watts.96
Posts: 5
Joined: Sun Jun 10, 2012 12:11 am

Re: Help with shadows and speed

Post by joey.watts.96 »

REDDemon wrote:only profiling can tall that to you. If bottleneck is number of drawcalls, increase size of chunks. If updating time for chunks is bottleneck reduce size of chunks. (or split updating to several frames)

If geometry is still a bottleneck...
Are you drawing also invisible cubes? For example if you have a cube wich is surrounded by other 6 cubes (1 for each face) there is no need for draw that cube.

A smaller volume can contain a insane amount of cubes, removing invisible ones (or just invisible faces of 2 adiacent cubes) can be complex but will give nice boost.
The PolyVox cubic surface extractor only extracts the faces that can be seen. I guess I'll have to do some profiling...
Post Reply