2 registered members (AndrewAMD, 7th_zorro),
1,285
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
projection shaders ... again
#74828
05/20/06 14:14
05/20/06 14:14
|
Joined: Jul 2001
Posts: 6,904
HeelX
OP
Senior Expert
|
OP
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
originally basing on this topic: http://www.coniserver.net/ubbthreads/showflat.php?Cat=&Board=SHADER&Number=495256Dennis_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]
#74830
05/21/06 00:15
05/21/06 00:15
|
Joined: Feb 2003
Posts: 195
slacker
Member
|
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: Matt_Aufderheide]
#74832
05/21/06 09:05
05/21/06 09:05
|
Joined: Jul 2001
Posts: 6,904
HeelX
OP
Senior Expert
|
OP
Senior Expert
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: Matt_Aufderheide]
#74834
05/21/06 10:41
05/21/06 10:41
|
Joined: Jul 2001
Posts: 6,904
HeelX
OP
Senior Expert
|
OP
Senior Expert
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
Matt_Aufderheide
Expert
|
Expert
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.
|
|
|
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
Senior Developer
|
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:
|
|
|
|