Spot lighting

I have a scene like so.

         

        (spot L)

            /

          @@@

       @@@@@

      @@@@@@

       @@@@@

        / @@@

      /             

     /__________



(Spot light shining down on a sphere. SL is the only light in scene)



I can understand why the sides are not lit but how come the bottom of the sphere is lit?  Shouldn't the top be the only part illuminated?



As a note the bottom is lit with the sphere's ambient color.

What is the globalAmbient of the lightstate set at?



Also, maybe some code or a pic would help.

It's possible you already have some lights in the scene; SimpleGame and some other jME application classes come with lights already attached. Try removing the spot light, if the sphere is completely black or completly white then there are no other lights on the scene.

Here is the code:


protected void simpleInitGame() {
       
        Sphere s1 = new Sphere("sphere",30,30,5);
        Sphere light = new Sphere("Light",new Vector3f(0,10,0),10,10,1);               
        rootNode.attachChild(s1);
        rootNode.attachChild(light);     
        MaterialState sms = display.getRenderer().createMaterialState();
            sms.setAmbient(ColorRGBA.gray);
            sms.setDiffuse(ColorRGBA.blue);
            sms.setShininess(100);
            s1.setRenderState(sms);           
        MaterialState lms = display.getRenderer().createMaterialState();
            lms.setEmissive(ColorRGBA.white);
            light.setRenderState(lms);                       
        lightState.detachAll();       
         SpotLight sl = new SpotLight();
            sl.setDiffuse(ColorRGBA.white);
            sl.setLocation(new Vector3f(0,10,0));
            sl.setDirection(new Vector3f(0,-1,0));
            sl.setAngle(20);
            sl.setEnabled(true);                                           
       LightState ls = display.getRenderer().createLightState();
            ls.attach(sl);   
       rootNode.setRenderState(ls);   
       
    }



sorry no pic. I don't know how to load one to the fourm

Looks like you are removing all the lights from ONE lightstate, then creating anouther and adding lights to it.



Maybe just try using the first lightstate.



Also, check your code.  You have a s1 AND a sl variable, be careful since they look so similar.



BUT the problem is your Emisive state, try removing that and seeing what happens.

That piece of code makes two spheres (light and s1) one that represents the light and the other is the sphere being lit. The emissive material is set to the light sphere not the sphere being lit. So that can't be what is wrong.



As far as I know LightState.detachAll() is put in to remove default lights of jme before I start making my own lights.



Oh right I will change s1 and sl in the future; could be confusing.

LightStates are different than openGL lights



you can ONLY have 8 openGL lights per lightState

you can have as many lightStates as resources allow (I believe)



If an object has more than 8 lights applied to it (through applied light states) it will only render 8



Also, if you add a lightstate to a node all objects in that node will have the light state attached.

Lightstates by default are also additive, if a parent node has a lightstate and the child node has a light state then the child node will actually have 2 lightstates (the parents and its own).



Each lightstate can also have an global Ambient light.









Your rootNode actually has 2 lightStates applied to it, the one called lightState and the one you created called ls.



BTW: this is all just information to help you out. :slight_smile:

Thanks that was helpful.



But I still don't understand why the spotlight seems to go right through s1 and light the top and bottom.  Considering what I learned,  "LightState" lightstate has any lights shut off and "ls" lightstate has one light "sl". So in the end s1 is only being lit by one light. Correct? 

BUT the problem is your Emisive state, try removing that and seeing what happens.

You're not listening  :expressionless:



That emissive is not set to the sphere I am lighting it is just set to a sphere that represents the position of the spot light.  This code has the exact same result. Just without the second sphere that represents the light.


 protected void simpleInitGame() {
       
        Sphere sphere = new Sphere("sphere",30,30,5);               
        rootNode.attachChild(sphere);   
        MaterialState sms = display.getRenderer().createMaterialState();
            sms.setAmbient(ColorRGBA.gray);
            sms.setDiffuse(ColorRGBA.blue);
            sms.setShininess(100);
            sphere.setRenderState(sms);           
                 
        lightState.detachAll();       
         SpotLight sl = new SpotLight();
            sl.setDiffuse(ColorRGBA.white);
            sl.setLocation(new Vector3f(0,10,0));
            sl.setDirection(new Vector3f(0,-1,0));
            sl.setAngle(20);
            sl.setEnabled(true);                                           
       lightState.attach(sl);
       rootNode.setRenderState(lightState);   
       
    }



Don't take this as hostilities,  :(  I just want a straight answer.

I wish i could post a pic to show you.



Maybe someone else try runing the code see what results.

i’m not expirenced enough to tell you what exactly happens.

You already pointed out in your first post, that this is the ambient color, so if you set the ambient color of the SpotLight to black, you’ll get more what you would expect.



Maybe someone else can shed some more Light on it :slight_smile:



The triangles at the bottom are inside the spotlight's "beam", so they use the light's characteristics.  Since their normals are facing away from the light though, only the ambient terms of the material and light are considered.  The default ambient of a light is new ColorRGBA(0.4f, 0.4f, 0.4f, 1.0f) in jME, so unless you set it to black, this type of thing will show…  I hope that helps explain things.  Perhaps the default SpotLight ambient should be black.

Boy, wouldn't it be easier if people understood at least a little about openGL before trying to use jME.

Thanks for posting the pic and for answering my question.  I understand now.



With all do respect basixs, I don't think snide remarks like that are needed here. This is a forum for collaborative learning; if everyone were sent away, this forum would be futile.  (Now my turn at a snide remark and we will be even  ;)) If you are such an expert why did you not incisively answer the question in your first post?

I cannot answer for Baxis about this, but from what I can see, he was just being doubly sarcastic about it… blaming also himself for not knowing the issue.



I have to say it didn't strike me either at first, it was until Renanse pointed out the are of effect of the light that it just made sense… So I don't think this was a st00pid question or anything.



Give us a chance, we are a great community here at jME. 

Okay, ://

I didn't read that post as merely sarcasm.



I have read many threads in this forum and did conclude this is a good community. 

This is a GREAT community.



For instance, let's just let this go; no need for a flame war. 


If you are such an expert why did you not incisively answer the question in your first post?




I apologize if you took offense to what I said, I was just commenting on a trend I have been noticing on the forums (probably an inappropriate time).  Having said that one of the things that makes this such a great community is people's understanding and tolerance, not to mention the time taken out of one's own project to try to help someone else ;).