Working texture projectors :)

Posted By: Matt_Aufderheide

Working texture projectors :) - 09/02/04 05:27

Ok i have perfected my texture projector method.. is a little complicated so bare with me...

the way it works is you need to have a light projector object.. it will project according to its pan, tilt, roll and position... just think of it like a slide projector. assign this action the projector and make it's skill4=6666 in wed(this could be any number in any skill):

//put these vars somewhere before the action..
var scan_radius=210;
//how far it scans for objects.. if you use multiple projectors make sure the scan radius is small enough so they wont intersect..

var lighttimer=0; //needed for wait() statement.. this way the camera view are initialized.. you'll see later.

Code:
ACTION lightobject

{
MY.passable=ON;
MY.shadow=OFF;
my.flare=off;
my.transparent=off;
my.invisible=on;
my.enable_detect=on;
my.event=light_data;

my.skill100=lighttimer;
lighttimer+=1;

if my.skill4==6666 //is a projector
{
wait(my.skill100);

light_view_matrix();

while(1)
{

temp.pan = 360;
temp.tilt = 360;
temp.z = 220;
indicator=NULL;
scan_entity(my.x,temp);
wait(1);
}
}
)



before this action, you need this function:

Code:
 var tempmatrix[16];


function light_view_matrix()
{

//temporary matrix to store view matrix
vec_set(camera.x,my.x);
vec_set(camera.pan,my.pan);

wait(1);

mat_set(tempmatrix,matView);

my.skill80=tempmatrix[0];
my.skill81=tempmatrix[1];
my.skill82=tempmatrix[2];
my.skill83=tempmatrix[3];

my.skill84=tempmatrix[4];
my.skill85=tempmatrix[5];
my.skill86=tempmatrix[6];
my.skill87=tempmatrix[7];

my.skill88=tempmatrix[8];
my.skill89=tempmatrix[9];
my.skill90=tempmatrix[10];
my.skill91=tempmatrix[11];

my.skill92=tempmatrix[12];
my.skill93=tempmatrix[13];
my.skill94=tempmatrix[14];
my.skill95=tempmatrix[15];

}



what this is does move the camera around to each projector and stores the view matrix for each one in its skills 80-95.

now you need the projectors event function..put this before everything else:
Code:
 function light_data()

{

if event_type==event_detect && my.skill4 == 6666 //projector
{

your.material=mat_projection;
//you.skill100=6666;
//texture projection matrix
you.skill80=my.skill80;
you.skill81=my.skill81;
you.skill82=my.skill82;
you.skill83=my.skill83;

you.skill84=my.skill84;
you.skill85=my.skill85;
you.skill86=my.skill86;
you.skill87=my.skill87;

you.skill88=my.skill88;
you.skill89=my.skill89;
you.skill90=my.skill90;
you.skill91=my.skill91;

you.skill92=my.skill92;
you.skill93=my.skill93;
you.skill94=my.skill94;
you.skill95=my.skill95;

// return;
}

}



this assings the view matrix values to the object and also tells it to use the projection material if it isnt set already.

now on to the shader..

first you need the init function:
Code:
var matTexProj[16];


function mat_projection_init()
{

mtl.enable_render=on;

//set up the texture projection matrix

matTexProj[0]=my.skill80;
matTexProj[1]=my.skill81;
matTexProj[2]=my.skill82;
matTexProj[3]=my.skill83;

matTexProj[4]=my.skill84;
matTexProj[5]=my.skill85;
matTexProj[6]=my.skill86;
matTexProj[7]=my.skill87;

matTexProj[8]=my.skill88;
matTexProj[9]=my.skill89;
matTexProj[10]=my.skill90;
matTexProj[11]=my.skill91;

matTexProj[12]=my.skill92;
matTexProj[13]=my.skill93;
matTexProj[14]=my.skill94;
matTexProj[15]=my.skill95;

mat_set(mtl.matrix,matWorld);
mat_multiply(mtl.matrix,matTexProj);

}



now here is a very simple one pass shader set.. obviously this technique can be combined with others to mix projectors with per pixel lights etc..

Code:
 

material mat_projection
{

skin1 = projectiontex;

event = mat_projection_init;

flags = tangent;
effect =
"

texture mtlSkin1; //projector
texture entSkin1; //colormap
matrix matWorldViewProj;
//matrix matWorld;
matrix matMtl;

technique projector
{

pass p0 //projector
{

//load matrices
VertexShaderConstant[0] = <matWorld>; //World Matrix
VertexShaderConstant[8] = <matWorldViewProj>; //World*View*Proj Matrix
VertexShaderConstant[95] = <matMtl>;


//range constant
VertexShaderConstant[33] = (0.01f, 0.5f, 0.05f, 0.0f);

Texture[0] = <mtlSkin1>; //projection tex
Texture[1] = <entSkin1>; //projection tex

AddressU[0] = Clamp; // don't wrap around edges
AddressV[0] = Clamp;
AddressU[1] = Clamp; // don't wrap around edges
AddressV[1] = Clamp;

zWriteEnable=true; // enables writing to the z-buffer
//AlphaBlendEnable=true; // disables alpha blending
//srcblend=destcolor;
//destblend=one;


VertexShader=
decl
{
stream 0;
float v0[3]; //position
float v3[3]; //normal
float v7[3]; //uv
float v8[3]; //tangent
}
asm
{
vs.1.1

; position in clip space
m4x4 oPos, v0, c8

; position in texture projection space
m4x4 r10,v0,c95

; Divide each component by the range value
mul r10, r10, c33.x

; multiply with 0.5 and add 0.5
mad r10, r10, c33.yyyy, c33.yyyy

; map the x and y components into the first texture
mov oT0.xy, r10.xy

mov oT1.xy, v7.xy; color

};

PixelShader=
asm
{

ps.1.1

tex t0
tex t1

mov r0,t0
mul r0,r0,t1

};
}

}
";
}



i hope this all makes sense.. ive something doesnt work let me know and i can help. btw rememebr to setup a bitmap called projectiontex like so: bmap projectiontex = <light_alpha_1.tga>;

**NOTE-one problem that is inherent in this kind of texture projection is that it will project in front AND behind the projector.. if you want a true spot light projector there is probably somwway to clip the backside out but i dont know what it is.. can someone figure this out?

I dont think i will be making a demo.. if someone else wants to that would be great. but i'm too busy :P
Posted By: bupaje

Re: Working texture projectors :) - 09/02/04 05:32

For the dummies among us would you consider posting this as a minimalistic demo? Many thanks for your contribution.

Edit: Missed your note. If anybody with too much free time wants to post this as a demo it would be appreciated by certain nameless individuals

Interesting project -thanks again. I'd been wanting to try something like the Tarzan cartoon effect of having the shadows of tree branches cast on things for some time.
Posted By: Matt_Aufderheide

Re: Working texture projectors :) - 09/02/04 05:37

see above note^
Posted By: blaaaaa

Re: Working texture projectors :) - 09/02/04 05:44

can someone explain me what a texture projector is? i have no clue
Posted By: Orange Brat

Re: Working texture projectors :) - 09/02/04 06:00

Quote:

can someone explain me what a texture projector is? i have no clue




It's a mask for a light. You can "fake" a fancy shape for your shadows. Kind of like the cool shadow effects in Far Cry, Splinter Cell, and the new Thief. Not sure if the last two are using that method, but that's similar. See here:

http://w1.312.telia.com/~u31225218/fc/effects.html

Does this work with dynamic lights(according to the link it can only be used with them..at least in that engine)? Can the projected texture move around? Say I have a grate and a torch is on one side and projecting a grate shadow texture on the wall. Can I make the projector texture flicker/strobe like it's being affected by the torch?
Posted By: Alexander Esslinger

Re: Working texture projectors :) - 09/02/04 06:27

Here's a shot of my shader, showing projective texturing in GameStudio (so you can imagin what it looks like):


Posted By: Matt_Aufderheide

Re: Working texture projectors :) - 09/02/04 06:56

Quote:


Does this work with dynamic lights(according to the link it can only be used with them..at least in that engine)? Can the projected texture move around? Say I have a grate and a torch is on one side and projecting a grate shadow texture on the wall. Can I make the projector texture flicker/strobe like it's being affected by the torch?




it has nothing to do with dynamic lights or any other light in my example.. its a perpixel effect.. you make an object that acts as the projector.. in my example so far i dont think you can move the light around really.. because the projection matrix is set up at the begining of the game. To do it dynamically you would need to generate a projector view matrix every frame.. can be done but i cant get it work yet. However.. you can certainly add flickering lights by jiggling with mtl skills.. i haven't done this yet but should be possible without much trouble.. maybe i will take a look at it

however.. this projection shader is really meant to be used along with per-pixel lighting.. that way you can blend the two.. and then you can move the per pixel light around "behind" the projector and it will ac as a light mask.. i have all the relevant code work done in my project for this and more. I've gone beyond my old diffspec shader and have implemented single pass ps 1.4 lights with cube normalization.. maybe i will post this stuff when i have time.
Posted By: Steempipe

Re: Working texture projectors :) - 09/02/04 08:13

Hey Matt, it's really great that you post the results from all the hard work you have done with these effects. It is appreciated.
Posted By: William

Re: Working texture projectors :) - 09/02/04 10:08

Looks Great! Thanks.
Posted By: EX Citer

Re: Working texture projectors :) - 09/02/04 13:47

looks like this would be usefull to use it for liquids wrapped around the geometry... Hm, not really, better for shadows. Or maybe better for strange lights.

EX Citer
Posted By: Matt_Aufderheide

Re: Working texture projectors :) - 09/02/04 14:06

yes its most common use would be lights shining through a grating or some such.. also good for tree leaf shadows.
Posted By: ello

Re: Working texture projectors :) - 09/02/04 15:25

cool.. this is for sure extreeem usefull. lets see:)

in pass p0 there is a typo: shouldnt it be mtlSkin4 for the projection?
Posted By: MMike

Re: Working texture projectors :) - 09/02/04 21:26

i had to change mtlskin4 to mtlskin1..
and add mtlworldprojection matrix
And how do you did the shadow on the screen shot!?
I casn't make it to chow on the ground, but player is affected and it shows the shadow, but now on the floor.. HOw do i di that?

Thx in advance


The code is this.. i don't know if i follow the order of intructions.. maybe thats the problem...

here is it.. i won't use code tag, cause it doesn't work in script editor when pasting..

var matTexProj[16];
var tempmatrix[16];
function mat_projection_init()

{



mtl.enable_render=on;



//set up the texture projection matrix



matTexProj[0]=my.skill80;

matTexProj[1]=my.skill81;

matTexProj[2]=my.skill82;

matTexProj[3]=my.skill83;



matTexProj[4]=my.skill84;

matTexProj[5]=my.skill85;

matTexProj[6]=my.skill86;

matTexProj[7]=my.skill87;



matTexProj[8]=my.skill88;

matTexProj[9]=my.skill89;

matTexProj[10]=my.skill90;

matTexProj[11]=my.skill91;



matTexProj[12]=my.skill92;

matTexProj[13]=my.skill93;

matTexProj[14]=my.skill94;

matTexProj[15]=my.skill95;



mat_set(mtl.matrix,matWorld);

mat_multiply(mtl.matrix,matTexProj);



}






bmap projectiontex = <light_alpha_1.tga>;
material mat_projection

{



skin1 = projectiontex;



event = mat_projection_init;



flags = tangent;

effect =

"



texture mtlSkin1; //projector// skill4

texture entSkin1; //colormap



matrix matWorld;

matrix matMtl;

matrix matWorldViewProj;



technique projector

{



pass p0 //projector

{



//load matrices

VertexShaderConstant[0] = <matWorld>; //World Matrix

VertexShaderConstant[8] = <matWorldViewProj>; //World*View*Proj Matrix

VertexShaderConstant[95] = <matMtl>;





//range constant

VertexShaderConstant[33] = (0.01f, 0.5f, 0.05f, 0.0f);



Texture[0] = <mtlSkin1>; //projection tex

Texture[1] = <entSkin1>; //projection tex



AddressU[0] = Clamp; // don't wrap around edges

AddressV[0] = Clamp;

AddressU[1] = Clamp; // don't wrap around edges

AddressV[1] = Clamp;



zWriteEnable=true; // enables writing to the z-buffer

//AlphaBlendEnable=true; // disables alpha blending

//srcblend=destcolor;

//destblend=one;





VertexShader=

decl

{

stream 0;

float v0[3]; //position

float v3[3]; //normal

float v7[3]; //uv

float v8[3]; //tangent

}

asm

{

vs.1.1



; position in clip space

m4x4 oPos, v0, c8



; position in texture projection space

m4x4 r10,v0,c95



; Divide each component by the range value

mul r10, r10, c33.x



; multiply with 0.5 and add 0.5

mad r10, r10, c33.yyyy, c33.yyyy



; map the x and y components into the first texture

mov oT0.xy, r10.xy



mov oT1.xy, v7.xy; color



};



PixelShader=

asm

{



ps.1.1



tex t0

tex t1



mov r0,t0

mul r0,r0,t1



};

}



}

";

}




var scan_radius=210;
var lighttimer=0;





function light_data()

{



if event_type==event_detect && my.skill4 == 6666 //projector

{



your.material=mat_projection;

//you.skill100=6666;

//texture projection matrix

you.skill80=my.skill80;

you.skill81=my.skill81;

you.skill82=my.skill82;

you.skill83=my.skill83;



you.skill84=my.skill84;

you.skill85=my.skill85;

you.skill86=my.skill86;

you.skill87=my.skill87;



you.skill88=my.skill88;

you.skill89=my.skill89;

you.skill90=my.skill90;

you.skill91=my.skill91;



you.skill92=my.skill92;

you.skill93=my.skill93;

you.skill94=my.skill94;

you.skill95=my.skill95;



// return;

}



}






function light_view_matrix()

{



//temporary matrix to store view matrix

vec_set(camera.x,my.x);

vec_set(camera.pan,my.pan);



wait(1);



mat_set(tempmatrix,matView);



my.skill80=tempmatrix[0];

my.skill81=tempmatrix[1];

my.skill82=tempmatrix[2];

my.skill83=tempmatrix[3];



my.skill84=tempmatrix[4];

my.skill85=tempmatrix[5];

my.skill86=tempmatrix[6];

my.skill87=tempmatrix[7];



my.skill88=tempmatrix[8];

my.skill89=tempmatrix[9];

my.skill90=tempmatrix[10];

my.skill91=tempmatrix[11];



my.skill92=tempmatrix[12];

my.skill93=tempmatrix[13];

my.skill94=tempmatrix[14];

my.skill95=tempmatrix[15];



}

ACTION lightobject

{

MY.passable=ON;

MY.shadow=OFF;

my.flare=off;

my.transparent=off;

my.invisible=on;

my.enable_detect=on;

my.event=light_data;



my.skill100=lighttimer;

lighttimer+=1;



if my.skill4==6666 //is a projector

{

wait(my.skill100);



light_view_matrix();



while(1)

{



temp.pan = 360;

temp.tilt = 360;

temp.z = 220;

indicator=NULL;

scan_entity(my.x,temp);

wait(1);

}

}

}


Posted By: Alexander Esslinger

Re: Working texture projectors :) - 09/02/04 21:53

The screenshot is from my shader, Matt's may look different.
Posted By: MMike

Re: Working texture projectors :) - 09/02/04 21:55

ah.ok..heh
Posted By: Matt_Aufderheide

Re: Working texture projectors :) - 09/03/04 00:10

you are right.. i have edited those mistakes.. i had to clean it up to post here and forgot to change a few things.. everything should work now.

as it is now the shader wont project on world geometry.. however this is can be done easily enough.. just use material skills instead of entity skills to pass the matrix values.
Posted By: MMike

Re: Working texture projectors :) - 09/03/04 01:38

Well but then update the code , to project geometry too...

Other thing i noticed it that , the player is affected by the light mask, but not all of them, and if you get out of range .. then the player is all black..

ehhe.. is that a bug or ..
<.<
>.>

:P
Posted By: Matt_Aufderheide

Re: Working texture projectors :) - 09/03/04 01:51

make sure player has enable_scan=on
it should work.. if not theres something wrong with your implementation.

im not going to update to project on world geometry because i dont need it. Maybe someone else can modify this. In any case there needs a lot more work on the engine before world geometry can use most lighting shaders correctly.
Posted By: Helghast

Re: Working texture projectors :) - 10/23/04 03:03

matt,
could you help me implement it in my game??
please mail me, or add me on msn/icq..
i am having lots of trouble implementing it, i am being busy on it for 3 hours now, but i cant seem to let it work.
my video card does support it tho, could you please help me out??

regards,
Posted By: Helghast

Re: Working texture projectors :) - 10/24/04 04:09

no-one else who is able to help me out on this shader??
Posted By: PHeMoX

Re: Working texture projectors :) - 10/24/04 07:48

Have you done it exactly as the above code said, the big code part should be above the small part, and changed the typos it has? At the moment I don't really have time to help, but it should work actually, it does at my pc...

Cheers
Posted By: M3PHiSTOPH3L3S

Re: Working texture projectors :) - 10/24/04 09:19

Out of curiosity, should it be possible to use this shader to cast soft shadows of clouds on terrain and player models like the terrain of UT2004? I think that would be really cool.

M3PHiSTO
Posted By: Helghast

Re: Working texture projectors :) - 10/25/04 00:07

i really cant seem to get it to work...
phemox, if you do have the time, could you please contact me, i'd be most happy ^^

regards,
Posted By: Matt_Aufderheide

Re: Working texture projectors :) - 10/25/04 00:44

yes it could be used to cast cloud shadows.
Posted By: MMike

Re: Working texture projectors :) - 10/25/04 05:12

Does anyone can post the whole code.. Without typos please
Posted By: Matt_Aufderheide

Re: Working texture projectors :) - 10/26/04 02:14

there are no typos.. it works in directX 8..
Posted By: MMike

Re: Working texture projectors :) - 10/26/04 04:29

BUt ..when i run it.. The texture is project on all map places..
Like.. my babe is always black ... or the cross(the texture a used) is on the same place...

I just wanted to demand a code.. that you just need to paste.. cause i guess my problem is on the order of code..

So is there anyone to do such favor..?
Posted By: Matt_Aufderheide

Re: Working texture projectors :) - 10/26/04 05:19

the order of the code is described in deatil in my original post.. i can't do it any better. The reason you can't just paste it in is that it depends on how your project is coded to begin with.. if you cant figure out what it doing then basically dont bother
Posted By: Orange Brat

Re: Working texture projectors :) - 10/26/04 08:28

That's the spirit!
Posted By: Matt_Aufderheide

Re: Working texture projectors :) - 10/26/04 14:49

lol.. i dont mean to be nasty.. what i am saying is that is is for relatively advanced users..dont expect to just copy and paste
Posted By: MMike

Re: Working texture projectors :) - 10/26/04 22:38

The prblem is that i did all that ..but when i run it.. The code Is weird.. Like.. is nomral that the texture for exaple a (X) sprite.. is always at the same place.. all for all over the map.. like.. The texture is projected along not only its size..but for all tha map...
Posted By: MMike

Re: Working texture projectors :) - 12/08/04 03:39

matt .. this thing works, but .. just allow 1 projector right? and one reciever?

and why the projector projects black parts ( when the pic that is being projected is out of range)


Posted By: Matt_Aufderheide

Re: Working texture projectors :) - 12/08/04 06:18

first you need a texture for the projector that fades out at the edges, otherwise you get a sharp egde between the light and dark parts.. you can multiple projectors but not affecting the same models..

Also of course you have to implement some sort of lighting scheme in the shader also, other wise all the models can only be lit by the projector..it's really meant to be used in a multi pass per pixel lighting method
Posted By: MMike

Re: Working texture projectors :) - 12/08/04 08:14

EDIT:// OKay now I can have them all working, and fading cool.. but, it just works when fading to black, and .. When there are 2 entityes on the level , that are affected by the projector, both of them get them , but Shared, like if the other entity moves, the my material is shared and f it moves mine moves too even if im still
Sorry grammar.
eh






Posted By: Matt_Aufderheide

Re: Working texture projectors :) - 12/08/04 15:30

I'm sorry, i dont understand
Posted By: MMike

Re: Working texture projectors :) - 12/09/04 06:24

Humm let me explain:

* I have 2 entities that have a enable_scan=on;
* I have 2 projectors
* One of the entities has a actor_follow function; the other one is the player
NOw:
When the player and the other entity are under the projector, Both get the projetor material... but , just one works correctly because:

-> It seems they share the same material, so if the player moves , the projetion on the other entity will move when the player moves, and if the other one moves , my projetion will pause and give the control to the other one.

I hope you understand.. Thanks.
Posted By: A.Russell

Re: Working texture projectors :) - 07/08/06 16:43

I've just tried this one, too. It doesn't work as is. Perhaps it is old syntax?

Firstly, this line craps out: VertexShaderConstant[0] = <matWorld>; //World Matrix

I saw that the definition of matWorld was commented out ofr some reason, so I uncommented it, which got me as far as this line:

//range constant
VertexShaderConstant[33] = (0.01f, 0.5f, 0.05f, 0.0f);

And that was where I threw in the towel.



What I want is an image projected over the map all models as a cursor to select things in the environment. Is this posible, who can do it, and what do you want for it?
Posted By: PHeMoX

Re: Working texture projectors :) - 07/09/06 13:52

This shader needs to be converted to directx 9 code, that's probably all there is to it. If I can get it to work, you'll get it for free, no promises though, because I'm not sure wether I could fix it, nor if I've got the time for it to do it ...

Cheers
Posted By: Hummel

Re: Working texture projectors :) - 07/09/06 14:03

Coooool...thank you Phemox!!!
Posted By: A.Russell

Re: Working texture projectors :) - 07/11/06 01:33

Thanks Phemox. That would really be appreciated.
Posted By: EpsiloN

Re: Working texture projectors :) - 07/24/06 22:52

So , what exactly does this shader do ? Gets the texture behind the model and places it on the model ? Atleast thats what I saw on the screenshot....
Posted By: Hummel

Re: Working texture projectors :) - 07/25/06 07:01

http://www.coniserver.net/ubbthreads/showflat.php/Cat/0/Number/656165/an/0/page/1#Post656165
Posted By: Stansmedia

Re: Working texture projectors :) - 07/29/06 21:11

I dont know if this is the correct word im looking for, but water caustics? You know when your underwater and you see the light refractions from the water surface on the bottom of the pool and its all wavey and crazy. Yes, thats it. If you could animate the texture thats being projected you could make one helluvah sweet underwater enviorment.
© 2024 lite-C Forums