Files
chameleon/Assets/Shaders/MeshPaintPackMS.shader
adminandClaude Opus 4.8 c7ec12e6d9 Split mesh painter into partials and add occlusion via combined mask map
- Split MeshPainter into partial classes (Setup/Backend/Gpu/Cpu) for maintainability
- Add ambient occlusion painting, packed with metallic/smoothness into one
  MSO mask map (R=metallic, G=occlusion, A=smoothness) bound to both
  _MetallicGlossMap and _OcclusionMap, kept independently paintable via
  per-channel ColorMask
- Gate painting from a single IsChannelActive source so AO-only strokes work
- Blend albedo/emission in linear space on CPU to match the GPU framebuffer
- Pre-compensate data-channel writes for sRGB->linear so GPU matches CPU
- Harden GPU shader fallback to reflect real backend state

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 19:31:52 +02:00

48 lines
1.5 KiB
Plaintext

// Packs the mask-map WORK layout into the URP mask-map layout.
//
// While painting, the mask map is kept in a "work" RenderTexture as
// R = metallic, G = smoothness, B = occlusion, A = coverage (painted marker for dilation).
// This lets the same brush + dilate shaders (which use alpha as the coverage marker)
// drive it exactly like the albedo map. The packed result is one texture bound to BOTH
// _MetallicGlossMap (URP reads R = metallic, A = smoothness) and
// _OcclusionMap (URP reads G = occlusion).
// This pass converts work -> final after each stroke: out = (work.r, work.b, 0, work.g)
// = (metallic, occlusion, 0, smoothness).
//
// Both work and final are linear RenderTextures (these 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);
// work (R=metallic, G=smoothness, B=occlusion) -> (metallic, occlusion, 0, smoothness)
return fixed4(c.r, c.b, 0.0, c.g);
}
ENDCG
}
}
Fallback Off
}