arkavo-org / arkavo-org/VRMMetalKit
Deduplicate per-light shading code in MToon fragment shader
- Dominant language
- Swift
- Stars
- 6
- Forks
- 2
- Avg merge
- 18h 51m
- Merged PRs (30d)
- 26
Description
## Problem
`mtoon_fragment_v2` in `MToonShader.metal` (lines 461-517) contains three copy-pasted blocks of ~18 lines each for per-light shading. Each block has identical logic: `vrmVersion` branching, `smoothstep` vs `linearstep`, weight calculation, shade color blending, and diffuse accumulation.
## Impact
- Large function body increases register pressure and can reduce GPU occupancy
- Instruction cache pollution
- Bug fixes must be applied 3 times
## Fix
Extract a static inline helper:
```metal
static inline float3 computeLightContribution(
float3 normal, float3 lightDir, float3 lightColor,
float shadingShift, float shadingToony,
float3 baseColor, float3 shadeColor,
uint vrmVersion
);
```
## Location
- `MToonShader.metal` lines 461-517
Contributor guide
Research direction
Start in MToonShader.metal around lines 461-517 and compare the three per-light shading blocks, including the vrmVersion branching, step calculation, weight, shade blending, and diffuse accumulation. Confirm that the shared helper replaces the duplicated logic and that the shader still builds successfully.
Written by the indexing model from the issue text.
Assessment
- Domain
- computer-graphics, performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100