Hello everyone. I am trying to create a particular shader effect.
Basically, I want the emissivity of the vertex to scale with its relative speed with the camera.
Right now, I manage to scale the emissivity of the vertex with its distance from the camera with the following shader:
Shader "Unlit/EmissiveSpeed Shader" {
Properties{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo (RGB)", 2D) = "white" {}
_Dist("Distance", Float) = 1
_Glossiness("Smoothness", Range(0,1)) = 0.5
_Metallic("Metallic", Range(0,1)) = 0.0
_EmissionColor("Color", Color) = (0,0,0)
_EmissionMap("Emission", 2D) = "white" {}
_Emission("Bloom", Float) = 1
}
SubShader{
Tags{ "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard vertex:vert fullforwardshadows
//#pragma surface surf Lambert vertex:vert
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _EmissionMap;
half _Dist;
half _Emission;
half _Glossiness;
half _Metallic;
fixed4 _Color;
struct Input {
float2 uv_MainTex, uv_EmissionMap;
float3 viewDir;
half relativeSpeed;
};
void vert(inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input, o);
half3 viewDirW = _WorldSpaceCameraPos - mul((half4x4)unity_ObjectToWorld, v.vertex);
half viewDist = length(viewDirW);
o.relativeSpeed = saturate(viewDist / 1000);
}
void surf(in Input IN, inout SurfaceOutputStandard o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Emission = tex2D(_EmissionMap, IN.uv_EmissionMap) * _Color * _Emission * IN.relativeSpeed;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
This creates the following, already kinda neat effect:
Now, my plan is to somehow store the vertex-camera distance for a frame, and use it to calculate the vertex-camera head-on relative speed on the next one, while also updating the vertex-camera distance.
Anyone has pointers on how I might do that? Or a better idea to achieve it altogether?