diff --git a/common.go b/common.go index 8f68b16..811e789 100644 --- a/common.go +++ b/common.go @@ -11,7 +11,7 @@ import ( "time" ) -const version = "0.98.365-experimental1" +const version = "0.98.366-experimental1" const appDisplayName = "Projection Mapper - Built by Instinct" diff --git a/fxphys.go b/fxphys.go index c163c44..d00515c 100644 --- a/fxphys.go +++ b/fxphys.go @@ -334,6 +334,7 @@ func (e *physEngine) render() { } func (e *physEngine) sample(sx, sy float64) (rgb, float32) { + if s,ok:=e.sim.(*realFXStudioSim);ok&&s.sel==8&&(s.bloom366==nil||!s.bloom366.contains(sx,sy)){return rgb{},0} if tank,ok:=e.sim.(*fishTank);ok&&tank.blockedExact364(sx,sy){return rgb{},0} if e.aquaticRoom354!=nil{if b,_:=e.aquaticRoom354.at(sx,sy);b{return rgb{},0}} g := e.g @@ -758,6 +759,7 @@ func (r *Renderer) physFieldFor(sc *Scene, pl *plan, as Assign, plans []*plan, t if e.started && t < e.lastT-0.5 { e.restart() } + if s,ok:=e.sim.(*realFXStudioSim);ok{s.prepareBloom366(r,plans,wall)} e.lastT = t e.lastUse = wall diff --git a/realfx_bloom366.go b/realfx_bloom366.go new file mode 100644 index 0000000..00f550b --- /dev/null +++ b/realfx_bloom366.go @@ -0,0 +1,365 @@ +package main + +import ( + "math" + "time" +) + +// Photo-coordinate growth over explicitly authored wall regions. Furniture is +// an obstacle, never a made-up 3D object. Distances below are field pixels. +type realFXBloom366 struct { + w, h int + head *plan + sig uint64 + dm *depthMap + checked time.Time + wallBoxes, obstacleBoxes [][4]float64 + walls, obstacles []physOutline + allowed []bool + distance []int + parent []int + anchors []int + normals [][3]float64 +} + +func realFXWall366(s *Surface) bool { + return s != nil && s.visible() && !s.Occluder && !s.Uncertain && !s.Tiny && (s.Cls == "wall" || s.Cls == "facade") +} +func newRealFXBloom366(plans []*plan, w, h int, dm *depthMap) *realFXBloom366 { + if !realFXInputOK366(plans) || len(plans) == 0 || w < 1 || h < 1 || w > 1024 || h > 1024 { + return nil + } + b := &realFXBloom366{w: w, h: h, head: plans[0], sig: realFXGeometrySig366(plans), dm: dm, allowed: make([]bool, w*h), distance: make([]int, w*h), parent: make([]int, w*h), normals: make([][3]float64, w*h)} + for _, p := range plans { + if p == nil || p.s == nil || !p.s.visible() { + continue + } + s := p.s + poly := s.Poly + if len(poly) < 3 { + poly = s.Quad + } + if len(poly) < 3 { + continue + } + o := physOutline{id: s.ID, poly: append([][2]float64(nil), poly...), rings: cloneRealFXRings366(s.Rings), modelRings: true, cls: s.Cls} + if realFXWall366(s) { + b.walls = append(b.walls, o) + b.wallBoxes = append(b.wallBoxes, realFXBox366(o)) + } else if s.Cls != "wall" && s.Cls != "floor" && s.Cls != "ceiling" { + b.obstacles = append(b.obstacles, o) + b.obstacleBoxes = append(b.obstacleBoxes, realFXBox366(o)) + } + } + for y := 0; y < h; y++ { + for x := 0; x < w; x++ { + i := y*w + x + u, v := (float64(x)+.5)/float64(w), (float64(y)+.5)/float64(h) + b.allowed[i] = b.contains(u, v) + b.distance[i] = -1 + b.parent[i] = -1 + b.normals[i] = [3]float64{0, 0, 1} + if dm != nil { + _, nx, ny, nz, ok := dm.NormalAtOK(u, v) + if ok { + b.normals[i] = [3]float64{nx, ny, nz} + } + } + } + } + // Deterministic bottom-most wall seeds. Breadth-first growth routes around + // furniture and cannot jump disconnected regions or ring holes. + queue := make([]int, 0, w*h) + for x := 0; x < w; x += maxi(1, w/5) { + for y := h - 1; y >= 0; y-- { + i := y*w + x + if b.allowed[i] { + b.distance[i] = 0 + queue = append(queue, i) + break + } + } + } + for k := 0; k < len(queue); k++ { + i := queue[k] + x, y := i%w, i/w + for _, d := range [][2]int{{-1, -1}, {1, -1}, {0, -1}, {-1, 0}, {1, 0}, {0, 1}, {-1, 1}, {1, 1}} { + xx, yy := x+d[0], y+d[1] + if xx < 0 || yy < 0 || xx >= w || yy >= h { + continue + } + j := yy*w + xx + if d[0] != 0 && d[1] != 0 && (!b.allowed[y*w+xx] || !b.allowed[yy*w+x]) { + continue + } + if !b.allowed[j] || b.distance[j] >= 0 { + continue + } + b.distance[j] = b.distance[i] + 1 + b.parent[j] = i + queue = append(queue, j) + } + } + // Separated bloom anchors are selected from the traversable actual wall, + // not its bounding rectangle. At most 48 keeps both draw and routing bounded. + for gy := 0; gy < 6; gy++ { + for gx := 0; gx < 8; gx++ { + x := clampi((2*gx+1)*w/16+int(math.Sin(float64(gx*17+gy*31))*float64(w)/24), 0, w-1) + y := clampi((2*gy+1)*h/12+int(math.Sin(float64(gx*37+gy*13))*float64(h)/18), 0, h-1) + i := y*w + x + if b.allowed[i] && b.distance[i] > 4 { + b.anchors = append(b.anchors, i) + } + } + } + return b +} +func (b *realFXBloom366) contains(u, v float64) bool { + if b == nil || math.IsNaN(u+v) || math.IsInf(u+v, 0) || u < 0 || v < 0 || u >= 1 || v >= 1 { + return false + } + wall := false + for i, o := range b.walls { + if realFXInBox366(b.wallBoxes[i], u, v) && modelOutlineContains(o, u, v) { + wall = true + break + } + } + if !wall { + return false + } + for i, o := range b.obstacles { + if realFXInBox366(b.obstacleBoxes[i], u, v) && modelOutlineContains(o, u, v) { + return false + } + } + return true +} +func (s *realFXStudioSim) bloomShade366(e *physEngine) bool { + b := s.bloom366 + if b == nil || b.w != s.sw || b.h != s.sh || e.g == nil || e.g.dx0 != 0 || e.g.dy0 != 0 || e.g.dx1 != 1 || e.g.dy1 != 1 { + return false + } + s.clearHDR() + + // Artistic growth, with a held full garden and a short fade before regrowth. + cycle := math.Mod(s.t, 20) + growth := clamp01(cycle / 6) + fade := float32(1 - clamp01((cycle-18)/2)) + limit := growth * float64(b.w+b.h) + sc := float64(b.w) / 320 + for k, anchor := range b.anchors { + if b.distance[anchor] < 0 { + continue + } + i, steps := anchor, 0 + for i >= 0 && steps < b.w*b.h { + j := b.parent[i] + d := float64(b.distance[i]) + if j >= 0 && d <= limit { + x, y := float64(i%b.w)+.5, float64(i/b.w)+.5 + xx, yy := float64(j%b.w)+.5, float64(j/b.w)+.5 + // Bending depends on the actual routed growth path, not a moving stage. + sway := math.Sin(d*.075+float64(k)*1.3+s.t*.28) * 2.5 * sc + s.line(x+sway, y, xx+sway, yy, 2*sc, .035*fade, .16*fade, .045*fade) + if steps%maxi(1, int(21*sc)) == 0 { + side := 1. + if (steps/maxi(1, int(21*sc)))%2 == 0 { + side = -1 + } + b.ellipse366(&s.hxBase, x+sway+side*5*sc, y-3*sc, 9*sc, 3.5*sc, -side*.65, rgb{.05 * fade, .42 * fade, .12 * fade}, true) + } + } + i = j + steps++ + } + age := clamp01((limit - float64(b.distance[anchor])) / (22 * sc)) + if age <= 0 { + continue + } + x, y := float64(anchor%b.w)+.5, float64(anchor/b.w)+.5 + size := (9 + 3*math.Sin(float64(k)*1.7)) * sc * age * (1 + .035*math.Sin(s.t*1.2+float64(k))) + n := b.normals[anchor] + light := fade * float32(.55+.45*math.Max(0, -n[0]*.35-n[1]*.3+n[2]*.85)) + phase := float64(k)*.73 + .03*math.Sin(s.t*.6) + c := []rgb{{.95, .18, .32}, {.85, .38, .12}, {.72, .22, .85}, {.93, .69, .4}}[k%4].scale(light) + for layer := 0; layer < 3; layer++ { + for p := 0; p < 8; p++ { + a := float64(p)*2*math.Pi/8 + phase + float64(layer)*.38 + r := size * (.65 - float64(layer)*.16) + cx, cy := x+math.Cos(a)*r*.8, y+math.Sin(a)*r*.8 + b.ellipse366(&s.hxBase, cx, cy, r, r*.48, a, c.scale(1+float32(layer)*.12), false) + } + } + b.ellipse366(&s.hxBase, x, y, math.Max(1, size*.19), math.Max(1, size*.19), 0, rgb{1 * light, .63 * light, .12 * light}, false) + } + s.finish(e, 1, .18, .1) + // Keep bloom/resampling from leaking into obstacles before final sampling. + for y := 0; y < e.fh; y++ { + for x := 0; x < e.fw; x++ { + u, v := (float64(x)+.5)/float64(e.fw), (float64(y)+.5)/float64(e.fh) + i := clampi(int(v*float64(b.h)), 0, b.h-1)*b.w + clampi(int(u*float64(b.w)), 0, b.w-1) + if !b.allowed[i] { + o := (y*e.fw + x) * 4 + e.back[o], e.back[o+1], e.back[o+2], e.back[o+3] = 0, 0, 0, 0 + } + } + } + return true +} + +// Locally lit petal/leaf surface. This is authored 2.5D artwork, not a mesh or +// a measured plant. Only the optional normal lighting comes from bound depth. +func (b *realFXBloom366) ellipse366(h *hxBase, cx, cy, rx, ry, a float64, c rgb, leaf bool) { + ca, sa := math.Cos(a), math.Sin(a) + rad := math.Max(rx, ry) + if rad < .5 { + return + } + for y := maxi(0, int(cy-rad-1)); y <= mini(h.sh-1, int(cy+rad+1)); y++ { + for x := maxi(0, int(cx-rad-1)); x <= mini(h.sw-1, int(cx+rad+1)); x++ { + i := y*b.w + x + if !b.allowed[i] { + continue + } + dx, dy := float64(x)+.5-cx, float64(y)+.5-cy + u, v := (dx*ca+dy*sa)/rx, (-dx*sa+dy*ca)/ry + r2 := u*u + v*v + if r2 >= 1 { + continue + } + z := math.Sqrt(1 - r2) + shade := float32(.25 + .68*math.Max(0, .75*z-.38*u-.3*v)) + if leaf { + shade *= float32(.65 + .35*math.Abs(math.Sin(u*18+v*7))) + if math.Abs(v) < .075 { + shade *= 1.5 + } + } else { + shade *= float32(.85 + .15*math.Cos(math.Atan2(v, u)*14)) + } + alpha := float32(math.Min(1, (1-r2)*8)) + o := i * 3 + h.hdr[o] = h.hdr[o]*(1-alpha) + c.r*shade*alpha + h.hdr[o+1] = h.hdr[o+1]*(1-alpha) + c.g*shade*alpha + h.hdr[o+2] = h.hdr[o+2]*(1-alpha) + c.b*shade*alpha + } + } +} + +func cloneRealFXRings366(rs []MaskRing) []MaskRing { + out := make([]MaskRing, len(rs)) + for i, r := range rs { + out[i].Outer = append([][2]float64(nil), r.Outer...) + for _, hole := range r.Holes { + out[i].Holes = append(out[i].Holes, append([][2]float64(nil), hole...)) + } + } + return out +} +func realFXGeometrySig366(plans []*plan) uint64 { + h := uint64(14695981039346656037) + for _, p := range plans { + if p == nil || p.s == nil { + continue + } + s := p.s + for _, x := range []byte(s.ID + s.Cls) { + h = (h ^ uint64(x)) * 1099511628211 + } + if s.visible() { + h ^= 1 + } + if realFXWall366(s) { + h ^= 2 + } + h = physPolySig(h, s.Poly) + h = physPolySig(h, s.Quad) + for _, r := range s.Rings { + h = physPolySig(h, r.Outer) + for _, hole := range r.Holes { + h = physPolySig(h, hole) + } + } + } + return h +} + +func realFXInBox366(b [4]float64, u, v float64) bool { + return u >= b[0] && v >= b[1] && u <= b[2] && v <= b[3] +} +func realFXBox366(o physOutline) [4]float64 { + b := [4]float64{1, 1, 0, 0} + add := func(ps [][2]float64) { + for _, p := range ps { + b[0] = math.Min(b[0], p[0]) + b[1] = math.Min(b[1], p[1]) + b[2] = math.Max(b[2], p[0]) + b[3] = math.Max(b[3], p[1]) + } + } + add(o.poly) + for _, r := range o.rings { + add(r.Outer) + } + return b +} +func realFXInputOK366(plans []*plan) bool { + if len(plans) > 64 { + return false + } + n := 0 + for _, p := range plans { + if p == nil || p.s == nil { + continue + } + s := p.s + ps := [][][2]float64{s.Poly, s.Quad} + for _, r := range s.Rings { + ps = append(ps, r.Outer) + ps = append(ps, r.Holes...) + } + for _, poly := range ps { + n += len(poly) + if len(poly) > 512 || n > 8192 { + return false + } + for _, q := range poly { + if math.IsNaN(q[0]+q[1]) || math.IsInf(q[0]+q[1], 0) || q[0] < 0 || q[0] > 1 || q[1] < 0 || q[1] > 1 { + return false + } + } + } + } + return true +} + +// The projectDepth gate validates authoring-photo and depth bytes. Live mode +// checks at most once per second; virtual exports check each frame. A failed +// check drops optional normals and rebuilds without inventing depth. +func (s *realFXStudioSim) prepareBloom366(r *Renderer, plans []*plan, now time.Time) { + if s.sel != 8 { + return + } + if !realFXInputOK366(plans) { + s.bloom366 = nil + return + } + sig := realFXGeometrySig366(plans) + b := s.bloom366 + rebuild := b == nil || b.head != plans[0] || b.sig != sig + var dm *depthMap + checked := now + if !rebuild && !r.exportVirtual && now.Sub(b.checked) < time.Second { + return + } + dm = r.projectDepth() + if !rebuild && dm == b.dm { + b.checked = now + return + } + s.bloom366 = newRealFXBloom366(plans, s.sw, s.sh, dm) + if s.bloom366 != nil { + s.bloom366.checked = checked + } +} diff --git a/realfx_bloom366_test.go b/realfx_bloom366_test.go new file mode 100644 index 0000000..2c3089c --- /dev/null +++ b/realfx_bloom366_test.go @@ -0,0 +1,311 @@ +package main + +import ( + "fmt" + "image" + "image/color" + "image/png" + "math" + "os" + "path/filepath" + "testing" + "time" +) + +func bloomProject366() *Project { + p := roomTestProject(320, 200) + wall := [][2]float64{{.03, .03}, {.97, .03}, {.97, .97}, {.03, .97}} + obstacle := [][2]float64{{.3, .35}, {.7, .35}, {.7, .8}, {.55, .8}, {.55, .55}, {.3, .55}} + p.Surfaces = []Surface{{ID: "wall", Cls: "wall", Poly: wall, Quad: wall}, {ID: "couch", Cls: "couch", Poly: obstacle, Quad: obstacle}} + return p +} +func bloomScene366(p *Project) Scene { + return Scene{ID: "bloom366", Assign: map[string]Assign{"wall": {Type: "fx", ID: "phys:realfx", Speed: 1, Phys: &PhysParams{Shared: true, HX: []float64{8}}}}} +} +func Test366GrowthRoutesAndNeutral(t *testing.T) { + p := bloomProject366() + plans := []*plan{{s: &p.Surfaces[0]}, {s: &p.Surfaces[1]}} + b := newRealFXBloom366(plans, 160, 100, nil) + if b == nil || len(b.anchors) == 0 { + t.Fatal("no wall seeds") + } + for i, d := range b.distance { + if d < 0 { + continue + } + for j, n := i, 0; j >= 0 && n <= len(b.parent); n++ { + if !b.allowed[j] { + t.Fatal("path crossed obstacle") + } + j = b.parent[j] + } + } + if b.contains(.4, .4) || !b.contains(.4, .7) { + t.Fatal("concave obstacle is bounding box") + } + p.Surfaces[1].Poly = nil + p.Surfaces[1].Quad = nil + c := newRealFXBloom366(plans, 160, 100, nil) + delta := 0 + for i := range b.distance { + if b.distance[i] != c.distance[i] { + delta++ + } + } + if delta < 10 { + t.Fatal("geometry did not change growth") + } + if x := newRealFXBloom366([]*plan{{s: &Surface{Cls: "couch", Poly: p.Surfaces[0].Poly}}}, 160, 100, nil); len(x.anchors) != 0 { + t.Fatal("invented wall") + } +} +func Test366ActualRendererMotionAndMasks(t *testing.T) { + p := bloomProject366() + sc := bloomScene366(p) + r := newRenderer(p, "") + r.directorIsolatedHub = &physHub{owner: r, eng: map[string]*physEngine{}} + dir := os.Getenv("PM366_PIXELS") + if dir != "" { + os.MkdirAll(dir, 0755) + } + changed, lit := 0, 0 + var prior []byte + maxStep := 300 + if os.Getenv("PM366_FULL_CYCLE") != "" { + maxStep = 660 + } + for step := 0; step <= maxStep; step++ { + f := newFrame(320, 200) + r.RenderScene(&sc, float64(step)/30, f, 1, time.Unix(100, 0).Add(time.Duration(step)*time.Second/30)) + if step%10 != 0 { + continue + } + for y := 0; y < 200; y++ { + for x := 0; x < 320; x++ { + i := (y*320 + x) * 4 + u, v := (float64(x)+.5)/320, (float64(y)+.5)/200 + energy := int(f.Pix[i]) + int(f.Pix[i+1]) + int(f.Pix[i+2]) + inside := modelOutlineContains(physOutline{poly: p.Surfaces[0].Poly}, u, v) && !modelOutlineContains(physOutline{poly: p.Surfaces[1].Poly}, u, v) + if !inside && energy > 0 { + t.Fatalf("mask leak %v %v %d", u, v, energy) + } + if energy > 0 { + lit++ + } + if prior != nil && f.Pix[i] != prior[i] { + changed++ + } + } + } + if dir != "" { + im := image.NewRGBA(image.Rect(0, 0, 320, 200)) + for i := 0; i < len(f.Pix); i += 4 { + im.SetRGBA((i/4)%320, (i/4)/320, color.RGBA{f.Pix[i+2], f.Pix[i+1], f.Pix[i], 255}) + } + name := filepath.Join(dir, time.Unix(int64(step), 0).UTC().Format("150405")+".png") + ff, e := os.Create(name) + if e != nil { + t.Fatal(e) + } + png.Encode(ff, im) + ff.Close() + } + prior = append(prior[:0], f.Pix...) + } + if changed < 100 || lit < 100 { + t.Fatal("too little moving artwork", changed, lit) + } + t.Log("changed", changed, "lit", lit) +} + +func Test366RingsSnapshotsAndNoSources(t *testing.T) { + p := bloomProject366() + w := &p.Surfaces[0] + w.Rings = []MaskRing{{Outer: w.Poly, Holes: [][][2]float64{{{.12, .2}, {.22, .2}, {.22, .4}, {.12, .4}}}}} + plans := []*plan{{s: w}, {s: &p.Surfaces[1]}} + b := newRealFXBloom366(plans, 160, 100, nil) + if b.contains(.17, .3) { + t.Fatal("ring hole filled") + } + sig := b.sig + w.Rings[0].Holes[0][0][0] = .4 + if b.contains(.17, .3) { + t.Fatal("snapshot mutated") + } + if sig == realFXGeometrySig366(plans) { + t.Fatal("hole edit not invalidated") + } + e := newPhysEngine(func() physKind { k, _ := physKindOf("phys:realfx"); return k }(), physCfg{seed: 42, hx: []float64{8}}, physBuildGrid(nil, [4]float64{0, 0, 1, 1}, 1.6, 160, false, nil, "", nil)) + s := e.sim.(*realFXStudioSim) + s.bloom366 = newRealFXBloom366(plans, s.sw, s.sh, nil) + s.live = hxLiveQ{} + s.step(e, .1) + if s.pulse != 0 || s.in.Level != 0 || s.in.Beat { + t.Fatal("invented input") + } + s.t = 0 + s.shade(e) + for i := 0; i < len(e.back); i += 4 { + if e.back[i]+e.back[i+1]+e.back[i+2] != 0 { + t.Fatal("black growth start lifted") + } + } + s.bloom366 = nil + for i := range e.back { + e.back[i] = 1 + } + s.shade(e) + for _, v := range e.back { + if v != 0 { + t.Fatal("missing walls fell back to video") + } + } +} + +func Test366LimitsDepthInvalidationAndCosts(t *testing.T) { + p := bloomProject366() + plans := []*plan{{s: &p.Surfaces[0]}, {s: &p.Surfaces[1]}} + bad := append([]*plan(nil), plans...) + if newRealFXBloom366(make([]*plan, 65), 160, 100, nil) != nil { + t.Fatal("unbounded outlines") + } + old := p.Surfaces[0].Poly + p.Surfaces[0].Poly = append([][2]float64(nil), old...) + p.Surfaces[0].Poly[0][0] = math.NaN() + if newRealFXBloom366(bad, 160, 100, nil) != nil { + t.Fatal("invalid polygon accepted") + } + p.Surfaces[0].Poly = old + g := physBuildGrid(nil, [4]float64{0, 0, 1, 1}, 1.6, 160, false, nil, "", nil) + k, _ := physKindOf("phys:realfx") + e := newPhysEngine(k, physCfg{hx: []float64{8}}, g) + s := e.sim.(*realFXStudioSim) + r := newRenderer(p, "") + dm := &depthMap{W: 2, H: 2, V: []float32{.2, .2, .2, .2}} + s.bloom366 = newRealFXBloom366(plans, s.sw, s.sh, dm) + s.bloom366.checked = time.Unix(0, 0) + s.prepareBloom366(r, plans, time.Unix(10, 0)) + if s.bloom366 == nil || s.bloom366.dm != nil { + t.Fatal("unbound depth remained cached") + } + first := s.bloom366 + p.Surfaces[1].Poly = append([][2]float64(nil), p.Surfaces[1].Poly...) + p.Surfaces[1].Poly[0][0] += .01 + s.prepareBloom366(r, plans, time.Unix(10, 0)) + if first == s.bloom366 { + t.Fatal("geometry edit did not rebuild immediately") + } + start := time.Now() + for n := 0; n < 5; n++ { + s.bloom366 = newRealFXBloom366(plans, s.sw, s.sh, nil) + } + t.Log("cache prepare mean", time.Since(start)/5, "field", s.sw, s.sh) + s.t = 8 + start = time.Now() + for n := 0; n < 10; n++ { + s.shade(e) + } + t.Log("shade mean", time.Since(start)/10) + for _, a := range s.bloom366.anchors { + if !s.bloom366.allowed[a] { + t.Fatal("bad anchor") + } + } +} + +func Test366RealBoundDepthFreshnessAndSpeed(t *testing.T) { + p := bloomProject366() + p.Scene.W, p.Scene.H = 16, 16 + d := t.TempDir() + photo, dp := filepath.Join(d, "source.png"), filepath.Join(d, "depth.png") + src := depthPNGFixture(t, photo, 100) + raw := depthPNGFixture(t, dp, 50) + p.Depth = &DepthRef{File: dp, SourceFile: photo, DataSHA256: depthSHA(raw), SourceSHA256: depthSHA(src), SourceW: 16, SourceH: 16, IW: 16, IH: 16} + p.Depth.AuthoringSHA256 = depthAuthoringSHA(p) + r := &Renderer{P: p} + plans := []*plan{{s: &p.Surfaces[0]}, {s: &p.Surfaces[1]}} + k, _ := physKindOf("phys:realfx") + g := physBuildGrid(nil, [4]float64{0, 0, 1, 1}, 1.6, 160, false, nil, "", nil) + e := newPhysEngine(k, physCfg{hx: []float64{8}}, g) + s := e.sim.(*realFXStudioSim) + s.prepareBloom366(r, plans, time.Unix(100, 0)) + if s.bloom366.dm == nil { + t.Fatal("bound depth not loaded") + } + depthPNGFixture(t, dp, 150) + s.prepareBloom366(r, plans, time.Unix(102, 0)) + if s.bloom366.dm != nil { + t.Fatal("changed depth bytes remained cached") + } + a, b := newPhysEngine(k, physCfg{hx: []float64{8}}, g), newPhysEngine(k, physCfg{hx: []float64{8}}, g) + a.exportMode, b.exportMode = true, true + a.advance(0, 1) + b.advance(0, 2) + for j := 1; j <= 100; j++ { + a.advance(float64(j)*.01, 1) + b.advance(float64(j)*.01, 2) + } + if math.Abs(b.sim.(*realFXStudioSim).t-2*a.sim.(*realFXStudioSim).t) > .04 { + t.Fatal("speed clock") + } +} +func Test366WorstOutlineCost(t *testing.T) { + p := bloomProject366() + plans := []*plan{{s: &p.Surfaces[0]}} + for j := 0; j < 63; j++ { + x, y := float64(j%9)*.1+.04, float64(j/9)*.12+.04 + plans = append(plans, &plan{s: &Surface{ID: fmt.Sprint(j), Cls: "object", Poly: [][2]float64{{x, y}, {x + .03, y}, {x + .03, y + .03}, {x, y + .03}}}}) + } + start := time.Now() + b := newRealFXBloom366(plans, 320, 200, nil) + if b == nil { + t.Fatal("bounded fixture rejected") + } + t.Log("64 outline cache", time.Since(start)) + start = time.Now() + for y := 0; y < 200; y++ { + for x := 0; x < 320; x++ { + b.contains((float64(x)+.5)/320, (float64(y)+.5)/200) + } + } + t.Log("64000 exact bounded samples", time.Since(start)) +} + +func Test366RendererSavedHoleAndGeometryChange(t *testing.T) { + p := bloomProject366() + wall := &p.Surfaces[0] + wall.Rings = []MaskRing{{Outer: wall.Poly, Holes: [][][2]float64{{{.08, .6}, {.2, .6}, {.2, .85}, {.08, .85}}}}} + sc := bloomScene366(p) + r := newRenderer(p, "") + r.directorIsolatedHub = &physHub{owner: r, eng: map[string]*physEngine{}} + var before []byte + for step := 0; step <= 250; step++ { + f := newFrame(320, 200) + r.RenderScene(&sc, float64(step)/30, f, 1, time.Unix(100, 0).Add(time.Duration(step)*time.Second/30)) + if step == 250 { + before = append([]byte(nil), f.Pix...) + } + } + for y := 121; y < 169; y++ { + for x := 27; x < 63; x++ { + i := (y*320 + x) * 4 + if before[i]+before[i+1]+before[i+2] != 0 { + t.Fatal("saved hole lit", x, y) + } + } + } + plans := []*plan{{s: &p.Surfaces[0]}, {s: &p.Surfaces[1]}} + var s *realFXStudioSim + for _, e := range r.directorIsolatedHub.eng { + s = e.sim.(*realFXStudioSim) + } + if s == nil { + t.Fatal("missing production engine") + } + old := s.bloom366 + wall.Rings = nil + s.prepareBloom366(r, plans, time.Unix(110, 0)) + if old == s.bloom366 || !s.bloom366.contains(.15, .7) { + t.Fatal("removed hole not reflected") + } +} diff --git a/roomfx_queue.go b/roomfx_queue.go index ff4d411..b1eafed 100644 --- a/roomfx_queue.go +++ b/roomfx_queue.go @@ -81,11 +81,11 @@ var roomFXQueue = []roomFXConcept{ LocalOnly: true, }, { - ID: "rq-09", Name: "Material-Matched Wall Bloom", Room: "Indoor / outdoor", - Targets: "Separate plaster, brick, wood, and trim faces with opening masks", - ContentCue: "Local material labels plus garden, moss, root, or floral scene tags", - Technique: "Textured 3D growth follows the detected material and wall edges, shading each face without covering trim or openings.", - Interaction: "Choose the wall and growth theme; unknown materials remain unfilled rather than guessed.", + ID: "rq-09", Name: "Mapped Wall Bloom (2.5D)", Room: "Indoor / outdoor", + Targets: "Saved wall / facade outlines; furniture and opening masks", + ContentCue: "Procedural layered flowers, leaves and routed stems", + Technique: "2.5D garden growth routes around authored obstacles. Optional photo-bound depth normals shade blooms, without material matching or measured 3D.", + Interaction: "Use Test or Add. Missing wall outlines stay black. Other 29 concepts keep their virtual-stage renderer.", LocalOnly: true, }, { diff --git a/roomfx_queue_ui_windows.go b/roomfx_queue_ui_windows.go index 551004b..218abd8 100644 --- a/roomfx_queue_ui_windows.go +++ b/roomfx_queue_ui_windows.go @@ -122,7 +122,8 @@ func (a *app) roomFXQueueStartPreview() { request:=make(chan int,1) if !enqueue(func(){roomFXQueueUI.mu.Lock();valid:=roomFXQueueUI.previewGeneration==gen;roomFXQueueUI.mu.Unlock();if !valid||a.ctl!=ctl||U.page!=roomFXQueuePageIdx{request<- -1;return};selected,_:=roomFXQueueSnapshot();request<-selected}){return} selected:=-1;select{case selected=<-request:case <-quit:return;case <-time.After(time.Second):return};if selected<0{return} - frame:=roomFXRenderFrame(selected,320,180,time.Since(start).Seconds()) + var frame *Frame + if selected!=8{frame=roomFXRenderFrame(selected,320,180,time.Since(start).Seconds())} ack:=make(chan bool,1) if !enqueue(func(){roomFXQueueUI.mu.Lock();valid:=roomFXQueueUI.previewGeneration==gen;roomFXQueueUI.mu.Unlock();if !valid||a.ctl!=ctl||U.page!=roomFXQueuePageIdx{ack<-false;return};current,_:=roomFXQueueSnapshot();if current==selected{roomFXQueueUI.mu.Lock();roomFXQueueUI.preview=frame;roomFXQueueUI.previewIndex=selected;roomFXQueueUI.mu.Unlock();a.relayout(ctl);pInvalidateRect.Call(ctl,0,0)};ack<-true}){return} select{case ok:=<-ack:if !ok{return};case <-quit:return;case <-time.After(time.Second):return} @@ -145,10 +146,10 @@ func (a *app) roomFXQueueLayout(add func(widget) int, rx, rw, y, bh, pad int) { button := func(id int, text string, l, top, r, bottom, style int, enabled bool) { add(widget{kind: kBtn, id: id, text: text, l: l, t: top, r: r, b: bottom, style: style, enabled: enabled}) } - add(widget{kind: kCard, text: "RealFX Studio · 30 animated mesh prototypes", l: rx, t: y, r: rx + rw, b: y + sc(40)}) - label("Local virtual-stage previews only. They do not change scenes, calibration, or projector output.", rx+sc(16), y+sc(44), rx+rw-sc(16)) - label("Room-map fit and the high-quality asset/still/motion review gate are still pending; none is production-playable.", rx+sc(16), y+sc(64), rx+rw-sc(16)) - controlY := y + sc(88) + add(widget{kind: kCard, text: "RealFX Studio · Wall Bloom + 29 mesh prototypes", l: rx, t: y, r: rx + rw, b: y + sc(40)}) + noteY:=y+sc(44) + for _,note:=range []string{"Wall Bloom: Test uses saved wall outlines. Other thumbnails are virtual-stage prototypes.","Test / Add affect projector output. No calibration changes. Experimental; hardware quality unverified."}{for _,line:=range roomFXQueueWrap(note,maxi(20,(rw-sc(32))/sc(8))){label(line,rx+sc(16),noteY,rx+rw-sc(16));noteY+=sc(19)}} + controlY:=noteY+sc(8) half := (rw - 2*sc(16) - sc(8)) / 2 prevText := "< Previous page" if page == 0 { @@ -171,7 +172,7 @@ func (a *app) roomFXQueueLayout(add func(widget) int, rx, rw, y, bh, pad int) { leftW = rw / 2 } detailLines := []string{"Room: " + idea.Room, "Mapped targets: " + idea.Targets, "Content cue: " + idea.ContentCue, "Technique: " + idea.Technique, "Interaction: " + idea.Interaction} - wrapCount := maxi(36, (leftW-sc(32))/sc(8)) + wrapCount := maxi(18, (leftW-sc(32))/sc(8)) var wrapped []string for _, text := range detailLines { wrapped = append(wrapped, roomFXQueueWrap(text, wrapCount)...) @@ -187,7 +188,8 @@ func (a *app) roomFXQueueLayout(add func(widget) int, rx, rw, y, bh, pad int) { if previewH < detailH { previewH = detailH } - add(widget{kind: kCard, text: "3D preview · local only, 8-second runs", l: previewX, t: detailY, r: rx + rw, b: detailY + previewH}) + previewTitle:="3D stage preview - 8-second runs";if selected==8{previewTitle="Mapped Wall Bloom - use Test"} + add(widget{kind: kCard, text: previewTitle, l: previewX, t: detailY, r: rx + rw, b: detailY + previewH}) roomFXQueueUI.mu.Lock() preview := roomFXQueueUI.preview if roomFXQueueUI.previewIndex!=selected{preview=nil} @@ -195,7 +197,9 @@ func (a *app) roomFXQueueLayout(add func(widget) int, rx, rw, y, bh, pad int) { if preview != nil { add(widget{kind: kThumb, img: preview, l: previewX + sc(12), t: detailY + sc(38), r: rx + rw - sc(12), b: detailY + sc(38) + int(float64(previewW-sc(24))*9/16)}) } - label("Triangle mesh + PBR material preview; no room-fit claim.", previewX+sc(12), detailY+previewH-sc(22), rx+rw-sc(12)) + previewNote:="Triangle mesh stage preview. No room-fit claim.";if selected==8{previewNote="Use Test for your saved walls. No wall outlines means black. 2.5D artwork, not measured plants."} + notes:=roomFXQueueWrap(previewNote,maxi(15,(previewW-sc(24))/sc(8))) + for i,line:=range notes{label(line,previewX+sc(12),detailY+previewH-sc(20*(len(notes)-i)),rx+rw-sc(12))} listY := detailY + previewH + sc(8) listH := sc(162) add(widget{kind: kCard, text: fmt.Sprintf("Ordered prototypes · page %d of %d", page+1, pages), l: rx, t: listY, r: rx + rw, b: listY + listH}) @@ -228,7 +232,7 @@ func (a *app) roomFXQueueLayout(add func(widget) int, rx, rw, y, bh, pad int) { return len(ideas) > 0 }, }, rx, rw, gateY, bh, sc(8)) - label("Promotion gate: individually reviewed mesh assets, still + motion proof, A/A+ virtual-window grades, and verified fit to the mapped room.", rx+sc(16), gateY, rx+rw-sc(16)) + for _,line:=range roomFXQueueWrap("Experimental. Motion and room fit need review. Other prototypes are not measured-room qualified.",maxi(20,(rw-sc(32))/sc(8))){label(line,rx+sc(16),gateY,rx+rw-sc(16));gateY+=sc(19)} } func roomFXQueueAssignNow() Assign { diff --git a/roomfx_renderer.go b/roomfx_renderer.go index 103f022..f31603e 100644 --- a/roomfx_renderer.go +++ b/roomfx_renderer.go @@ -650,6 +650,7 @@ func roomFXApplyBloom(f *Frame) { } type realFXStudioSim struct { + bloom366 *realFXBloom366 ofxBase sel int } @@ -678,6 +679,7 @@ func (s *realFXStudioSim) step(e *physEngine, dt float64) { } func (s *realFXStudioSim) shade(e *physEngine) { + if s.sel==8 { if !s.bloomShade366(e){clear(e.back)};return } s.content(e, false) w, h := s.sw, s.sh if w <= 0 || h <= 0 || len(s.hdr) < w*h*3 { @@ -708,7 +710,7 @@ func (s *realFXStudioSim) shade(e *physEngine) { func init() { physKinds = append(physKinds, physKind{ id: "phys:realfx", - name: "RealFX Studio (30 3D Mesh Prototypes)", + name: "RealFX Studio (Wall Bloom + 29 Prototypes)", tags: "realfx 3d mesh prototype studio", fill: 0, boxes: false,