Page 1 of 1

how do i scale a parallax texture?

Posted: Fri Sep 26, 2008 5:39 pm
by yellowfever13
normal scaling doesnt work with parallax type..

I've always used material.getTextureMatrix(0).setTextureScale

Now that I am experimenting with parallax mapping, that doesnt do the trick. What am I missing?

FYI I need a repeating pattern on an object to be the same size in the world on an object that will be different at each run time.

Thanks!

Posted: Fri Sep 26, 2008 6:28 pm
by hybrid
The shaders don't support texture matrices. You'd have to do the texture scaling inside the shader.

damn

Posted: Fri Sep 26, 2008 8:04 pm
by yellowfever13
so there is no way to do this at runtime? seems pretty odd. This is very disappointing to my project :(

Thanks for the information, if anyone else has something to add please do.

Thanks!

Posted: Fri Sep 26, 2008 8:12 pm
by hybrid
If we had a GLSL version of the parallax shaders it wouldn't be too hard to add this feature, but for the ASM shaders I really don't know how this would work.

Posted: Fri Sep 26, 2008 8:31 pm
by yellowfever13
any idea why its repeating 3 times on my model instead of once? What controls the tiling then?

Posted: Fri Sep 26, 2008 8:52 pm
by hybrid
The texture coords :)

well...

Posted: Mon Sep 29, 2008 2:34 pm
by yellowfever13
so if the texture coords are making it tile 3 times by default...can I modify the texture coords to make it repeat more like I need? Sorry, I dont know much about texture coords in Irr...I know what they are but never played with them.

So in summary can I edit texture coords to control my diffuse and parralax maps?

Thanks!

Posted: Mon Sep 29, 2008 4:20 pm
by hybrid
Yes, that's possible. You have to access the vertices of the underlying Mesh structure (hopefully an SMesh, otherwise it becomes complicated). The vertices hold the texture coords, you can set them to [0..1] for non-repeating and [-n..m] for repeating textures in both U and V direction (where the span [0..10] means that the texture will repeat ten times).

more help...sorry

Posted: Tue Sep 30, 2008 8:11 pm
by yellowfever13

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.

Posted: Tue Sep 30, 2008 11:13 pm
by hybrid
the planar mapping method *calculates* texture coords, so you cannot expect that your texture coords are preserved. Could you show screenshots of what you want and what you get?

Posted: Wed Oct 01, 2008 2:00 pm
by yellowfever13
https://photos-2.getdropbox.com/i/l/Xgs ... 4_zZFX6k#6

https://photos-3.getdropbox.com/i/l/uj4 ... E_BzSAlE#7

in the first image, I acheived this look by changing the makePlanarTextureMapping resolution to 0.5. This is the look I want.

The other image is with the default of 0.001. As you can see in the title bar the first one is 8 FPS and second is 16FPS both of which are too slow, slows down the whole computer and mouse etc. I must be doing something wrong because irrlicht usually runs fast on this machine. The parralax demo runs great on this machine, so surely I am screwing something up.

But I need to scale the texture the right way, I have a feeling changing that resolution is not the right way!

Posted: Wed Oct 01, 2008 2:31 pm
by hybrid
I ddin't really looked at your code so far, but there are many *major* (havok, insane, you get it?) problems as I can see:
* You're creating S3DVertex nodes, while parallax mapping needs S3DVertexTangents, you should use the correct type from start.
* You're creating 2000*4 nodes, which are almost all upon each other, the structure makes absolutely no sense
* Using set_used this was is absolutely wrong: Either use set_used and direct access or use reallocate and push_back!
* Doing the reallocate in a loop kills performance, you know the number of vertices from the start
* makePlanarMapping makes no sense, you can define the texture coords in the vertices

Fixing all thses issues should at least deliver a much better mesh, maybe all the problems are fixed by then.

thanks

Posted: Wed Oct 01, 2008 4:29 pm
by yellowfever13
thank you for the info hybrid. I will fix some of the things you mentioned. Some of the things will stay however, this was a test app for my project in which I will be importing poly coordinates from an autocad dwg file, I wont know the number of polys at runtime, hence the push. I realize this mesh makes no logical sense, but it will have to be this way in my project.

I will try using S3DVertexTangents instead and take out the makePlanarMapping. I will also take out the set_used.

Thanks for your help!