Official Codebase of 3DCodeVerse
Python
lib: drop two GLSL functions nothing calls; neon test reads the rendered phase
gaoypeng6153d70aefed
diff --git a/harness/codeverse3d/languages/scene_threejs/starter/src/lib/neon.js b/harness/codeverse3d/languages/scene_threejs/starter/src/lib/neon.jsindex c08ef1a2..37e9d5e2 100644--- a/harness/codeverse3d/languages/scene_threejs/starter/src/lib/neon.js+++ b/harness/codeverse3d/languages/scene_threejs/starter/src/lib/neon.js@@ -652,13 +652,6 @@ function trailMaterial(name, color, dir, count, rate, gain, hot, fore,'uniform vec3 uColor; uniform float uDir; uniform float uCount;','uniform float uRate; uniform float uGain; uniform float uHot;','uniform float uFore; uniform float uKey; uniform float uVary;',- // The phase one vehicle rides. Written as its own function- // so the direction it travels is a property of the source,- // not something only a rendered frame could tell you.- 'float astraTrailPhase(float v, float dir, float t,',- ' float rate, float count) {',- ' return fract(dir * v * count - t * rate);',- '}',TEMP_GLSL,].join('\n'),fragmentMain: [diff --git a/harness/codeverse3d/languages/scene_threejs/starter/src/lib/shader.js b/harness/codeverse3d/languages/scene_threejs/starter/src/lib/shader.jsindex 5c90e9ec..16a430ff 100644--- a/harness/codeverse3d/languages/scene_threejs/starter/src/lib/shader.js+++ b/harness/codeverse3d/languages/scene_threejs/starter/src/lib/shader.js@@ -125,12 +125,6 @@ export const GLSL_UTIL = ['float astraFacing(vec3 n, vec3 v) {',' return abs(dot(normalize(n), normalize(v)));','}',- // Free fall: distance goes as time squared, so a packet's AGE is the- // square root of how far it has dropped. Riding features at a- // constant rate in age is what makes falling water accelerate.- 'float astraFallAge(float drop) {',- ' return sqrt(clamp(drop, 0.0, 1.6));',- '}',// Decorrelate neighbouring filaments. Offsets under 2*PI leave them// correlated and their fronts weave a herringbone across the sheet.'float astraStagger(float x) {',diff --git a/harness/tests/scene_runtime/lib/test_neon.py b/harness/tests/scene_runtime/lib/test_neon.pyindex a19e3ea7..97de4ee7 100644--- a/harness/tests/scene_runtime/lib/test_neon.py+++ b/harness/tests/scene_runtime/lib/test_neon.py@@ -303,16 +303,27 @@ def test_the_two_lanes_of_traffic_run_in_opposite_directions():"""Warm one way and red the other is what says a road has twodirections. Both lanes riding the same sign of `uDir` is a road whereevery vehicle travels the same way — measured by tracking each lane's- comet HEADS along the shipped phase function."""- out = measure(_GLSL_AS_JS + """+ comet HEADS along the phase the fragment stage actually renders."""+ out = measure("""import { makeLightTrails } from './lib/neon.js';+// The phase main() RENDERS — its own `s` line and `fract(s)`, lifted out+// with the uniforms bound — not a helper nothing in the shader calls.+const renderedPhase = (src) => {+ const m = /float s = ([^;]+);\\s*float f = fract\\(s\\);/.exec(src);+ if (!m) throw new Error('no rendered phase in the shipped source');+ const s = new Function('uDir', 'vTrailUv', 'uCount', 'uTime', 'uRate',+ 'return ' + m[1] + ';');+ return (v, dir, t, rate, count) => {+ const x = s(dir, { y: v }, count, t, rate);+ return x - Math.floor(x);+ };+};const g = makeLightTrails({ path: [[-20, 0, 0], [20, 0, 0]], count: 5,speed: 14, seed: 7 });const heads = (mesh, t) => {const u = mesh.material.uniforms;- const phase = glslFn(mesh.material.fragmentShader, 'astraTrailPhase',- ['v', 'dir', 't', 'rate', 'count']);+ const phase = renderedPhase(mesh.material.fragmentShader);const at = (v) => phase(v, u.uDir.value, t, u.uRate.value,u.uCount.value);const out = [];diff --git a/harness/tests/scene_runtime/lib/test_shader.py b/harness/tests/scene_runtime/lib/test_shader.pyindex b9c9ec21..ad2a9e27 100644--- a/harness/tests/scene_runtime/lib/test_shader.py+++ b/harness/tests/scene_runtime/lib/test_shader.py@@ -232,7 +232,7 @@ console.log(JSON.stringify({ util: GLSL_UTIL, inShader: m.fragmentShader.includepatchedFsDefine: shader.fragmentShader.includes('#define ASTRA_FRAG'),patchedVsDefine: shader.vertexShader.includes('#define ASTRA_FRAG') }));""")- for fn in ("astraStroke", "astraFacing", "astraFallAge", "astraStagger", "astraHueBreak", "astraFresnel"):+ for fn in ("astraStroke", "astraFacing", "astraStagger", "astraHueBreak", "astraFresnel"):assert f"{fn}(" in out["util"], fnassert "fwidth(v)" in out["util"] and out["inShader"]# fwidth is fragment-only and the util block ships in BOTH stages.