Front projected texture

does someone have a shader or shader snippet for a front projected texture like used in sphere(DX)https://vvvv.org/sites/default/files/imagecache/large/images/shadersnippet.PNG

Out.TexCd = (mul(PosO, tWVP)*0.5)-.5;

Would do it, theres probably a cleverer way to do it though!

cheers man!

mm, not working. i have a sphere and i want to image to stick in the front. with your code, the texture moves.

Out.TexCd = (mul(PosO, tP)*0.5)-.5;
worked…

Damn, works without a perspective node in there, must need to inverse the projection I guess…

Hmm, that doesnt seem to work for me, still distorts around the edges…

yep, setting this thread to “solution” was a bit overhasty.

still not working like front projection, anyone ?

I made a streaming gsfx for basic uv projection, maybe that helps if you are using dx11.

But in general if you declare your view & perspective nodes without the system vales (the : VIEW & : PROJECTION) then you are free to choose what you feed to the pins- Ie from the camera for camera projection or from an independent matrix for projector or pinned texture style.

UV_Coords (GSFX).zip (3.3 kB)

i guess the term “front projected” is a bit misleading here.
it actually has nothing to do with view and projection of the renderer.

what is tries to communicate is: the texturing shall look like somebody projected the texture frontally onto the object. (orthogonally, ignoring z, like a slide projector that has nothing to do with the camera … ruling out all tP, tVP, tWVP etc matrices)

so FrontProjected_XY is about x and y of the object. The idea is to just take object coordinates and map them in a most trivial way to texture coords.

And that is what is done in the dx9 particle. it just copies x and y of the object coordinates.

float2 texcd = Pos.xy;

there are two other steps you will want though:

  • transform with a texture transform matrix
  • map to texture coord space (0,0…1,1)

here is how you could do this in a dx9 shader:

//relate texture coords to xy-coords of object (front view)
float2 texcd = Pos.xy;

//TT) do some texture transform
texcd = mul(texcd, tTex);	
	
//MAP) map to texture coord space: (-0.5,-0.5 .. 0.5,0.5) to (0.0,1.0 .. 1.0,0.0)
texcd.x = texcd.x + 0.5;
texcd.y = 0.5 - texcd.y;	
	
//you could also do MAP before TT. check out the different scaling behavior
	        
Out.TexCd = float4(texcd, 0, 1);  //this is bloated. float2 would be enough (no perspective distortion in texture needed). anyway to lazy to change that vs2ps.TexCd from float4 to float2. super happy though with writing comments like this

i’d rather do it this way tho:

//take transformed object position
float4 texcd=mul(In.PosO,tTex);
//undistort when tTex contains projection transform, otherwise .w equals 1
texcd.xy=texcd.xy/texcd.w;
//map to UV-space
texcd.xy=texcd.xy*float2(0.5,-0.5)+0.5;
//output
Out.TexCd=float4(texcd.xy,0,1);

then if you want to change that from front projection (xy) to top (xz) or side (yz), just pass a corresponding rotation transform to it
also, if worldviewprojection matrix is passed to this texture transform, texture will match the fullscreen quad mapping=)

note that tTex in this case should be a regular transform not a :TEXTUREMATRIX (or uvspace=true in dx11 case)

unc really nice versatile solution!

only i am not sure about the wanted default behavior. i guess i would prefer seeing more of the texture if no scale is attached.

so the hybrid of our solutions provides the code for that:

float4x4 tTex <string uiname="Texture Transform";>; // no TEXTUREMATRIX semantics this time




//take transformed object position
float4 texcd=mul(Pos,tTex);
//undistort when tTex contains projection transform, otherwise .w equals 1
texcd.xy=texcd.xy/texcd.w;
//map to UV-space
texcd.x = texcd.x + 0.5;
texcd.y = 0.5 - texcd.y;   
//output
Out.TexCd=float4(texcd.xy,0,1);

however for your billboarding texture trick to work you now need to feed (WVP*0.5).

didn’t try, but this should work for volume textures as well.

//take object position
float4 texcd = Pos;

//custom texture transform (optional)
texcd = mul(texcd, tTex);

//undistort when tTex contains projection transform, otherwise .w equals 1
texcd = texcd / texcd.w;

//map to UV-space
texcd.y = -texcd.y;   //flip y
texcd.xyz = texcd.xyz + 0.5;  //notch -0.5 .. 0.5 --> 0..1

//output
Out.TexCd = texcd;

ehm. just as a side note for whom it may concern.

when using the billboardish texturing trick: you get cleaner output by doing the division by w in the pixelshader…

in your vertexshader you then have some uber simple code like this:

Out.Pos = mul(Pos, tWVP); //transform position
Out.TexCd = mul(Pos, tTex); //transform position with texture matrix and treat as TexCoords

in your pixelshader do the division by w (like seen in the default shaders)

float4 texcd = In.TexCd;

//undistort when tTex contains projection transform, otherwise .w equals 1
texcd = texcd / texcd.w; 

//map to UV-space
texcd.y = -texcd.y;   //flip y
texcd.xyz = texcd.xyz + 0.5;  //notch -0.5 .. 0.5 --> 0..1

float4 col = tex2D(Samp, texcd);

almost forgot about this thread, unc and gregsn…thank you very much for all your answers. very kind.

Is there a shader to do this in DX11? Unfortunately this is beyond my ability…

dx11 version: https://github.com/unc-quite/dx11-vvvv-girlpower/blob/master/nodes/dx11/ConstantProjection.fx