Comments and answers for "Image Effect - Screen coordinates"
http://answers.unity.com/questions/1027365/image-effect-screen-coordinates.html
The latest comments and answers for the question "Image Effect - Screen coordinates"Comment by MaT227 on MaT227's answer
http://answers.unity.com/comments/1027867/view.html
Thank again !Thu, 13 Aug 2015 06:40:59 GMTMaT227Comment by zach-r-d on zach-r-d's answer
http://answers.unity.com/comments/1027709/view.html
Sure. UV coordinates go from (0,0) to (1,1) whereas screen coordinates go from (0,0) to (screenWidth, screenHeight). So multiplying by _ScreenParams.xy is necessary to get the pixel coordinates.Wed, 12 Aug 2015 23:17:26 GMTzach-r-dComment by MaT227 on MaT227's answer
http://answers.unity.com/comments/1027663/view.html
Thank you very much for your answer. Could you explain your last line a bit more ?
o.screenPos = uv *_ScreenParams.xy;Wed, 12 Aug 2015 20:58:50 GMTMaT227Answer by zach-r-d
http://answers.unity.com/answers/1027483/view.html
The first way only works in image effect/screen-space shaders, but is more accurate. Basically, the uv coordinate of a fragment in the screen-space plane will be equal to its normalized viewport coordinate. So that value can be trivially manipulated to get the screen-space coordinate (although UV_STARTS_AT_TOP needs to be accounted for). In that code sample I think to get the screen position in pixel coordinates requires the last line to be "o.screenPos = uv*_ScreenParams.xy" though.
The second way works in any kind of shader, but will not be quite as accurate, and potentially more expensive to compute. It takes a world-space position, multiplies it by the MVP matrix to get it into viewport coordinates, then translates that into pixel coordinates.
tl;dr use the first one when making an image effect, second when making a normal (object) shader.Wed, 12 Aug 2015 15:45:34 GMTzach-r-d