Hi,
I’m making a simple lens flare type effect by creating a billboard shader, putting it on a quad and then fading out and scaling the object based on the camera angle to the quad.
I’ve cobbled something together by cutting and pasting from the internet so as usual I’m not 100% sure how it works…
Basically I’ve smashed together a rim shader and a billboard shader, which kind of works, however. The problem is that I’m using the dot product from the rim shader to determine the angle between the camera and the quad and using that to scale the billboard and the billboard seems to scale non-uniformly.
v2f vert(appdata v)
{
v2f o;
o.uv = v.uv;
float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
float dotProduct = dot(v.normal, viewDir);
float rimWidth = _RimWidth;//0.3;
o.rim = smoothstep(1 - rimWidth, 1.0, dotProduct);
half fScale = dotProduct * _Scale;
//v.vertex.xyz *= fScale;
o.vertex = mul(UNITY_MATRIX_P,
mul(UNITY_MATRIX_MV, float4(0, 0.0, 0.0, 1.0))
+ float4(v.vertex.x, v.vertex.y, 0, 0)
* float4(fScale, fScale, 1, 1.0));
return o;
}
If I set fScale to a constant the the scale is uniform. But if I use the dotProduct to get fScale the the scale is non uniform.
I’m assuming that the because the doitProduct is being calculated per vertex then the fscale will be slightly different for each vertex and so it distorts.
Is there any way around this?
Thanks in advance