Been working on a environment that uses a bending vertex shader, and have been trying to get my lens flares to match up with the positions as well.
The internal-flare.shader file looked like a pretty basic shader so i tried this.
Shader "Hidden/Internal-Flare"
{
SubShader {
Tags {"RenderType"="Overlay"}
ZWrite Off ZTest Always
Fog {Mode Off}
Cull Off
Blend One One
ColorMask RGB
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _FlareTexture;
float _XTransform;
float _YTransform;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 pos : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
float4 _FlareTexture_ST;
v2f vert (appdata_t v)
{
v2f o;
float4 vv = mul(_Object2World, v.vertex);
vv.xyz -= _WorldSpaceCameraPos.xyz;
vv = float4((vv.z * vv.z) * 0.00005 * _XTransform, (vv.z * vv.z) * 0.00005f * _YTransform, 0.0f, 0.0f);
v.vertex += mul(_World2Object, vv);
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = v.color;
o.texcoord = TRANSFORM_TEX(v.texcoord, _FlareTexture);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
return tex2D(_FlareTexture, i.texcoord) * i.color;
}
ENDCG
}
}
}
But it seemed to apply that vertex transformation in screenspace as opposed to worldspace like it did for everything else i have the same vertex shader applied too.
Anyone got any ideas of what this is happening and a way to work around it.