[Solved] Alpha/color for non-lit HUD elements

I can't seem to get alpha and color (AlphaState + MaterialState) to work for my HUD.  Transparency works just fine for textured elements with alpha channels (i.e. the Text).  And the alpha and colors also work if I turn on Lighting for the HUD.  But, since it's a HUD, I want it to be unlit, so that all texture images show at the same brightness, etc.



Here's some code (this is inside the init for a HUD Node):


      setRenderQueueMode(Renderer.QUEUE_ORTHO);

      ZBufferState buf = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
      buf.setEnabled(false);
      setRenderState(buf);
      
      AlphaState alphaState = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
      alphaState.setBlendEnabled(true);
      alphaState.setSrcFunction(AlphaState.SB_SRC_ALPHA);
      alphaState.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
      alphaState.setTestEnabled(true);
      alphaState.setEnabled(true);
      alphaState.setTestFunction(AlphaState.TF_GREATER);
      setRenderState(alphaState);
      
      MaterialState backgroundMaterialState = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
      backgroundMaterialState.setEnabled(true);
      backgroundMaterialState.setDiffuse(new ColorRGBA(0.2f, 0.2f, 0.2f, 0.5f));

      Quad quad = new Quad("quad", width, height);
      quad.setRenderState(backgroundMaterialState);
      quad.setRenderState(alphaState);
      attachChild(quad);



So the quad is always just solid white.  Is there no way to use MaterialState colors/alpha without lighting?

Have you tried using a light state with no lights but setting the global Ambient value?

Have you tried using a light state with no lights but setting the global Ambient value?


Hi basixs,  yes I have, and the alpha does work then, but the problem then is that the only color of the MaterialState that shows up is the ambient.  Which is kind of annoying.  I could only use MaterialState.ambient to set all the colors of the HUD, but that just seems like a hack.

What about just using a directional light with direction +Z (into the screen)

Finally figured it out!  You have to setDefaultColor any primitive that you want to render with color/alpha, but no lighting. 

if u dont want it to be lit, just disable the light combine mode. that should be easy~



setLightCombineMode(Light.OFF);