Skip to content

Commit

Permalink
Add templatized text decal shader
Browse files Browse the repository at this point in the history
  • Loading branch information
drewcassidy committed Jul 26, 2024
1 parent 7286202 commit ce55f07
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 186 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ProjectSettings/
Temp/

# Autogenerated shaders
Assets/ConformalDecals/Shaders/Generated/*.shader
Assets/ConformalDecals/Shaders/Decal/*.shader

# Unity Assetbundle Manifest Files
GameData/ConformalDecals/Resources/Resources
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#include "../DecalsCommon.cginc"
#include "../SDF.cginc"

float4 _DecalColor;

float4 _OutlineColor;
float _OutlineWidth;

void surf(DecalSurfaceInput IN, inout SurfaceOutputStandardSpecular o) {
void surf(DecalSurfaceInput IN, inout SurfaceOutput o) {
float4 color = _DecalColor;
float dist = _Cutoff - tex2D(_Decal, IN.uv_decal).r; // text distance
o.Specular = 0.4;
o.Occlusion = 1;

o.Gloss = _Shininess;

float dist = _Cutoff - tex2D(_Decal, IN.uv_decal).r; // text distance

#ifdef DECAL_OUTLINE
// Outline
float outlineOffset = _OutlineWidth * 0.25;
Expand All @@ -30,8 +34,8 @@ void surf(DecalSurfaceInput IN, inout SurfaceOutputStandardSpecular o) {

dist = max(dist, BoundsDist(IN.uv, IN.vertex_normal, _DecalNormal));
float ddist = SDFdDist(dist); // distance gradient magnitude
o.Alpha = _DecalOpacity * SDFAA(dist, ddist);
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
o.Albedo = color.rgb;
o.Alpha *= SDFAA(dist, ddist);

#ifdef DECAL_BASE_NORMAL
float3 normal = IN.normal;
Expand All @@ -44,9 +48,4 @@ void surf(DecalSurfaceInput IN, inout SurfaceOutputStandardSpecular o) {
float4 specular = tex2D(_SpecMap, IN.uv_specmap);
o.Specular = specular;
#endif

o.Smoothness = _Shininess;

half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
o.Emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
}
39 changes: 39 additions & 0 deletions Assets/ConformalDecals/Shaders/Decal/TextDecal.shader.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% extends "StandardDecal.shader.template" %}
{% block shader_name %}ConformalDecals/Decal/Text{% endblock %}

{% block properties %}
[Header(Decal)]
[Toggle(DECAL_FILL)] _Fill ("Fill", int) = 0
_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
{% endblock %}

{% block pragmas %}
#pragma multi_compile_local __ DECAL_SPECMAP
#pragma multi_compile_local __ DECAL_OUTLINE
#pragma multi_compile_local __ DECAL_FILL
#pragma skip_variants DECAL_BUMPMAP
{% endblock %}

{% block body %}
#include "TextDecal.cginc"
{% endblock %}
174 changes: 0 additions & 174 deletions Assets/ConformalDecals/Shaders/TextDecal.shader

This file was deleted.

Binary file modified GameData/ConformalDecals/Resources/conformaldecals.shab
Binary file not shown.

0 comments on commit ce55f07

Please sign in to comment.