projection shaders ... again

Posted By: HeelX

projection shaders ... again - 05/20/06 14:14

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
Posted By: mk_1

Re: projection shaders ... again - 05/20/06 17:36

All you need is to transform the vertices to the projection matrix. I couldn't find any useful information to do that though.
Posted By: slacker

Re: projection shaders ... again - 05/21/06 00:15

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?
Posted By: Matt_Aufderheide

Re: projection shaders ... again - 05/21/06 06:04

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.
Posted By: HeelX

Re: projection shaders ... again - 05/21/06 09:05

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
Posted By: Matt_Aufderheide

Re: projection shaders ... again - 05/21/06 10:25

well of course you have to generate the matMtl matrix somehow ....how are you making this matrix?
Posted By: HeelX

Re: projection shaders ... again - 05/21/06 10:41

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.
Posted By: Matt_Aufderheide

Re: projection shaders ... again - 05/21/06 16:22

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.
Posted By: Josh_Arldt

Re: projection shaders ... again - 06/09/06 23:58

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:


Posted By: Matt_Aufderheide

Re: projection shaders ... again - 06/11/06 04:14

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!
Posted By: xoNoid

Re: projection shaders ... again - 06/15/06 17:22

@Josh_Arldt: Any chance of posting a demo .
Posted By: A.Russell

Re: projection shaders ... again - 07/07/06 19:11

Did anyone ever get this shader to work?

I followed this post, but when I tried to add Matt's ASM code to the .fx file I got errors.

If no-one has done it, is anyone here capable of doing it? I'd be prepared to pay a commission for a working projection shader.
Posted By: Captain_Kiyaku

Re: projection shaders ... again - 01/16/07 16:52

i know this one is old, but...
i tried the shader and i get it to work that its always infront of the camera. but how can i let it project just down from the top? I replaced the positions with a model but that doesnt work either:




entity* ptrproject;

action projector
{
my.invisible = on;
my.passable = on;
ptrproject = me;
}



material* tempMat;

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

while(!ptrproject) { wait(1); }

my.material = matProjector;

while (1) {

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

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

tempMat = my.material;

mat_set(tempMat.matrix, matView);

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

wait(1);
}
}
Posted By: Captain_Kiyaku

Re: projection shaders ... again - 01/16/07 17:30

okay it works now with a second view. but now i need more than one "picture" to be projected, too Is there any way to do that?

EDIT: and how can i add it to more entitys ? It only works for one model now...
Posted By: mk_1

Re: projection shaders ... again - 01/18/07 15:52

Render on a quad model and use it as view entity.
Posted By: JetpackMonkey

Re: projection shaders ... again - 06/12/07 10:12

I'm trying to create water caustics for an ocean floor -- hs anyone on this thread had further success or made newer versions of the projection shader?
Posted By: Orange Brat

Re: projection shaders ... again - 06/12/07 10:42

Quote:

I'm trying to create water caustics for an ocean floor -- hs anyone on this thread had further success or made newer versions of the projection shader?




I know you mentioned a shader for caustics, but have you seen this little program:

http://www.dualheights.se/caustics/

It's specifically made for caustics. Perhaps you could create an animated sequence and somehow render to texture of the results (or by any other means that can be done to execute this) on the geometry that requires the effect?

There's a free and commercial version:

Quote:


Caustics Generator (free version):








Graphical user interface
Several parameters to control the caustics
Preview the output while changing the parameters
Available for the Microsoft Windows platform
Open Source
Free!










Caustics Generator Pro (commercial):









Command line interface for stand alone use or integration into third party programs
High Dynamic Range Image output (HDRI)
Available for Linux and Microsoft Windows platforms
Source code can be licensed for integration into own tools






BACK TO TOPIC (sort of ): I'm interested in a Shader 2.0 projection shader. Since learning that there is much more standardized goings on behind the scenes with 2.0+ shaders, I've become more interested in them. I see no need to support 1.x anymore given this one huge advantage; however I'm not quite ready to start beating the 3.0 or 4.0 drum just yet. Anyway, for my title, a projection shader, per pixel lighting and dynamic hard to soft shadows, shader fog (don't know what to call it), and other fancy lighting/shadows effects are what I'm interested in. To get a better idea, go take a look at the Alan Wake tech demo on Youtube. The very brief part where they go inside the building are the type of effects I'm after, as well as the Unreal3 tech demo of the lantern coming down the stairs that's been out for months (I'll have to find it and post some day).

I'm not too interested in normalmapping, and I'm also wanting to experiment with a toon shader for the style I want for my characters. All of this would need to be 2.0 and work on all 2.0 cards (for obvious reason....FX cards need not be worried about).
Posted By: JetpackMonkey

Re: projection shaders ... again - 06/12/07 11:21

Hi, thanks Orange Brat-- yup already got the caustics animation rendered!

That might work.. hm tho its a large scene with many objects.. problem is that the surface is one of those large multi-texture mdl terrains.
Posted By: DexLoomer

Re: projection shaders ... again - 06/15/07 10:33

Hi, excuse my bad English!
I also try to use the "Projection Shader" but I don't succeed!
Is there an example scene where someplace the Shader is used?
Greetings,
Dex
Posted By: DexLoomer

Re: projection shaders ... again - 06/20/07 21:46

Still am on the search for an example script of ´Projection Shader´!
Can somebody help me along?
I would like to make a flashlight with that like in the game FarCry.
Greetings Dex
© 2024 lite-C Forums