Hello,
I got a billboard shader from Cg Programming/Unity/Billboards - Wikibooks, open books for an open world
I adjusted it a little to work with the default plane and with textures having an alpha channel:
Shader "Cg shader for billboards" {
Properties {
_MainTex ("Billboard Image", 2D) = "white" {}
}
SubShader {
Tags {"Queue"="Transparent" "RenderType"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha
Pass {
CGPROGRAM
// compilation directives
#pragma vertex vert // tells that the code contains a vertex program in the given function (vert here).
#pragma fragment frag // tells that the code contains a fragment program in the given function (frag here).
// User-specified uniforms
uniform sampler2D _MainTex; // define variable in order to have access to the property.
struct vertexInput {
float4 vertex : POSITION; // position in local space
float4 tex : TEXCOORD0;
};
struct vertexOutput {
float4 pos : SV_POSITION; // position after being transformed into projection space
float4 tex : TEXCOORD0;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
float4 camDir = 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.pos = camDir;
output.tex = input.tex;
return output;
}
float4 frag(vertexOutput input) : COLOR
{
return tex2D(_MainTex, float2(input.tex.xy));
}
ENDCG
}
}
}
This shader rotates the billboard in all directions (on all axes). I’m new to shader programming (like you can see from the comments ) and don’t know how to achive a rotation only on one axis. I’d like to have it only rotate on the global axis going up (y). Can you help me out?
PS: I have seen this question a lot in the forums/answers but never with a solution.