# Projecting texture from an arbitrary position

I'm trying to write a surface shader (not a projector) to project a texture to a surface in a very similar way of what projectors do.

Currently I can easily obtain a shader that uses screenspace as UV:

        float2 screenUV = IN.screenPos.xy / IN.screenPos.w;


What I'm trying to achieve is to have an arbitrary plane to project the texture over the mesh that uses the shader.

I'm checking some resource online like https://en.wikibooks.org/wiki/Cg_Programming/Unity/Cookies but this is strongly related to light space.

My main doubt is how can I generate the UV coordinates from another plane? should I define somehow plane sizes or is it enough to define its position?

• There are three pieces of information you'll need to specify: 1) the direction of the plane (eg. its normal vector) 2) the scale of the texture relative to distances along the plane (eg. 1 unit of uv space = 1 unit of world space) 3) the origin point of the texture (where on the plane should we see 0,0 mapped to?) — you might be able to skip this last one if your texture is tiling seamlessly and you don't care about aligning the repeats in any particular way. – DMGregory Aug 22 '17 at 16:02
• @DMGregory should I specify the direction of the plane in world space? – MatterGoal Aug 22 '17 at 16:06
• Do you want the plane to be fixed in worldspace? If so, yes. If you want it to move/rotate with the object, or with the camera, then no. The right space for your plane depends on what you want to do with it. ;) – DMGregory Aug 22 '17 at 16:08
• understood! I'm trying to write the code for it! – MatterGoal Aug 22 '17 at 16:09
• @DMGregory any chance to get a code example for this old question or a link to a resource with more detailed info? – MatterGoal Feb 18 '18 at 8:59