Rotation on screenPos Vector

Hi, is it possible to make a 180° rotation to the screenPos vector?

I have the reflexion of my object but I want my reflexion not to be inverted so I figured to multiply the screenPos vector (the on I use as a coordinate for my _GrabTexture) by a 2x2 180° rotation matrix (-1,0,0,-1) and when I do that, the reflexion just disapear…

Am I doing this right?

here is a snippet of my code to illustrate :

float2 screenPos = IN.screenPos.xy / IN.screenPos.w;
float2x2 rot180 = float2x2(-1,0,0,-1); //180deg
screenPos = mul(screenPos,rot180);
float3 reflexion = tex2D(_GrabTexture, screenPos);

OUT.viewDirWorldReflect = -WorldSpaceViewDir(v.vertex); //<–flipped texture coordinate for reflection in a vertex fragment
and then;
float3 reflectionVec = normalize(reflect(IN.viewDirWorldReflect ,worldNormal));

something like above will do your reflection.

Thanks for the reply but I don’t understand in which part of my code I should use the reflectionVec because it’s a float3 and I need a float2 as a coordinate for my _GrabTexture UV!

oh sorry i was thinking you would use a cube texture for reflection.

For the grabpass texture, you can check the example for refractive glass shader which comes with unity pro.

They use somethin like the following to flip the texture:
#if UNITY_UV_STARTS_AT_TOP
float scale = -1.0;
#else
float scale = 1.0;
#endif
o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
o.uvgrab.zw = o.vertex.zw;

I found the shader you mentionned and followed the creation of the uvgrab coordinates step by step. However, when I switch my screenPos for the uvgrab coordinates, my reflection is not visible on the screen…

in my vert function :

in my surf function :

You know grabtexture grabs the view which is behind the object, i dont know if it makes sense to use it for reflection.

Actually, it’s great because I just want to grab the mesh trapped inside my wave, so it’s perfect for that!

In Fact, I’d just like to reverse upside down my ScreenPos coordinates beceause I managed to display my reflection of my mesh on the wave with the screenPos coordinate, but I’d like to reverse these to actually project a second projection on the wave in order to see my mesh when he is behind it! Here is a low res (sorry) to explain better!

I tried multiple Math thing to the screenPos vector4 (including multiplication by rotation matrix) but in vain…) so if someone knows how to do it, please let me know! :]

http://dl.dropbox.com/u/24855439/screenPos.jpg

Thanks in advance.

Maybe before and/or after multiplying my rotation matrix I have to multiply a translation matrix in order to rotate it with the pivot in the center, maybe that’s why my texture disappear when rotating?

EDIT: Nevermind.

lol :]

So, no one knows how to do suck a thing? or to see where I’m mistaken? :]

Thanks!

After weeks of battle with that, I managed to find a way to break the symetry of my rider. I post the solution if anyone needs it one day :

That just inverted vertically my _grabbedTexture!