getting scene node in shader callback

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

getting scene node in shader callback

Post 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
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post 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]
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post 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...
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

He doesn't ask for that, he asks for the nodes position in world space.
Eldritch
Posts: 33
Joined: Mon Feb 26, 2007 12:33 pm

Post 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.
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post 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
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post 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)
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post 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...
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post 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?
If you don't have anything nice to say, don't say anything at all.
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post 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.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
Post Reply