How to make Lighting Materials Transparent

Hi there,

tried to figure this out like forever now. Cant get a Box transparent when Using Lighting/Light Material.

My Code:

`

Box b = new Box(1, .5f, 1);
Geometry device = new Geometry("Device", b);

Material mat = new Material(assets, "Common/MatDefs/Light/Lighting.j3md");
mat.setParam("Ambient", VarType.Vector4, new ColorRGBA(1, 1, 1, .5f));
mat.setBoolean("UseAlpha",true);
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

device.setMaterial(mat);
device.setQueueBucket(Bucket.Transparent);

`

I added light sources and aded it to the root node. With the Unshaded Material it is visible and transparent :frowning:

Please help!

Cheers,
Gem

1 Like

Hi

I think you need to set material color if you do not use texture then enable it to use material color :

mat.setColor("Diffuse", new ColorRGBA(1, 1, 1, 0.5f));
mat.setBoolean("UseMaterialColors", true);

for using material parameters please look at wiki page : https://wiki.jmonkeyengine.org/doku.php/jme3:advanced:materials_overview

1 Like

Thank you, this partly works now. But the top of the box is still opaque.

Cheers,
Gem

Glad it helped.
but about the new problem I really have no clue of what may cause it.sorry !
I did test with two boxes (1-one is behind the other 2- one is inside the other) and it worked correctly for me for all sides.
Hope guys here can help.

1 Like

try setting the specular light colour to transparent also…

mat.setColor("Specular", new ColorRGBA(1, 1, 1, 0.5f));

Thanks for your tip, but unforunately that didn’t work either. Still white.

`

public Node createNetworkDevice(Vector3f position, NodeType nt) {
    Node deviceNode = new Node("Device Node");

    Box b = new Box(1, .5f, 1);
    Geometry device = new Geometry("Device", b);

    Material mat = new Material(assets, "Common/MatDefs/Light/Lighting.j3md");
    mat.setParam("Ambient", VarType.Vector4, new ColorRGBA(1, 1, 1, .5f));
    mat.setBoolean("UseAlpha",true);
    mat.setColor("Diffuse", new ColorRGBA(1, 1, 1, 0.5f));
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Specular", new ColorRGBA(1, 1, 1, 0.5f));

    device.setMaterial(mat);

    mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
    device.setQueueBucket(Bucket.Transparent);

    // Calculate Translation
    // set pipe to correct position by translating it right between start and end
    device.setLocalTranslation(position);

    deviceNode.attachChild(device);
    return deviceNode;
}

`

perhaps the issue is not with the box, but with the other objects… are they in the transparent bucket also, how are they defined? can you make a super simple test case with only the box that doesnt render correctly, one light and one other object ?

Which version you are using ?
I am using jme 3.1 alpha 5
and get run time error in this line :
mat.setParam("Ambient", VarType.Vector4, new ColorRGBA(1, 1, 1, .5f));

also tried it with
mat.setColor(“Ambient”, ColorRGBA.White);

java.lang.ClassCastException: com.jme3.math.Vector4f cannot be cast to com.jme3.math.ColorRGBA
    at com.jme3.shader.Uniform.setValue(Uniform.java:323)
    at com.jme3.material.Material.updateShaderMaterialParameters(Material.java:804)
    ...

That should be bad on any JME version.

That should work, though.

when I remove this line
mat.setBoolean("UseMaterialColors", true);
it does not throw that exception anymore .

That exception comes from this line:

It cannot come from else.

If you are seeing an exception from that other line then it is a different exception or you are rebuilding improperly or something. Put some System.out.println(“Kilroy was here”) lines or something.

Thanks for your answers, I use jME3.0
This:

mat.setParam("Ambient", VarType.Vector4, new ColorRGBA(1, 1, 1, .5f));

actually worked in 3.0 without throwing an exception. I got it somewhere from the wiki. Changed it to this now:

mat.setColor("Ambient", new ColorRGBA(1, 1, 1, .5f));

Edit: for testing purposes I created nothing but the box and the transparency problem persists.

Cheers,
Gem

Yeah, I forgot that VarType is a representation of the shader types… but anyway setColor() is better. (There is a now-fixed bug in JME that was causing the exception before.)

Good morning .
I am an Android developer in Korea.
Like blue lines and yellow lines in your post
I would like to. Can you help me?