Gamestudio Links
Zorro Links
Newest Posts
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
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Ayumi, Power_P), 1,065 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
projection shaders ... again #74828
05/20/06 14:14
05/20/06 14:14
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline OP
Senior Expert
HeelX  Offline OP
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
originally basing on this topic: http://www.coniserver.net/ubbthreads/showflat.php?Cat=&Board=SHADER&Number=495256

Dennis_fantasy and I tried to reimplement the projection shader of the WIKI and we both had in collaboration no success.

Rhuarc posted some WIP pictures of his shader which applies on both models and WMB surfaces...



dennis and I just wanted to play with it but we bite both into our keyboards because the WIKI shader is just submitted as a C&P and with no comments we werent able to reproduce it.

What we are looking for is a projection shader that supports at least projecting on models and intersected projections.. so that if two projected spotlight for instance intersect, it should keep working without any buggy behavior. WMB surface support would be nice, but we would be happy if there is at least one shader avaiable bound into a small demo (one room, two entities with 2 different projection images stored as the first entity skin, for instance), both projectors are rotating).

Thank you all in advance,
Christian

Re: projection shaders ... again [Re: HeelX] #74829
05/20/06 17:36
05/20/06 17:36
Joined: Dec 2000
Posts: 4,608
mk_1 Offline

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,608
All you need is to transform the vertices to the projection matrix. I couldn't find any useful information to do that though.


Follow me on twitter
Re: projection shaders ... again [Re: HeelX] #74830
05/21/06 00:15
05/21/06 00:15
Joined: Feb 2003
Posts: 195
slacker Offline
Member
slacker  Offline
Member

Joined: Feb 2003
Posts: 195
http://blogs.wdevs.com/tybon/articles/3074.aspx
http://www.ati.com/developer/ShaderX2_IntroductionToHLSL.pdf

found these - not sure how much they help. I am trying to get the basic theory here. When a model comes close enough to a projector, the projectors event is triggered, and the triggering entity has skills set to the projector position and orientation. This data is used in the shader to apply a texture to the model.

So the model would have to change it's material when it came within range of the projector, no?

Re: projection shaders ... again [Re: HeelX] #74831
05/21/06 06:04
05/21/06 06:04
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
Dont bother trying to use shaders on WMBs; they are too slow to be of any use.

Anyway, the problem with texture projection in A6 is that there is no easy way to set up your matrices--this is where you need to use D3DX.

Of course you can compute your matrices manually, but this will be difficult for anyone who isnt well versed in matrix math and 3d theory.

The basic procedure is this:
texprojmatrix = entityWorld * projectorView * projectorProjection

This computation should be done per-entity

Bascially, you need to read how d3d matrices are set up and manually construct them.


Sphere Engine--the premier A6 graphics plugin.
Re: projection shaders ... again [Re: Matt_Aufderheide] #74832
05/21/06 09:05
05/21/06 09:05
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline OP
Senior Expert
HeelX  Offline OP
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Ok.. let me see. I stored my shader in a .fx file. Here is the assignment in my code:

Code:

bmap pSkin = <projector_sprite.pcx>;

material matProjector
{
skin1 = pSkin;
effect = "projector.fx";
}

action actProjector
{
my.material = matProjector;
}



And this is my .fx file. This is a copy and paste of the shader of the Wiki. The first skin of the cube which I use as projector is identical to the PCX file I declare in the material settings.. I wondered why there are two skins used.. well this is the code:

Code:

texture mtlSkin1;
texture entSkin1;

matrix matWorldViewProj;
matrix matWorld;
matrix matMtl;

technique projector {
pass p0 {

VertexShaderConstant[0] = <matWorld>; //World Matrix
VertexShaderConstant[8] = <matWorldViewProj>;
VertexShaderConstant[95] = <matMtl>;

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

VertexShader=
asm {
vs_1_1
dcl_position v0
dcl_normal v3
dcl_texcoord0 v7
dcl_texcoord1 v8
; 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
};
}
}



Dont blame me for the copy and paste - I suspected that it doesnt work.

Well.. I dont know much about shaders and when I tried to get information about that VertexShaderConstant array, which I dont understand because later there is no reference to it for calculations, I didnt found anything useful or explaining on the MSDN. The ASM part is mostly not understandable for me.

In my test environment my model cube - which is the projector - is surrounded only by MDLs. When I run it, the cube has no shading at all, but you can see the texture. No projected sprite anywhere.

I don't beg that anyone explains me everything - but in the case of shaders I still need some help. AND I bought a book about it.. but the learning curve isnt that fast.

ciao
Christian

Last edited by HeelX; 05/21/06 09:05.
Re: projection shaders ... again [Re: HeelX] #74833
05/21/06 10:25
05/21/06 10:25
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
well of course you have to generate the matMtl matrix somehow ....how are you making this matrix?


Sphere Engine--the premier A6 graphics plugin.
Re: projection shaders ... again [Re: Matt_Aufderheide] #74834
05/21/06 10:41
05/21/06 10:41
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline OP
Senior Expert
HeelX  Offline OP
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Well, I didnt knew I should ^^

Ok, I set in a loop of the projector the camera's position and its angle to the according values of the projector, copy teh matView matrix into the material matrix.. well, here is the code:

Code:

material* tempMat;

action actProjector
{
var saveCamX[3];
var saveCamAng[3];

my.material = matProjector;

while (1) {

vec_set(saveCamX.x, camera.x);
vec_set(saveCamAng.pan, camera.pan);

vec_set(camera.x, my.x);
vec_set(camera.pan, my.pan);

tempMat = my.material;

mat_set(tempMat.matrix, matView);

vec_set(camera.x, saveCamX.x);
vec_set(camera.pan, saveCamAng.pan);

wait(1);
}
}



Now something happens.. when I center the view on the cube, there is something going on... I think something of the sprite is projected on the cube.. argh, but I didnt wanted that the camera projects on the cube, I want that the cube projects on every other entity.

Re: projection shaders ... again [Re: HeelX] #74835
05/21/06 16:22
05/21/06 16:22
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
Ok but that still wont work, because ..

m4x4 r10,v0,c95 ..this result needs to be a world*view*projection .. right now you are just doing position*view

so the way to do this in your shader is something like this:

VertexShaderConstant[0] = <matWorld>; //World Matrix
VertexShaderConstant[32] = <matProj>;
VertexShaderConstant[95] = <matMtl>;

m4x4 r10,v0,c0
m4x4 r10,r10,c95
m4x4 r10,r10,c32

this gives you something like this:
float4 temp = mul(Pos,matWorld);
temp=mul(temp,projectorView);
temp=mul(temp,matProj);

btw, i reccomend switching over to HLSL, this assembly stuff sucks.


Sphere Engine--the premier A6 graphics plugin.
Re: projection shaders ... again [Re: Matt_Aufderheide] #74836
06/09/06 23:58
06/09/06 23:58
Joined: Sep 2004
Posts: 1,214
Austin, Texas
Josh_Arldt Offline
Senior Developer
Josh_Arldt  Offline
Senior Developer

Joined: Sep 2004
Posts: 1,214
Austin, Texas
I got projective texturing working before.
The only problem is that I need support for sun light, dynamic lights and more projected textures.
I should go ahead and add sun light and dynamic lights...
I have no idea how to add more projected textures properly yet...

Here is a screenshot of a tree projecting a shadow texture:



Re: projection shaders ... again [Re: Josh_Arldt] #74837
06/11/06 04:14
06/11/06 04:14
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
To do multiple projected shadows for trees you would need to rende the trees from a virtual sun view camera to a render target. Then just project it once in the shader... need pro for this, or Sphere!


Sphere Engine--the premier A6 graphics plugin.
Page 1 of 2 1 2

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