- Home /
getting custom shader to work
hi all, ive been searching the internet for a shader to get a quad or sprite billboard to always face the camera. ive found a couple that people say work. ive pasted the code into a new shader, compliled it, added it to a new material, but they dont seem to do anything?
i dont know if there is something im not doing to implement my own shader - i mean, the texture im using for the test is rendering ok , but it doesnt face the camera, or change direction in any sense at all... im on unity 2017 i found this code on wikibooks... but it doesnt seem to do anything...
Shader "Cg shader for billboards" {
Properties {
_MainTex ("Texture Image", 2D) = "white" {}
_ScaleX ("Scale X", Float) = 1.0
_ScaleY ("Scale Y", Float) = 1.0
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// User-specified uniforms
uniform sampler2D _MainTex;
uniform float _ScaleX;
uniform float _ScaleY;
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.y, 0.0, 0.0)
* float4(_ScaleX, _ScaleY, 1.0, 1.0));
output.tex = input.tex;
return output;
}
float4 frag(vertexOutput input) : COLOR
{
return tex2D(_MainTex, float2(input.tex.xy));
}
ENDCG
}
}
}
thanks everyone. any help please?
paul uk
Your answer
![](https://koobas.hobune.stream/wayback/20220612133627im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Vertex Billboard Shader Depth? 1 Answer
Terrain Tree Billboard have bright outline against dark background 6 Answers
Need help applying an x-rotation to a billboard shader (i.e. cylindrical sprite) 0 Answers
shaders not compiling properly in monodevelop? 0 Answers
Need help with billboard shader 0 Answers