VeeDub Customizer

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
m3ltd0wn
Posts: 107
Joined: Wed Dec 12, 2007 8:32 am
Location: Romania

Post by m3ltd0wn »

Code: Select all

class MyShaderCallBack : public video::IShaderConstantSetCallBack
{
public:

	virtual void OnSetConstants(video::IMaterialRendererServices* services,
			s32 userData)
	{
		video::IVideoDriver* driver = services->getVideoDriver();

		// set clip matrix

		//core::matrix4 worldViewProj;
		//worldViewProj = driver->getTransform(video::ETS_PROJECTION);			
		//worldViewProj *= driver->getTransform(video::ETS_VIEW);
		//worldViewProj *= driver->getTransform(video::ETS_WORLD);

		//services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);
				

		// set camera position

		core::vector3df pos_cam = device->getSceneManager()->
			getActiveCamera()->getAbsolutePosition();

		core::vector3df pos_light = device->getSceneManager()->getSceneNodeFromId(66,0)->getAbsolutePosition();
		
		services->setVertexShaderConstant("fvEyePosition", reinterpret_cast<f32*>(&pos_cam), 3);

		services->setVertexShaderConstant("fvLightPosition", reinterpret_cast<f32*>(&pos_light), 3);
				
		// set transposed world matrix
			
		core::matrix4 world = driver->getTransform(video::ETS_WORLD);
		world = world.makeInverse();
		world = world.getTransposed();

		services->setVertexShaderConstant("matWorldInverseTranspose", world.pointer(), 16);
		
	}
};

Code: Select all

//apply the shaders
	gpu = driver->getGPUProgrammingServices();
	carReflectionMaterial = gpu->addHighLevelShaderMaterialFromFiles("data/shaders/reflection.vert",
																				"main", EVST_VS_2_0,
																				"data/shaders/reflection.frag",
																				"main", EPST_PS_2_0, mc, video::EMT_SPHERE_MAP, 0);

	car_chassis_node->setMaterialTexture(0, driver->getTexture(ChassisTexture.c_str()));
	car_chassis_node->setMaterialTexture(1, driver->getTexture(ChassisTexture.c_str()));
	car_chassis_node->setMaterialType(video::EMT_SOLID_2_LAYER);
	car_chassis_node->setMaterialFlag(EMF_LIGHTING, false);

	car_body_node->setMaterialTexture(0, driver->getTexture(ChassisTexture.c_str()));	
	car_body_node->setMaterialType(video::EMT_SOLID);
	//car_body_node->setMaterialTexture(1, driver->getTexture(ChassisTexture.c_str()));
	//car_body_node->setMaterialType((video::E_MATERIAL_TYPE)carReflectionMaterial);
	car_body_node->setMaterialFlag(EMF_LIGHTING, false);
	//car_body_node->getMaterial(0).Shininess = 100.0f;
the callback and the material shader for reflection, it is applied just to the body of the car, the part wich is white and black, but the texture is gone
m3ltd0wn
Posts: 107
Joined: Wed Dec 12, 2007 8:32 am
Location: Romania

strange problem

Post by m3ltd0wn »

bah...another strange problem with irrXML, i'm trying to make the color selection for the car, and i have about 6 textures that i need to change in order to change the car color (body, fenders, chassis, hood, bumpers, spoilers), i have an xml file for the paths of the textures eg : data/textures/mk1golf/colors/red/red.xml ... and red.xml contains a node eg: red, and the node contains the paths of textures eg: CarChassis = "data/textures/mk1golf/colors/red/car_chassis.jpg", now when i want to change the color of the car i was thinking to do it like this :

car_color = "gray"
->load the xml file "data/textures/mk1golf/colors/gray/gray.xml
->function to apply the textures : applyTextures();

now the problem is like that, if in directory "colors" i have multiple directories with textures, when i first start the program and load the mk1 golf, the hood texture and car body texture are from directory "gray" thus the red.xml is loaded by default and the paths for red color are correct, i'm using one xml reader for textures that change the color of the car , one for 3D models, one for components that do not change the texture.

then another problem when calling the function applyTextures() the color of the car doesn't change even if that function contains : car_chassis_node->setMaterialTexture(0, driver->getTexture(ChassisTexture.c_str()));

and after the function is called the FPS drop.
any suggestion ?
i just want to keep the paths in xml files so the user has the flexibility to change most parts/textures of the car :roll:
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

dont call getTexture as it is slow...operate with pointers

WRONG MATERIAL

video::EMT_SPHERE_MAP, 0);

RIGHT ONE
video::EMT_SOLID,0);

your pseudo shader is...

Code: Select all

//Vertex Shader
uniform mat4 inverseView;
uniform mat4 inverseViewProj;

void main() {
   gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
   gl_TexCoord[0] = reflect(normalize(inverseViewProj*gl_Position),normalize(inverseView*(gl_NormalMatrix*gl_Normal)));
}

Code: Select all

//Pixleshader
uniform sampler2D front;
uniform sampler2D back;

void main () {
   vec3 new = normalize(gl_TexCoord[0].xyz);
  gl_FragColor = new.x>0.0 ? texture2D(front,ew.yz*0.5+0.5):texture2D(back,new.yz*0.5+0.5);
}
and you should have two RTTs "back" and "front"!
you set them at texture indexes 0 and 1
then make two cameras! with view angle of 180
both at the same position (center of your car)
BUT
1st camera has a target of 1,0,0
2nd has a target of -1,0,0

then each render do this

car->setVisible(false)
set render target of "front"
setActiveCamera(1st)
1st->OnAnimate
1st->Render
drawAll
set render target of "back"
setActiveCamera(2nd)
2nd->OnAnimate
2nd->Render
drawAll
car->setVisible(true)
set render target to 0
setActiveCamera(the normal cam)
drawall
m3ltd0wn
Posts: 107
Joined: Wed Dec 12, 2007 8:32 am
Location: Romania

reply

Post by m3ltd0wn »

hey 10x for the shader :)

i will implement it in the project as soon as i finish the car handler :)
Post Reply