0
\$\begingroup\$

I need to project the light onto the quad and use its value for translating the vertices.

I'm currently having 6 vertices, two quads,
The points are A X C B Y D

Point X, Y are coming from two ray casting downwards.

C =  X + RightVector
D =  Y +  RightVector
A =  X - RightVector
B =  Y - RightVector

Now I want to translate the vertices based on lightDirectionVector, how would I do that ? I have a directional light, and that mesh of the two quads acting as a shadow quad.

    Vector3 lightDir = mDirectionalLight.transform.forward;
    Vector3 normLight = lightDir.normalized;
    normaLight.y = 0;
\$\endgroup\$
  • \$\begingroup\$ I have no idea what you're asking here. Can you add a diagram or screenshot or something that explains what you're trying to do? \$\endgroup\$ – Nathan Reed Apr 17 '14 at 20:10
  • \$\begingroup\$ @NathanReed I have uploaded a picture. \$\endgroup\$ – Andre Apr 17 '14 at 20:19
  • \$\begingroup\$ On your screenshot the shadow is wrongly rotated, you don´t expect that to change, right? So if I understand you correctly, you want to project the light direction onto the plane given by those vertices? \$\endgroup\$ – Slin Apr 17 '14 at 20:59
  • \$\begingroup\$ @Slin yes typically that's what I want to do. project the light direction onto the plane. just simulate a fake shadow \$\endgroup\$ – Andre Apr 17 '14 at 21:11
0
\$\begingroup\$

I am not sure if projection is actually the correct word for this, but I hope it is what you are looking for.

First you need the planes normal which is the cross product of the directions from one of your vertices to two of the others, which in case of your image could be C-A and B-A. (the three vertices may not lay in the same line, there is a simple mathematical term for it, but I guess I forgot it :( something with linearity...).

If you got the normal, you can calculate the closest distance of some arbitrary point of which your light direction is the position vector by building the dot product between your light direction and the normal.

Now you can calculate the position of that point within the plane by moving it along the normal towards the plane with the previously calculated distance: newdirection = direction - normal * dot(normal, direction)

But this will only give you the direction to the closest point on your plane to some arbitrary point defined by the light direction and I currently can´t get my head around if it really exactly is what you need or if it is only close.

\$\endgroup\$
  • \$\begingroup\$ looks correct to me, but I can't Imagine/visualize at all what you explained unfortunately :(. Especially this: , you can calculate the closest distance of some arbitrary point of which your light direction is the position vector by building the dot product between your light direction and the normal.I think the math term is co-planer. Would you recommend something to let me solve those kind of problems in future? \$\endgroup\$ – Andre Apr 17 '14 at 22:41
  • \$\begingroup\$ The term I was looking for was "independent" :) because your two vectors need to be independent. \$\endgroup\$ – Slin Apr 17 '14 at 22:45
  • \$\begingroup\$ they are in the same mesh.I can't visualize your solution and how did you come up with it. also please recommend me something to read so that I be able to solve those problems in future ? \$\endgroup\$ – Andre Apr 17 '14 at 22:47
  • \$\begingroup\$ is it wrong to just calculate one Normal from just one Plane (X-A, Y-A) for example? \$\endgroup\$ – Andre Apr 17 '14 at 22:47
  • \$\begingroup\$ Check this for a better explanation: stackoverflow.com/questions/9605556/… \$\endgroup\$ – Slin Apr 17 '14 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.