Material Propagation

I was reading Node.setMaterial() in that it would propagate down to its children.

I was hoping that it would merge materials but that doesnt seem the case unless there is a particular setting that I am unaware of?

In my test I have a node and a child both set with ColouredTextured Materials and both have different colors set.

I was hoping the colours would be merged ie ColorRGBA.multi(patrent.color) but the behaviour seems that the spatial will only use the parent material if it doesnt have one of its own.

Is this correct? or is there a setting where I can tell it to merge colours?

I am quite happy to write a controller to merge the colors on the fly.

Please advise.
Regards

Not sure what you mean by merge the color.

node.setMaterial(mat) will set the SAME instance of the material to all geometries in the subgraph.

I you want to mutiply the colors you have to do it explicitely. Though if you keep a reference on the material instance, you just have to multiply (multLocal and not mult) the color once.

Thanks, you have confirmed that I need to do it explicitly and that there isnt a setting like… Texture.Mode.Combine.Modulate

Thanks

I guess he ment like in blender where you can actually blend Materials using different modes like multiply, subtract etc.

IT would be nice to have but i guess stacked Materials require a huge refactoring in both, the shader as well as the materialsystem

Blender allows texture layers to be blended, not materials themselves.
The way this is normally accomplished is by writing a custom shader that performs the blending. For example, see the terrain shader which blends several textures together based on weights specified in another texture. Thus allowing multiple textures such as sand, grass, dirt, etc with a single material.

1 Like

@Momoko_Fan pretty much specified the “big idea”.

For a more realistic approach for what you are wanting to do…
you would be doing a 2d Ops on your texture in an Offscreen Texture2d
you would be writing an OpenGL “Filter” type script (per pixel from Samplers)
you would trigger its run in the bucket queue for PreProcess
you would not have to change the Material (which in jme is just the shader code), just work on the various underlying Texture2Ds

I would recommend coordinated Meshes and Texture Atlases for your models to do this… and you can have the atlases on a big ol’ spritesheet… cause… well…
Mainly because you probably want “pulsing vein animations” underneath fish scales for your hero-eating aliens… just sayin’ :sweat_smile: