Material colour vs texture colour vs lights

My scene has a behaviour attached that changes the light levels to create a day/night type effect. It works fine during the day phase but although I am sure that none of my objects have any emissive colour to them and the ambient and directional lights are both set to be (0, 0, 0) the objects are still drawing very clearly.

As far as I can tell, this is to do with the Material ambient colour and how it relates to the blend colour of the texture, but no matter what I change them to, I seem to get the scene drawn as though unlit when there isn’t a light source on it (by which I mean, as though there were no lights in the scene and it was just drawing the textures neatly, not a dark scene, which is what I want!) and responding to the brightness increasing. Or, I set both to black and I get a completely black object that doesn’t respond to any change in light level.

What settings do I need to use if I want the brightness to increase and decrease so the object is dark when unlit and light when lit?

I think its more likely to be the emissive colour you want to play with.

Kev

But the emissive colour is set to black on the material anyways.

The code that creates it is like this:


Appearance aper = new Appearance();

Color3f Black = new Color3f(0f, 0f, 0f);
Color3f White = new Color3f(0.5f, 0.5f, 0.5f);
javax.media.j3d.Material Mser = new javax.media.j3d.Material(White, Black, Black, Black, 0.05f);
aper.setMaterial(Mser);
TextureLoader Texget=new TextureLoader(new java.net.URL(ourFile), null);
Texture2D ourTex=(Texture2D) Texget.getTexture();
TextureAttributes texatt=new TextureAttributes(TextureAttributes.BLEND, new Transform3D(), new Color4f(0.5f, 0.5f, 0.5f, 0.5f), TextureAttributes.NICEST);
aper.setTextureAttributes(texatt);
aper.setTexture(ourTex);
this.setAppearance(aper);

By changing the Color4f and the Ambient colour I am getting a general colour change but losing the ability to respond to lighting. It actually looks as though I have another ambient light lying about somewhere, but I can’t find one, so I’m guessing it must be something in this appearance handling.

A wild shot in the dark, but have you set your texture blend mode correctly? To mix your object colour (from surface colour and light colour) with your texture colour you need the mode set to ‘MODULATE’ (although i forget where this constant is defined :-[ ).

Although shouldn’t you be messing with diffuse colours, not emissive or ambient to get the lighting to affect the objects?

You’re completely right about the diffuse and specular colours, in theory at least, but I am finding that using those two just comes out black. Maybe my lights aren’t strong enough.

I’m also finding that changing the colour of my AmbientLight doesn’t seem to do much. The directional light you can see because it changes, but no matter how I try to call setColor on the ambientLight it doesn’t seem to change, and when I tried to do a getColor I got a NullPointerException- could it be something about the AmbientLight?

[quote]You’re completely right about the diffuse and specular colours, in theory at least, but I am finding that using those two just comes out black. Maybe my lights aren’t strong enough.
[/quote]
You have set a sufficiantly huge bounds for the light, havn’t you…?

Yes - I am currently only doing this on one part of the scene until I get the appearance settings correct, and the rest of it is reacting normally to the lights (except that when unlit it just looks normal)

This is so annoying - I just know I’m missing something simple.

OK, here is how to do it:

  1. Make sure you have high white diffusecolor, something like 0.8 or 0.9 values.

  2. You MUST use TextureAttributes.MODULATE

  3. The ambient should be white(in most cases) and about half strength or lower.

PS. Remember to use DirectionalLight for the sun and moon, not pointlight.

The above will work, I does for me.

Regards
Nikolai

What about the texture blend colour in the TextureAttributes- any recommended settings for that?

Still keeps coming out black. The only one I’ve found that works at all at the moment is using the BLEND - everything else is just drawing black.