Light rotating with node

hello,

i am rotating a geometry using quaternions

but for some strange reason, it renders like if the light was following the rotation with the object
just as if the light was rotating with and around the object

here is the code for rotation

[java]
Quaternion rotY = new Quaternion();
rotY.fromAngleAxis(90 * FastMath.PI / 180f, new Vector3f(0, 1, 0));
object.setLocalRotation(rotY.multLocal(object.getLocalTransform().getRotation()));
[/java]

here is the light setup

[java]
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.Gray);
rootNode.addLight(al);

    lightDir = new Vector3f(-0.5f, -1.0f, -0.5f).normalizeLocal();
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.Gray);
    dl.setDirection(lightDir);
    rootNode.addLight(dl);
         
    DirectionalLight dl2 = new DirectionalLight();
    dl2.setColor(ColorRGBA.Gray);
    dl2.setDirection(new Vector3f(0.5f, -1.0f, -0.5f).normalizeLocal());
    rootNode.addLight(dl2);

    DirectionalLight dl3 = new DirectionalLight();
    dl3.setColor(ColorRGBA.Gray);
    dl3.setDirection(new Vector3f(0.5f, -1.0f, 0.5f).normalizeLocal());
    rootNode.addLight(dl3);

[/java]

anyway rotating the object should not influence the lights

is there some update i need to do on the geometry when i rotate it

anyway i used opengl for years, and rotating an object usualy appears rendered with the light staying where it is

plz help

thx

The light shouldn’t be moving unless you move it. My guess is that maybe the object doesn’t have normals or isn’t really lit and the lighting is baked in. Based on the limited information provided, that’s my best guess.

Put together a simple one class test case the illustrates the problem and you will probably find your bug.

Why don’t you just call object.rotate(a,b,c)?

The behaviour you are seeing isn’t what I would expect so you are doing something odd…

<cite>@pspeed said:</cite> The light shouldn't be moving unless you move it. My guess is that maybe the object doesn't have normals or isn't really lit and the lighting is baked in. Based on the limited information provided, that's my best guess.

Put together a simple one class test case the illustrates the problem and you will probably find your bug.

no it has normals, it is correctly shaded
it’s just wicked, i’ll keed digging
never saw something similar before
thx anyway

<cite>@zarch said:</cite> Why don't you just call object.rotate(a,b,c)?

The behaviour you are seeing isn’t what I would expect so you are doing something odd…

oops did know about that, i’ll give it a try

thx mate

@curtisnewton said: no it has normals, it is correctly shaded it's just wicked, i'll keed digging never saw something similar before thx anyway

As I said, put together a simple test case… maybe with a box or a sphere. If that works (which it will) then you can start sorting what is different about your code that breaks it. In fact, I’d eliminate your model from the testing right away. Instead of loading your model use a box or a sphere and see if the light still moves. It could be something specific to your model… maybe it has its own light, for example.

<cite>@pspeed said:</cite> As I said, put together a simple test case... maybe with a box or a sphere. If that works (which it will) then you can start sorting what is different about your code that breaks it. In fact, I'd eliminate your model from the testing right away. Instead of loading your model use a box or a sphere and see if the light still moves. It could be something specific to your model... maybe it has its own light, for example.

yep th’at’s what i’ve done

it is working with an ico sphere imported from blender

but as i check my model normals, they are all ok , pointing outside
i’l keep digging
thx for your help

Do you use normal mapping?
If you are you have to generate the tangents and binormal on your model, otherwise the lighting will be completely screwed up
TangentBinormalGenerator.generate(model);

<cite>@zarch said:</cite> Why don't you just call object.rotate(a,b,c)?

The difference there is in the coordinate spaces. rotate () does it in the local space of the spatial, while what he did will rotate it in global space. Whether thats what he want idk :stuck_out_tongue:

@nehon said: Do you use normal mapping? If you are you have to generate the tangents and binormal on your model, otherwise the lighting will be completely screwed up TangentBinormalGenerator.generate(model);

Small correction… binormals are calculated in the shader. You only need the tangents… and I’m 99% sure that’s all that the generator adds now. But I can’t be bothered to recheck the code. :slight_smile:

If it does generate binormals then it’s wasteful because the lighting shader only uses normal and tangent.

Other than that, you are 100% correct about needing tangents if you are using normal mapping and/or bump mapping. You get sometimes really strange results otherwise.

@pspeed said: Small correction... binormals are calculated in the shader. You only need the tangents... and I'm 99% sure that's all that the generator adds now. But I can't be bothered to recheck the code. :)

If it does generate binormals then it’s wasteful because the lighting shader only uses normal and tangent.

Other than that, you are 100% correct about needing tangents if you are using normal mapping and/or bump mapping. You get sometimes really strange results otherwise.


lol yes it only computes the tangents and the binormal is computed in the shader Mr pedantic ;), I just though it was an irrelevant detail for the issue.

Maybe the model coming in from blender has its own lights in the blender import?

They would move with it and maybe drown out the other lights you added yourself.

Open the model in scene explorer and take a look. I find the SceneExplorer tree view very useful for looking at just what is inside a j3o file and making sure it is as expected.

hi everyone,

thx for all the support

the issue was that indeed, there was a light attached to the scene i was loading

as the model is a small object, i had it in really closed zoom in the blender view
i just completely forgot to remove camera and light

i feel so ashamed, ha ha ha

thx anyway

i 've learned my lesson

First rule of debugging: Always check your assumptions :slight_smile: