diff --git a/Assets/ConformalDecals/Shaders/Decal/DecalBase.shader.template b/Assets/ConformalDecals/Shaders/Decal/DecalBase.shader.template new file mode 100644 index 0000000..2451359 --- /dev/null +++ b/Assets/ConformalDecals/Shaders/Decal/DecalBase.shader.template @@ -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 + } + } +} \ No newline at end of file diff --git a/Assets/ConformalDecals/Shaders/DecalsCommon.cginc b/Assets/ConformalDecals/Shaders/Decal/DecalsCommon.cginc similarity index 99% rename from Assets/ConformalDecals/Shaders/DecalsCommon.cginc rename to Assets/ConformalDecals/Shaders/Decal/DecalsCommon.cginc index 7d57353..338ed46 100644 --- a/Assets/ConformalDecals/Shaders/DecalsCommon.cginc +++ b/Assets/ConformalDecals/Shaders/Decal/DecalsCommon.cginc @@ -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 diff --git a/Assets/ConformalDecals/Shaders/Decal/StandardDecal.cginc b/Assets/ConformalDecals/Shaders/Decal/StandardDecal.cginc index 982a744..c8d7021 100644 --- a/Assets/ConformalDecals/Shaders/Decal/StandardDecal.cginc +++ b/Assets/ConformalDecals/Shaders/Decal/StandardDecal.cginc @@ -1,4 +1,4 @@ -#include "../DecalsCommon.cginc" +#include "DecalsCommon.cginc" #include "../SDF.cginc" void surf(DecalSurfaceInput IN, inout SurfaceOutput o) { diff --git a/Assets/ConformalDecals/Shaders/Decal/StandardDecal.shader.template b/Assets/ConformalDecals/Shaders/Decal/StandardDecal.shader.template index 770904d..169326b 100644 --- a/Assets/ConformalDecals/Shaders/Decal/StandardDecal.shader.template +++ b/Assets/ConformalDecals/Shaders/Decal/StandardDecal.shader.template @@ -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 @@ -17,7 +15,7 @@ [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 @@ -25,161 +23,18 @@ [Toggle(DECAL_EMISSIVE)] _Decal_Emissive ("Has Emissive", int) = 0 _Emissive("_Emissive", 2D) = "black" {} _EmissiveColor("_EmissiveColor", Color) = (0,0,0,1) - //{% endblock %} +{% 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 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 %} +{% 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 - - #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 - } - } -} \ No newline at end of file +{% block pragmas_deferred_prepass %} + #pragma skip_variants DECAL_SPECMAP DECAL_EMISSIVE DECAL_BUMPMAP +{% endblock %} \ No newline at end of file diff --git a/Assets/ConformalDecals/Shaders/Decal/TextDecal.cginc b/Assets/ConformalDecals/Shaders/Decal/TextDecal.cginc index 2d34f83..d129153 100644 --- a/Assets/ConformalDecals/Shaders/Decal/TextDecal.cginc +++ b/Assets/ConformalDecals/Shaders/Decal/TextDecal.cginc @@ -1,4 +1,4 @@ -#include "../DecalsCommon.cginc" +#include "DecalsCommon.cginc" #include "../SDF.cginc" float4 _DecalColor; diff --git a/Assets/ConformalDecals/Shaders/Decal/TextDecal.shader.template b/Assets/ConformalDecals/Shaders/Decal/TextDecal.shader.template index 8dbc70e..6932979 100644 --- a/Assets/ConformalDecals/Shaders/Decal/TextDecal.shader.template +++ b/Assets/ConformalDecals/Shaders/Decal/TextDecal.shader.template @@ -1,5 +1,5 @@ -{% extends "StandardDecal.shader.template" %} -{% block shader_name %}ConformalDecals/Decal/Text{% endblock %} +{% extends "DecalBase.shader.template" %} +{% block shader_name %}Text{% endblock %} {% block properties %} [Header(Decal)] @@ -27,13 +27,15 @@ _Shininess ("Shininess", Range (0.03, 10)) = 0.3 {% endblock %} -{% block pragmas %} +{% block body %} + #pragma multi_compile_local __ DECAL_BASE_NORMAL #pragma multi_compile_local __ DECAL_SPECMAP #pragma multi_compile_local __ DECAL_OUTLINE #pragma multi_compile_local __ DECAL_FILL - #pragma skip_variants DECAL_BUMPMAP + + #include "TextDecal.cginc" {% endblock %} -{% block body %} - #include "TextDecal.cginc" +{% block pragmas_deferred_prepass %} + #pragma skip_variants DECAL_SPECMAP {% endblock %} \ No newline at end of file diff --git a/Assets/ConformalDecals/Shaders/DecalBack.shader b/Assets/ConformalDecals/Shaders/DecalBack.shader index c6442f9..07936f7 100644 --- a/Assets/ConformalDecals/Shaders/DecalBack.shader +++ b/Assets/ConformalDecals/Shaders/DecalBack.shader @@ -63,12 +63,12 @@ Shader "ConformalDecals/Decal Back" // 45° rotation uv_MainTex.x = IN.uv_MainTex.x - IN.uv_MainTex.y; uv_MainTex.y = IN.uv_MainTex.x + IN.uv_MainTex.y; - + // stagger every other row + uv_MainTex.y *= 2; int row = floor(uv_MainTex.y); uv_MainTex.x += row * _RowOffset; - uv_MainTex.y *= 2; - + float4 color = _Color * tex2D(_MainTex,(uv_MainTex)); float3 normal = UnpackNormal(tex2D(_BumpMap, uv_BumpMap)); diff --git a/Assets/ConformalDecals/Shaders/LegacyToStandard.cginc b/Assets/ConformalDecals/Shaders/LegacyToStandard.cginc deleted file mode 100644 index 0ef519f..0000000 --- a/Assets/ConformalDecals/Shaders/LegacyToStandard.cginc +++ /dev/null @@ -1,25 +0,0 @@ -// Taken from https://github.com/LGhassen/Deferred - -//TODO: remove this debug settings -float blinnPhongShininessPower = 0.215f; - -// An exact conversion from blinn-phong to PBR is impossible, but the look can be approximated perceptually -// and by observing how blinn-phong looks and feels at various settings, although it can never be perfect -// 1) The specularColor can be used as is in the PBR specular flow, just needs to be divided by PI so it sums up to 1 over the hemisphere -// 2) Blinn-phong shininess doesn't stop feeling shiny unless at very low values, like below 0.04 -// while the PBR smoothness feels more linear -> map shininess to smoothness accordingly using a function -// that increases very quickly at first then slows down, I went with something like x^(1/4) or x^(1/6) then made the power configurable -// I tried various mappings from the literature but nothing really worked as well as this -// 3) Finally I noticed that some parts still looked very shiny like the AV-R8 winglet while in stock they looked rough thanks a low -// specularColor but high shininess and specularMap, so I multiplied the smoothness by the sqrt of the specularColor and that caps -// the smoothness when specularColor is low -void GetStandardSpecularPropertiesFromLegacy(float legacyShininess, float specularMap, float3 legacySpecularColor, - out float smoothness, out float3 specular) -{ - legacySpecularColor = saturate(legacySpecularColor); - - smoothness = pow(legacyShininess, 0.215) * specularMap; - smoothness *= sqrt(length(legacySpecularColor)); - - specular = legacySpecularColor * (1 / UNITY_PI); -} \ No newline at end of file diff --git a/Assets/ConformalDecals/Shaders/LightingKSP.cginc b/Assets/ConformalDecals/Shaders/LightingKSP.cginc deleted file mode 100644 index 9038bce..0000000 --- a/Assets/ConformalDecals/Shaders/LightingKSP.cginc +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef LIGHTING_KSP_INCLUDED -#define LIGHTING_KSP_INCLUDED - -inline fixed4 LightingBlinnPhongSmooth(SurfaceOutput s, fixed3 lightDir, half3 viewDir, fixed atten) -{ - s.Normal = normalize(s.Normal); - half3 h = normalize(lightDir + viewDir); - - fixed diff = max(0, dot(s.Normal, lightDir)); - - float nh = max(0, dot(s.Normal, h)); - float spec = pow(nh, s.Specular*128.0) * s.Gloss; - - fixed4 c; - c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * _SpecColor.rgb * spec) * (atten); - c.a = s.Alpha + _LightColor0.a * _SpecColor.a * spec * atten; - return c; -} - - - - -inline half4 LightingUnlit(SurfaceOutput s, half3 lightDir, half atten) -{ - // half diff = max (0, dot (s.Normal, lightDir)); - - half4 c; - c.rgb = s.Albedo; - c.a = s.Alpha; - return c; -} - - - - -inline half4 LightingUnlit_PrePass(SurfaceOutput s, half4 light) -{ - half4 c; - c.rgb = s.Albedo; - c.a = s.Alpha; - return c; -} - - - - -fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten) { return fixed4(0, 0, 0, 0); } - - - - - -float4 _Color; -half _LightBoost; -half4 LightingLightWrapped(SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) { - float3 w = _Color.rgb*0.5; - half3 NdotL = dot(s.Normal, lightDir); - - //Specular term - half3 h = normalize(lightDir + viewDir); - s.Normal = normalize(s.Normal); - float NdotH = dot(s.Normal, h); - float spec = pow(max(NdotH, 0), s.Specular * 128.0) * s.Gloss; - fixed3 specColor = _SpecColor.rgb * _LightColor0.rgb; - - half3 diff = NdotL * (1 - w) + w; - half4 c; - c.rgb = ((s.Albedo * _LightColor0.rgb * diff) + (specColor * spec)) * (atten * _LightBoost); - c.a = s.Alpha + (_LightColor0.a * _SpecColor.a * spec * atten); - return c; -} - - - -float4 _LocalCameraPos; -float4 _LocalCameraDir; -float4 _UnderwaterFogColor; -float _UnderwaterMinAlphaFogDistance; -float _UnderwaterMaxAlbedoFog; -float _UnderwaterMaxAlphaFog; -float _UnderwaterAlbedoDistanceScalar; -float _UnderwaterAlphaDistanceScalar; -float _UnderwaterFogFactor; - -float4 UnderwaterFog(float3 worldPos, float3 color) -{ - float3 toPixel = worldPos - _LocalCameraPos.xyz; - float toPixelLength = length(toPixel); ///< Comment out the math--looks better without it. - //float angleDot = dot(_LocalCameraDir.xyz, toPixel / toPixelLength); - //angleDot = lerp(0.00000001, angleDot, saturate(sign(angleDot))); - //float waterDist = -_LocalCameraPos.w / angleDot; - //float dist = min(toPixelLength, waterDist); - - - float underwaterDetection = _UnderwaterFogFactor * _LocalCameraDir.w; ///< sign(1 - sign(_LocalCameraPos.w)); - float albedoLerpValue = underwaterDetection * (_UnderwaterMaxAlbedoFog * saturate(toPixelLength * _UnderwaterAlbedoDistanceScalar)); - float alphaFactor = 1 - underwaterDetection * (_UnderwaterMaxAlphaFog * saturate((toPixelLength - _UnderwaterMinAlphaFogDistance) * _UnderwaterAlphaDistanceScalar)); - - return float4(lerp(color, _UnderwaterFogColor.rgb, albedoLerpValue), alphaFactor); -} - -#endif \ No newline at end of file diff --git a/Assets/ConformalDecals/Textures/Decal-Blank.afdesign b/Assets/ConformalDecals/Textures/Decal-Blank.afdesign new file mode 100644 index 0000000..63e98d4 Binary files /dev/null and b/Assets/ConformalDecals/Textures/Decal-Blank.afdesign differ diff --git a/Assets/ConformalDecals/Textures/Decal-Blank.afdesign~lock~ b/Assets/ConformalDecals/Textures/Decal-Blank.afdesign~lock~ new file mode 100644 index 0000000..ecd3403 Binary files /dev/null and b/Assets/ConformalDecals/Textures/Decal-Blank.afdesign~lock~ differ diff --git a/Assets/ConformalDecals/Textures/Icons Generic.afdesign b/Assets/ConformalDecals/Textures/Icons Generic.afdesign new file mode 100644 index 0000000..2f5b96e Binary files /dev/null and b/Assets/ConformalDecals/Textures/Icons Generic.afdesign differ diff --git a/Assets/ConformalDecals/Textures/Munar.afdesign b/Assets/ConformalDecals/Textures/Munar.afdesign new file mode 100644 index 0000000..0e4a5be Binary files /dev/null and b/Assets/ConformalDecals/Textures/Munar.afdesign differ diff --git a/Assets/ConformalDecals/Textures/Semiotic.afdesign b/Assets/ConformalDecals/Textures/Semiotic.afdesign new file mode 100644 index 0000000..bb99dcd Binary files /dev/null and b/Assets/ConformalDecals/Textures/Semiotic.afdesign differ diff --git a/Assets/ConformalDecals/Textures/paper-spec.png b/Assets/ConformalDecals/Textures/paper-spec.png new file mode 100644 index 0000000..2881d9b Binary files /dev/null and b/Assets/ConformalDecals/Textures/paper-spec.png differ diff --git a/Assets/ConformalDecals/Textures/paper.png b/Assets/ConformalDecals/Textures/paper.png new file mode 100644 index 0000000..44ac660 Binary files /dev/null and b/Assets/ConformalDecals/Textures/paper.png differ diff --git a/GameData/ConformalDecals/Assets/Paper-Wrinkle-n.dds b/GameData/ConformalDecals/Assets/Paper-Wrinkle-n.dds index bc2d017..001096b 100644 Binary files a/GameData/ConformalDecals/Assets/Paper-Wrinkle-n.dds and b/GameData/ConformalDecals/Assets/Paper-Wrinkle-n.dds differ diff --git a/GameData/ConformalDecals/Assets/decal-blank.mu b/GameData/ConformalDecals/Assets/decal-blank.mu index 55c05b9..fd5f3fb 100644 Binary files a/GameData/ConformalDecals/Assets/decal-blank.mu and b/GameData/ConformalDecals/Assets/decal-blank.mu differ diff --git a/GameData/ConformalDecals/Assets/paper.dds b/GameData/ConformalDecals/Assets/paper.dds new file mode 100644 index 0000000..fe994a2 Binary files /dev/null and b/GameData/ConformalDecals/Assets/paper.dds differ diff --git a/GameData/ConformalDecals/Resources/conformaldecals.shab b/GameData/ConformalDecals/Resources/conformaldecals.shab index ff20a82..19c1927 100644 Binary files a/GameData/ConformalDecals/Resources/conformaldecals.shab and b/GameData/ConformalDecals/Resources/conformaldecals.shab differ