Prof. Monster's Fading and Transparency for all Shading modes

Hi Blenderheads,

this Tutorial shows you how you can establish (semi-)transparent materials in the BGE.

The will appear transparent in all shading modes:

  • Singletexture
  • Multitexture
  • GLSL


Be aware the materials will look a bit different in the various mode. This is because of different shading support.

Hint:
If you want Multitexture and GLSL appear nearly the same: switch the light’s fall-off to “Inverse Linear”.

Requirements:

  • A Game Object with a Mesh (e.g. a Plane)
  • The mesh should be completely unwrapped
  • An image texture should be assigned to the mesh

(Please look for according unwrap tutorials if you do not know how to do that)

Semi-transparency:

  • Select the object

  • Switch to Properties
    [LIST]

  • Material tab

  • Add a material to the game object (if there is not any)

  • Choose a name for the material (e.g. smoke or force field)

  • Texture tab
    [LIST=1]

  • Add a texture

  • Give the texture a good name (e.g. smoke, force field)

  • Set Type: Image or Movie

  • I recommend to set Preview to: Both and enable Show Alpha

  • Image: Choose the image you applied to the game object earlier

  • Mapping: Change the Coordinates from Generated to UV

  • Influence: enable Color (maybe set already) and enable Alpha

  • Leave Blend with Mix untouched

  • Material tab

  • Game Settings: set Alpha Blend: Alpha Sort

  • Options: enable Face Texture and Object Color

  • Transparency: Enable Transparency

  • Transparency: enable Z Transparency

  • Transparency: set Alpha to 0.000

  • Object tab

  • Display: hover over object color ensure Alpha is 1.00 and press <I> to make a object color key frame

[/LIST]
Switch to Logic Editor

  • AlwaysSensor, name: Init, No Pulses connect with
  • OR controller connect with
  • ActionActuator “SetColor” Mode: Play; Action: object color action; Start: 1.0; End: 1.0

[/LIST]

Do not forget to check the appearance of the materials in the various shading modes.

Hint: You can reuse the object color action for other objects. I recommend to name it like that (e.g. Fading)

Fading:
Fading is quite simple now. We just need a few additional steps.

  • go to another frame (e.g. 11)

  • Properties
    [LIST]

  • Object tab

  • Display: object color change Alpha to 0.0

  • Display: hover over the object color and press <I> to create a second keyframe

  • Logic Editor

  • Add any sensor to evaluate if fading should start (e.g. a Keyboard sensor) connect with

  • OR controller connect with

  • ActionActuator “Fading” Mode: Flipper, Action: object color action; Start:1.0; End:11.0

[/LIST]

Hints:

  • You can choose whatever sensor you like.
  • You can choose whatever controller you like.
  • You can choose whatever play mode you like.
  • Do not remove the previously added logic. Otherwise the material might not be visible after game start.
  • You can add more object color actions to get other fading effects.
  • You can set the “initial” logic to play another pose to get (semi-)transparent materials after game start. E.g. 6.0 = 50%, 11.0 = full transparent

I hope it helps

Attachments

FadeOutDemo.blend (165 KB)

This is exactly what Ive been looking for, for quite some time.

So cheers Monster, for yet again a comprehensive and easy to follow guide/tutorial for something pretty important. Really appreciating the time and effort youve been going to lately!

I’ve been trying to use this to fade objects into a scene that I have emitted from an empty, but am having a problem. The obj I’m fading is working on another layer fine. The amimation starts with zero alpha then over 25 frames it goes to alpha of one. But when i use an empty to bring it into the main game layer it flashes once at alpha one thengoes to alpha zero and starts the alpha fade in for as long as the animation is. How do I get it to come into the game with alpha at zero so it does not flash?

Could it be alright that will put thing about this in my small personal wephorum if I post a reference to blenderartists.org ? Best regards!

A link to here is fine
A copy is fine as long as you reference where you got it from.

Feel free to write your own instructions (with your words rather than a 1:1 copy) .

thanks for this prof! starting today i’ll be your number one fan! gonna search for more of your tutorials, (i’m quite new here hehe)

Any ideas on how to use this to fade an object into the game layer. Whe I try it it starts at aplha 1 then goes to alpha 0 and then fades in. I’m trying to get it to fade in from alpha 0 so it looks like it’s just magicly appearing? Any ideas at all? Thanks.

Sure, just revert the color action. You can even play it reverse.

As the object will start with its default color, you have following options:

  • start with the frame that shows full transparency (easiest method) e.g. frame 0
  • make the object invisible first and toggle visibility together with playing the object color (safest method, most efficient rendering) e.g. always sensor -> visibilityActuator + play action actuator

This was CRAZY helpful. Thank you so much Monster.

hi and thank you for all these infromation. One more question: is there a way to CAST (and receive for other materials) SHADOWS from “Transparent” png, ie. trees, in GLSL/multitexture mode ?

I haven’t played with shadows and do not consider it within these settings (they are default). I know this feature was asked a few years ago. I do not know if it already is build in.