Make some objects darker and some other brighter

I have some objects repeated on my scene, they are all the same type of objects (loaded from OBJ file), but I want to make some of them more darker and some other more brighter.



I am using only one point-light in my scene.



How do I change properties on those objects to make them more darker / brighter on the scene?



I guess I should change some properties on their materials, but I am not sure where to set the changes.



Thank you  :slight_smile:

you can give the object different MaterialStates.

Dark object with a black emissive, bright objects with a white emisive color.

Or Diffuse / ambient color, depending on what results you want.

Thanks for your answer Core-Dump.



The doubt I have is that I load those objects from an OBJ file, which it already has a material. Moreover, after loading them I attach a texture to those objects.



Can I do something to manipulate emissive-diffuse-ambient, but conserving those textures, is it possible? that would be great… I have no much experience in this…



Regards  :slight_smile:

Just apply a new MaterialState once the model is loaded, it should replace the existing MaterialState.



(Don't forget to call UpdateRenderState() on the node after the MaterialState change)

Well, actually, that won't work unless the material loaded on the model is only at the root level.  Otherwise, you can recursively go through the scenegraph and remove or replace the state at each spatial.

oh, right I (stupidly) assumed it was a single mesh; thanx for correcting me renanse.

Humm… I am wondering if I understand you:



I have the following tree:



rootNode

  |


node1
                |
node2
                                |
mesh

If I load the mesh (OBJ) and I set the Texture material to it, then if I want it to be more brighter or darker I just have to set a new render-state to node2 or node1 to take effect?

To be more explicit, I have the following:



a mesh

a textureState - a texture loaded from a JPG. When I load the mesh I apply this textureState.

a darkState - dark material conditions

a brightState - bright material conditions



Ok, the point is this:


  1. when I need the mesh to be more darker, I would like to have the mesh with textureState + darkState applying. I mean the mesh with the texture, but with dark material conditions


  2. when I need the mesh to be more brighter, the same as before but using brightState.



    How can I make to apply both materials textureState + dark(or bright)State at the same time to make the mesh darker or brighter?



    That's what I trying to find out. I guess it has to be with two render-state superposition, both applying merged.

you could have 2 textures, a light one and a dark one; that would be an easy fix.



As far as manipulating the material state, you will have to loop through the node (call node.getChildren() ) and determine where the material state is and apply a new one.

basixs, there is no way to make an object-with-texture to be more sensible to light (brighter) or less sensible (darker), without having to use an additional texture?



I have a lot of textures to switch in that object, and is really undesirable for me to have to repeat all textures in dark…



Thank you for your help, I have to resolve this issue asap and I am not finding the "bright" way yet.  :slight_smile:

Try to change MaterialState values from ALL your MESH children.

Thanks for your suggestion, clovis, but the point is I have only 1 mesh with a TextureState, not a MaterialState. What I was wondering at my posts before is if it was possible to combine the already setted TextureState with new MaterialState, something like adding these two RenderState's, and achieve the desired brightness or darkness by means of this superimposition of TextureState + MaterialState.



Is this possible, to combine a TextureState with MaterialState?



Thanks  :slight_smile:

You can have multiple "unique type" renderstates on your Spatial. This means you can set a texturestate, a materialstate, a lightstate, a …state etc. on the same spatial  but you cannot apply 2 texturestates  the last set state will override the current state of that type. 



Hellmaster.

Thank you very much, Hellmaster. I'm gonna try that. :slight_smile:

Sorry maybe i was unclear or maybe i'm misunderstanding you.



But why not set the texturestate like normal and then apply the materialstate.



for example the following box has a texture and greenish color( from the material state) mixed with the texture


Box cube = new Box("borg cube", new Vector3f(-size / 2, -size / 2,
            -size / 2), new Vector3f(size / 2, size / 2, size / 2));

      TextureState borgCubeTS = DisplaySystem.getDisplaySystem()
            .getRenderer().createTextureState();

      borgCubeTS.setTexture(TextureManager.loadTexture(ResourceLocatorTool
            .locateResource(ResourceLocatorTool.TYPE_TEXTURE,
                  "borg_COLOR.png")), 0);
      
      MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
      ms.setEmissive(ColorRGBA.green.clone());
      cube.setRenderState(ms);
      cube.setRenderState(borgCubeTS);
      cube.updateRenderState();



Hellmaster.

When i started with jME i have the same impression about RenderStates just because the method is setRenderState and not addRenderState. The set method make us think that the old RenderState will be replaced.

It could be changed on 2.0 or there is an explanation for that that i dont know?

I totally agree with clovis  :slight_smile:



setRenderState method abstraction as a setter it's not clear considering what learnt about multiple render-states possible to be applied to an object.



Then addRenderState may be easier to understand :wink: