Skip to content

Commit 410083e

Browse files
authored
Create Paintable
New, improved paintable parts shader
1 parent f2ac74c commit 410083e

File tree

1 file changed

+107
-0
lines changed
  • Assets/KSP2UnityTools/Shaders/KSP2/Parts

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
};
50+
51+
fixed4 _Color;
52+
sampler2D _MainTex;
53+
54+
sampler2D _MetallicGlossMap;
55+
half _Metallic;
56+
half _GlossMapScale;
57+
half _MipBias;
58+
59+
sampler2D _BumpMap;
60+
61+
sampler2D _OcclusionMap;
62+
sampler2D _EmissionMap;
63+
fixed4 _EmissionColor;
64+
65+
sampler2D _PaintMaskGlossMap;
66+
fixed4 _PaintA;
67+
fixed4 _PaintB;
68+
float _PaintGlossMapScale;
69+
bool _SmoothnessOverride;
70+
71+
72+
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
73+
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
74+
// #pragma instancing_options assumeuniformscaling
75+
UNITY_INSTANCING_BUFFER_START(Props)
76+
// put more per-instance properties here
77+
UNITY_INSTANCING_BUFFER_END(Props)
78+
79+
void surf (Input IN, inout SurfaceOutputStandard o)
80+
{
81+
// Albedo comes from a texture tinted by color
82+
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
83+
fixed4 PaintMaskColor = tex2D(_PaintMaskGlossMap, IN.uv_MainTex);
84+
fixed4 MetallicValue = tex2D(_MetallicGlossMap, IN.uv_MainTex);
85+
86+
fixed4 paintAColor = lerp(c.rgba, _PaintA * PaintMaskColor.g, _PaintA.a);
87+
c.rgba = lerp(c.rgba, paintAColor, PaintMaskColor.g);
88+
fixed4 paintBColor = lerp(c.rgba, _PaintB * PaintMaskColor.r, _PaintB.a);
89+
c.rgba = lerp(c.rgba, paintBColor, PaintMaskColor.r);
90+
91+
fixed4 paintColor = lerp(paintAColor, paintBColor, PaintMaskColor.r);
92+
93+
if(_SmoothnessOverride){
94+
_Metallic = PaintMaskColor.a * _PaintGlossMapScale * PaintMaskColor.g;
95+
}
96+
97+
o.Albedo = c;
98+
o.Metallic = MetallicValue.a;
99+
o.Smoothness = _Metallic * _GlossMapScale;
100+
o.Emission = tex2D(_EmissionMap, IN.uv_MainTex) * _EmissionColor;
101+
o.Occlusion = tex2D(_OcclusionMap, IN.uv_MainTex);
102+
o.Normal = UnpackNormal (tex2D(_BumpMap, IN.uv_MainTex));
103+
}
104+
ENDCG
105+
}
106+
FallBack "Diffuse"
107+
}

0 commit comments

Comments
 (0)