Skip to content

Commit

Permalink
More decal shader reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
drewcassidy committed Jul 30, 2024
1 parent ce55f07 commit 9469752
Show file tree
Hide file tree
Showing 20 changed files with 182 additions and 296 deletions.
156 changes: 156 additions & 0 deletions Assets/ConformalDecals/Shaders/Decal/DecalBase.shader.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
Shader "ConformalDecals/Decal/{% block shader_name %}UNKNOWN{% endblock %}"
{
Properties
{

// Shader-specific properties
{% block properties %}
{% endblock %}

// Common decal properties
_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
[PerRendererData]_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
#pragma fragment frag_forward

#pragma multi_compile_fwdbase
#pragma skip_variants LIGHTMAP_ON DIRLIGHTMAP_COMBINED DYNAMICLIGHTMAP_ON LIGHTMAP_SHADOW_MIXING
#pragma multi_compile_local __ DECAL_PREVIEW

{% block body %}
#error No body provided
{% endblock %}

ENDCG
}

Pass
{
Name "FORWARD"
Tags
{
"LightMode" = "ForwardAdd"
}
ZWrite Off
ZTest LEqual
Blend SrcAlpha One
Offset -1, -1

CGPROGRAM
#pragma vertex vert
#pragma fragment frag_forward

#pragma multi_compile DIRECTIONAL SPOT POINT
#pragma multi_compile __ LIGHTPROBE_SH
#pragma multi_compile_local __ DECAL_PREVIEW

{{ self.body() }}

ENDCG
}

Pass
{
Name "DEFERRED_PREPASS"
Tags
{
"LightMode" = "Deferred"
}
ZWrite Off
ZTest LEqual
Offset -1, -1
Blend 1 Zero OneMinusSrcColor, Zero OneMinusSrcAlpha

Stencil
{
Ref 1
Comp Equal
Pass Keep
}

CGPROGRAM
#pragma vertex vert
#pragma fragment frag_deferred_prepass
#pragma target 3.0

#pragma multi_compile_local __ DECAL_PREVIEW

{{ self.body() }}

{% block pragmas_deferred_prepass %}
{% endblock %}

ENDCG
}

Pass
{
Name "DEFERRED"
Tags
{
"LightMode" = "Deferred"
}
ZWrite Off
ZTest LEqual
Offset -1, -1
Blend 0 SrcAlpha OneMinusSrcAlpha, Zero One
Blend 1 One One
Blend 2 SrcAlpha OneMinusSrcAlpha, Zero One
Blend 3 SrcAlpha OneMinusSrcAlpha, Zero One

Stencil
{
Ref 1
Comp Equal
Pass Keep
}

CGPROGRAM
#pragma vertex vert
#pragma fragment frag_deferred
#pragma target 3.0

#pragma multi_compile __ LIGHTPROBE_SH
#pragma multi_compile __ UNITY_HDR_ON
#pragma multi_compile_local __ DECAL_PREVIEW

{{ self.body() }}

ENDCG
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "AutoLight.cginc"
#include "Lighting.cginc"
#include "LightingKSPDeferred.cginc"
#include "../LightingKSPDeferred.cginc"

#define CLIP_MARGIN 0.05
#define EDGE_MARGIN 0.01
Expand Down
2 changes: 1 addition & 1 deletion Assets/ConformalDecals/Shaders/Decal/StandardDecal.cginc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../DecalsCommon.cginc"
#include "DecalsCommon.cginc"
#include "../SDF.cginc"

void surf(DecalSurfaceInput IN, inout SurfaceOutput o) {
Expand Down
169 changes: 12 additions & 157 deletions Assets/ConformalDecals/Shaders/Decal/StandardDecal.shader.template
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
Shader "{% block shader_name %}ConformalDecals/Decal/Standard{% endblock %}"
{
Properties
{
// Shader-specific properties
//{% block properties %}
{% extends "DecalBase.shader.template" %}
{% block shader_name %}Standard{% endblock %}

{% block properties %}
[Header(Decal)]
_Decal("Decal Texture", 2D) = "gray" {}
[Toggle(DECAL_SDF_ALPHA)] _Decal_SDF_Alpha ("SDF in Alpha", int) = 0
Expand All @@ -17,169 +15,26 @@

[Header(Specularity)]
[Toggle(DECAL_SPECMAP)] _Decal_SpecMap ("Has SpecMap", int) = 0
_SpecMap ("Specular Map)", 2D) = "black" {}
_SpecMap ("Specular Map", 2D) = "black" {}
_SpecColor ("_SpecColor", Color) = (0.25, 0.25, 0.25, 1)
_Shininess ("Shininess", Range (0.03, 10)) = 0.3

[Header(Emissive)]
[Toggle(DECAL_EMISSIVE)] _Decal_Emissive ("Has Emissive", int) = 0
_Emissive("_Emissive", 2D) = "black" {}
_EmissiveColor("_EmissiveColor", Color) = (0,0,0,1)
//{% endblock %}

// Common decal properties
_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
[PerRendererData]_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
{% endblock %}

CGPROGRAM
#pragma vertex vert
#pragma fragment frag_forward

#pragma multi_compile DIRECTIONAL
#pragma multi_compile_local __ DECAL_PREVIEW
#pragma multi_compile_local __ DECAL_BASE_NORMAL DECAL_BUMPMAP
//{% block pragmas %}
{% block body %}
#pragma multi_compile_local __ DECAL_BASE_NORMAL
#pragma multi_compile_local __ DECAL_SPECMAP
#pragma multi_compile_local __ DECAL_EMISSIVE
#pragma multi_compile_local __ DECAL_SDF_ALPHA
//{% endblock %}

//{% block body %}
#include "StandardDecal.cginc"
//{% endblock %}

ENDCG
}

Pass
{
Name "FORWARD"
Tags
{
"LightMode" = "ForwardAdd"
}
ZWrite Off
ZTest LEqual
Blend SrcAlpha One
Offset -1, -1

CGPROGRAM
#pragma vertex vert
#pragma fragment frag_forward

#pragma multi_compile DIRECTIONAL SPOT POINT
#pragma multi_compile_local __ DECAL_PREVIEW
#pragma multi_compile_local __ DECAL_BASE_NORMAL DECAL_BUMPMAP
//{{ self.pragmas() }}

//{{ self.body() }}
ENDCG
}

Pass
{
Name "DEFERRED_PREPASS"
Tags
{
"LightMode" = "Deferred"
}
ZWrite Off
ZTest LEqual
Offset -1, -1
Blend 1 Zero OneMinusSrcColor, Zero OneMinusSrcAlpha

Stencil
{
Ref 1
Comp Equal
Pass Keep
}

CGPROGRAM
#pragma vertex vert
#pragma fragment frag_deferred_prepass
#pragma target 3.0

#pragma multi_compile_local __ DECAL_PREVIEW
#pragma multi_compile_local __ DECAL_BASE_NORMAL
//{{ self.pragmas() }}

//{% block prepass_skip_variants %}
#pragma skip_variants DECAL_SPECMAP DECAL_EMISSIVE
//{% endblock %}

#define DECAL_PREPASS

//{{ self.body() }}
ENDCG
}

Pass
{
Name "DEFERRED"
Tags
{
"LightMode" = "Deferred"
}
ZWrite Off
ZTest LEqual
Offset -1, -1
Blend 0 SrcAlpha OneMinusSrcAlpha, Zero One
Blend 1 One One
Blend 2 SrcAlpha OneMinusSrcAlpha, Zero One
Blend 3 SrcAlpha OneMinusSrcAlpha, Zero One

Stencil
{
Ref 1
Comp Equal
Pass Keep
}

CGPROGRAM
#pragma vertex vert
#pragma fragment frag_deferred
#pragma target 3.0
{% endblock %}

#pragma multi_compile __ UNITY_HDR_ON
#pragma multi_compile_local __ DECAL_PREVIEW
#pragma multi_compile_local __ DECAL_BASE_NORMAL DECAL_BUMPMAP
//{{ self.pragmas() }}

//{{ self.body() }}
ENDCG
}
}
}
{% block pragmas_deferred_prepass %}
#pragma skip_variants DECAL_SPECMAP DECAL_EMISSIVE DECAL_BUMPMAP
{% endblock %}
2 changes: 1 addition & 1 deletion Assets/ConformalDecals/Shaders/Decal/TextDecal.cginc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../DecalsCommon.cginc"
#include "DecalsCommon.cginc"
#include "../SDF.cginc"

float4 _DecalColor;
Expand Down
Loading

0 comments on commit 9469752

Please sign in to comment.