Skip to content

urp: editor material importer for .vpe packages (keeps UrpMaskRemap masks) - #31

Open
dcbenji wants to merge 1 commit into
VisualPinball:masterfrom
dcbenji:feat/urp-material-editor-importer
Open

dcbenji wants to merge 1 commit into
VisualPinball:masterfrom
dcbenji:feat/urp-material-editor-importer

Conversation

@dcbenji

@dcbenji dcbenji commented Oct 19, 2026

Copy link
Copy Markdown

AI disclosure: written and submitted by Claude (AI; Anthropic Claude Opus 5.5 with Sonnet 5.5 sub-agents) at @dcbenji's request, found while converting the Attack From Mars table HDRP -> URP through VPE's .vpe path. Tested as described below; it has not had a human line-by-line review.

Engine has IVpeMaterialEditorImporter and HDRP registers HdrpMaterialEditorImporter, but the URP package has no implementation, so an editor/batch .vpe import into a URP project leaves the materials unconverted.

Change: UrpMaterialEditorImporter, a port of the HDRP importer that drives UrpMaterialResolver with the imported texture assets and saves the materials as .mat assets, registered with [InitializeOnLoad]. HDRP-only parts (templates, normal-map packing, ray tracing mode) are left out.

It also keeps the masks UrpMaskRemap bakes. For HDRP mask remaps that URP scalars cannot express, UrpMaskRemap.Bake assigns a RenderTexture to _MetallicGlossMap / _OcclusionMap and sets metallic 0 / smoothness 1 (the mask carries the values). The RenderTexture is alive after CreateMaterial, but AssetDatabase.CreateAsset drops a material's references to objects that are not assets, so the saved material had an empty mask slot. The importer now reads each baked RenderTexture back into a Texture2D right after CreateMaterial and, after CreateAsset, saves it as a linear PNG next to the materials (one file per distinct bake, shared by every material that uses it) and assigns that asset.

Evidence (Attack From Mars, Engine .221 / Urp .205):

  • Before: 4 of 7 steel/chrome materials saved with _MetallicGlossMap empty, metallic 0, smoothness 1 (e.g. AFM Steel - Microscratch (Light) ST5), although the package carries the mask and remaps (MetallicRemap 0..0.983, SmoothnessRemap 0.22..0.97, same as the HDRP source). In the player every wire ramp, bracket and rail rendered matte white.
  • After (this change): 0 of 7 metal materials lose their mask; AFM Steel ST5 references steel-microscratch(light)-mask (remapped).png (linear). Material folder 25 MB (an earlier variant that embedded the masks uncompressed in the .mat files was 329 MB). In the player the wire ramps, brackets and rails are chrome again, matching the pre-.205 conversion (before/after screenshots available).

Tests: the URP repo has no test assembly. Manual: batch import of the AFM .vpe (350 material profiles) into a URP project, then reopen the scene and check that the materials and the remapped masks persist. Results: the AFM import above (Linux, Unity 6000.5, batch). We have used the importer (without the RenderTexture part) in our AFM URP pipeline since 2026-10-15.

🤖 Generated with Claude Code

Implements IVpeMaterialEditorImporter for URP (port of the HDRP importer) so an
editor/batch .vpe import rebuilds URP materials and saves them as assets. Masks
UrpMaskRemap bakes into RenderTextures are read back and saved as linear PNGs:
AssetDatabase.CreateAsset drops references to non-asset textures, which left
remapped steel materials without their mask (matte white).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dcbenji
dcbenji marked this pull request as ready for review October 19, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant