mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Add glow shader for bounding cube
This commit is contained in:
parent
e27267c862
commit
a42084bf1c
71
Assets/Shaders/SelectionGlow.shader
Normal file
71
Assets/Shaders/SelectionGlow.shader
Normal file
@ -0,0 +1,71 @@
|
||||
Shader "ConformalDecals/SelectionGlow"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[Header(Effects)]
|
||||
_RimEdgeGlow("Rim Edge Glow", Range(0, 1)) = 0.45
|
||||
_RimEdgePow("Rim Edge Falloff", Range(0,5)) = 5
|
||||
_RimEdgeOpacity("Rim Edge Opacity", Range(0,1)) = 0.2
|
||||
_RimFalloff("Rim Falloff", Range(0.01,5) ) = 0.1
|
||||
_RimColor("Rim Color", Color) = (0,0,0,0)
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "Queue" = "Transparent" }
|
||||
Cull Back
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend One One
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
half _RimEdgeGlow;
|
||||
half _RimEdgePow;
|
||||
half _RimEdgeOpacity;
|
||||
float _RimFalloff;
|
||||
float4 _RimColor;
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Lighting.cginc"
|
||||
#include "AutoLight.cginc"
|
||||
|
||||
struct v2f {
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float3 worldPosition : TEXCOORD1;
|
||||
half3 worldNormal : TEXCOORD2;
|
||||
};
|
||||
|
||||
v2f vert(float4 vertex : POSITION, float3 normal : NORMAL, float2 uv : TEXCOORD0) {
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos(vertex);
|
||||
o.uv = uv;
|
||||
o.worldPosition = mul(unity_ObjectToWorld, vertex).xyz;
|
||||
o.worldNormal = UnityObjectToWorldNormal(normal);
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target {
|
||||
fixed4 c = 0;
|
||||
|
||||
float3 worldViewDir = normalize(UnityWorldSpaceViewDir(i.worldPosition));
|
||||
half rim = 1.0 - saturate(dot (normalize(worldViewDir), i.worldNormal));
|
||||
c.rgb = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
|
||||
half edgeGlow = 0;
|
||||
edgeGlow = max(edgeGlow, pow(1-saturate(i.uv.x / _RimEdgeGlow), _RimEdgePow));
|
||||
edgeGlow = max(edgeGlow, pow(1-saturate(i.uv.y / _RimEdgeGlow), _RimEdgePow));
|
||||
edgeGlow = max(edgeGlow, pow(1-saturate((1-i.uv.x) / _RimEdgeGlow), _RimEdgePow));
|
||||
edgeGlow = max(edgeGlow, pow(1-saturate((1-i.uv.y) / _RimEdgeGlow), _RimEdgePow));
|
||||
|
||||
c.rgb = max(c.rgb, _RimColor.rgb * _RimColor.a * edgeGlow * _RimEdgeOpacity);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user