- Home /
Sprite facing multiple cameras?
Okay, it's a weird question, but say there is an item on the ground, and i'm using a sprite to represent it in a 3D space, i know how to make it face one camera, but what if it's a multiplayer game, is there a way to make it look like it's facing everyones camera no matter where it is, like when one player moves around the object, they say it always facing them, but the other player's version of the object never moves around, it just stays looking at them? If you need me to explain more, feel free to leave your 'what are you talking about?'
Answer by grahnzz · Apr 20, 2014 at 12:59 PM
Yes this is doable, i cant give you a straightforward implementation though. Take a look here for some reading: [http://www.gamedev.net/topic/358493-vertex-shader-for-screen-aligned-quads/][1]
Edit: found a billboard shader on this wiki: [http://en.wikibooks.org/wiki/Cg_Programming/Unity/Billboards][2]
Shader "Cg shader for billboards" {
Properties {
_MainTex ("Texture Image", 2D) = "white" {}
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// User-specified uniforms
uniform sampler2D _MainTex;
struct vertexInput {
float4 vertex : POSITION;
float4 tex : TEXCOORD0;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float4 tex : TEXCOORD0;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.pos = mul(UNITY_MATRIX_P,
mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1.0))
- float4(input.vertex.x, input.vertex.z, 0.0, 0.0));
output.tex = input.tex;
return output;
}
float4 frag(vertexOutput input) : COLOR
{
return tex2D(_MainTex, float2(input.tex.xy));
}
ENDCG
}
}
}
tested it and it and it doesnt work with quad mesh but cube and plane works fine. [1]: http://www.gamedev.net/topic/358493-vertex-shader-for-screen-aligned-quads/ [2]: http://en.wikibooks.org/wiki/Cg_Programming/Unity/Billboards