Light position transformation

Started by kkl, February 08, 2015, 09:19:16 AM

Previous topic - Next topic

kkl

Hi egon,

How do we apply light position final transformation for shader? I tried use Camera.transform the the light position and the final result is incorrect. I need it for uploading custom light position to shader. Thanks n look forward to ur reply.

EgonOlsen

The final light positions in world space will be injected into the shader if that's what you mean. If it's then...what do you mean exactly?

kkl

I thought final light position for shader is in camera space. How do we get it in world space?

EgonOlsen

My bad. You are right, they are in camera space. If you need them in world space, you have to add your own uniform and inject the position that you can obtain from each light into it but with y and z negated. But what do you need them for anyway?

kkl

Quotethey are in camera space. If you need them in world space, you have to add your own uniform and inject the position that you can obtain from each light into it but with y and z negated
Im using the same light calculation from JPCT default shader. So should the final light position in shader be in camera space or world space? If camera space, we just use Camera.tranform(), else negate y and z for world space?

QuoteBut what do you need them for anyway?
I want certain objects to receive light from different location, while not affecting the rest.

EgonOlsen

Camera space, if you want to apply the same calculations on it. You can obtain such a position by simply using Camera.transform() and then negate y and z, just as you've mentioned.

kkl

Strangely, it works correctly when I negate first, and then camera.tranform() it. I tested again using modelViewMatrix * originalLightPosition and it gives the same result. But it's different result when I camera.tranform() first, then negate it. What's going on there exactly? Wonder if I missed anything. 

EgonOlsen

I've double checked what i'm doing with all the normal lights and it's exactly that: transform into camera space, negate y and z, inject it into the shader. Where do your initiali light positions come from? Maybe they are already negated somehow!?

kkl

My bad.. The initial light position is negated at the beginning. Im using Blender to convert the light and other 3D object position into OBJ model and grab the position from there, so I dun have to rotate the mesh again. And the mapping is -Y for Y up and -Z for Z forward in Blender. But is it the correct way if we negate first and camera.tranform in this case? I tried just tranform w/o negating it, but the result seems incorrect.

EgonOlsen

Not sure what you mean. Convert the positions so that their locations in jPCT's world space are fine and then do the transform/negate steps mentioned above.

kkl

I mean the initial light position is already negated. I think it might mess up the whole mapping coordination. I'll try to adjust the mapping and use the method you mentioned earlier to transform. Thanks alot ; )

kkl

Hi egon,

I saw the Camera.transform() is creating new SimpleVector object for every use. Can we have another method to pass our own object for the result?

EgonOlsen

Yes, i've noticed that myself. I'll add such a method.


kkl