Shield Hit Effect (JME2)


Is it ok to post JME2 related questions here? If not, please remove this :slight_smile:

I want to create an effect like in many sci-fy media where the shields of a ship (like an energy force field) become somewhat visible when hit by weaponfire. Well you could just draw a transparent sphere around the ship for a short time, but that would’nt look very nice would it :slight_smile:

To make clear what I mean:

The shield effect should not only be a sphere around the object, but the effect should be stronger where the weaponfire acutally hit.

Could this be done with a shader?

Please let me know your thoughts on this :slight_smile:



yes it should be doable with a shader.

You would need to detect the collision on the shield too.

you could create a sphere around your model with a greenish color with alpha value to 0 on the impact. You send to the shader the impact position. In the vert shader you compute the alpha value from …let’s say, 0.5 to 0. the closer the current vertex is from the impact the higher would be its alpha value. this could be easy to do and the result might be nice.

if you don’t just want a plain color, map an “impact” texture made by an artist on the sphere. rotate the sphere on impact so that the impact on the texture match the impact position, and do the same alpha calculation.

Additionally, you could use a sine function to distort the alpha value so the texture looks wavy.

I did not test any of this, but those are the directions I would look into :wink:

Thanks for your response!

I guess I shouldn’t mentioned shaders, because I have no idea how they work and I am not able to produce one. So unless someone can code this for me… nevermind :slight_smile:

The hit detection is the smallest problem here, also getting the exact coordinate is easy in my setup. Maybe I’m going to try out this shader programing stuff, but thats not my highest priority right now. Thanks for your input though :slight_smile:

If anyone has some other idea how one might realize this (without having to program a shader g) you’re welcome to post here :slight_smile:


Maybe just use multiple spheres with mostly transparent textures. One that has the general “shield” (a half-transparent pattern of sorts) and others that are added when an impact happens. These would have a texture with an “impact point” and you turn that point towards the correct location. Then you maybe tweak the global transparency of the sphere to fade in and out when that happens and jiggle a bit or w/e.

Is global transparency part of any existing shader? I ended up having to tweak one to add in global transparency. Can post it here if needed, but I am sure someone else has posted something similar elsewhere.

What do you mean by global transparency?

DiffuseColor alpha and mix mode? Also remember he’s using jME2, I really dont know anymore how it was there, and I want to forget it too ^^

I have never used jME2, as I started after jME3 was introduced, so perhaps some of this does not apply the same, but here is a simple way that you could do it if all these components were in jME2…

Couldn’t you just make a sphere with the color or texture that you wanted the shield to look like, make the sphere require lighting, and put a light source just above the point of impact? Just make sure none of your other light sources can affect the sphere (are not in parent nodes), and your sphere will only be visible when you turn on the light source(s) (which you would only do on impact), and it would be more intense at the point of impact and less intense elsewhere. Also, notice the optional plurality of the word sources above; you could easily take into account multiple hits from different angles and have the shield respond to all hits appropriately just by having one light source per collision.

So let’s say you wanted just a solid green colored energy shield. You would use the Lighting material and set its diffuse and specular colors to green, probably make it very “shiny,” and apply it to a sphere. When you have an impact, you can get a vector from the center of the sphere to the point of impact, multiply it by 2, get its world coordinates, and put a light source there in the sphere’s immediate parent node. To make it quickly “brighten up” and then quickly fade away, you could even have the light source’s color start out at black and very rapidly increase it toward white then back down to black again before removing the light.

If you wanted a cool shield texture instead of just a solid color, then set its diffuse map to the shield texture you have.

This should be extremely simple to do. Again, I can’t say how this will work out in jME2, if at all, but hopefully there is a close equivalent.

nehon said:
What do you mean by global transparency?

If this was directed towards me... I mean an overall alpha that you can adjust in the shader frag: i.e. something along the lines of:

gl_FragColor.a *= m_Alpha; // assuming that m_Alpha was defined, etc, etc.

@loduwijk: That sounds like a great idea, assuming that this can be done in JME2. Question to the others: Can it? :slight_smile:

When I have time I’ll try to implement this quickly (and dirty at first, just to try it out) and I’ll post the results here whether it works (if nobody else posted before here that it won’t work ^^).

Thanks for all your input!


Well, after trying some stuff out now, I came to realize that I have no idea how to do the “make the sphere require lighting” part. How is this done in JME3? In JME2 the whole light thing is done with these Lightstates, which get Lights attached to, and Matrialstates I guess. There is also this LightCombineMode, but I can’t tell whats that all about :smiley: I also don’t know how to work with this stuff exactly, basically copy-pasted the stuff from tutorials and changed it a little bit (like colors and coordinates). So maybe someone can help me out here :slight_smile:

Is it even possible to realize loduwijk’s idea in JME2?

That is indeed different than jME3. In jME3, objects in your scene graph have a material (Actually an instance of a class of type Material) that references/uses the shaders you supply to it. The material dictates how the object will look. If you use the SolidColor material, the object will just be a solid color of your choice, no matter what. If it uses the Lighting material, you can specify parameters that tell how it reacts to light. So, to make it “require lighting” you just use the Lighting material. ‘Material m = new Material(“Common/MatDefs/Light/Lighting.j3md”)’ set that as the object’s material and set its ambient color properly, then you will not see it unless there is a light source nearby.

Check out the jME3 light test packages. That’s what I looked at to see how it worked.

Obviously the system in JME3 is much more flexible, nice work developers :wink:

But can this particular behaviour be done in JME2? I’m way to far into the development of my game to just switch to JME3, so I’m stuck here :slight_smile:

t0neg0d said:
If this was directed towards me... I mean an overall alpha that you can adjust in the shader frag: i.e. something along the lines of:

gl_FragColor.a *= m_Alpha; // assuming that m_Alpha was defined, etc, etc.

You can set the alpha value in the diffuse color to get the same effect.
Momoko_Fan said:
You can set the alpha value in the diffuse color to get the same effect.

Yeah, with shaders it's obvious it's gonna work, but since I don't know how to program them, I wanted to know, if you can do this without using shaders but with simple lighting manipulation, like the method loduwijk posted.
I guess in JME2 this requires shader programing. So I will post pone this one until I'm ready to dig deeper into the shaders ;)

Shaders are not as difficult as they seems, really.

A lot of capable programmers are reluctant to look into shaders because they think this is too difficult, but they would just do fine if they’d just take the leap…

This should be very simple to do even with jME2. Just project a “blow” texture onto the sphere, then dynamically change the alpha of the material.

There were many games that had the “shield” effect even before shaders even existed, so essentially there are many ways to make it.

1 Like

So I figured out how to dynamically change the alpha value of my shield (which is a simple sphere object). I use a controller that decreases the alpha value after a hit, works quite nice so far. But right now the shield only has a color, no texture. Also the whole shield is affected right now, but I would be nice to have a decreasing effect away from the hit-location.

I tried to add a simple pattern-like texture to the shield, but it won’t wrap around it the way I want it. The whole texture is somewhat wrapped around it once, there is no real repetition going on, and I have no idea how to change it. I searched for texture coordinates, but I can’t find how to use this correctly at my sphere.

Here is what I want:

The right sphere is the way it should look like, so it should repeat itself like a net around it.

How can I do this?

Divide the UV mapping to two domes (or don’t and let the pattern mirror repeat on the other side) and flatten them… like:

I’m sure there are a million other ways to do it. But this works. /shrug


Thanks for your answer, but I have no idea how to do this :slight_smile: I still don’t understand how to use these texture coordinates. Maybe you can help me ^^"