- Home /
Project UVs from Camera Shader
Hey there. For a project I need a shader that permanently projects the UVs from the view of the camera. So far I could not find a shader preset like this, not in unity and not on the internet. So i tried to program it on my own but guess what, I failed gloriously.
Actually I don't even know how exactly to start or what to connect in the code with each other to get a shader with this effect. Has anyone done something like that before? Or does anybody know how to do it and cloud show me the programcode? I would be very thankful!
Do you have any picture examples of the effect you are trying to achieve? Almost sounds like you want to use world coordinates? I've seen those shaders, nice.
Hi. Thank you for your answer. I don't have pictures, but you can imagine it as a shader that will always show the same picutre in the same angle on an object, because the uv's are projected from the camera. I think the most plausible example would be a sphere where you have a picture on it, that will always look towards you, no matter how you turn your camera to the sphere. $$anonymous$$aybe something like the 'figure in a sphere'-effect, just that the figure is always shown from (for example) the front view :)
PS guys there is no apostrophe on plurals. It is just UVs.
Answer by OP_toss · Aug 19, 2013 at 05:03 PM
You mean like this? (detail texture in screen-space)
Shader "Example/ScreenPos" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_Detail ("Detail", 2D) = "gray" {}
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
float4 screenPos;
};
sampler2D _MainTex;
sampler2D _Detail;
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
float2 screenUV = IN.screenPos.xy / IN.screenPos.w;
screenUV *= float2(8,6); //half the tiling x/y
o.Albedo *= tex2D (_Detail, screenUV).rgb * 2;
}
ENDCG
}
Fallback "Diffuse"
}
Directly stolen from Unity's Docs. If this is what you want, please try to look at Unity Docs first before asking a question.
Hope this helps!
Thank you very much for your answer. Yes, i meant something like this, the texture looking towards me works just fine with it. But I'm trying to get a shader that will leave the size of the tiling and the textures position on the object always the same. So with this shader, if I zoom in and out or if I shift the camera, the tiling ajusts with the distance or the position of the camera (f.e. there will be more tiling if I'm far away). Is there any possibility to make the texture always turn towards me, but if I shift the camera, it will follow it and if I zoom, the tiling stays the same? I think this could work with the sphere, if I calculate the closest point on the object to the camera and this point should always be a specific point on the UV, for example 0.5, 0.5 (the middle). But I just don't know how to program that. Could anyone help?
Answer by Cec · Apr 10, 2014 at 01:41 PM
Sorry to dig up a height months tread... You might search for Project UV from camera asset on the asset store. https://www.assetstore.unity3d.com/#/content/16133
This is not a shader but it allows you to project UV from camera screen space AND you can do it ones with single button or with the API), or in realtime. So you can project your UVs, then fix it up, and move your camera as you wish, without the UVs to be modified. You can even place the shaders you want on you gameObjects without affecting the projection.