Skip to content

Commit 9f577cc

Browse files
authored
fixed metallic map and paint map
- Metallic map wasn't accounting for black pixels as non-metallic - Paint map was overriding all smoothness when _OverrideSmoothness was true - Now paint map will only override the smoothness if the pixel is either red or green - Also it won't override if _PaintA or _PaintB is transparent - Both this changes lerp with the alpha of the color
1 parent 81645c2 commit 9f577cc

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

Assets/KSP2UnityTools/Shaders/KSP2/Parts/Paintable.shader

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ Shader "KSP2/Parts/Paintable"
4646
struct Input
4747
{
4848
float2 uv_MainTex;
49+
float2 uv_MetallicGlossMap;
50+
float2 uv_BumpMap;
51+
float2 uv_OcclusionMap;
52+
float2 uv_EmissionMap;
53+
float2 uv_PaintMaskGlossMap;
4954
float3 viewDir;
5055
};
5156

@@ -61,6 +66,7 @@ Shader "KSP2/Parts/Paintable"
6166

6267
sampler2D _OcclusionMap;
6368
half _OcclusionStrength;
69+
6470
sampler2D _EmissionMap;
6571
fixed4 _EmissionColor;
6672

@@ -85,29 +91,32 @@ Shader "KSP2/Parts/Paintable"
8591
{
8692
// Albedo comes from a texture tinted by color
8793
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
88-
fixed4 PaintMaskColor = tex2D(_PaintMaskGlossMap, IN.uv_MainTex);
89-
fixed4 MetallicValue = tex2D(_MetallicGlossMap, IN.uv_MainTex);
94+
fixed4 PaintMaskColor = tex2D(_PaintMaskGlossMap, IN.uv_PaintMaskGlossMap);
95+
fixed4 MetallicValue = tex2D(_MetallicGlossMap, IN.uv_MetallicGlossMap);
9096

9197
fixed4 paintAColor = lerp(c.rgba, _PaintA * PaintMaskColor.g, _PaintA.a);
9298
c.rgba = lerp(c.rgba, paintAColor, PaintMaskColor.g);
9399
fixed4 paintBColor = lerp(c.rgba, _PaintB * PaintMaskColor.r, _PaintB.a);
94100
c.rgba = lerp(c.rgba, paintBColor, PaintMaskColor.r);
95101

96102
fixed4 paintColor = lerp(paintAColor, paintBColor, PaintMaskColor.r);
103+
104+
_Metallic = MetallicValue.a;
97105

98106
if(_SmoothnessOverride){
99-
_Metallic = PaintMaskColor.a * _PaintGlossMapScale * PaintMaskColor.g;
107+
_Metallic = lerp(_Metallic, PaintMaskColor.a, _PaintA.a * PaintMaskColor.g);
108+
_Metallic = lerp(_Metallic, PaintMaskColor.a, _PaintB.a * PaintMaskColor.r);
100109
}
101110

102111
o.Albedo = c;
103-
o.Metallic = MetallicValue.a;
112+
o.Metallic = MetallicValue.rgb;
104113
o.Smoothness = _Metallic * _GlossMapScale;
105-
o.Normal = UnpackNormal (tex2D(_BumpMap, IN.uv_MainTex));
106-
o.Occlusion = tex2D(_OcclusionMap, IN.uv_MainTex);
114+
o.Normal = UnpackNormal (tex2D(_BumpMap, IN.uv_BumpMap));
115+
o.Occlusion = tex2D(_OcclusionMap, IN.uv_OcclusionMap);
107116
o.Occlusion = o.Occlusion * _OcclusionStrength;
108117

109118
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
110-
o.Emission = tex2D(_EmissionMap, IN.uv_MainTex) * _EmissionColor + (_RimColor.rgb * pow (rim, _RimFalloff));
119+
o.Emission = tex2D(_EmissionMap, IN.uv_EmissionMap) * _EmissionColor + (_RimColor.rgb * pow (rim, _RimFalloff));
111120

112121
}
113122
ENDCG

0 commit comments

Comments
 (0)