# B04: five procedural texture families, height/ORM channels, and .lmmat round trips. mkdir("build");program=_lmcode_ cli="lmvideo" install="github:lmctl-ai/lmvideo@v0.1.38"; let scene=scene3d().threads(4).background("#16202c").ambient(0.08);scene.camera(camera3d().look_at(4.0,4.0,9.0,0.0,0.0,0.0).perspective(35.0,0.1,100.0));let sphere=mesh_sphere(0.52,18,28);let orm=texture_from_image(image_pattern(128,128,"1","0.35+0.5*x","0.2+0.7*y","1"),"linear").filter("trilinear"); let h=image_pattern(128,128,"0.5+0.18*sin(x*25.1327412287)*cos(y*25.1327412287)","0.5+0.18*sin(x*25.1327412287)*cos(y*25.1327412287)","0.5+0.18*sin(x*25.1327412287)*cos(y*25.1327412287)","1");let a=texture_noise("perlin",17,8).mix(texture_checker("#d8aa5f","#315573",8),0.28).bake(128,128,"srgb").filter("trilinear");let m=material("#b8a07c",0.0,0.22).albedo(a).orm(orm).height(h,1.2,true);scene.add(sphere,m).position(-2.7,0.0,0.0);m.save("build/bench-04-perlin.lmmat"); let b=texture_noise("worley",29,8).bake(128,128,"srgb").filter("trilinear");m=material("#b8a07c",0.25,0.38).albedo(b).orm(orm).height(h,1.2,true);scene.add(sphere,m).position(-1.35,0.0,0.0);m.save("build/bench-04-worley.lmmat"); let c=texture_bricks("#b65c42","#e4c28e",7).bake(128,128,"srgb").filter("trilinear");m=material("#b8a07c",0.5,0.54).albedo(c).orm(orm).height(h,1.2,true);scene.add(sphere,m).position(0.0,0.0,0.0);m.save("build/bench-04-brick.lmmat"); let d=texture_checker("#e9e1cf","#38536b",8).bake(128,128,"srgb").filter("trilinear");m=material("#b8a07c",0.75,0.7).albedo(d).orm(orm).height(h,1.2,true);scene.add(sphere,m).position(1.35,0.0,0.0);m.save("build/bench-04-checker.lmmat"); let e=texture_radial("#1e3855","#e0a14c",1).bake(128,128,"srgb").filter("trilinear");m=material("#b8a07c",1.0,0.86).albedo(e).orm(orm).height(h,1.2,true);scene.add(sphere,m).position(2.7,0.0,0.0);m.save("build/bench-04-radial.lmmat"); scene.directional_light(-2.0,5.0,4.0,"#fff1d4",2.0).directional_light(3.0,2.0,-3.0,"#b8d8ff",0.6);scene.shadows(1024,0.0004,0.001,1);let image=scene.render_image(900,560,2);image_assert_true(image.width()==900&&image.height()==560&&image.stddev(0)>0.005);image.save("build/bench-04-tiled-pbr-swatches.png"); let warm=scene3d().threads(4).background("#16202c").ambient(0.08);warm.camera(camera3d().look_at(4.0,4.0,9.0,0.0,0.0,0.0).perspective(35.0,0.1,100.0)); warm.add(sphere,material_load("build/bench-04-perlin.lmmat")).position(-2.7,0.0,0.0);warm.add(sphere,material_load("build/bench-04-worley.lmmat")).position(-1.35,0.0,0.0);warm.add(sphere,material_load("build/bench-04-brick.lmmat")).position(0.0,0.0,0.0);warm.add(sphere,material_load("build/bench-04-checker.lmmat")).position(1.35,0.0,0.0);warm.add(sphere,material_load("build/bench-04-radial.lmmat")).position(2.7,0.0,0.0);warm.directional_light(-2.0,5.0,4.0,"#fff1d4",2.0).directional_light(3.0,2.0,-3.0,"#b8d8ff",0.6).shadows(1024,0.0004,0.001,1);image_assert_true(image.rgba()==warm.render_image(900,560,2).rgba());out.print("Five cold-baked packs reproduce byte-identical warm-loaded materials."); end _lmcode_ r=run_lmcode(program);assert(r.ok,(r.ok ? "" : r.message));println(json_stringify(r.result));