diff --git a/Assets/Shaders/DecalFeatureBumped.shader b/Assets/Shaders/DecalFeatureBumped.shader index 279aff5..52919ac 100644 --- a/Assets/Shaders/DecalFeatureBumped.shader +++ b/Assets/Shaders/DecalFeatureBumped.shader @@ -4,7 +4,7 @@ Shader "ConformalDecals/Feature/Bumped" { [Header(Texture Maps)] _Decal("Decal Texture", 2D) = "gray" {} - _DecalBumpMap("Decal Bump Map", 2D) = "bump" {} + _BumpMap("Decal Bump Map", 2D) = "bump" {} _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 _Opacity("_Opacity", Range(0,1) ) = 1 @@ -35,16 +35,18 @@ Shader "ConformalDecals/Feature/Bumped" #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap sampler2D _Decal; - sampler2D _DecalBumpMap; + sampler2D _BumpMap; float4 _Decal_ST; - float4 _DecalBumpMap_ST; + float4 _BumpMap_ST; float _Cutoff; float _Opacity; float _RimFalloff; float4 _RimColor; + #define DECAL_NORMAL + #include "UnityCG.cginc" #include "Lighting.cginc" #include "AutoLight.cginc" @@ -54,7 +56,7 @@ Shader "ConformalDecals/Feature/Bumped" void surf (DecalSurfaceInput IN, inout SurfaceOutput o) { float4 color = tex2D(_Decal, IN.uv_decal); - float3 normal = UnpackNormal(tex2D(_DecalBumpMap, IN.uv_decal)); + float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_bump)); // clip alpha clip(color.a - _Cutoff); @@ -84,16 +86,18 @@ Shader "ConformalDecals/Feature/Bumped" #pragma multi_compile_fwdadd nolightmap nodirlightmap nodynlightmap sampler2D _Decal; - sampler2D _DecalBumpMap; + sampler2D _BumpMap; float4 _Decal_ST; - float4 _DecalBumpMap_ST; + float4 _BumpMap_ST; float _Cutoff; float _Opacity; float _RimFalloff; float4 _RimColor; + #define DECAL_NORMAL + #include "UnityCG.cginc" #include "Lighting.cginc" #include "AutoLight.cginc" @@ -103,7 +107,7 @@ Shader "ConformalDecals/Feature/Bumped" void surf (DecalSurfaceInput IN, inout SurfaceOutput o) { float4 color = tex2D(_Decal, IN.uv_decal); - float3 normal = UnpackNormal(tex2D(_DecalBumpMap, IN.uv_decal)); + float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_bump)); // clip alpha clip(color.a - _Cutoff); diff --git a/Assets/Shaders/DecalPaintSpecular.shader b/Assets/Shaders/DecalPaintSpecular.shader new file mode 100644 index 0000000..0f95716 --- /dev/null +++ b/Assets/Shaders/DecalPaintSpecular.shader @@ -0,0 +1,172 @@ +Shader "ConformalDecals/Paint/Specular" +{ + Properties + { + [Header(Texture Maps)] + _Decal("Decal Texture", 2D) = "gray" {} + _BumpMap("Bump Map", 2D) = "bump" {} + _SpecMap("Specular Map", 2D) = "black" {} + + _EdgeWearStrength("Edge Wear Strength", Range(0,100)) = 0 + _EdgeWearOffset("Edge Wear Offset", Range(0,1)) = 0 + + _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 + _Opacity("_Opacity", Range(0,1) ) = 1 + + [Header(Specularity)] + _SpecColor ("_SpecColor", Color) = (0.5, 0.5, 0.5, 1) + _Shininess ("Shininess", Range (0.03, 10)) = 0.4 + + + [Header(Effects)] + [PerRendererData]_Opacity("_Opacity", Range(0,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+400" } + ZWrite Off + ZTest LEqual + Offset -1, -1 + + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardBase" } + Blend SrcAlpha OneMinusSrcAlpha + + CGPROGRAM + #pragma vertex vert_forward + #pragma fragment frag_forward + + #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap + + sampler2D _Decal; + sampler2D _BumpMap; + sampler2D _SpecMap; + + float4 _Decal_ST; + float4 _BumpMap_ST; + float4 _SpecMap_ST; + + float _EdgeWearStrength; + float _EdgeWearOffset; + + half _Shininess; + + float _Cutoff; + float _Opacity; + float _RimFalloff; + float4 _RimColor; + + #define DECAL_BASE_NORMAL + #define DECAL_SPECULAR + + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "AutoLight.cginc" + #include "LightingKSP.cginc" + #include "DecalsCommon.cginc" + + void surf (DecalSurfaceInput IN, inout SurfaceOutput o) + { + float4 color = tex2D(_Decal, IN.uv_decal); + float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_base)); + float3 specular = tex2D(_SpecMap, IN.uv_spec); + + // clip alpha + clip(color.a - _Cutoff); + + half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal)); + float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a; + + float wearFactor = 1 - normal.z; + float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor); + + color.a *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor)); + color.a *= _Opacity; + + o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb; + o.Alpha = color.a; + o.Emission = emission; + o.Normal = normal; + o.Specular = _Shininess; + o.Gloss = specular.r * color.a; + } + + ENDCG + } + + Pass + { + Name "FORWARD" + Tags { "LightMode" = "ForwardAdd" } + Blend One One + + CGPROGRAM + #pragma vertex vert_forward + #pragma fragment frag_forward + + #pragma multi_compile_fwdadd nolightmap nodirlightmap nodynlightmap + + sampler2D _Decal; + sampler2D _BumpMap; + sampler2D _SpecMap; + + float4 _Decal_ST; + float4 _BumpMap_ST; + float4 _SpecMap_ST; + + float _EdgeWearStrength; + float _EdgeWearOffset; + + half _Shininess; + + float _Cutoff; + float _Opacity; + float _RimFalloff; + float4 _RimColor; + + #define DECAL_BASE_NORMAL + #define DECAL_SPECULAR + + #include "UnityCG.cginc" + #include "Lighting.cginc" + #include "AutoLight.cginc" + #include "LightingKSP.cginc" + #include "DecalsCommon.cginc" + + void surf (DecalSurfaceInput IN, inout SurfaceOutput o) + { + float4 color = tex2D(_Decal, IN.uv_decal); + float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_base)); + float3 specular = tex2D(_SpecMap, IN.uv_spec); + + // clip alpha + clip(color.a - _Cutoff); + + half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal)); + float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a; + + float wearFactor = 1 - normal.z; + float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor); + + color.a *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor)); + + o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb; + o.Alpha = color.a * _Opacity; + o.Emission = emission; + o.Normal = normal; + o.Specular = _Shininess; + o.Gloss = specular.r; + } + + ENDCG + } + + // shadow casting support + UsePass "Legacy Shaders/VertexLit/SHADOWCASTER" + } +} \ No newline at end of file diff --git a/Assets/Shaders/DecalsCommon.cginc b/Assets/Shaders/DecalsCommon.cginc index 3697622..6382817 100644 --- a/Assets/Shaders/DecalsCommon.cginc +++ b/Assets/Shaders/DecalsCommon.cginc @@ -4,9 +4,23 @@ struct DecalSurfaceInput { float2 uv_decal; + + #ifdef DECAL_NORMAL + float2 uv_bump; + #endif //DECAL_NORMAL + + #ifdef DECAL_SPECULAR + float2 uv_spec; + #endif //DECAL_SPECULAR + + #ifdef DECAL_EMISSIVE + float2 uv_glow; + #endif //DECAL_EMISSIVE + #ifdef DECAL_BASE_NORMAL float2 uv_base; #endif //DECAL_BASE_NORMAL + float3 normal; float3 viewDir; float3 worldPosition; @@ -146,10 +160,24 @@ fixed4 frag_forward(v2f IN) : SV_Target // initialize surface input UNITY_INITIALIZE_OUTPUT(DecalSurfaceInput, i) - i.uv_decal = TRANSFORM_TEX(uv_projected, _Decal);; + i.uv_decal = TRANSFORM_TEX(uv_projected, _Decal); + + #ifdef DECAL_NORMAL + i.uv_bump = TRANSFORM_TEX(uv_projected, _BumpMap); + #endif //DECAL_NORMAL + + #ifdef DECAL_SPECULAR + i.uv_spec = TRANSFORM_TEX(uv_projected, _SpecMap); + #endif //DECAL_SPECULAR + + #ifdef DECAL_EMISSIVE + i.uv_glow = TRANSFORM_TEX(uv_projected, _GlowMap); + #endif //DECAL_EMISSIVE + #ifdef DECAL_BASE_NORMAL i.uv_base = IN.uv_base; - #endif + #endif //DECAL_BASE_NORMAL + i.normal = IN.normal; i.viewDir = viewDir; i.worldPosition = worldPosition; @@ -178,12 +206,13 @@ fixed4 frag_forward(v2f IN) : SV_Target //KSP lighting function - c += LightingBlinnPhongSmooth(o, lightDir, viewDir, atten); + c += LightingBlinnPhongSmooth(o, lightDir, worldViewDir, atten); // Forward base emission and ambient/vertex lighting #ifdef UNITY_PASS_FORWARDBASE c.rgb += o.Emission; c.rgb += o.Albedo * IN.vlight; + c.a = saturate(c.a); #endif //UNITY_PASS_FORWARDBASE // Forward add multiply by alpha diff --git a/Assets/Textures/Paint-Scratches.tif b/Assets/Textures/Paint-Scratches.tif new file mode 100644 index 0000000..9bd5d04 --- /dev/null +++ b/Assets/Textures/Paint-Scratches.tif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c1fdc5b0ace8225abd8a09a96f03666d5a127ac0ef1561eccde75a8df2dc885f +size 590087 diff --git a/Assets/Textures/Paint-Scuffs.tif b/Assets/Textures/Paint-Scuffs.tif new file mode 100644 index 0000000..dba1b58 --- /dev/null +++ b/Assets/Textures/Paint-Scuffs.tif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b107570db4498f60718879a417f1fc30322f3e6ac5f2029a45284b785b96de24 +size 187725