Page 1 of 1

getting scene node in shader callback

Posted: Wed Mar 14, 2007 4:40 pm
by white tiger
hi all.

i have a phong GLSL shader that support infinite lights trought array, but i would like to calculate only two nearest lights from node. to do this i have no problem to insert the lights into an array but i have to know what node is going to pass trought the shader, to compute the distance between the node and all the lights.

unfortunately IShaderConstantSetCallBack has no parameters for the scene node. i can use user data by setting user data as node id. but user data is create with material, so different materials have different user data. so if i have 999 nodes in my scene? i have to create 999 different materials?

So my question is: how can i get scene node from IShaderConstantSetCallBack ?

Please help me

Greetings

Posted: Wed Mar 14, 2007 8:18 pm
by Luben

Code: Select all

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

		// set inverted world matrix
		// if we are using highlevel shaders (the user can select this when
		// starting the program), we must set the constants by name.

		core::matrix4 World = driver->getTransform(video::ETS_WORLD);
The world matrix contain information about the current nodes rotation, scale and translation.[/quote]

Posted: Thu Mar 15, 2007 12:45 am
by vitek
But that does nothing for accessing the current material. i.e. there is no access to the MaterialParam that the original poster is talking about...

Posted: Thu Mar 15, 2007 6:53 am
by Luben
He doesn't ask for that, he asks for the nodes position in world space.

Posted: Thu Mar 15, 2007 8:01 am
by Eldritch
Looks to me like he's asking about how to get the node that is currently being handled in the event, what node the current shader is applied to.

Posted: Thu Mar 15, 2007 12:37 pm
by white tiger
Thanks.

this solve the problem, but so is there noways to get the node wich current shader is applied? for example i create a high level material called 'g' and assign it to 10 nodes. Is there a method to get in shader constant callback the node among 10 nodes wich the shader is applied to?

Thanks for answering

Posted: Thu Mar 15, 2007 3:30 pm
by Luben
Since you can always add something like this directly to your main loop, it isn't always certain that the thing being drawn is drawn from a node. So in other words, not in irrlicht, at least until you've made your own hack to solve the problem

Code: Select all

	driver->setMaterial(Material);
		driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
		driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 4);
(Code copy-pasted from example 3)

Posted: Sun Mar 18, 2007 5:52 pm
by omaremad
Well, i thought of a hack. but it requires a dll mod.

Add a pointer to a scenenode in the scenemanager class. and then on Prender call of the shaded node set the pointer in the scenemanager to that node

smgr->Shadednode=this.

then call that pointer out of the set constants (which can get the scenemanger via device)

In short:
so you just make a pointer in the scenemanger which on rendering a node is set to point to that node. Then the constants callback checks the pointer in smgr to get the current node being renderd.

Btw one thing my experiments with infinite lights taught me, is that on pre shader model three cards you can only send very few uniforms and varyings. and lights eat up a lot of floats esp with lots of options like pos, colour, radius, falloff etc...

Posted: Sun Mar 18, 2007 7:24 pm
by Luben
Is there some place where you actually can see the specs of the different models, in a way that doens't require reading trough 20+ pages per model?

Posted: Sun Mar 18, 2007 10:17 pm
by omaremad
Nvidia cg toolkit, the refrence manual covers mainly cg but also details the shader models(and covers some diffrences in the api's of ogl and dx in respect to shaders) just use search on pdf.

Best way to deal with refrence manuals is not to read them sequientally lol.