code:
action shadow
{
var pos[3];
var lightpos[3];
var lightdir[3];
my.passable=on;
my.unlit=on;
my.ambient=-100;
//my.transparent=on;
//my.alpha=75;
lightpos.x=0;
lightpos.y=0;
lightpos.z=0;
var numverts;
numverts=ent_vertices(my);
while(1)
{
vec_set(my.x,p_player.x);
var i=0;
while(i<numverts)
{
vec_for_vertex(pos,p_player,i);
trace_mode=ignore_models;
vec_set(lightdir,pos);
vec_sub(lightdir,lightpos);
vec_normalize(lightdir,100000);
trace(pos,lightdir);
vec_set(temp,target);
vec_normalize(normal,1); //shadow offset to avoid z-fighting
vec_add(temp,normal);
vec_sub(temp,my.x); //vec_to_mesh needs relative coords to my.x
vec_to_mesh(temp,my,i);
i+=1;
}
wait(1);
}
}
ent_create(shadowmdl,my.x,shadow);
you have to call ent_create to create the shadow.
shadowmdl can not be the same file as the model that should cast the shadow. this is another disadvantage. you have to make a copy with a different filename.
this was just an experiment. i don't think it's really useable or that it can be improved to be useable...
my model has 1200 faces and i didn't notice a slowdown.