|
|
View Entity's Transformation Matrices
#143527
07/26/07 12:27
07/26/07 12:27
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
this may seem dumb to some, but i just have to be sure.
since view entities are handled (via C-script and lite-C) in screen space, can we translate vertices of view entities straight from object space to view space? or do they still need to go object space -> world space -> view space?
julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: View Entity's Transformation Matrices
[Re: JibbSmart]
#143528
07/28/07 19:12
07/28/07 19:12
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
result = mul(In.Pos, matWorldView); ... tex2DProj(mapWhatever, result);
matWorldView takes care of this, which to answer your question, object -> world -> view...
However, you'll need to scale result to fit the image to the screen properly, which can be a pain in the ass...
xXxGuitar511 - Programmer
|
|
|
Re: View Entity's Transformation Matrices
[Re: xXxGuitar511]
#143529
07/29/07 01:26
07/29/07 01:26
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
oh yeh... i hadn't done any practical shader work in a while and for some reason had the idea in the back of my mind that i had to do the object->world and world->view translations individually  thanks, julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: View Entity's Transformation Matrices
[Re: JibbSmart]
#143530
07/29/07 06:08
07/29/07 06:08
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
na, that would be a pain in the ass and most likely give you some "unexpected results"... Also, tex2DProj didn't quick work well enbough for me, so I used some offsets/scales with tex@D (and a tiny bit-o-math). On 1024x768 resolution @ 60 arc (In PS after passing above VS) VS: [float3] Out.Tex = mul(In.Pos, matWorldView).xyz; PS: float2 sPos = In.Tex.xy / In.Tex.z; sPos.y = 0.5 - (sPos.y* 1.142); sPos.x = sPos.x* 0.852 + 0.5; float4 colScreen = tex2D(mapScreen, sPos); Hope that helps. With my current 2.5D project, I'm relying on this shader. Right now I've got to calculate a formula for different resolutions and camera arc's. While resolution will be a linear equation, camera arc has proven (through a little graphing) to be quadratic, so I'm going to have A LOT OF FUN with this *sarcasm*...
xXxGuitar511 - Programmer
|
|
|
Re: View Entity's Transformation Matrices
[Re: xXxGuitar511]
#143531
07/29/07 11:20
07/29/07 11:20
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
wow man that looks less-than-fun. when u mentioned tex2DProj before, i wasn't sure what it was related to -- my question was just about the matrix maths used in just about every vertex shader (though i hadn't seen it used on view entities). i had a look on msdn (regarding tex2DProj) and as usual it wasn't very helpful. i assume its supposed to allow us to texture an object based on positions in screenspace -- good for pp effects? i was thinking about how i would do it (in mental pseudocode) a short while ago and thought that might be a bit simpler, so i'm not sure what you're showing me  do you mind a little explaining? i've seen a few references to your 2.5D project around the forums and my first guess is for pp texturing. julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: View Entity's Transformation Matrices
[Re: JibbSmart]
#143532
07/30/07 05:13
07/30/07 05:13
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
This is "simply" for drawing a texture onto the model at screen coords... kind of hard to explain, but here's an example (not the best reason to use these shaders, but the first one I could think of [besides portals, but thats more technical]  ) say you were doing a 2.5D game (as I am). You therefore have a background image that needs to be rendered, with invisible models for collision. Since we can't put panels/images behind the rendered level (character/objects, we use this shader The model will render exactly what would be behind it if there were an image. say we had our background image, and at our mouse_pos was a spherical model. When you move the mouse around the screen, you'd only see the portion of the image where the model was (like a spotlight). The shape of the model will not affect how the texture is drawn... back to the code: VS: [float3] Out.Tex = mul(In.Pos, matWorldView).xyz; PS: float2 sPos = In.Tex.xy / In.Tex.z; sPos.y = 0.5 - (sPos.y*1.142); sPos.x = sPos.x*0.852 + 0.5; float4 colScreen = tex2D(mapScreen, sPos); First, we do our calculations in the vertex shader. I don't know why each part has to be in VS or PS, but if there not, you'll get distortions) in our vertex shader, we find the position in view space of the vertex. float3 screenPos = mul(In.Position, matWorldView).xyz;Then, we send it to the pixel shader. I'm not sure how exactly this works (though I soon need to find out why), but you have to divide the screen portion [.xy] by the depth factor [.z]... float2 sPos = In.Tex.xy / In.Tex.z; then simply lookup the pixel with the given coords float4 colScreen = tex2D(mapScreen, sPos); Thats it really. the easy work is done, and not the texture is rendered with screen coords! The hard part though, is that the texture has to be scaled to match the screen size. The size of the inputed texture does not matter, as the coords are percentual (between 0 & 1). But the result of the screens arc and resolution is important... you must scale the texture to fit (which is what I'm working on). Hope this helps. Any more questions please feel free to ask, it's why I'm here 
xXxGuitar511 - Programmer
|
|
|
Re: View Entity's Transformation Matrices
[Re: xXxGuitar511]
#143533
07/30/07 07:35
07/30/07 07:35
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
okay, that's something like what i thought you were doing  i read somewhere that after "Out.Tex = mul(In.Pos, matWorldView).xyz;" the position of a vertex (or pixel) if it is onscreen is between -1,-1 (bottom left) and 1,1 (top right). in this case, if we have a texture representing the entire screen and we want to render it onto another model (such as a plane for pp effects or something else for portal effects), wouldn't the shader be really simple: Code:
VS: Out.Tex = mul(In.Pos, matWorldViewProj).xyz;
PS: float2 sPos = In.Tex.xy; sPos.x = (sPos.x+1)*0.5; // now ranges from 0 to 1 sPos.y = -(sPos.x+1)*0.5; // same deal, but not sure of 0,0 corresponds to top or bottom left in a texture float4 colScreen = tex2D(mapScreen, sPos);
of course i'm sure you would've thought of that if that was what you're after, so i hope that instead of me being wrong about implementation, i'm wrong about goal  i'm approaching the end of school and the deadline for a project so i don't have time to play around with ideas until late november  and so i don't have time to test my stuff. could you please let me know what i'm wrong about, whether it's in my code or in my assumptions of your goal? and another less-related question: is matWorldView basically the same as matWorldViewProj without perspective (like an orthographic view)? and i'd assume without the -1 to 1 range because it doesn't really have screen space. thanks mate, this is much appreciated julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: View Entity's Transformation Matrices
[Re: JibbSmart]
#143534
07/31/07 07:27
07/31/07 07:27
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
alright, my idea was way off, but i had read somewhere that screen space would be in the -1 to 1 range (obviously doesn't apply here) and if it was it would've been great.
how does it work then? i assume matWorldView is position relative to the camera (in quants) and matWorldViewProj is something similar but taking perspective into account or something. am i right? and what range does matWorldViewProj have?
sorry for all the questions, but the manual and msdn aren't very helpful in this area.
julz
EDIT: found something fairly nice with tex2Dproj: // float4 sPos = InTex; // sPos.y *= -0.5; // sPos.x *= 0.5; // float4 colScreen = tex2Dproj(ScreenSampler,sPos); this gave almost perfect results! no distortion whatsoever and simple code. except i need to offset the texture by 0.5% both axes (the corner of the texture is in the centre of the screen). this offsetting isn't so easy with tex2Dproj -- any ideas?
i tried your code and didn't get good results, but i haven't tried in your resolution. i'll take your word for it that it works, but i'd really like to get this offsetting in tex2Dproj right because this might prove simpler with varying resolutions/arcs.
Last edited by JulzMighty; 07/31/07 10:52.
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Almost Got View Entity's Transformation Matrices
[Re: JibbSmart]
#143535
07/31/07 12:01
07/31/07 12:01
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
OP
Expert
|
OP
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
yay! almost there: on GameDev i came across a matrix they used in projected shadows, and this is a bit of an approximation (it required other variables calculated in which i approximated) Code:
ballMat.matrix11 = 0.5; ballMat.matrix12 = 0.; ballMat.matrix13 = 0.; ballMat.matrix14 = 0.; ballMat.matrix21 = 0.; ballMat.matrix22 = -0.5; ballMat.matrix23 = 0.; ballMat.matrix24 = 0.; ballMat.matrix31 = 0.; ballMat.matrix32 = 0.; ballMat.matrix33 = 1.; ballMat.matrix34 = 0.; ballMat.matrix41 = 0.5; ballMat.matrix42 = 0.5; ballMat.matrix43 = 0.; ballMat.matrix44 = 1.0;
needless to say, ballMat is my material. now: Code:
float4x4 matMtl;
VS: OutPos = mul(InPos, matWorldViewProj); float4x4 matOffset = mul(matWorldViewProj,matMtl); OutTex = mul(InPos, matOffset);
PS: float4 colScreen = tex2Dproj(ScreenSampler,sPos); return colScreen;
easy as pie! i set other view to imitate the properties and positions of my camera to see if it made the ball invisible (after discovering projection was working great, and making the ball invisible to the other view). it works almost perfectly: there are some slight misalignments (looks like a cool offset stealth effect) which i partly associate with my slightly approximated matrix, and partly associate with something else: the image was being squashed vertically a bit, but had no rendering problems at the top or the bottom of the screen. this means that the second view is rendering more (vertically) than the first view, because of aspect differences. the trouble is, both views have the same size and aspect. as usual, any ideas would be appreciated. also, the GameDev articles said that the bottom two to the left (in gamestudio its matrix41 and matrix42) should be (float)0.5+(0.5/imagesize). since the image size tends to be fairly large, i decided it's close enough to 0.5 anyway because i wasn't sure what to use for imagesize, as my second view isn't a square. i hope i explained everything well enough, and maybe get a reply or something because this thread is getting lonely  julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: Almost Got View Entity's Transformation Matrices
[Re: JibbSmart]
#143536
08/01/07 04:45
08/01/07 04:45
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
*sigh* well, you found more thn I did. After 2.5 hours of research, and nt many results, I gave up... I did run accross the same thing you did on gameDev though. Something about a texture/material matrix. I didn't want to mess with it though... tex2Dproj(map, sPos) is the same as tex2D(map, sPos.xy / sPos.z). Just shorter... I just wish I knew the range of matWorldView and I'm not sure what the difference between matWorldView & matWorldViewProj is (other than proj  ) - but what difference does proj make? I need to do some more testing...
xXxGuitar511 - Programmer
|
|
|
|