Transparency and Lightning

Hello,



in my game i use the force field fence from flagrushtutorial (same code). But strangely the transparent textures of the fence seem less transparent from certain viewing angles.



this picture shows how it looks.

In the upper part of the image, it looks just how it’s supposed to look.

But when you turn the camera a bit, the texture on the right side looks alot brighter and less transparent (middle part of the picture).

Another part of the force field looks brightened all the time, no matter from which angle you look at it (bottom part of the picture)



I suspect that this might have to do with the lightning, but i am not really sure. Maybe someone got a clue how to make the force field look the same all the time ?



private void setupLighting() {
   
      /** Set up a basic, default light. */
      DirectionalLight light = new DirectionalLight();
      light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
      light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
      light.setDirection(new Vector3f(1, -1, 0));
      light.setEnabled(true);

      /** Add a second light for more brightness */
      DirectionalLight light2 = new DirectionalLight();
      light2.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
      light2.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
      light2.setDirection(new Vector3f(1, -1, 0));
      light2.setEnabled(true);

      /** Attach the light to a lightState and the lightState to rootNode. */
      LightState lightState = display.getRenderer().createLightState();
      lightState.setGlobalAmbient(new ColorRGBA(1f, 1f, 1f, 0f));
      lightState.setEnabled(true);
      lightState.attach(light);
      lightState.attach(light2);
      rootNode.setRenderState(lightState);
   }

Hey papercut,



I had the same exact problem and I figured out how to solve it just now so here is what I did.



I used two lights just like you, but I had them face opposite directions. In your code you have two lights but they are facing the same direction: down and to the right. Because your lights are facing one direction this causes your transparent textures to not be lit properly. I'm not really sure why this is but messing with the directions of the lights will fix the problem.



I created two separate lights, just like you, but for the setDirection methods I had one face down and to the right/front corner and then the other faces down and to the left/back corner. Thus your code will need to look like this:



private void setupLighting() {
   
      /** Set up a basic, default light. */
      DirectionalLight light = new DirectionalLight();
      light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
      light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));

                //Have light face down and the right/front corner
      light.setDirection(new Vector3f(1, -1, 1));

      light.setEnabled(true);

      /** Add a second light for more brightness */
      DirectionalLight light2 = new DirectionalLight();
      light2.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
      light2.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));

      //Have light face down and the left/back corner
      light.setDirection(new Vector3f(-1, -1, -1));

      light2.setEnabled(true);

      /** Attach the light to a lightState and the lightState to rootNode. */
      LightState lightState = display.getRenderer().createLightState();
      lightState.setGlobalAmbient(new ColorRGBA(1f, 1f, 1f, 0f));
      lightState.setEnabled(true);
      lightState.attach(light);
      lightState.attach(light2);
      rootNode.setRenderState(lightState);
   }



This should fix your lighting problems.
Hope it helps!

Jack  :)

"Lighting" or illumination is the deliberate application of light to achieve some aesthetic or practical effect.

"Lightning" is an atmospheric discharge of electricity accompanied by thunder.

:smiley:

MrCoder said:

"Lighting" or illumination is the deliberate application of light to achieve some aesthetic or practical effect.
"Lightning" is an atmospheric discharge of electricity accompanied by thunder.
:D

I *love* smartasses, really I do :)
normen said:

I *love* smartasses, really I do :)


That smartass did much to help turn jME into the engine you know and love..  He may be partially wrong about the accompaniment of thunder though... you can see lightning further than you can hear it  :roll:

/On Topic:
JackKnifeZero, I'm going to try applying this to some trouble areas I've been having.. great tip!

There was no irony in my words :slight_smile:

And lightning in an atmosphere always goes with thunder, it does not matter if you stand next to it and hear it, the person whose roof has been hit surely heard it :smiley: And since sound travels with only about 3ms/meter you never hear what you see at the same time :stuck_out_tongue:

wow i really ruined this post with my faked smartassing :slight_smile: sorry about that!

The tags of this post, really sum it up!  XD

sbook,

Glad I could help!  :smiley:



MrCoder,

No worries! Your work on the engine has granted you rights to fake smartassery!  XD

XD