Use forced material for all but one node

Hi All,

I am trying to figure out how to best acomplish the following rendering.

I want to draw attention to one node, selected by the player. I want to do this by changing the material of all other objects in the scene. I tried to acheive this by using setForcedMaterial, but this seems to affect the GUI node aswell ( as well as the selected node, ofcourse )

Anyone has an idea how to do this? I would like to avoid traversing the entire scene graph and setting the materials.

Cheers nihal

Rules of coding troubleshooting.

1 - Explain expected result of the code.
2 - Explain the actual result of the code.
3 - Post the main code affecting the expected/actual results.
Optional: Screenshots to explain complex visuals or things that are hard to explain.

You’re missing #3. :slight_smile:

@madjack said: Rules of coding troubleshooting.

1 - Explain expected result of the code.
2 - Explain the actual result of the code.
3 - Post the main code affecting the expected/actual results.
Optional: Screenshots to explain complex visuals or things that are hard to explain.

You’re missing #3. :slight_smile:

Well, this is not really troubleshooting, I wasn’t quite sure where to post more conceptual questions.

The actual code that I have played with is:

[java]
renderManager.setForcedMaterial( mat );
[/java]

But obviously I did not expect that to do the job, as I need exceptions to the forced material…

What I want to acheive, is similar to the edit mode of buildings in Sim City 5, demonstrated here ( 4:50 notice the background has a white material )

The way I would do it is put a filter on that “backdrop” that would colorize the scene in a bluish tint (like in the video) and using a viewport, put the normally colored models.

But that’s just a spur-of-the-moment thing without giving it much thought.

@nihal said: I would like to avoid traversing the entire scene graph and setting the materials.
Why? This is the easiest, more straight forward way. And it surely won't kill your perfs even if you have 1000 objects in your scene. Also this is not something that you are going to run on every frame....
@nehon said: Why? This is the easiest, more straight forward way. And it surely won't kill your perfs even if you have 1000 objects in your scene. Also this is not something that you are going to run on every frame....

For two reasons.

  1. I would need to traverse the whole tree and store original materials for each geometry. Which I thought was a bit messy.
  2. Any objects added in “the background” in the meantime, would need to be assigned the unshaded material, which is problematic, since this introduces dependencies between different parts of my architecture.

I think it is an easy solution, but I do not think it is elegant. I would much prefer a “selective forced material”. Could this be done with forced RenderStates or RenderTechniques and a modified material?

Mhhh ok…and you feel that is elegant?
Forced materials are not used for this. Their purpose is to force the renderer to use a material for ALL objects in the scene. This is used for shadows and post filtering and so on.

I think you’re a bit over thinking this.

1 Like
@nehon said: Mhhh ok...and you feel that is elegant? Forced materials are not used for this. Their purpose is to force the renderer to use a material for ALL objects in the scene. This is used for shadows and post filtering and so on.

I think you’re a bit over thinking this.

Any post filtering would break my implementation then, I did not realize that… Thank you for bringing that to my attention.

I’ll implement it as a scene graph traversal. And I’ll remove my code, to not confuse anyone dropping by this topic in the future.

Thank you.

Edit: Still, I would have liked a method of intercepting the Material in the RenderManager or similar, as any other piece of my game that adds geometry will need to check in to see if it can use it’s own material or another. I might make an alteration to my RenderManager to allow that.

Idk what is your shader skill, but you could have your own material that just switch from color to grey scale according to a parameter, this way you wouldn’t have to switch materials really (and not have to store them), but just set and remove the parameter to the material according if the object is selected or not.

1 Like
@nehon said: Idk what is your shader skill, but you could have your own material that just switch from color to grey scale according to a parameter, this way you wouldn't have to switch materials really (and not have to store them), but just set and remove the parameter to the material according if the object is selected or not.

I have done some shader programming, and I should be able to implement this into the shaders.

Would I not still need to travers all materials and set the parameter in the materials of all non-selected objects? Or is there a better way to do that for materials?

I sure have a lot less materials than geometries, so this solution is preferable I think.

Well now that you mention it, doing this you’ll be forced to have a different material for each geometry so that’s maybe not the better way to go…

How many objects do you have? and how many materials?

@nehon said: Well now that you mention it, doing this you'll be forced to have a different material for each geometry so that's maybe not the better way to go...

How many objects do you have? and how many materials?

Well, I think I could avoid having materials for each geometry, buy using a copy of the material with the flag set on the selected node only, and then revert to a general material once I exit my selection.

My number of geometry is very variable, but up to 200 I’d say ( I use a lot of batching ). As for materials, I currently have about 2-3 instances ( not including particle and post processing materials ), at any time, but I have not added assets, and was intending to increase that number rather significantly, one material per asset.

@nihal said: Well, I think I could avoid having materials for each geometry, buy using a copy of the material with the flag set on the selected node only, and then revert to a general material once I exit my selection. Seems doable?
yep it could indeed
1 Like

I would just do a controller on any geomtery you use.
instead of the model set the amterial to the controller.
The controller than can ask the gamestate if it should apply the normal material or the other one.

I don’t like that approach empire - it would involve constant checking for something that only transitions rarely.