Uneven GetPixels reading

Hi all,

I’m working in a game where I must change a texture as an object pass over it.

I know I can get texture coords with “RaycastHit.textureCoord” and raycasting from four corners of a rectangular object (A,B,C,D) I can get a portion of the texture and extrapolate to the list generated with GetPixels.

So, no problem while the rectangular object is aligned with the underlying mesh, but I cannot figure out how to get the corrrect pixel list when the object rotates in a for loop or something like that.

See attached pic, the pixels in the blue texture are exagerated for easier understanding. What I need is the pixel list where the shadow hits.

I know my math is limited and maybe it’s a newbie question, but some help would be appreciated.

If you know how far your plane, so may be you needs just find intersection between 4 enough long lines (which passing through top object vertical edges) and the plane.

I duno if Unity can calculate intersections, but if not this is only math problem ( Line–plane intersection - Wikipedia ), see Delphi code from Пересечение прямой и плоскости / FAQ / Программирование игр / GameDev.ru — Разработка игр with my comments translation

type
  xyz = record 
  x,y,z : real;
  end;

var
  NotIntersectPlaneLine:boolean;

Function CreateVector(A,B:xyz):xyz;
//Function create vector from two points A,B.
//АВ = (В.х-А.х,В.y-А.y,В.z-А.z)
begin
CreateVector.x := B.x-A.x;
CreateVector.y := B.y-A.y;
CreateVector.z := B.z-A.z;
end;

Function  VectorProduct(A,B:xyz):xyz;
//Function makes vector multiply
begin
VP.x := A.y*B.z-B.y*A.z;
VP.y := A.z*B.x-B.z*A.x;
VP.z := A.x*B.y-B.x*A.y;
end;

Function  DotProduct(A,B:xyz):real;
//Function scalar multiply
begin
SP := A.x*B.x + A.y*B.y + A.z*B.z;
end;

Procedure Normalize(var A:xyz);
//Function of vector length normalization
var R,mlr:real;
begin
mlr := sqrt(sqr(A.x)+sqr(A.y)+sqr(A.z));

A.x := A.x/mlr;
A.y := A.y/mlr;
A.z := A.z/mlr;
end;

Function PlaneIntersectLine(A,B,C,X,Y:xyz):xyz;
//A,B,C - is the points of plane and X,Y is a points of direct
var N,V,W : xyz;
    e,d : real;
begin
NotIntersectPlaneLine := true;

N :=  VectorProduct(CreateVector(A,B),CreateVector(A,C));
Normalize(N);
V := CreateVector(X,A);
// distance to plane through normal
d :=  DotProduct(N,V);
W := CreateVector(X,Y);
// approximation to the plane of the normal when passing through the segment 
e :=  DotProduct(N,W);

if e<>0 then // one point,
//in any other case ( direct owns by plane or parallel) point of intersection not found

begin
PlaneIntersectLine.x := X.x  +  W.x*d/e;
PlaneIntersectLine.y := X.y  +  W.y*d/e;
PlaneIntersectLine.z := X.z  +  W.z*d/e;
NotIntersectPlaneLine := false;
end;
end;