|
| 1 | +Shader "KSP2/Parts/Paintable" |
| 2 | +{ |
| 3 | + Properties |
| 4 | + { |
| 5 | + [Header(Color)] _Color ("Color", Color) = (1,1,1,1) |
| 6 | + _MainTex ("Albedo Map", 2D) = "white" { } |
| 7 | + [Space()] [Header(Metallic Smoothness)] _MetallicGlossMap ("Metallic", 2D) = "white" { } |
| 8 | + _Metallic ("Metallic/Smoothness Map", Range(0, 1)) = 0 |
| 9 | + _GlossMapScale ("Smoothness Scale", Range(0, 1)) = 1 |
| 10 | + _MipBias ("Mip Bias", Range(0, 1)) = 0.8 |
| 11 | + [Space()] [Header(Normals)] _BumpMap ("Normal Map", 2D) = "bump" { } |
| 12 | + _DetailBumpMap ("Detail Normal Map", 2D) = "bump" { } |
| 13 | + _DetailMask ("Detail Mask", 2D) = "white" { } |
| 14 | + _DetailBumpScale ("Detail Normal Scale", Range(0, 1)) = 1 |
| 15 | + _DetailBumpTiling ("Detail Normal Tiling", Range(0.01, 10)) = 1 |
| 16 | + [Space()] [Header(Occlusion)] _OcclusionMap ("Occlusion Map", 2D) = "white" { } |
| 17 | + _OcclusionStrength ("Strength", Range(0, 1)) = 1 |
| 18 | + [Space()] [Header(Emission)] _EmissionMap ("Emission Map", 2D) = "white" { } |
| 19 | + _EmissionColor ("Emission Color", Color) = (0,0,0,1) |
| 20 | + [Space()] [Toggle(USE_TIME_OF_DAY)] _UseTimeOfDay ("Use Time of Day", Float) = 0 |
| 21 | + _TimeOfDayDotMin ("Min", Range(-1, 1)) = -0.005 |
| 22 | + _TimeOfDayDotMax ("Max", Range(-1, 1)) = 0.005 |
| 23 | + [Space()] [Header(Paint)] _PaintA ("Paint Color A", Color) = (1,1,1,0) |
| 24 | + _PaintB ("Paint Color B", Color) = (1,1,1,0) |
| 25 | + _PaintMaskGlossMap ("Paint Mask (RG Masks B Dirt A Smooth)", 2D) = "white" { } |
| 26 | + _PaintGlossMapScale ("Paint Smoothness Scale", Range(0, 1)) = 1 |
| 27 | + [Toggle] _SmoothnessOverride ("Use PaintMask for Paint Smoothness (And not the Metallic Map)?", Float) = 0 |
| 28 | + _RimFalloff ("_RimFalloff", Range(0.01, 5)) = 0.1 |
| 29 | + _RimColor ("_RimColor", Color) = (0,0,0,0) |
| 30 | + [Header(Rendering)] [Enum(UnityEngine.Rendering.CullMode)] _Culling ("Cull Mode", Float) = 2 |
| 31 | + _Offset ("Depth Offset", Range(-1, 1)) = 0 |
| 32 | + } |
| 33 | + SubShader |
| 34 | + { |
| 35 | + Tags { "RenderType"="Opaque" } |
| 36 | + LOD 200 |
| 37 | + |
| 38 | + CGPROGRAM |
| 39 | + // Physically based Standard lighting model, and enable shadows on all light types |
| 40 | + #pragma surface surf Standard fullforwardshadows |
| 41 | + |
| 42 | + // Use shader model 3.0 target, to get nicer looking lighting |
| 43 | + #pragma target 3.0 |
| 44 | + |
| 45 | + |
| 46 | + struct Input |
| 47 | + { |
| 48 | + float2 uv_MainTex; |
| 49 | + float2 uv_MetallicGlossMap; |
| 50 | + float2 uv_BumpMap; |
| 51 | + float2 uv_OcclusionMap; |
| 52 | + float2 uv_EmissionMap; |
| 53 | + float2 uv_PaintMaskGlossMap; |
| 54 | + float3 viewDir; |
| 55 | + }; |
| 56 | + |
| 57 | + fixed4 _Color; |
| 58 | + sampler2D _MainTex; |
| 59 | + |
| 60 | + sampler2D _MetallicGlossMap; |
| 61 | + half _Metallic; |
| 62 | + half _GlossMapScale; |
| 63 | + half _MipBias; |
| 64 | + |
| 65 | + sampler2D _BumpMap; |
| 66 | + |
| 67 | + sampler2D _OcclusionMap; |
| 68 | + half _OcclusionStrength; |
| 69 | + |
| 70 | + sampler2D _EmissionMap; |
| 71 | + fixed4 _EmissionColor; |
| 72 | + |
| 73 | + sampler2D _PaintMaskGlossMap; |
| 74 | + fixed4 _PaintA; |
| 75 | + fixed4 _PaintB; |
| 76 | + float _PaintGlossMapScale; |
| 77 | + bool _SmoothnessOverride; |
| 78 | + |
| 79 | + fixed4 _RimColor; |
| 80 | + float _RimFalloff; |
| 81 | + |
| 82 | + |
| 83 | + // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader. |
| 84 | + // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing. |
| 85 | + // #pragma instancing_options assumeuniformscaling |
| 86 | + UNITY_INSTANCING_BUFFER_START(Props) |
| 87 | + // put more per-instance properties here |
| 88 | + UNITY_INSTANCING_BUFFER_END(Props) |
| 89 | + |
| 90 | + void surf (Input IN, inout SurfaceOutputStandard o) |
| 91 | + { |
| 92 | + // Albedo comes from a texture tinted by color |
| 93 | + fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; |
| 94 | + fixed4 PaintMaskColor = tex2D(_PaintMaskGlossMap, IN.uv_PaintMaskGlossMap); |
| 95 | + fixed4 MetallicValue = tex2D(_MetallicGlossMap, IN.uv_MetallicGlossMap); |
| 96 | + |
| 97 | + fixed4 paintAColor = lerp(c.rgba, _PaintA * PaintMaskColor.g, _PaintA.a); |
| 98 | + c.rgba = lerp(c.rgba, paintAColor, PaintMaskColor.g); |
| 99 | + fixed4 paintBColor = lerp(c.rgba, _PaintB * PaintMaskColor.r, _PaintB.a); |
| 100 | + c.rgba = lerp(c.rgba, paintBColor, PaintMaskColor.r); |
| 101 | + |
| 102 | + fixed4 paintColor = lerp(paintAColor, paintBColor, PaintMaskColor.r); |
| 103 | + |
| 104 | + _Metallic = MetallicValue.a; |
| 105 | + |
| 106 | + if(_SmoothnessOverride){ |
| 107 | + _Metallic = lerp(_Metallic, PaintMaskColor.a, _PaintA.a * PaintMaskColor.g); |
| 108 | + _Metallic = lerp(_Metallic, PaintMaskColor.a, _PaintB.a * PaintMaskColor.r); |
| 109 | + } |
| 110 | + |
| 111 | + o.Albedo = c; |
| 112 | + o.Metallic = MetallicValue.rgb; |
| 113 | + o.Smoothness = _Metallic * _GlossMapScale; |
| 114 | + o.Normal = UnpackNormal (tex2D(_BumpMap, IN.uv_BumpMap)); |
| 115 | + o.Occlusion = tex2D(_OcclusionMap, IN.uv_OcclusionMap); |
| 116 | + o.Occlusion = o.Occlusion * _OcclusionStrength; |
| 117 | + |
| 118 | + half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal)); |
| 119 | + o.Emission = tex2D(_EmissionMap, IN.uv_EmissionMap) * _EmissionColor + (_RimColor.rgb * pow (rim, _RimFalloff)); |
| 120 | + |
| 121 | + } |
| 122 | + ENDCG |
| 123 | + } |
| 124 | + FallBack "Diffuse" |
| 125 | +} |
0 commit comments