Code: Select all
/////////////////////////////////////////////////////////////////////////////////////////
S3DVertex Vertices[4];
SMeshBuffer* mbuf = new SMeshBuffer();
for( int p = 0; p < 2000; p++ )
{
{
Vertices[0] = S3DVertex( p ,0 ,0 ,0,-1,0, SColor(255,255,255,255), 1, 0 );
Vertices[1] = S3DVertex( p+12 ,0 ,0 ,0,-1,0, SColor(255,255,255,255), 1, 1 );
Vertices[2] = S3DVertex( p+12 ,0 ,100 ,0,-1,0, SColor(255,255,255,255), 0, 1 );
Vertices[3] = S3DVertex( p ,0 ,100 ,0,-1,0, SColor(255,255,255,255), 0, 0 );
u16 indices[6] = { 0,1,2 ,0,2,3 };
mbuf->Vertices.set_used( p * 4 );
for( int i = 0; i < 4; i++ )
mbuf->Vertices.push_back( Vertices[i] );
mbuf->Indices.set_used( p * 6 );
for( int i = 0; i < 6; i++ )
mbuf->Indices.push_back( indices[ i ] + p );
}
}//end poly loop
SMesh* wall_mesh = new SMesh;
SAnimatedMesh* wallmesh = new SAnimatedMesh;
wall_mesh->addMeshBuffer( mbuf );
wallmesh->addMesh( wall_mesh );
smgr->getMeshManipulator()->makePlanarTextureMapping( wall_mesh, 0.001f );
scene::ISceneNode* wall = 0;
ITexture* colorMap = driver->getTexture("panel_color.jpg");
ITexture* normalMap = driver->getTexture("panel_height.jpg");
driver->makeNormalMapTexture(normalMap, 5.0f);
scene::IMesh* tangentMesh = smgr->getMeshManipulator()->createMeshWithTangents( wall_mesh );
scene::IMeshManipulator *manipulator = smgr->getMeshManipulator();
wall = smgr->addMeshSceneNode(tangentMesh);
wall->setMaterialTexture(0, colorMap);
wall->setMaterialTexture(1, normalMap);
wall->getMaterial(0).SpecularColor.set(255,220,220,220);
wall->setMaterialFlag(video::EMF_FOG_ENABLE, true);
wall->setMaterialType( video::EMT_PARALLAX_MAP_SOLID );//EMT_NORMAL_MAP_SOLID or video::EMT_PARALLAX_MAP_SOLID or video::EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA
wall->getMaterial(0).MaterialTypeParam = .01; // adjust height for parallax effect
// drop mesh because we created it with a create.. call.
tangentMesh->drop();
wall->setScale(vector3df(0.03,0.03,0.03));
wall->setPosition(vector3df(4.5,0.5,4));
video::IMaterialRenderer* renderer = driver->getMaterialRenderer( video::EMT_PARALLAX_MAP_SOLID );//video::EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA
//room->setMaterialTexture( 0, wall_texture );
wall->getMaterial(0).setFlag( video::EMF_LIGHTING, true );
//room->getMaterial(0).setFlag( video::EMF_ANISOTROPIC_FILTER, true );
//room->getMaterial(0).setFlag( video::EMF_BILINEAR_FILTER, true );
wall->getMaterial(0).setFlag( video::EMF_BACK_FACE_CULLING, false );
//room->addShadowVolumeSceneNode( -1,true,10000 );
//room->setMaterialType(video::EMT_SOLID_2_LAYER dx only
/////////////////////////////////////////////////////////////////////////////////////////
scene::ILightSceneNode* light = smgr->addLightSceneNode(0, vector3df( 1000,1000,1000 ),
SColorf( 0.5f, 0.5f, 0.5f, 1.0f ), 2000 );
light->getLightData().CastShadows = true;
light->getLightData().AmbientColor.set(0.4,0.4,0.4);
light->getLightData().DiffuseColor.set(0.8,0.8,0.8);
light->getLightData().SpecularColor.set(1,1,1,1);
smgr->setShadowColor( video::SColor(50,0,0,0) );
u32 frames=0;
while(device->run())
{
driver->beginScene(true, true, video::SColor(0,100,100,100));
light->setPosition( maincam->getPosition() );
smgr->drawAll();
driver->endScene();
wchar_t tmp[255];
swprintf(tmp,255,L"%i, %i",driver->getPrimitiveCountDrawn(), driver->getFPS() );
device->setWindowCaption(tmp);
}
I have made my own mesh now and I still need to control the parralax texure scaling. I have played with the u v values in my vertex data but it doesnt seem to matter what i put there, always ends up the same. The only thing that seems to control the scale of the parralax map is the "resoluion" on the "smgr->getMeshManipulator()->makePlanarTextureMapping( wall_mesh, 0.001f );"
But when the scale starts to get right, up towards 1 instead of .001, my framerate goes to crap. Which is strange considering theres only a couple thousand polys. I have ran 40k+ on here at much better FPS with lighting and shadows.
What am I doing wrong with the texture coordinates? I have tried different values and the outcome is the same.