How to get a border around a single object?

Let’s start with a little puzzle: in the image below, you see a depiction of a brain. It is the brain of one of the little guys in the picture. Can you spot which one?

I’ll give you a hint: it is one of the more stupid guys.

Now, please do guess but do not hope for any feedback if your answer was right. I forgot on which of the guys I clicked. I wanted to give the ‘active’ guy - whose brain will be on screen - a glowing border and tried the Bloom Effect. But this made the entire guy yellow, and did not just add a yellow border.

So my question is: how can I add a border to a single object. It does not need to glow, just a coloured line will do.

1 Like

See the below topic for a few solutions

1 Like

I did search, but there is a lot of very old stuff on this forum that just does not work anymore. In this case, the suggested solutions outline every sharp edge and not juust the silhouette.

Unfortunately its not as simple as it sounds.

for a temporary solution you can add a light to the character you select. Then the way jme handles lights makes actually sense one time

2 Likes

Very interesting article, even though those solutions are out of scope for me.

I will have to find another way to highlight the selected guy.

As Ali said, the absolute simplest way possible is:
model.addLight(new AmbientLight(ColorRGBA.Pink.mult(4)));
…or something like that.

Remove it again when unselected. The light will only affect that model.

The next easiest way is to grab the world bound (a bounding box) and turn that into a wire frame attached to the model. The code for that is a little more complicated but straight forward.

Neither of these are “borders around the object” but will definitely serve as an indicator of which one is selected and you can move on to the next item on your to-do list.

Edit: and if you really do want a border around the object then the link from that other thread:

…really is the best you can do. It’s relatively simple. Always works, etc… It will draw outlines on things projecting towards the camera but often times that’s desirable.

…and the only way to get a true 2D border effect is to render the model off-screen and then calculate where it’s border would be using 2D approaches and render that image on the gui node over the object. Very complicated.

2 Likes

I love the ambient light solution. It looks nice.

1 Like

there is also a lib for outline:

https://library.jmonkeyengine.org/#!entry=24022%2F5246c9ac-3f4c-4a5d-9fb0-470eb4026246

tho most easy solution would be some shader parameter solution(it is also light example that affect shader too, but it can also be different thing like texture change or anything else)

Well, I think adding an ambient light is even easier since it requires no code change other than the line adding the light. And OP seems to like the effect. (Indeed, there are many styles of game where an outline would look out of place but a highlight(literally) looks nice.)

adding the light is 1 line code, same like setting material(shader) parameter is 1 line

that is what i mean. no code changes, just 1 line.

But how did the material know about that parameter?

material know about parameter from 1 line user code like for example “mat.setColor()” then JME pass it to shader in appropriate way. Light list is also passed to shader. Im not sure why you ask this question.

Anyway what i mean, again, is that using simple things like for example:

  • mat.setColor()
  • mat.setTexture() (but in this case would need remember old one)
  • mat.getAdditionalRenderState().setWireframe()
  • etc etc

can be used to “mark” selected object, so dont really need outline. (ofc if Material is not shared between this objects)

I thought you meant some custom highlight feature in the shader.

If we are just talking about Lighting.j3md then…

Overrides the existing color so you have to remember the old one. You also need to set diffuse and ambient. So two lines plus remembering the settings to put it back. (And my recollection is that JME makes it extra-stupid-difficult to get the color from a material parameter safely… like 5 steps where one should do or something.)

As you say.

Makes really ugly geometry and unless you also clone it then it makes the solid version disappear. Frankly, if wire frame were enough then this thread wouldn’t exist.

This is why I still contend that adding the ambient light is the easiest way. It also looks nice and in some cases is actually the best aesthetic choice. As it stands today, I think it even works for PBR materials.

1 Like