Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: select toon palette bands from continuous lighting (#10713)

Adam Eivy4e03916a9522
diff --git a/server/services/musicVideo/documentTemplates/shared/toonWorld.browser.test.js b/server/services/musicVideo/documentTemplates/shared/toonWorld.browser.test.js
index 2f465a86b6..b421422597 100644
--- a/server/services/musicVideo/documentTemplates/shared/toonWorld.browser.test.js
+++ b/server/services/musicVideo/documentTemplates/shared/toonWorld.browser.test.js
@@ -58,6 +58,14 @@ describe.skipIf(!canRun)('toon world headless dish proof', () => {
expect(results.ratio).toBeLessThanOrEqual(2);
}, 60000);
+ it('selects all three explicit palette colors from illumination before receiving shadows', async () => {
+ const colors = await page.evaluate(() => window.paletteProof());
+ for (const [i, expected] of [[87, 69, 111], [186, 129, 123], [246, 206, 134]].entries()) {
+ for (let channel = 0; channel < 3; channel++) expect(Math.abs(colors[i][channel] - expected[channel])).toBeLessThanOrEqual(1);
+ }
+ expect(errors).toEqual([]);
+ });
+
it('supports a manual/layered post stack and restores the caller target', async () => {
const result = await page.evaluate(() => window.manualProof());
expect(result.changed).toHaveLength(2);
@@ -95,6 +103,21 @@ ground.rotation.x=-Math.PI/2;ground.receiveShadow=true;scene.add(ground);
const pixels=()=>{const gl=renderer.getContext(),p=new Uint8Array(640*360*4);gl.readPixels(0,0,640,360,gl.RGBA,gl.UNSIGNED_BYTE,p);return p;};
const changed=(a,b,region=()=>true)=>{let count=0;for(let i=0;i<a.length;i+=4)if(region(i/4)&&a.slice(i,i+3).some((v,j)=>Math.abs(v-b[i+j])>3))count++;return count;};
const draw=(lens={})=>{post.render(scene,camera,lens,0);renderer.getContext().finish();return pixels();};
+window.paletteProof=()=>{
+ const world=new THREE.Scene(),view=new THREE.OrthographicCamera(-1,1,1,-1,.1,10);
+ view.position.z=3;
+ const mat=kit.toonMaterial(THREE),geometry=new THREE.PlaneGeometry(2,2);
+ world.add(new THREE.Mesh(geometry,mat));
+ const light=new THREE.DirectionalLight('#ffffff',1);world.add(light);
+ const colors=[];
+ for(const dot of [.1,.5,.9]){
+ light.position.set(Math.sqrt(1-dot*dot),0,dot);
+ renderer.setRenderTarget(null);renderer.render(world,view);
+ const p=pixels(),center=(180*640+320)*4;colors.push([...p.slice(center,center+3)]);
+ }
+ mat.dispose();geometry.dispose();
+ return colors;
+};
window.manualProof=()=>{
const input=new THREE.WebGLRenderTarget(640,360,{type:THREE.HalfFloatType,depthTexture:new THREE.DepthTexture(640,360,THREE.FloatType)});
const output=new THREE.WebGLRenderTarget(640,360,{depthBuffer:false});
diff --git a/server/services/musicVideo/documentTemplates/shared/toonWorld.js b/server/services/musicVideo/documentTemplates/shared/toonWorld.js
index 873617af57..1f4f4b015c 100644
--- a/server/services/musicVideo/documentTemplates/shared/toonWorld.js
+++ b/server/services/musicVideo/documentTemplates/shared/toonWorld.js
@@ -11,6 +11,11 @@ export function toonMaterial(THREE, { lit = '#f6ce86', mid = '#ba817b', shadow =
toonShadow: { value: new THREE.Color(shadow) }, toonBands: { value: bands },
});
shader.fragmentShader = 'uniform vec3 toonLit, toonMid, toonShadow; uniform float toonBands;\n' + shader.fragmentShader;
+ // Accumulate continuous light before selecting the palette band. Three's
+ // default two-step irradiance would quantize the light a second time and
+ // can collapse the mid/shadow bands under a bright directional light.
+ shader.fragmentShader = shader.fragmentShader.replace('#include <gradientmap_pars_fragment>',
+ 'vec3 getGradientIrradiance(vec3 normal, vec3 lightDirection) { return vec3(max(dot(normal, lightDirection), 0.)); }');
shader.fragmentShader = shader.fragmentShader.replace(
'vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;',
`vec3 illumination = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;