Shading

hi, I tried to use shading in my small program. It is actually the HelloXith3D-code. I deactivated the colors of the cube, put a PointLight to the cam’s position and enabled lighting in the cube’s material and in the RenderAttributes of the canvasPeer.
Now the cube is lit in a nice red light but without shading. You can’t see the edges in front of the cam. It’s like one level surface that is now red.
I belive someone here can help me,
thx & cu

what do you set for the material? (diffuse shading,…)
Have you also added an Ambientlight? If yes, this would explain, why there’s no shading.

hi & thx for your answer.
I use the normal HelloXith3D-demo with a light:

PointLight l=new PointLight();
l.setEnable(true);
l.setColor(new Color3f(1,0,0));
l.setLocation(new Point3f(0,0,4f));
scene.addChild(l);

and the cube with some attributes:

Geometry geo = Cube.createCubeViaTriangles(0, 0, 0, 1, true);
Appearance ap=new Appearance();
Material m=new Material(true);
m.setDiffuseColor(1,0.5f,0.5f);
m.setEmissiveColor(new Color3f(1,0.5f,0.5f));
m.setShininess(0.9f);
m.setSpecularColor(1,0.5f,0.5f);
ap.setMaterial(m);
ColoringAttributes ca=new ColoringAttributes(new Color3f(1,0.5f,0.5f), ColoringAttributes.SHADE_FLAT);
ap.setColoringAttributes(ca);
Shape3D sh=new Shape3D(geo, ap);

I played a bit with the settings but none did what I wanted them to do :frowning:

You shouldn’t set Emissive Color I think, cause it makes the Object shine. I would set it like that:


   Material m=new Material(true);
  m.setAmbientColor(0.3f,0.3f,0.3f); // You'll need some ambient settings, too
  m.setDiffuseColor(1,0.5f,0.5f);
  m.setSpecularColor(0,0,0);    // disable reflections (I don't like them)

  • You will have to use setColorTarget I think, but I don’t know what the best mode is for you and even if you need to set it.

Arne

hi & thx. I’m trying it on Monday, althoug I don’t know how that influences shading.
cu

:frowning: it doesn’t work. Is it really that complicated to use simple shading in Xith? Has noone ever used it succesfully? In poor openGL it’s quite simple. It seems I have to use it directly.
cu

no don’t !! It works fine (for me, so it will probably also for you :wink: )

here is my code I use succesfully to set my Appearance:


         Appearance appear = new Appearance();
         Material m = new Material(true);
         m.setAmbientColor(0.5f,0.5f,0.5f);
         m.setDiffuseColor(1,1,1);
         //m.setEmissiveColor(0.5f,0.5f,0.5f);
         m.setSpecularColor(0.0f,0.0f,0.0f);
         if(textures.size() == 0) m.setColorTarget(m.AMBIENT_AND_DIFFUSE);
         else  m.setColorTarget(m.NONE);
         appear.setMaterial(m);
         TextureUnitState[] texStates = new TextureUnitState[textures.size()];
        for(int i = 0; i < textures.size(); i++) {
            texStates[i] = getTexture(i).calculateTextureUnitState();
        }
        appear.setTextureUnitState(texStates);

Do you generate Normals for your object?
What does happen when you don’t add the light?
Could you also post an image?

Arne

thank you very much arne, it finally works now :slight_smile:
I forgot to add normals :frowning:
thx & cu