Files
chameleon/Assets/Shaders/MeshPaintPackMS.shader
T
admin 86c0a33687 Add metallic, smoothness, and emission painting to mesh painter
Extend the painter from a single albedo map to three paint maps:
albedo (_BaseMap), packed metallic+smoothness (_MetallicGlossMap,
R=metallic A=smoothness), and emission (_EmissionMap/_EmissionColor).

- Per-channel toggles (paint albedo / metallic+smoothness / emission)
- Metallic/Smoothness sliders and emission color + intensity brush params
- One brush shader drives all maps; metallic-smoothness uses a work
  layout (R=metallic G=smoothness A=coverage) and a pack pass
  (Hidden/MeshPaintPackMS) to the URP layout after each stroke
- GPU and CPU backends mirror all three maps with the same mask and
  seam-dilation logic
- Material keywords (_METALLICSPECGLOSSMAP, _EMISSION) enabled and the
  new maps seeded from the original material values
2026-06-23 16:08:32 +02:00

45 lines
1.3 KiB
Plaintext

// Packs the metallic-smoothness WORK layout into the URP _MetallicGlossMap layout.
//
// While painting, the metallic-smoothness map is kept in a "work" RenderTexture as
// R = metallic, G = smoothness, A = coverage (painted marker for the dilation pass).
// This lets the same brush + dilate shaders (which use alpha as the coverage marker)
// drive it exactly like the albedo map. But URP's _MetallicGlossMap expects
// R = metallic, A = smoothness.
// This pass converts work -> final after each stroke: out = (work.r, 0, 0, work.g).
//
// Both work and final are linear RenderTextures (metallic/smoothness are data, not
// color), so no gamma conversion happens.
Shader "Hidden/MeshPaintPackMS"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType" = "Opaque" }
Pass
{
ZTest Always
ZWrite Off
Cull Off
Blend Off
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
fixed4 frag (v2f_img i) : SV_Target
{
fixed4 c = tex2D(_MainTex, i.uv);
return fixed4(c.r, 0.0, 0.0, c.g); // R = metallic, A = smoothness
}
ENDCG
}
}
Fallback Off
}