mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Add text decal shader
This commit is contained in:
parent
2994da628b
commit
30870b263a
@ -29,10 +29,17 @@ float sdRoundedUVBox( float2 uv, float r ) {
|
||||
return sdRoundedBox(pos, halfDim, r);
|
||||
}
|
||||
|
||||
float SDFAA(float dist) {
|
||||
float ddist = length(float2(ddx(dist), ddy(dist)));
|
||||
inline float SDFdDist(float dist) {
|
||||
return length(float2(ddx(dist), ddy(dist)));
|
||||
}
|
||||
|
||||
inline float SDFAA(float dist, float ddist) {
|
||||
float pixelDist = dist / ddist;
|
||||
return saturate(0.5-pixelDist);
|
||||
}
|
||||
|
||||
inline float SDFAA(float dist) {
|
||||
return SDFAA(dist, SDFdDist(dist));
|
||||
}
|
||||
|
||||
#endif
|
41
Assets/Shaders/TextDecal.cginc
Normal file
41
Assets/Shaders/TextDecal.cginc
Normal file
@ -0,0 +1,41 @@
|
||||
float4 _DecalColor;
|
||||
float _Weight;
|
||||
|
||||
float4 _OutlineColor;
|
||||
float _OutlineWidth;
|
||||
|
||||
void surf(DecalSurfaceInput IN, inout SurfaceOutput o) {
|
||||
float4 color = _DecalColor;
|
||||
|
||||
float bias = _Cutoff - (_Weight / 4);
|
||||
#ifdef DECAL_OUTLINE
|
||||
bias -= _OutlineWidth * 0.25;
|
||||
#endif
|
||||
float dist = bias - tex2D(_Decal, IN.uv_decal).r;
|
||||
float ddist = SDFdDist(dist);
|
||||
|
||||
#ifdef DECAL_OUTLINE
|
||||
float outlineDist = (_OutlineWidth * 0.5) + dist;
|
||||
float outline = SDFAA(outlineDist, -ddist);
|
||||
color = lerp(color, _OutlineColor, outline);
|
||||
#endif
|
||||
|
||||
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
|
||||
o.Alpha = _DecalOpacity * SDFAA(dist, ddist);
|
||||
|
||||
#ifdef DECAL_BASE_NORMAL
|
||||
float3 normal = IN.normal;
|
||||
float wearFactor = 1 - normal.z;
|
||||
float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor);
|
||||
o.Alpha *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor));
|
||||
#endif
|
||||
|
||||
#ifdef DECAL_SPECMAP
|
||||
float4 specular = tex2D(_SpecMap, IN.uv_specmap);
|
||||
o.Gloss = specular.r;
|
||||
o.Specular = _Shininess;
|
||||
#endif
|
||||
|
||||
half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
|
||||
o.Emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
|
||||
}
|
109
Assets/Shaders/TextDecal.shader
Normal file
109
Assets/Shaders/TextDecal.shader
Normal file
@ -0,0 +1,109 @@
|
||||
Shader "ConformalDecals/Decal/Text"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[Header(Decal)]
|
||||
_Decal("Decal Texture", 2D) = "gray" {}
|
||||
_DecalColor("Decal Color", Color) = (1,1,1,1)
|
||||
|
||||
_Weight("Text Weight", Range(0,1)) = 0
|
||||
|
||||
[Header(Outline)]
|
||||
[Toggle(DECAL_OUTLINE)] _Outline ("Outline", int) = 0
|
||||
_OutlineColor("Outline Color", Color) = (0,0,0,1)
|
||||
_OutlineWidth("Outline Width", Range(0,1)) = 0.1
|
||||
|
||||
[Header(Normal)]
|
||||
[Toggle(DECAL_BASE_NORMAL)] _BaseNormal ("Use Base Normal", int) = 0
|
||||
_BumpMap("Bump Map", 2D) = "bump" {}
|
||||
_EdgeWearStrength("Edge Wear Strength", Range(0,500)) = 100
|
||||
_EdgeWearOffset("Edge Wear Offset", Range(0,1)) = 0.1
|
||||
|
||||
[Header(Specularity)]
|
||||
[Toggle(DECAL_SPECMAP)] _Decal_SpecMap ("Has SpecMap", int) = 0
|
||||
_SpecMap ("Specular Map)", 2D) = "black" {}
|
||||
_SpecColor ("_SpecColor", Color) = (0.25, 0.25, 0.25, 1)
|
||||
_Shininess ("Shininess", Range (0.03, 10)) = 0.3
|
||||
|
||||
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
|
||||
_DecalOpacity("Opacity", Range(0,1) ) = 1
|
||||
_Background("Background Color", Color) = (0.9,0.9,0.9,0.7)
|
||||
|
||||
[Enum(UnityEngine.Rendering.CullMode)] _Cull ("Cull", int) = 2
|
||||
[Toggle] _ZWrite ("ZWrite", Float) = 1.0
|
||||
|
||||
[Toggle(DECAL_PREVIEW)] _Preview ("Preview", int) = 0
|
||||
|
||||
[Header(Effects)]
|
||||
[PerRendererData]_Opacity("_Opacity", Range(0,1) ) = 1
|
||||
_Color("_Color", Color) = (1,1,1,1)
|
||||
[PerRendererData]_RimFalloff("_RimFalloff", Range(0.01,5) ) = 0.1
|
||||
[PerRendererData]_RimColor("_RimColor", Color) = (0,0,0,0)
|
||||
[PerRendererData]_UnderwaterFogFactor ("Underwater Fog Factor", Range(0,1)) = 0
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "Queue" = "Geometry+100" "IgnoreProjector" = "true" "DisableBatching" = "true"}
|
||||
Cull [_Cull]
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "FORWARD"
|
||||
Tags { "LightMode" = "ForwardBase" }
|
||||
ZWrite [_ZWrite]
|
||||
ZTest LEqual
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert_forward
|
||||
#pragma fragment frag_forward
|
||||
|
||||
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap
|
||||
#pragma skip_variants SHADOWS_DEPTH SHADOWS_CUBE SHADOWS_SHADOWMASK LIGHTMAP_SHADOW_MIXING POINT_COOKIE
|
||||
#pragma multi_compile_local __ DECAL_PREVIEW
|
||||
#pragma multi_compile_local __ DECAL_BASE_NORMAL
|
||||
#pragma multi_compile_local __ DECAL_SPECMAP
|
||||
#pragma multi_compile_local __ DECAL_OUTLINE
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "DecalsCommon.cginc"
|
||||
#include "DecalsSurface.cginc"
|
||||
#include "SDF.cginc"
|
||||
#include "TextDecal.cginc"
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "FORWARD"
|
||||
Tags { "LightMode" = "ForwardAdd" }
|
||||
ZWrite Off
|
||||
ZTest LEqual
|
||||
Blend One One
|
||||
Offset -1, -1
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert_forward
|
||||
#pragma fragment frag_forward
|
||||
|
||||
#pragma multi_compile_fwdadd nolightmap nodirlightmap nodynlightmap
|
||||
#pragma skip_variants SHADOWS_DEPTH SHADOWS_CUBE SHADOWS_SHADOWMASK LIGHTMAP_SHADOW_MIXING POINT_COOKIE
|
||||
#pragma multi_compile_local __ DECAL_PREVIEW
|
||||
#pragma multi_compile_local __ DECAL_BASE_NORMAL
|
||||
#pragma multi_compile_local __ DECAL_SPECMAP
|
||||
#pragma multi_compile_local __ DECAL_OUTLINE
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "DecalsCommon.cginc"
|
||||
#include "DecalsSurface.cginc"
|
||||
#include "SDF.cginc"
|
||||
#include "TextDecal.cginc"
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// shadow casting support
|
||||
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user