# Projecting a light onto a quad

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;

• 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? Apr 17, 2014 at 20:10
• @NathanReed I have uploaded a picture. Apr 17, 2014 at 20:19
• 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?
– Slin
Apr 17, 2014 at 20:59
• @Slin yes typically that's what I want to do. project the light direction onto the plane. just simulate a fake shadow Apr 17, 2014 at 21:11

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.

• 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? Apr 17, 2014 at 22:41
• The term I was looking for was "independent" :) because your two vectors need to be independent.
– Slin
Apr 17, 2014 at 22:45
• 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 ? Apr 17, 2014 at 22:47
• is it wrong to just calculate one Normal from just one Plane (X-A, Y-A) for example? Apr 17, 2014 at 22:47
• Check this for a better explanation: stackoverflow.com/questions/9605556/…
– Slin
Apr 17, 2014 at 22:50