Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (kzhao, AndrewAMD, bigsmack), 824 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
perspective projection matrix #162825
10/22/07 16:26
10/22/07 16:26
Joined: Mar 2007
Posts: 99
Germany
zSteam Offline OP
Junior Member
zSteam  Offline OP
Junior Member

Joined: Mar 2007
Posts: 99
Germany
i try to programm a texture projection shader in HLSL.. it works but
the projected picture must be smaller in the near than in the far distance like a flashlight.

Joey told me that i need a perspective projection matrix. but i dont know how to solve this problem.

screenshot:


demo:
Texture Projection Shader.exe

my shader:
Code:

//--------------------------------------------------------------
// Texture Projection Shader HLSL
//
// © by zSteam
//
// date: 19.10.2007
// -------------------------------------------------------------

float4x4 matWorldViewProj;
float4x4 matMtl;

struct VS_OUTPUT
{
float4 Pos : POSITION;
float2 texCoord : TEXCOORD0;
float3 lightVec : TEXCOORD1;
};

VS_OUTPUT mainVS( float4 Pos : POSITION, float2 texCoord : TEXCOORD0 )
{
VS_OUTPUT Out = (VS_OUTPUT) 0;

Out.Pos = mul(Pos, matWorldViewProj);

float2 tps = (mul(Pos, matMtl) * 0.005f) + 0.5f; // ? und korrektur der position des projizierten bildes

Out.texCoord = tps;
Out.lightVec.xy = texCoord.xy;

return Out;
}

texture entSkin1;
texture mtlSkin1;

sampler BaseTex = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};

sampler ProjTex = sampler_state
{
Texture = <mtlSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = clamp;
AddressV = clamp;
};

float4 mainPS(float2 texCoord : TEXCOORD0, float2 lightVec : TEXCOORD1 ) : COLOR
{
float4 base = tex2D( BaseTex, lightVec );
float4 proj = tex2D( ProjTex, texCoord ) * 4;

return (base + 0.1 * proj);
}

technique projector
{
pass p1
{
VertexShader = compile vs_1_1 mainVS();
PixelShader = compile ps_1_1 mainPS();
}
}

technique fallback { pass one { } }




=> www.alrik-online.de
A7 Commercial
Re: perspective projection matrix [Re: zSteam] #162826
10/22/07 16:54
10/22/07 16:54
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
You need to alter the way your matMtl is setup. Try searching for "perspective projection matrix" in google, and use that to construct your matrix. Or put a view at the projector position, and get it's matView and copy that to your matMtl before rendering.

Re: perspective projection matrix [Re: Excessus] #162827
10/22/07 18:48
10/22/07 18:48
Joined: Mar 2007
Posts: 99
Germany
zSteam Offline OP
Junior Member
zSteam  Offline OP
Junior Member

Joined: Mar 2007
Posts: 99
Germany
hi .. sry but i don't understand what you mean .... what must i change

my script for the shader:
Code:

bmap projectiontex = <Spotlight.jpg>;

var scan_radius=1000;
var lighttimer=0;
var matTexProj[16];
var tempmatrix[16];
var WorldToProjection[16];
var matClipProj[16];

entity* beamer;

var d3d_automaterial = 1;

function mat_projection_init()
{
//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);

/*
mat_set(mtl.matrix,matView);
mat_multiply(mtl.matrix,matProj);

mat_inverse(mtl.matrix, mtl.matrix);
mat_transpose(mtl.matrix, mtl.matrix);
*/
}


material mat_projection
{
skin1 = projectiontex;

event = mat_projection_init;

flags = tangent | enable_render | translucent;
//effect = "tproj_asm.fx";
effect = "tproj_hlsl.fx";
}

function mat_projection_init_test()
{
if(!beamer){wait(1);}

//set up the texture projection matrix
matTexProj[0]=beamer.skill80;
matTexProj[1]=beamer.skill81;
matTexProj[2]=beamer.skill82;
matTexProj[3]=beamer.skill83;

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

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

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

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

/*
mat_set(mtl.matrix,matView);
mat_multiply(mtl.matrix,matProj);

mat_inverse(mtl.matrix, mtl.matrix);
mat_transpose(mtl.matrix, mtl.matrix);
*/

}
/*
material rockywall
{
skin1 = projectiontex;

event = mat_projection_init_test;

flags = tangent | enable_render | translucent;
//effect = "tproj_asm.fx";
effect = "tproj_hlsl.fx";
}
*/
function light_data()
{
if event_type==event_detect && my.skill4 == 6666 //projector
{
your.material=mat_projection;

//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;
}
}

function light_view_matrix()
{
//temporary matrix to store view matrix
//vec_set(proj_view.x,my.x);
//vec_set(proj_view.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
{
beamer=me;
MY.passable=ON;
my.invisible=off;
my.enable_detect=on;
my.event=light_data;

my.skill100=lighttimer;
lighttimer+=1;

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

wait(my.skill100);

while(1)
{
temp.pan = 360;
temp.tilt = 360;
temp.z = scan_radius;
//indicator=NULL;
scan_entity(my.x,temp);

light_view_matrix();

//vec_set(my.x,camera.x);
//vec_set(my.pan,camera.pan);
my.pan+=5*time;

wait(1);
}
}
}

action leinenwand
{
my.enable_scan=on;
}




=> www.alrik-online.de
A7 Commercial
Re: perspective projection matrix [Re: zSteam] #162828
10/22/07 19:08
10/22/07 19:08
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
Oh I see now, the matrix is correct but you forgot the perspective divide.

Try this:
struct VS_OUTPUT
{
float4 Pos : POSITION;
float4 texCoord : TEXCOORD0; // float 4
float3 lightVec : TEXCOORD1;
};


float4 tps = (mul(Pos, matMtl) * 0.005f) + 0.5f; // tps is float4 too.
tps.xyz /= tps.w;

Re: perspective projection matrix [Re: Excessus] #162829
10/22/07 19:20
10/22/07 19:20
Joined: Mar 2007
Posts: 99
Germany
zSteam Offline OP
Junior Member
zSteam  Offline OP
Junior Member

Joined: Mar 2007
Posts: 99
Germany
hi Thanks .. but this doesn't work and it's tilted :/




=> www.alrik-online.de
A7 Commercial
Re: perspective projection matrix [Re: zSteam] #162830
10/22/07 20:22
10/22/07 20:22
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
Ok keep the float4s, remove the division and change the tex2D to tex2Dproj. I'm just trying some things here, it's been a very long time since I've programmed shaders.

Re: perspective projection matrix [Re: Excessus] #162831
10/22/07 20:48
10/22/07 20:48
Joined: Mar 2007
Posts: 99
Germany
zSteam Offline OP
Junior Member
zSteam  Offline OP
Junior Member

Joined: Mar 2007
Posts: 99
Germany
ok thx i looks better but not real ... i think i need the z-axis (near/far clip)...




=> www.alrik-online.de
A7 Commercial
Re: perspective projection matrix [Re: zSteam] #162832
11/10/07 20:28
11/10/07 20:28
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
Did you have any further progress with this shader which could be worth to be shared (in case you don´t care about sharing)?

In case you´ve got it done without any problems, it would be awsome if you could add it to the 3DGS wiki or post it here, so that I could add it.

Thank you,
Slin


Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1