- Home /
Billboard shader works in scene view but not game view
I'm trying to write a simple billboard shader for application on quads. It appears to be functioning as expected in the scene view, but the camera in the game view is completely wrong (objects clipping in and out of existence, not rotating with the viewpoint, etc.). The code for my shader is below, any help is much appreciated.
Shader "Custom/BillboardShader"
{
Properties{
_MainTex("Texture Image", 2D) = "white" {}
_ScaleX("Scale X", Float) = 1.0
_ScaleY("Scale Y", Float) = 1.0
}
SubShader{
Tags{"Queue" = "Transparent" "RenderType" = "Transparent" }
Pass{
CGPROGRAM
#include "UnityCG.cginc"
#pragma vertex vert
#pragma fragment frag
uniform sampler2D _MainTex;
uniform float _ScaleX;
uniform float _ScaleY;
struct vertexInput {
float4 vertex : POSITION;
float4 tex : TEXCOORD0;
};
struct vertexOutput {
float4 pos : POSITION;
float4 tex : TEXCOORD0;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.pos = mul(UNITY_MATRIX_P,
mul(UNITY_MATRIX_MV, float4(0,0,0,1))
+ float4(input.vertex.xyz, 0));
output.tex = input.tex;
return output;
}
float4 frag(vertexOutput input) : COLOR
{
return tex2D(_MainTex, float2(input.tex.xy));
}
ENDCG
}
}
}
Answer by IsaiahKelly · Sep 09, 2017 at 03:34 AM
Strange... Shader seems to work perfectly fine for me. Are you sure you have the shader assigned to the material for these objects that are misbehaving?
In any case, maybe this fantastic billboard shader pack can be of some help?
UPDATE: Looks like the shader works fine so long as I force the game camera to use Deferred rendering. Not sure why that fixes it, but for now that's good enough for me.
Funnily enough, I downloaded that shader pack and ran into the exact same problem I'm having with my own, haha. Perhaps I'm expecting behavior different from what's intended with these.
On the left is what I have in the scene view, with all the prefabs pointing directly at the camera. The right is the in-game camera viewpoint, which I've managed to move as closely as possible to match the scene view camera. It looks like the objects aren't adjusting properly in relation to the in-game view space. Is that how these shaders are supposed to work normally, or am I just running into some other weird issue?
I have the same problem, did you find a solution? I found that Billboard works in Game View ONLY if it has only one instance. If I create more than one it disappears, and if I delete all copies - it appears again. But for Editor View all is working always.
Answer by chantey · Dec 12, 2019 at 06:26 AM
I had the same issue after upgrading to Universal Render Pipeline from inbuilt. After pressing lots of buttons I found enabling "Use Post Processing" in the Camera Component solved the issue. The problem shader uses lots of in-built variables and screen space calculations, maybe post-processing updates these or something.
Your answer
Follow this Question
Related Questions
Transparent shader disappears with multiple objects 1 Answer
Unlit terrain shader 0 Answers
Change skybox shader color smoothly 1 Answer
Getting following error in outlog when I`d ran my game in Unity? 1 Answer
How can i combine shaders? 0 Answers