Light on a textured object?

Hi!

I can give light to an object that has no texture on it. But if i give the object a texture the light does not affect the object anymore. Why is this so and is there a possiblity how i could make that?

You need to add TextureAttributes to the Appearance.

 Appearance ap;
Material m = new Material();
Texture t = createTexture(8,sz); //This is my texture generation..
ap.setMaterial(m);
ap.setTexture(t);
TextureAttributes ta = new TextureAttributes();
ta.setTextureMode(TextureAttributes.MODULATE);  //This mix the texture and the light
ap.setTextureAttributes(ta);

  Rafael.-

Wow!! Thank you very much!!! Now it looks perfect!!

Can i ask another question? Could i make with a few lines of code that objects throw shadows onto other objects or is this a difficult task?

This is a difficult task.

You can implement some of the older solutions for shadows with the current Java3D like shadow volumes but thats a LOT of code and work to calculate them.

Newer solutions use multi-pass rendering and pixel shaders. Its still a fair bit of work and you cant do it with the current version of Java3D anyway as it doesnt support multi-pass rendering et.

There is no “shadow method” you can just call, sorry. I dont think there is likely to ever be one either as there are just too many tradeoffs to the differnt ways of doing shadows and an algortihm that does “perfect” shadows fast under all conditions is still very much an open research problem.

The best you are likely to find is exampel code for various techniques once Java3D becoems capable of supporting them…