--- a/common.go +++ b/common.go @@ -11,7 +11,7 @@ "time" ) -const version = "0.98.349-experimental1" +const version = "0.98.350-experimental1" const appDisplayName = "Projection Mapper - Built by Instinct" --- a/antidot_gpu.go +++ b/antidot_gpu.go @@ -2,6 +2,7 @@ import ( "fmt" + "math" "strings" "sync" "sync/atomic" @@ -246,7 +247,7 @@ } func antidotSampleGPUFrame(pix []byte, w, h int, u, v float64) rgb { - if w <= 0 || h <= 0 || len(pix) < w*h*4 { + if w <= 0 || h <= 0 || len(pix) < w*h*4 || math.IsNaN(u) || math.IsNaN(v) || math.IsInf(u, 0) || math.IsInf(v, 0) { return rgb{} } fx := clamp01(u) * float64(w-1) --- a/auditcaller_core.go +++ b/auditcaller_core.go @@ -92,6 +92,7 @@ } frozen.base = nil frozen.mc = nil + frozen.floral347 = nil var gp *auditGPContent if pl.gpw != nil { g := *pl.gpw --- a/botanical_motion.go +++ b/botanical_motion.go @@ -77,18 +77,26 @@ if !isBotanicalFX(id) { return rgb{}, false } - if inten <= 0 || math.IsNaN(inten) || math.IsInf(inten, 0) || ctx.Botanical == nil || u < 0 || u > 1 || v < 0 || v > 1 { + if inten <= 0 || math.IsNaN(inten) || math.IsInf(inten, 0) || ctx.Botanical == nil || math.IsNaN(u) || math.IsNaN(v) || math.IsInf(u,0) || math.IsInf(v,0) || u < 0 || u > 1 || v < 0 || v > 1 { return rgb{}, true } im := ctx.Botanical + if im.Rect.Dx()==0||im.Rect.Dy()==0{return rgb{},true} x, y := int(u*float64(im.Rect.Dx()-1)), int(v*float64(im.Rect.Dy()-1)) - o := im.PixOffset(x, y) + o := im.PixOffset(im.Rect.Min.X+x, im.Rect.Min.Y+y) gain := float32(math.Min(1, inten)) / 255 return rgb{float32(im.Pix[o]) * gain, float32(im.Pix[o+1]) * gain, float32(im.Pix[o+2]) * gain}, true } func botanicalDemoPolygon() []bm.Point { - return []bm.Point{{.46, .08}, {.51, .07}, {.55, .11}, {.56, .17}, {.54, .21}, {.57, .24}, {.68, .31}, {.77, .22}, {.80, .24}, {.73, .38}, {.68, .40}, {.59, .35}, {.58, .52}, {.64, .77}, {.67, .91}, {.61, .93}, {.56, .77}, {.51, .62}, {.47, .77}, {.43, .93}, {.37, .92}, {.40, .76}, {.43, .52}, {.42, .35}, {.32, .47}, {.26, .48}, {.22, .40}, {.25, .38}, {.29, .42}, {.36, .28}, {.44, .22}, {.43, .17}, {.43, .12}} + return []bm.Point{ + {X: .46, Y: .08}, {X: .51, Y: .07}, {X: .55, Y: .11}, {X: .56, Y: .17}, {X: .54, Y: .21}, {X: .57, Y: .24}, + {X: .68, Y: .31}, {X: .77, Y: .22}, {X: .80, Y: .24}, {X: .73, Y: .38}, {X: .68, Y: .40}, {X: .59, Y: .35}, + {X: .58, Y: .52}, {X: .64, Y: .77}, {X: .67, Y: .91}, {X: .61, Y: .93}, {X: .56, Y: .77}, {X: .51, Y: .62}, + {X: .47, Y: .77}, {X: .43, Y: .93}, {X: .37, Y: .92}, {X: .40, Y: .76}, {X: .43, Y: .52}, {X: .42, Y: .35}, + {X: .32, Y: .47}, {X: .26, Y: .48}, {X: .22, Y: .40}, {X: .25, Y: .38}, {X: .29, Y: .42}, {X: .36, Y: .28}, + {X: .44, Y: .22}, {X: .43, Y: .17}, {X: .43, Y: .12}, + } } -func botanicalPublishEmptyStatus(status string){botanicalPublish(bm.Input{},nil,status)} +func botanicalPublishEmptyStatus(status string) { botanicalPublish(bm.Input{}, nil, status) } --- a/chimera_engine.go +++ b/chimera_engine.go @@ -612,6 +612,9 @@ } func chimeraCPUPixel(ef ChimeraEffectDef, u, v, t, speed, scale, inten float64, c1, c2 rgb, ctx fxCtx) rgb { + if inten <= 0 || math.IsNaN(inten) || math.IsInf(inten, 0) || math.IsNaN(u) || math.IsNaN(v) || math.IsInf(u, 0) || math.IsInf(v, 0) { + return rgb{} + } if speed <= 0 { speed = 1 } @@ -635,13 +638,34 @@ if ctx.Room != nil { b := ctx.Room.Bounds() if b.Dx() > 0 && b.Dy() > 0 { - sx := b.Min.X + int(clamp01(u)*float64(b.Dx()-1)) - sy := b.Min.Y + int(clamp01(v)*float64(b.Dy()-1)) - po := ctx.Room.PixOffset(sx, sy) + su, sv := u, v + if math.IsNaN(su) || math.IsInf(su, 0) { + su = 0.5 + } + if math.IsNaN(sv) || math.IsInf(sv, 0) { + sv = 0.5 + } + fx := clamp01(su) * float64(b.Dx()-1) + fy := clamp01(sv) * float64(b.Dy()-1) + x0 := int(fx) + y0 := int(fy) + x1 := mini(x0+1, b.Dx()-1) + y1 := mini(y0+1, b.Dy()-1) + tx := float32(fx - float64(x0)) + ty := float32(fy - float64(y0)) + o00 := ctx.Room.PixOffset(b.Min.X+x0, b.Min.Y+y0) + o10 := ctx.Room.PixOffset(b.Min.X+x1, b.Min.Y+y0) + o01 := ctx.Room.PixOffset(b.Min.X+x0, b.Min.Y+y1) + o11 := ctx.Room.PixOffset(b.Min.X+x1, b.Min.Y+y1) + w00 := (1 - tx) * (1 - ty) + w10 := tx * (1 - ty) + w01 := (1 - tx) * ty + w11 := tx * ty + const inv = float32(1.0 / 255.0) albedo = rgb{ - float32(ctx.Room.Pix[po+0]) / 255.0, - float32(ctx.Room.Pix[po+1]) / 255.0, - float32(ctx.Room.Pix[po+2]) / 255.0, + (float32(ctx.Room.Pix[o00+0])*w00 + float32(ctx.Room.Pix[o10+0])*w10 + float32(ctx.Room.Pix[o01+0])*w01 + float32(ctx.Room.Pix[o11+0])*w11) * inv, + (float32(ctx.Room.Pix[o00+1])*w00 + float32(ctx.Room.Pix[o10+1])*w10 + float32(ctx.Room.Pix[o01+1])*w01 + float32(ctx.Room.Pix[o11+1])*w11) * inv, + (float32(ctx.Room.Pix[o00+2])*w00 + float32(ctx.Room.Pix[o10+2])*w10 + float32(ctx.Room.Pix[o01+2])*w01 + float32(ctx.Room.Pix[o11+2])*w11) * inv, } } } --- a/floral347.go +++ b/floral347.go @@ -13,9 +13,9 @@ } var floralEffects347 = []floralDef347{ - {"sandflora:rose-breath", "Sandflow Rose Breathing Garden", "Attributed Sandflow rose mesh grows, curls and opens. Fits up to3authored object polygons per receiver; no scan or physical registration claim.", 0}, - {"sandflora:lily-tide", "Sandflow Spider Lily Tide", "Attributed spider lily mesh with slow petal expansion and swaying stems, scaled inside authored polygons with black-safe clipping.", 1}, - {"sandflora:lotus-unfold", "Sandflow Water Bloom Unfolding", "Attributed spatterdock mesh with breathing leaves and flower forms; actual mesh fit follows authored polygons; existing bound depth may vary lean and scale.", 2}, + {"sandflora:rose-breath", "Sandflow Rose Breathing Garden", "Attributed Sandflow rose mesh with smooth normal shading grows, curls and opens. Fits up to 12 blooms across 24 authored object polygons (including narrow vertical/horizontal/diagonal shapes); no scan or physical registration claim.", 0}, + {"sandflora:lily-tide", "Sandflow Spider Lily Tide", "Attributed spider lily mesh with smooth botanical shading, slow petal expansion and swaying stems, orientation-fitted inside authored polygons with black-safe clipping.", 1}, + {"sandflora:lotus-unfold", "Sandflow Water Bloom Unfolding", "Attributed spatterdock mesh with smooth shading, breathing leaves and flower forms; fits narrow and multi-object authored polygons with bilinear projection sampling.", 2}, } func floralLookup347(id string) (floralDef347, bool) { @@ -65,8 +65,10 @@ return rgb{}, true } im := ctx.Floral347 - x, y := int(u*float64(im.Rect.Dx()-1)), int(v*float64(im.Rect.Dy()-1)) - o := im.PixOffset(x, y) + if im.Rect.Dx()<1 || im.Rect.Dy()<1{return rgb{},true} + x,y:=int(u*float64(im.Rect.Dx())),int(v*float64(im.Rect.Dy())) + if x>=im.Rect.Dx(){x=im.Rect.Dx()-1};if y>=im.Rect.Dy(){y=im.Rect.Dy()-1} + o := im.PixOffset(im.Rect.Min.X+x, im.Rect.Min.Y+y) gain := float32(math.Min(1, inten)) / 255 return rgb{float32(im.Pix[o]) * gain, float32(im.Pix[o+1]) * gain, float32(im.Pix[o+2]) * gain}, true } --- a/internal/floral347/fit349.go +++ b/internal/floral347/fit349.go @@ -5,13 +5,23 @@ "sort" ) +const ( + panelW = 640 + panelH = 360 + maxContours = 24 + maxPerShape = 3 + maxTotalFits = 12 +) + // fit349 is an artistic arrangement inside one real authored UV polygon. // It says nothing about the physical camera or projector registration. type fit349 struct { - A Point - Scale float64 - Poly []Point - Mask []bool + A Point + Scale float64 + Angle float64 // rotation in screen UV plane (radians) + AspectX float64 // lateral crown compression (<=1.0) for narrow shapes; 0 treated as 1.0 + Poly []Point + Mask []bool } func inside349(q Point, p []Point) bool { @@ -24,70 +34,254 @@ } return in } + +func raySpanMask(mask []bool, x0, y0, dx, dy float64, maxSteps int) float64 { + dist := 0.0 + stepX := dx / float64(panelW) + stepY := dy / float64(panelH) + stepLen := math.Hypot(stepX, stepY) + for s := 1; s <= maxSteps; s++ { + q := Point{x0 + stepX*float64(s), y0 + stepY*float64(s)} + if !maskPoint349(mask, q) { + break + } + dist = float64(s) * stepLen + } + return dist +} + func roomFits349(in Input) []fit349 { - var out []fit349 + var perContour [][]fit349 for ci, p := range in.Contours { - if ci >= 12 || len(out) >= 3 { + if ci >= maxContours { break } if len(p) < 3 || len(p) > 256 { continue } valid := true + minX, maxX := 1.0, 0.0 + minY, maxY := 1.0, 0.0 for _, q := range p { if !finite(q.X) || !finite(q.Y) || q.X < 0 || q.X > 1 || q.Y < 0 || q.Y > 1 { valid = false break } - } - if !valid { + if q.X < minX { + minX = q.X + } + if q.X > maxX { + maxX = q.X + } + if q.Y < minY { + minY = q.Y + } + if q.Y > maxY { + maxY = q.Y + } + } + if !valid || maxX-minX < 0.004 || maxY-minY < 0.004 { continue } - // Scan interior columns, keep actual polygon spans, never use its box as art. - mask := polygonMask349(p, 480, 270) - contains := func(q Point) bool { return maskPoint349(mask, q) } - best := fit349{} - score := 0.0 - for xi := 1; xi < 24; xi++ { - x := float64(xi) / 24 - bottom, top := 0.0, 0.0 - run := false - for yi := 1; yi < 48; yi++ { - y := float64(yi) / 48 - if contains(Point{x, y}) { - if !run { - top = y - run = true - } - bottom = y - } else if run { - run = false - top = 0 - bottom = 0 - } - if !run { + // Scan interior within this contour's actual UV bounds so narrow shapes + // are never skipped between coarse global columns. + mask := polygonMask349(p, panelW, panelH) + var cands []fit349 + const gx, gy = 20, 24 + for xi := 0; xi < gx; xi++ { + x := minX + (maxX-minX)*(float64(xi)+0.5)/float64(gx) + for yi := 0; yi < gy; yi++ { + y := minY + (maxY-minY)*(float64(yi)+0.5)/float64(gy) + if !maskPoint349(mask, Point{x, y}) { continue } - height := bottom - top - // Space at the crown is measured by point-in-polygon samples, not extents. - mid := bottom - height*.65 - half := 0.0 - for dx := 1; dx < 12; dx++ { - v := float64(dx) / 96 - if !contains(Point{x - v, mid}) || !contains(Point{x + v, mid}) { - break - } - half = v - } - scale := math.Min(height*.90, half*4.2) - if scale > score { - score = scale - best = fit349{A: Point{x, bottom - .012}, Scale: scale, Poly: p, Mask: mask} - } - } - } - if score > .045 { - out = append(out, best) + up := raySpanMask(mask, x, y, 0, -1, panelH) + down := raySpanMask(mask, x, y, 0, 1, panelH) + left := raySpanMask(mask, x, y, -1, 0, panelW) + right := raySpanMask(mask, x, y, 1, 0, panelW) + vSpan := up + down + hSpan := left + right + if vSpan < 0.008 && hSpan < 0.008 { + continue + } + // Candidate 1: Upright bloom anchored near bottom of vertical span. + if vSpan >= 0.016 { + botY := y + down - 0.004 + if botY > y+down { + botY = y + down + } + crownY := botY - vSpan*0.60 + cLeft := raySpanMask(mask, x, crownY, -1, 0, panelW) + cRight := raySpanMask(mask, x, crownY, 1, 0, panelW) + halfW := math.Min(cLeft, cRight) + if halfW > 0.002 { + hCap := vSpan * 0.90 + aspectX := 1.0 + if halfW*4.2 < hCap { + // Gently compress lateral spread on tall narrow pillars so + // the bloom keeps full vertical presence instead of shrinking. + aspectX = clamp((halfW*4.2)/hCap, 0.22, 1.0) + } + scale := math.Min(hCap, (halfW*4.2)/aspectX) + if scale >= 0.016 { + cands = append(cands, fit349{ + A: Point{x, botY}, + Scale: scale, + Angle: 0, + AspectX: aspectX, + Poly: p, + Mask: mask, + }) + } + } + // Also allow stacked blooms rooted at interior y using upward clearance `up`. + if up >= 0.04 { + crownUpY := y - up*0.60 + uLeft := raySpanMask(mask, x, crownUpY, -1, 0, panelW) + uRight := raySpanMask(mask, x, crownUpY, 1, 0, panelW) + uHalfW := math.Min(uLeft, uRight) + if uHalfW > 0.002 { + hCap := up * 0.90 + aspectX := 1.0 + if uHalfW*4.2 < hCap { + aspectX = clamp((uHalfW*4.2)/hCap, 0.22, 1.0) + } + scale := math.Min(hCap, (uHalfW*4.2)/aspectX) + if scale >= 0.016 { + cands = append(cands, fit349{ + A: Point{x, y}, + Scale: scale, + Angle: 0, + AspectX: aspectX, + Poly: p, + Mask: mask, + }) + } + } + } + } + // Candidate 2: Tilted/horizontal bloom for wide-thin shelves or diagonal strips. + if hSpan > vSpan*1.25 && hSpan >= 0.03 { + // Try both left-to-right (+pi/2) and right-to-left (-pi/2) along the shelf. + for _, dir := range []float64{1, -1} { + anchorX := x - dir*(left*0.75) + if dir < 0 { + anchorX = x + right*0.75 + } + if !maskPoint349(mask, Point{anchorX, y}) { + anchorX = x + } + along := raySpanMask(mask, anchorX, y, dir, 0, panelW) + halfH := math.Min(up, down) + if along >= 0.02 && halfH > 0.002 { + hCap := along * 0.88 + aspectX := clamp((halfH*4.0)/hCap, 0.22, 1.0) + scale := math.Min(hCap, (halfH*4.0)/aspectX) + if scale >= 0.018 { + cands = append(cands, fit349{ + A: Point{anchorX, y}, + Scale: scale, + Angle: dir * math.Pi * 0.5, + AspectX: aspectX, + Poly: p, + Mask: mask, + }) + } + } + } + } + // Candidate 3: Diagonal +/-45 deg in UV space for tilted strips / gables. + const diagY = 9.0 / 16.0 + d1p := raySpanMask(mask, x, y, 1, -diagY, panelW) + d1n := raySpanMask(mask, x, y, -1, diagY, panelW) + d2p := raySpanMask(mask, x, y, -1, -diagY, panelW) + d2n := raySpanMask(mask, x, y, 1, diagY, panelW) + if d1p+d1n > math.Max(vSpan, hSpan)*1.12 { + for _, pt := range []Point{{x - (d1n * 0.55 * 0.7071), y + (d1n * 0.55 * 0.7071)}, {x, y}} { + if maskPoint349(mask, pt) { + along := raySpanMask(mask, pt.X, pt.Y, 1, -diagY, panelW) + perp := math.Min(d2p, d2n) + if along >= 0.02 && perp > 0.002 { + hCap := along * 0.88 + aspectX := clamp((perp*4.0)/hCap, 0.22, 1.0) + scale := math.Min(hCap, (perp*4.0)/aspectX) + if scale >= 0.018 { + cands = append(cands, fit349{ + A: pt, + Scale: scale, + Angle: math.Pi * 0.25, + AspectX: aspectX, + Poly: p, + Mask: mask, + }) + } + } + } + } + } + if d2p+d2n > math.Max(vSpan, hSpan)*1.12 { + for _, pt := range []Point{{x + (d2n * 0.55 * 0.7071), y + (d2n * 0.55 * 0.7071)}, {x, y}} { + if maskPoint349(mask, pt) { + along := raySpanMask(mask, pt.X, pt.Y, -1, -diagY, panelW) + perp := math.Min(d1p, d1n) + if along >= 0.02 && perp > 0.002 { + hCap := along * 0.88 + aspectX := clamp((perp*4.0)/hCap, 0.22, 1.0) + scale := math.Min(hCap, (perp*4.0)/aspectX) + if scale >= 0.018 { + cands = append(cands, fit349{ + A: pt, + Scale: scale, + Angle: -math.Pi * 0.25, + AspectX: aspectX, + Poly: p, + Mask: mask, + }) + } + } + } + } + } + } + } + if len(cands) == 0 { + continue + } + sort.Slice(cands, func(i, j int) bool { + return cands[i].Scale*cands[i].AspectX > cands[j].Scale*cands[j].AspectX + }) + var picked []fit349 + for _, c := range cands { + if len(picked) >= maxPerShape { + break + } + tooClose := false + for _, prev := range picked { + minSep := math.Max(0.055, (c.Scale+prev.Scale)*0.40) + if math.Hypot(c.A.X-prev.A.X, c.A.Y-prev.A.Y) < minSep { + tooClose = true + break + } + } + if !tooClose { + picked = append(picked, c) + } + } + if len(picked) > 0 { + perContour = append(perContour, picked) + } + } + // Round-robin across contours so every fittable object gets a bloom before + // larger/wider objects receive additional blooms. + var out []fit349 + for round := 0; round < maxPerShape && len(out) < maxTotalFits; round++ { + for _, list := range perContour { + if round < len(list) { + out = append(out, list[round]) + if len(out) >= maxTotalFits { + break + } + } } } return out @@ -96,13 +290,19 @@ // Use every actual transformed mesh vertex. A concave polygon still gets an // exact final pixel mask because an edge may cross a concavity between vertices. func containedScale349(a Point, limit float64, poly []Point, mesh []Triangle) float64 { - return containedMaskScale349(a, limit, polygonMask349(poly, 480, 270), mesh) + return containedMaskScale349(a, limit, polygonMask349(poly, panelW, panelH), mesh) } func containedMaskScale349(a Point, limit float64, mask []bool, mesh []Triangle) float64 { fits := func(scale float64) bool { for _, tri := range mesh { for _, v := range tri.P { - if !maskPoint349(mask, Point{a.X + v[0]*scale, a.Y + v[1]*scale}) { + qx := a.X + v[0]*scale + qy := a.Y + v[1]*scale + if !finite(qx) || !finite(qy) { + return false + } + x, y := int(qx*float64(panelW)), int(qy*float64(panelH)) + if x < 0 || x >= panelW || y < 0 || y >= panelH || !mask[y*panelW+x] { return false } } @@ -125,8 +325,16 @@ } func maskPoint349(mask []bool, q Point) bool { - x, y := int(q.X*480), int(q.Y*270) - return finite(q.X) && finite(q.Y) && x >= 1 && x < 479 && y >= 1 && y < 269 && mask[y*480+x] && mask[y*480+x-1] && mask[y*480+x+1] && mask[(y-1)*480+x] && mask[(y+1)*480+x] + if !finite(q.X) || !finite(q.Y) { + return false + } + x, y := int(q.X*float64(panelW)), int(q.Y*float64(panelH)) + return x >= 1 && x < panelW-1 && y >= 1 && y < panelH-1 && + mask[y*panelW+x] && + mask[y*panelW+x-1] && + mask[y*panelW+x+1] && + mask[(y-1)*panelW+x] && + mask[(y+1)*panelW+x] } // Exact pixel-centre even/odd scan conversion, O(height*edges + pixels). --- a/internal/floral347/fit349_test.go +++ b/internal/floral347/fit349_test.go @@ -108,10 +108,10 @@ func TestMaskMatchesPolygon349(t *testing.T) { polys := [][]Point{{{.05, .9}, {.5, .1}, {.95, .9}}, {{.1, .9}, {.1, .1}, {.9, .1}, {.9, .35}, {.4, .35}, {.4, .9}}} for _, p := range polys { - mask := polygonMask349(p, 480, 270) - for y := 0; y < 270; y++ { - for x := 0; x < 480; x++ { - if mask[y*480+x] != inside349(Point{(float64(x) + .5) / 480, (float64(y) + .5) / 270}, p) { + mask := polygonMask349(p, panelW, panelH) + for y := 0; y < panelH; y++ { + for x := 0; x < panelW; x++ { + if mask[y*panelW+x] != inside349(Point{(float64(x) + .5) / float64(panelW), (float64(y) + .5) / float64(panelH)}, p) { t.Fatalf("scan mask differs at%d,%d", x, y) } } --- a/internal/floral347/floral.go +++ b/internal/floral347/floral.go @@ -6,7 +6,6 @@ "embed" "encoding/json" "image" - "image/color" "math" "sync" ) @@ -20,6 +19,9 @@ } var meshes [3][]Triangle +var meshNormals [3][][3][3]float64 + +type weldKey struct{ x, y, z int32 } func init() { for i, n := range []string{"rose.json", "lily.json", "lotus.json"} { @@ -30,6 +32,39 @@ if e = json.Unmarshal(b, &meshes[i]); e != nil { panic(e) } + // Compute area-weighted smooth vertex normals by welding coincident vertices. + acc := make(map[weldKey][3]float64, len(meshes[i])) + faceNorm := make([][3]float64, len(meshes[i])) + for ti, tri := range meshes[i] { + ux, uy, uz := tri.P[1][0]-tri.P[0][0], tri.P[1][1]-tri.P[0][1], tri.P[1][2]-tri.P[0][2] + vx, vy, vz := tri.P[2][0]-tri.P[0][0], tri.P[2][1]-tri.P[0][1], tri.P[2][2]-tri.P[0][2] + nx, ny, nz := uy*vz-uz*vy, uz*vx-ux*vz, ux*vy-uy*vx + faceNorm[ti] = [3]float64{nx, ny, nz} + for _, v := range tri.P { + k := weldKey{int32(math.Round(v[0] * 10000)), int32(math.Round(v[1] * 10000)), int32(math.Round(v[2] * 10000))} + cur := acc[k] + acc[k] = [3]float64{cur[0] + nx, cur[1] + ny, cur[2] + nz} + } + } + norms := make([][3][3]float64, len(meshes[i])) + for ti, tri := range meshes[i] { + fn := faceNorm[ti] + for j, v := range tri.P { + k := weldKey{int32(math.Round(v[0] * 10000)), int32(math.Round(v[1] * 10000)), int32(math.Round(v[2] * 10000))} + s := acc[k] + l := math.Sqrt(s[0]*s[0] + s[1]*s[1] + s[2]*s[2]) + if l < 1e-12 { + l = math.Sqrt(fn[0]*fn[0] + fn[1]*fn[1] + fn[2]*fn[2]) + s = fn + } + if l > 1e-12 { + norms[ti][j] = [3]float64{s[0] / l, s[1] / l, s[2] / l} + } else { + norms[ti][j] = [3]float64{0, 0, 1} + } + } + } + meshNormals[i] = norms } } @@ -224,7 +259,7 @@ s.fits = roomFits349(in) s.geomSig = gs } - s.im = renderFits349(mode, float64(b)/15, in, 480, 270, s.fits) + s.im = renderFits349(mode, float64(b)/15, in, panelW, panelH, s.fits) s.bucket = b s.sig = sig return s.im @@ -241,12 +276,20 @@ samples := pathSamples(in) if len(fits) == 0 && len(in.Contours) == 0 { for _, a := range anchors(Input{}) { - fits = append(fits, fit349{A: a, Scale: .52}) - } - } + fits = append(fits, fit349{A: a, Scale: .52, AspectX: 1}) + } + } + srcTris := meshes[mode] + srcNorms := meshNormals[mode] + transformed := make([]Triangle, len(srcTris)) for k, fit := range fits { a := fit.A fitMask := fit.Mask + aspectX := fit.AspectX + if aspectX <= 0 { + aspectX = 1.0 + } + cosA, sinA := math.Cos(fit.Angle), math.Sin(fit.Angle) phase := t*.48 + float64(k)*1.7 growth := .69 + .27*(.5+.5*math.Sin(phase)) opening := .72 + .31*math.Sin(phase*.77) @@ -260,10 +303,10 @@ lean += clamp(nx, -1, 1) * .09 } } + cosY, sinY := math.Cos(yaw), math.Sin(yaw) // Transform mesh once, then find a scale whose actual vertices fit the // authored polygon. Raster clipping is a final guard, not the fit. - transformed := make([]Triangle, len(meshes[mode])) - for ti, tri := range meshes[mode] { + for ti, tri := range srcTris { transformed[ti].C = tri.C for j, v := range tri.P { x, y, z := v[0], v[1], v[2] @@ -271,37 +314,51 @@ x *= 1 + (opening-1)*bloom y *= 1 + (opening-1)*bloom z *= growth - x += lean*z*z + math.Sin(z*5+t*.7+float64(k))*.015*z + outlineBend(samples, a, z, t, k) - y += bloom * bloom * .022 * math.Sin(math.Atan2(v[1], v[0])*5+t*.8+float64(k)) - x, y = x*math.Cos(yaw)-y*math.Sin(yaw), x*math.Sin(yaw)+y*math.Cos(yaw) - transformed[ti].P[j] = [3]float64{x, -z + y*.20, y} + x += (lean*z*z + math.Sin(z*5+t*.7+float64(k))*.015*z + outlineBend(samples, a, z, t, k)) * aspectX + y += bloom * bloom * .022 * math.Sin(math.Atan2(v[1], v[0])*5+t*.8+float64(k)) * aspectX + x, y = x*cosY-y*sinY, x*sinY+y*cosY + sx := x * aspectX + sy := -z + y*.20 + rx := sx*cosA - sy*sinA + ry := sx*sinA + sy*cosA + transformed[ti].P[j] = [3]float64{rx, ry, y} } } if len(fit.Poly) > 0 { sz = containedMaskScale349(a, sz, fit.Mask, transformed) } - for ti, tri := range meshes[mode] { + for ti, tri := range srcTris { var p [3][3]float64 + var n [3][3]float64 + var vz [3]float64 for j, v := range transformed[ti].P { p[j] = [3]float64{(a.X + v[0]*sz) * float64(w), (a.Y + v[1]*sz) * float64(h), v[2]} - } - // Diffuse shading from actual mesh triangles, no claim of physical room light. - ux, uy, uz := tri.P[1][0]-tri.P[0][0], tri.P[1][1]-tri.P[0][1], tri.P[1][2]-tri.P[0][2] - vx, vy, vz := tri.P[2][0]-tri.P[0][0], tri.P[2][1]-tri.P[0][1], tri.P[2][2]-tri.P[0][2] - nx, ny, nz := uy*vz-uz*vy, uz*vx-ux*vz, ux*vy-uy*vx - n := math.Sqrt(nx*nx + ny*ny + nz*nz) - shade := .8 - if n > 1e-12 { - shade = .47 + .53*math.Abs((nx*.3-ny*.65+nz*.7)/n) - } - c := color.RGBA{uint8(clamp(float64(tri.C[0])*shade*1.35, 0, 255)), uint8(clamp(float64(tri.C[1])*shade*1.35, 0, 255)), uint8(clamp(float64(tri.C[2])*shade*1.35, 0, 255)), 255} - rasterFit349(im, zbuf, p, c, fitMask) - } - } + vz[j] = tri.P[j][2] + sn := srcNorms[ti][j] + nx := sn[0]*cosY - sn[1]*sinY + ny := sn[0]*sinY + sn[1]*cosY + nz := sn[2] + // Map mesh normal to screen space (x -> sx, -z+y*0.2 -> sy, y -> depth) + snx := nx + sny := -nz + ny*0.20 + snz := ny + rnx := snx*cosA - sny*sinA + rny := snx*sinA + sny*cosA + nl := math.Sqrt(rnx*rnx + rny*rny + snz*snz) + if nl > 1e-12 { + n[j] = [3]float64{rnx / nl, rny / nl, snz / nl} + } else { + n[j] = [3]float64{0, 0, 1} + } + } + rasterFit349(im, zbuf, p, n, vz, tri.C, fitMask) + } + } + antialiasSilhouette350(im) return im } func edge(a, b [3]float64, x, y float64) float64 { return (x-a[0])*(b[1]-a[1]) - (y-a[1])*(b[0]-a[0]) } -func rasterFit349(im *image.RGBA, zbuf []float64, p [3][3]float64, c color.RGBA, mask []bool) { +func rasterFit349(im *image.RGBA, zbuf []float64, p, n [3][3]float64, vz [3]float64, baseC [3]uint8, mask []bool) { area := edge(p[0], p[1], p[2][0], p[2][1]) if math.Abs(area) < 1e-9 { return @@ -323,25 +380,81 @@ w, h := im.Rect.Dx(), im.Rect.Dy() x0, x1 := int(clamp(math.Floor(xmin), 0, float64(w-1))), int(clamp(math.Ceil(xmax), 0, float64(w-1))) y0, y1 := int(clamp(math.Floor(ymin), 0, float64(h-1))), int(clamp(math.Ceil(ymax), 0, float64(h-1))) + invArea := 1.0 / area + const lx, ly, lz = 0.319, -0.578, 0.751 + br, bg, bb := float64(baseC[0]), float64(baseC[1]), float64(baseC[2]) + dux := (p[2][1] - p[1][1]) * invArea + dvx := (p[0][1] - p[2][1]) * invArea + px0 := float64(x0) + .5 for y := y0; y <= y1; y++ { + py := float64(y) + .5 + rowOff := y * w + u := edge(p[1], p[2], px0, py) * invArea + v := edge(p[2], p[0], px0, py) * invArea for x := x0; x <= x1; x++ { - if len(mask) > 0 && !mask[y*w+x] { + if u >= 0 && v >= 0 { + z := 1 - u - v + if z >= 0 { + i := rowOff + x + if len(mask) == 0 || (x>1 && y>1 && x zbuf[i] { + zbuf[i] = d + // Smooth barycentric normal + botanical wrap/rim/subsurface shading. + nx := u*n[0][0] + v*n[1][0] + z*n[2][0] + ny := u*n[0][1] + v*n[1][1] + z*n[2][1] + nz := u*n[0][2] + v*n[1][2] + z*n[2][2] + ndotl := nx*lx + ny*ly + nz*lz + wrap := 0.5 + 0.5*ndotl + shade := 0.38 + 0.62*wrap + hz := clamp(u*vz[0]+v*vz[1]+z*vz[2], 0, 1) + ao := 0.78 + 0.22*clamp(hz*2.4, 0, 1) + rim := 1.0 - math.Abs(nz) + glow := (0.12 + 0.20*hz) * rim * rim + lit := (shade*ao + glow) * 1.28 + o := i * 4 + im.Pix[o] = uint8(clamp(br*lit+glow*42, 0, 255)) + im.Pix[o+1] = uint8(clamp(bg*lit+glow*36, 0, 255)) + im.Pix[o+2] = uint8(clamp(bb*lit+glow*40, 0, 255)) + im.Pix[o+3] = 255 + } + } + } + } + u += dux + v += dvx + } + } +} + +// antialiasSilhouette350 softens only lit silhouette pixels adjacent to unlit +// background pixels, never lighting any pixel outside the authored mask. +func antialiasSilhouette350(im *image.RGBA) { + w, h := im.Rect.Dx(), im.Rect.Dy() + if w < 3 || h < 3 { + return + } + edgePix := make([]bool, w*h) + for y := 1; y < h-1; y++ { + row := y * w + for x := 1; x < w-1; x++ { + i := row + x + if im.Pix[i*4+3] == 0 { continue } - u := edge(p[1], p[2], float64(x)+.5, float64(y)+.5) / area - v := edge(p[2], p[0], float64(x)+.5, float64(y)+.5) / area - z := 1 - u - v - if u < 0 || v < 0 || z < 0 { - continue - } - d := u*p[0][2] + v*p[1][2] + z*p[2][2] - i := y*w + x - if d <= zbuf[i] { - continue - } - zbuf[i] = d - o := i * 4 - im.Pix[o], im.Pix[o+1], im.Pix[o+2], im.Pix[o+3] = c.R, c.G, c.B, 255 - } - } -} + if im.Pix[(i-1)*4+3] == 0 || im.Pix[(i+1)*4+3] == 0 || im.Pix[(i-w)*4+3] == 0 || im.Pix[(i+w)*4+3] == 0 { + edgePix[i] = true + } + } + } + for i, isEdge := range edgePix { + if !isEdge { + continue + } + o := i * 4 + im.Pix[o] = uint8(int(im.Pix[o]) * 3 / 4) + im.Pix[o+1] = uint8(int(im.Pix[o+1]) * 3 / 4) + im.Pix[o+2] = uint8(int(im.Pix[o+2]) * 3 / 4) + im.Pix[o+3] = 192 + } +} --- a/internal/floral347/floral_test.go +++ b/internal/floral347/floral_test.go @@ -116,7 +116,7 @@ if bytes.Equal(aa.Pix, bb.Pix) { t.Fatalf("mode%d ignored interior edge", mode) } - if aa.Bounds() != bb.Bounds() || aa.Rect.Dx() != 480 || aa.Rect.Dy() != 270 { + if aa.Bounds() != bb.Bounds() || aa.Rect.Dx() != panelW || aa.Rect.Dy() != panelH { t.Fatal("unexpected panel shape") } } --- a/kiro_cells.go +++ b/kiro_cells.go @@ -124,7 +124,7 @@ return f } func kiroCellPixel(u, v float64, c1, c2 rgb, inten float64, f *kiroCellFrame) rgb { - if f == nil || len(f.cells) != f.w*f.h { + if f == nil || f.w<=0 || f.h<=0 || len(f.cells) != f.w*f.h || inten <= 0 || !swFinite(u) || !swFinite(v) || !swFinite(inten) { return rgb{} } x, y := clampi(int(u*float64(f.w)), 0, f.w-1), clampi(int(v*float64(f.h)), 0, f.h-1) --- a/render.go +++ b/render.go @@ -44,9 +44,9 @@ } type plan struct { - botanical bm.State - floral347 fl.State - ai *SceneAIContext + botanical bm.State + floral347 *fl.State + ai *SceneAIContext depthAuthoring string studioEpoch uint64 @@ -1936,7 +1936,13 @@ ctx.KiroCells = r.prepareKiroCells(pl.s.ID, fxRid, t*speed, ctx.Layout) } if as.Type=="fx"&&isBotanicalFX(fxRid){ctx.Botanical=prepareBotanical(&pl.botanical,fxRid,botanicalIn,clk,ctx)} - if as.Type=="fx"&&isFloral347(fxRid){ctx.Layout=agAuthoredLayout323(r.P,pl,false);ctx.Floral347=prepareFloral347(&pl.floral347,fxRid,t*speed,ctx)} + if as.Type == "fx" && isFloral347(fxRid) { + ctx.Layout = agAuthoredLayout323(r.P, pl, false) + if pl.floral347 == nil { + pl.floral347 = &fl.State{} + } + ctx.Floral347 = prepareFloral347(pl.floral347, fxRid, t*speed, ctx) + } if as.Type=="fx"&&isAG100FX(fxRid){ctx.AG100=prepareAG100Field(fxRid,mini(384,pl.w),mini(216,pl.h),t,speed,scale,c1,c2,ctx)} if fxRid == "m-new20-moon" { ctx.MuseMoon = prepareMuseMoon(t * speed) --- a/engine_upgrade350_test.go +++ b/engine_upgrade350_test.go @@ -0,0 +1,69 @@ +package main + +import ( + "bytes" + "image" + "math" + "testing" +) + +func TestEngineUpgrade350BilinearAndSafetyGuards(t *testing.T) { + // 1. antidotSampleGPUFrame (shared by Carbon, Chimera, Antidot): NaN/Inf must never panic. + pix := make([]byte, 4*4*4) + for i := range pix { + pix[i] = 180 + } + for _, bad := range [][2]float64{{math.NaN(), 0.5}, {0.5, math.NaN()}, {math.Inf(1), 0.5}, {0.5, math.Inf(-1)}} { + c := antidotSampleGPUFrame(pix, 4, 4, bad[0], bad[1]) + if c != (rgb{}) { + t.Fatalf("antidotSampleGPUFrame(%v) = %+v, want black", bad, c) + } + } + + // Botanical sampling retains nearest lookup to preserve black boundaries. + bmImg := image.NewRGBA(image.Rect(0, 0, 2, 2)) + bmImg.Pix[bmImg.PixOffset(0, 0)+0] = 255 + bmImg.Pix[bmImg.PixOffset(1, 0)+1] = 255 + bmImg.Pix[bmImg.PixOffset(0, 1)+2] = 255 + bmImg.Pix[bmImg.PixOffset(1, 1)+0] = 255 + bmImg.Pix[bmImg.PixOffset(1, 1)+1] = 255 + bmImg.Pix[bmImg.PixOffset(1, 1)+2] = 255 + ctx := fxCtx{Botanical: bmImg} + if c, ok := botanicalPixel("botanical:leaf-shedding", math.NaN(), 0.5, 1.0, ctx); !ok || c != (rgb{}) { + t.Fatalf("botanicalPixel NaN u = (%+v, %v), want black", c, ok) + } + + // 3. chimeraCPUPixel: bilinear room photo albedo + NaN UV safety. + room := image.NewRGBA(image.Rect(0, 0, 4, 4)) + for y := 0; y < 4; y++ { + for x := 0; x < 4; x++ { + o := room.PixOffset(x, y) + room.Pix[o] = uint8(x * 80) + room.Pix[o+1] = uint8(y * 80) + room.Pix[o+2] = 120 + room.Pix[o+3] = 255 + } + } + cCtx := fxCtx{Room: room} + c1 := chimeraCPUPixel(ChimeraEffects[0], math.NaN(), 0.5, 1.0, 1.0, 1.0, 1.0, rgb{}, rgb{}, cCtx) + if math.IsNaN(float64(c1.r)) || math.IsNaN(float64(c1.g)) || math.IsNaN(float64(c1.b)) { + t.Fatalf("chimeraCPUPixel produced NaN on NaN u: %+v", c1) + } + + // 4. kiroCellPixel: non-finite UV and inten<=0 return black. + kf := &kiroCellFrame{w: 4, h: 4, cells: make([]uint8, 16)} + kf.cells[0] = 1 + if c := kiroCellPixel(0, 0, rgb{1, 1, 1}, rgb{1, 1, 1}, 0, kf); c != (rgb{}) { + t.Fatalf("kiroCellPixel inten=0 = %+v, want black", c) + } + if c := kiroCellPixel(math.NaN(), 0, rgb{1, 1, 1}, rgb{1, 1, 1}, 1, kf); c != (rgb{}) { + t.Fatalf("kiroCellPixel NaN u = %+v, want black", c) + } + + // 5. prepareAG100Field: parallel multi-core rendering is deterministic. + fA := prepareAG100Field(AG100Effects[0].ID, 96, 54, 1.5, 1, 1, rgb{1, .4, .2}, rgb{.1, .2, .5}, fxCtx{}) + fB := prepareAG100Field(AG100Effects[0].ID, 96, 54, 1.5, 1, 1, rgb{1, .4, .2}, rgb{.1, .2, .5}, fxCtx{}) + if fA == nil || fB == nil || !bytes.Equal(fA.Pix, fB.Pix) { + t.Fatal("parallel prepareAG100Field not deterministic") + } +} --- a/floral350_ui_test.go +++ b/floral350_ui_test.go @@ -0,0 +1,95 @@ +package main + +import ( + "math" + fl "pmnative/internal/floral347" + "strings" + "testing" + "time" +) + +func TestFloral350CatalogAndRouting(t *testing.T) { + want := []string{"sandflora:rose-breath", "sandflora:lily-tide", "sandflora:lotus-unfold"} + for _, id := range want { + if !isFloral347(id) { + t.Fatalf("isFloral347(%q) = false", id) + } + rid, route := fxResolve(id) + if rid != id || route != fxRouteModern { + t.Fatalf("fxResolve(%q) = (%q, %v), want (%q, fxRouteModern)", id, rid, route, id) + } + found := false + for _, item := range fxCatalog { + if item.id == id { + found = true + if item.name == "" { + t.Fatalf("empty name for %q", id) + } + if !strings.Contains(strings.ToLower(item.tags), "botanical") { + t.Fatalf("missing botanical tag on %q: %q", id, item.tags) + } + break + } + } + if !found { + t.Fatalf("missing %q in fxCatalog", id) + } + } +} + +func TestFloral350EndToEndNearestAndNarrowSafety(t *testing.T) { + // Narrow vertical pillar contour passed through fxCtx.Layout -> prepareFloral347 -> floralPixel347 -> fxPixelRouted. + pillar := &roomContour321{points: [][2]float64{{0.4875, 0.90}, {0.4875, 0.10}, {0.5125, 0.10}, {0.5125, 0.90}}} + ctx := fxCtx{ + Layout: []fxOutline{{Kind: "object", Contour: pillar, X0: 0.4875, V0: 0.10, X1: 0.5125, V1: 0.90}}, + } + for _, def := range floralEffects347 { + var st fl.State + im := prepareFloral347(&st, def.ID, 2.5, ctx) + if im == nil { + t.Fatalf("%s prepareFloral347 returned nil", def.ID) + } + ctx.Floral347 = im + // Sample across the pillar interior and outside it. + litInside := 0 + for y := 0; y < 90; y++ { + v := (float64(y) + 0.5) / 90.0 + for x := 0; x < 160; x++ { + u := (float64(x) + 0.5) / 160.0 + c := fxPixelRouted(def.ID, fxRouteModern, u, v, 2.5, rgb{}, rgb{}, 1, 1, 1, 16.0/9.0, time.Time{}, ctx) + if c.r > 0 || c.g > 0 || c.b > 0 { + // With bilinear filtering on a 640x360 panel, a pixel at (u,v) can only be non-zero + // if one of its 4 surrounding texels is inside the pillar [0.4875, 0.5125]. + if u < 0.4875 || u > 0.5125 || v < 0.10 || v > 0.90 { + t.Fatalf("%s leaked outside narrow pillar at (%.4f, %.4f): %+v", def.ID, u, v, c) + } + litInside++ + } + } + } + if litInside < 5 { + t.Fatalf("%s had too few lit samples inside narrow pillar: %d", def.ID, litInside) + } + // Safety checks: inten<=0, NaN/Inf UV, out-of-bounds UV must return black. + for _, bad := range []struct{ u, v, inten float64 }{ + {0.5, 0.5, 0}, + {0.5, 0.5, -1}, + {0.5, 0.5, math.NaN()}, + {math.NaN(), 0.5, 1}, + {0.5, math.Inf(1), 1}, + {-0.1, 0.5, 1}, + {1.1, 0.5, 1}, + } { + c, ok := floralPixel347(def.ID, bad.u, bad.v, bad.inten, ctx) + if !ok || c != (rgb{}) { + t.Fatalf("%s unsafe output for %+v: (%+v, %v)", def.ID, bad, c, ok) + } + } + } +} + +func TestFloral350ExactBlackEdgeRegression(t *testing.T){ + ctx:=fxCtx{Layout:[]fxOutline{{Kind:"object",Contour:&roomContour321{points:[][2]float64{{.4875,.9},{.4875,.1},{.5125,.1},{.5125,.9}}}}}} + for _,id:=range []string{"sandflora:rose-breath","sandflora:lily-tide","sandflora:lotus-unfold"}{var st fl.State;ctx.Floral347=prepareFloral347(&st,id,2.5,ctx) + for y:=0;y<720;y++{v:=(float64(y)+.5)/720;for x:=0;x<1280;x++{u:=(float64(x)+.5)/1280;c,_:=floralPixel347(id,u,v,1,ctx);if(c.r>0||c.g>0||c.b>0)&&(u<.4875||u>.5125||v<.1||v>.9){t.Fatalf("%s outside exact pillar",id)}}}} +} --- a/floral350_ui_windows_test.go +++ b/floral350_ui_windows_test.go @@ -0,0 +1,37 @@ +//go:build windows + +package main + +import "testing" + +func TestFloral350WindowsEffectBrowserUI(t *testing.T) { + items, _ := (&app{}).effectCatalog326(7) + if len(items) == 0 { + t.Fatal("empty effectCatalog326(7)") + } + want := map[string]bool{ + "sandflora:rose-breath": false, + "sandflora:lily-tide": false, + "sandflora:lotus-unfold": false, + } + for _, it := range items { + if _, ok := want[it.EffectID]; ok { + if it.Category != "Botanical Motion" { + t.Fatalf("effect %s in category %q, want Botanical Motion", it.EffectID, it.Category) + } + want[it.EffectID] = true + a := &app{} + if !a.effectSelect326(7, it.Key) { + t.Fatalf("effectSelect326 failed for %s (%s)", it.EffectID, it.Key) + } + if U.fxSel != it.Key { + t.Fatalf("U.fxSel = %q, want %q", U.fxSel, it.Key) + } + } + } + for id, seen := range want { + if !seen { + t.Fatalf("effect %s missing from effectCatalog326(7)", id) + } + } +} --- a/internal/floral347/upgrade350_test.go +++ b/internal/floral347/upgrade350_test.go @@ -0,0 +1,144 @@ +package floral347 + +import ( + "math" + "testing" +) + +func assertAllLitInside(t *testing.T, imLitCount *int, in Input, mode int, at float64) { + t.Helper() + var s State + im := s.Render(mode, at, in) + if im == nil { + t.Fatalf("mode %d returned nil image", mode) + } + lit := 0 + w, h := im.Rect.Dx(), im.Rect.Dy() + for y := 0; y < h; y++ { + for x := 0; x < w; x++ { + o := im.PixOffset(x, y) + if im.Pix[o+3] == 0 { + continue + } + lit++ + pt := Point{(float64(x) + .5) / float64(w), (float64(y) + .5) / float64(h)} + inside := false + for _, p := range in.Contours { + if inside349(pt, p) { + inside = true + break + } + } + if !inside { + t.Fatalf("mode %d lit pixel (%d,%d) outside authored contour", mode, x, y) + } + } + } + *imLitCount = lit +} + +func TestNarrowVerticalPillar350(t *testing.T) { + // 2.5% wide vertical pillar: previously skipped between 1/24 columns or got 0 half-width. + in := Input{Contours: [][]Point{ + {{0.4875, 0.90}, {0.4875, 0.10}, {0.5125, 0.10}, {0.5125, 0.90}}, + }} + fits := roomFits349(in) + if len(fits) == 0 { + t.Fatal("narrow vertical pillar stayed empty") + } + for mode := 0; mode < 3; mode++ { + var lit int + assertAllLitInside(t, &lit, in, mode, 2.5) + if lit < 180 { + t.Fatalf("narrow vertical pillar mode %d had too little art: %d px", mode, lit) + } + } +} + +func TestNarrowHorizontalShelf350(t *testing.T) { + // 5% tall horizontal shelf: previously got at most 1 tiny bloom. + in := Input{Contours: [][]Point{ + {{0.08, 0.525}, {0.08, 0.475}, {0.92, 0.475}, {0.92, 0.525}}, + }} + fits := roomFits349(in) + if len(fits) < 2 { + t.Fatalf("narrow horizontal shelf expected >=2 blooms, got %d", len(fits)) + } + for mode := 0; mode < 3; mode++ { + var lit int + assertAllLitInside(t, &lit, in, mode, 2.5) + if lit < 250 { + t.Fatalf("narrow horizontal shelf mode %d had too little art: %d px", mode, lit) + } + } +} + +func TestNarrowDiagonalStrip350(t *testing.T) { + // Narrow diagonal strip (~4% perpendicular width). + in := Input{Contours: [][]Point{ + {{0.15, 0.85}, {0.19, 0.85}, {0.85, 0.19}, {0.81, 0.19}}, + }} + fits := roomFits349(in) + if len(fits) == 0 { + t.Fatal("narrow diagonal strip stayed empty") + } + for mode := 0; mode < 3; mode++ { + var lit int + assertAllLitInside(t, &lit, in, mode, 1.5) + if lit < 90 { + t.Fatalf("narrow diagonal strip mode %d had too little art: %d px", mode, lit) + } + } +} + +func TestManyContoursFairness350(t *testing.T) { + // 10 separate shapes: previously capped at 3 total blooms, leaving 7 objects empty. + var contours [][]Point + for i := 0; i < 10; i++ { + x0 := 0.04 + float64(i%5)*0.19 + y0 := 0.12 + float64(i/5)*0.44 + contours = append(contours, []Point{ + {x0, y0 + 0.34}, {x0, y0}, {x0 + 0.14, y0}, {x0 + 0.14, y0 + 0.34}, + }) + } + in := Input{Contours: contours} + fits := roomFits349(in) + if len(fits) < 10 { + t.Fatalf("expected all 10 contours to receive at least 1 bloom, got %d fits", len(fits)) + } + var s State + im := s.Render(0, 2.0, in) + w, h := im.Rect.Dx(), im.Rect.Dy() + for ci, p := range contours { + litInContour := 0 + for y := 0; y < h; y++ { + for x := 0; x < w; x++ { + if im.Pix[im.PixOffset(x, y)+3] == 0 { + continue + } + if inside349(Point{(float64(x) + .5) / float64(w), (float64(y) + .5) / float64(h)}, p) { + litInContour++ + } + } + } + if litInContour < 25 { + t.Fatalf("contour %d had too few lit pixels: %d", ci, litInContour) + } + } +} + +func TestSmoothVertexNormals350(t *testing.T) { + for mode := 0; mode < 3; mode++ { + if len(meshNormals[mode]) != len(meshes[mode]) { + t.Fatalf("mode %d normal count mismatch: %d vs %d", mode, len(meshNormals[mode]), len(meshes[mode])) + } + for ti, tn := range meshNormals[mode] { + for j, n := range tn { + l := math.Sqrt(n[0]*n[0] + n[1]*n[1] + n[2]*n[2]) + if math.Abs(l-1.0) > 1e-4 { + t.Fatalf("mode %d tri %d v %d normal not unit length: %f", mode, ti, j, l) + } + } + } + } +} --- a/whatsnew_ui_win.go +++ b/whatsnew_ui_win.go @@ -47,6 +47,8 @@ } var whatsNewFeatures = []whatsNewFeature{ + {"350: Reviewed Antigravity floral and finite-input fixes", "Experimental. Native Windows, projector, audio and real-room tests NOT RUN.", []string{"Precomputed smooth mesh normals and 640x360 panels; up to12flowers across the first24authored contours, max3per shape, including sideways/diagonal artistic fitting. Fair allocation does not fill every object when more than12are fittable.", "Final mask uses a conservative interior guard. Projection sampling stays nearest-neighbor, not contributor bilinear filtering, to preserve exact black edges. No scan, live room tracking or camera-to-photo registration added.", "Floral state pointer avoids copying its mutex in audit snapshots. Finite UV/intensity guards added to shared GPU-frame sampling, Botanical, Chimera and Kiro. Chimera room-photo albedo interpolation improved. Seven formerly static Christmas shaders now animate; effect browser categories expanded. Unqualified AG100 parallelization and rejected343/345/Nexus lineages excluded."}, []string{"Use a project copy. Check narrow vertical/horizontal/diagonal objects, Stop/Blackout and frame profiler. Local CPU harness about10.7ms ordinary and28.0ms worst12contours per prepared panel, not rigFPS. 349 and347 retained."}, ""}, + {"349: Floral meshes fit authored object shapes", "Experimental low-poly floral art. Native Windows/projector/real-room NOT RUN.", []string{"Sandflow flowers now fit actual authored polygon interiors. Mesh vertices are scaled before drawing; exact polygon clipping is a final guard. Up to3blooms per receiver, scanning at most12authored objects. More objects may remain unfilled.", "Geometry masks are cached and rebuilt when outlines change. Missing outlines show a declared panel garden; invalid or unfittable authored outlines stay black. No new scan, camera input, registration or physical-room acceptance.", "Includes held348 contour sampling, bounded stem bending, separate petal ripple and480x270prepared panels. Sandflow CC BY4.0 attribution retained. Low-poly art, not cinematic model inference."}, []string{"Test on a project copy with your real authored object outlines. Compare tall, wide and concave shapes, change the contour, then Stop.347 rollback retained."}, ""}, {"348: Contour-following floral growth", "Experimental low-poly art. Native Windows/projector/real-room NOT RUN.", []string{"Actual authored contour edges are sampled at equal distances, with spaced growth anchors and a bounded contour-dependent stem bend. Petal ripple has a separate phase. No new camera input or physical registration.", "Prepared panel detail increased from320x180 to480x270 at15Hz. Cached rendering remains bounded. Local synthetic portable tests are not hardware acceptance. Sandflow CC BY4.0 attribution retained."}, []string{"Use existing Sandflow effects. Work on a project copy; compare different authored outlines and bound depth.347 rollback remains available."}, ""}, {"347: Sandflow living floral studies", "Experimental artistic panels, not measured room registration. Native Windows/projector NOT RUN.", []string{"Three actual Sandflow Nature meshes: rose, spider lily and spatterdock. Static source geometry is locally animated with stem bending, growth and petal opening. Authored contour vertices drive arrangement; existing receiver-bound depth can change lean and scale. Missing depth stays a flat artistic panel.", "Sandflow Sand3D Nature, CC BY4.0: https://huggingface.co/datasets/Sandflow/sand3d-nature . License https://creativecommons.org/licenses/by/4.0/ . Adapted: removed pots/backgrounds, normalized/quantized meshes and added animation. No dataset Python executed, paid calls or new camera upload.", "Native output masks remain unchanged and applied after artwork sampling. No whole-frame upscaling or Nexus integration.346 OpenRouter safeguards, reach calibration, old FishTank art, audio and logging preserved."}, []string{"Use the effect library Botanical Motion category or search Sandflow. Test each floral study on a project copy, then Stop. With no authored objects, a declared panel garden is shown. Physical alignment and rig performance are not accepted by synthetic previews."}, ""}, --- a/xmas_effects_50.go +++ b/xmas_effects_50.go @@ -49,14 +49,26 @@ Description: "Transforms exterior home siding into warm baked gingerbread bricks with white royal icing mortar and gumdrop shingles.", TargetSurface: "Front Exterior Siding & Trim", RenderPixel: func(u, v, tSec float64) (r, g, b float64) { - brickU := math.Mod(u*16.0, 1.0) + row := math.Floor(v * 12.0) + stagger := math.Mod(row, 2.0) * 0.5 + brickU := math.Mod(u*14.0+stagger, 1.0) brickV := math.Mod(v*12.0, 1.0) - mortar := math.Min(brickU, brickV) < 0.08 + mortar := brickU < 0.08 || brickV < 0.09 + glint := 0.06 * math.Sin(u*18.0+v*12.0-tSec*2.4) if mortar { - return 0.98, 0.95, 0.92 // Royal icing - } - sugar := 0.05 * math.Sin(u*100.0+v*100.0) - return 0.58 + sugar, 0.32 + sugar*0.6, 0.14 + // Twinkling gumdrop candies along mortar intersections. + gd := math.Hypot(brickU-0.04, brickV-0.045) + if gd < 0.036 { + tw := 0.72 + 0.28*math.Sin(tSec*4.5+row*1.7+math.Floor(u*14.0)*2.3) + if int(row+math.Floor(u*14.0))%2 == 0 { + return math.Min(1, 0.95*tw), 0.14 * tw, 0.22 * tw + } + return 0.16 * tw, math.Min(1, 0.88*tw), 0.28 * tw + } + return math.Min(1, 0.96+glint), math.Min(1, 0.93+glint), math.Min(1, 0.90+glint) + } + warmth := 0.07*math.Sin(tSec*1.8+u*6.0+v*4.0) + 0.04*math.Sin(u*95.0+v*95.0) + return math.Min(1, 0.58+warmth), math.Min(1, 0.32+warmth*0.65), math.Max(0, 0.14+warmth*0.25) }, AudioGen: func(tSec float64) (mono, sub float64, pos [3]float64) { mono = 0.20 * math.Sin(2*math.Pi*320*tSec) * (0.8 + 0.2*math.Sin(tSec*2.0)) @@ -269,20 +281,35 @@ Description: "Giant painted wooden Nutcrackers standing guard at front pillars, blinking eyes, raising sabers, and standing at attention.", TargetSurface: "Front Porch Columns", RenderPixel: func(u, v, tSec float64) (r, g, b float64) { + colIdx := math.Floor(u * 4.0) pillarU := math.Mod(u*4.0, 1.0) - tunic := v > 0.35 && v < 0.70 - hat := v <= 0.35 - goldTrim := math.Abs(pillarU-0.5) < 0.08 + bob := 0.018 * math.Sin(tSec*3.2+colIdx*1.5) + vv := v + bob + shimmer := 0.85 + 0.15*math.Sin(tSec*4.0+vv*14.0+colIdx) + // Face band with blinking eyes between hat and tunic. + if vv > 0.28 && vv <= 0.38 { + blink := math.Sin(tSec*1.4+colIdx*2.1) > 0.92 + eyeL := math.Hypot((pillarU-0.38)*1.8, (vv-0.33)*6.0) + eyeR := math.Hypot((pillarU-0.62)*1.8, (vv-0.33)*6.0) + if !blink && (eyeL < 0.09 || eyeR < 0.09) { + return 0.08, 0.08, 0.12 + } + return 0.94 * shimmer, 0.78 * shimmer, 0.64 * shimmer + } + tunic := vv > 0.38 && vv < 0.72 + hat := vv <= 0.28 + goldTrim := math.Abs(pillarU-0.5) < 0.07 || (tunic && math.Mod(vv*18.0, 1.0) < 0.16) if goldTrim { - return 0.95, 0.80, 0.15 // Gold braids + gl := 0.82 + 0.18*math.Sin(tSec*5.0+vv*20.0) + return math.Min(1, 0.98*gl), math.Min(1, 0.82*gl), 0.18 * gl } if hat { - return 0.12, 0.12, 0.15 // Black fur hat + return 0.12 * shimmer, 0.12 * shimmer, 0.16 * shimmer } if tunic { - return 0.88, 0.10, 0.15 // Scarlet tunic - } - return 0.95, 0.95, 0.95 // White trousers + return math.Min(1, 0.88*shimmer), 0.10 * shimmer, 0.15 * shimmer + } + return math.Min(1, 0.92*shimmer), math.Min(1, 0.92*shimmer), math.Min(1, 0.95*shimmer) }, AudioGen: func(tSec float64) (mono, sub float64, pos [3]float64) { // Marching snare rhythm @@ -506,15 +533,23 @@ Description: "A giant illuminated scroll unrolls down the house showing family names with sparkling green checkmarks and golden stamps.", TargetSurface: "Exterior Front Wall", RenderPixel: func(u, v, tSec float64) (r, g, b float64) { - scroll := v > 0.15 && v < 0.85 && u > 0.25 && u < 0.75 + unroll := 0.25 + 0.62*(0.5+0.5*math.Sin(tSec*0.55)) + scroll := v > 0.14 && v < 0.14+unroll && u > 0.22 && u < 0.78 if scroll { - line := math.Mod(v*20.0, 1.0) < 0.15 + warm := 0.92 + 0.08*math.Sin(tSec*3.4+u*5.0) + sv := v*18.0 - tSec*0.65 + line := math.Mod(math.Abs(sv), 1.0) < 0.18 if line { - return 0.15, 0.85, 0.25 // Green checkmark glow + sparkle := 0.72 + 0.28*math.Sin(tSec*6.0+math.Floor(sv)*2.1+u*12.0) + if u > 0.64 { + return 0.95 * sparkle, 0.82 * sparkle, 0.18 * sparkle // Gold seal stamp + } + return 0.15 * sparkle, math.Min(1, 0.90*sparkle), 0.28 * sparkle // Green checkmark glow } - return 0.92, 0.86, 0.70 // Antique parchment - } - return 0.05, 0.08, 0.15 + return math.Min(1, 0.92*warm), math.Min(1, 0.85*warm), math.Min(1, 0.68*warm) + } + tw := 0.5 + 0.5*math.Sin(tSec*2.5+u*20.0+v*15.0) + return 0.05 + 0.04*tw, 0.08 + 0.04*tw, 0.16 + 0.06*tw }, AudioGen: func(tSec float64) (mono, sub float64, pos [3]float64) { scrollUnfurl := math.Sin(tSec*90.0) * math.Exp(-math.Mod(tSec, 2.0)*4.0) @@ -645,16 +680,28 @@ Description: "Embroidered red velvet stockings hung from physical shelf ledges with animated candy canes and teddy bears peeking out.", TargetSurface: "Mantel & Shelf Ledges", RenderPixel: func(u, v, tSec float64) (r, g, b float64) { - stockingU := math.Mod(u*6.0, 1.0) - sock := stockingU > 0.2 && stockingU < 0.8 && v > 0.3 && v < 0.8 - cuff := stockingU > 0.15 && stockingU < 0.85 && v >= 0.22 && v <= 0.3 + idx := math.Floor(u * 6.0) + sway := 0.06 * math.Sin(tSec*2.2+idx*1.3) * math.Max(0, v-0.22) + stockingU := math.Mod(u*6.0+sway+6.0, 1.0) + peek := 0.06 * (0.5 + 0.5*math.Sin(tSec*2.6+idx*1.9)) + hearth := 0.86 + 0.14*math.Sin(tSec*5.2+u*8.0) + // Peeking candy cane above cuff. + if stockingU > 0.42 && stockingU < 0.58 && v >= 0.14-peek && v < 0.22 { + if math.Sin((v*40.0+stockingU*12.0-tSec*3.0)*math.Pi) > 0 { + return 0.96, 0.16, 0.20 + } + return 0.98, 0.96, 0.96 + } + sock := stockingU > 0.20 && stockingU < 0.80 && v > 0.30 && v < 0.80 + cuff := stockingU > 0.15 && stockingU < 0.85 && v >= 0.22 && v <= 0.30 if cuff { - return 0.95, 0.95, 0.98 // White fur cuff + return math.Min(1, 0.95*hearth), math.Min(1, 0.95*hearth), math.Min(1, 0.98*hearth) } if sock { - return 0.85, 0.08, 0.12 // Red velvet - } - return 0.05, 0.05, 0.08 + fold := 0.82 + 0.18*math.Sin(stockingU*18.0) + return math.Min(1, 0.88*hearth*fold), 0.09 * hearth, 0.14 * hearth + } + return 0.06 * hearth, 0.04 * hearth, 0.07 }, AudioGen: func(tSec float64) (mono, sub float64, pos [3]float64) { mono = 0.22 * math.Sin(2*math.Pi*640*tSec) * (0.8 + 0.2*math.Cos(tSec*3.0)) @@ -850,11 +897,15 @@ Description: "Delicate dendritic ice crystals growing outward across physical walls and windows in fractal patterns.", TargetSurface: "Window Glass & Wall Corners", RenderPixel: func(u, v, tSec float64) (r, g, b float64) { - fractal := math.Sin(u*30.0+math.Sin(v*25.0)*3.0) * math.Cos(v*30.0) - frost := math.Pow(math.Max(0, fractal), 4.0) - r = frost * 0.75 - g = frost * 0.88 - b = frost * 0.98 + edge := math.Min(math.Min(u, 1-u), math.Min(v, 1-v)) + grow := 0.18 + 0.36*(0.5+0.5*math.Sin(tSec*0.65)) + front := math.Max(0, 1.0-edge/math.Max(0.05, grow)) + fractal := math.Sin(u*28.0+math.Sin(v*24.0+tSec*0.9)*3.0) * math.Cos(v*28.0-tSec*0.6) + frost := math.Pow(math.Max(0, fractal), 3.0) * (0.35 + 0.65*front) + spark := 0.22 * math.Pow(math.Max(0, math.Sin(u*60.0+v*50.0+tSec*4.2)), 8.0) * front + r = frost*0.72 + spark + g = frost*0.88 + spark + b = frost*0.98 + spark return math.Min(1, r), math.Min(1, g), math.Min(1, b) }, AudioGen: func(tSec float64) (mono, sub float64, pos [3]float64) { @@ -989,11 +1040,12 @@ Description: "A roaring mountain waterfall frozen mid-air in massive turquoise ice pillars and glittering icicles.", TargetSurface: "Vertical Room Walls", RenderPixel: func(u, v, tSec float64) (r, g, b float64) { - fluted := math.Sin(u*30.0) * math.Cos(v*10.0) - highlight := math.Pow(math.Max(0, fluted), 5.0) - r = 0.15 + highlight*0.7 - g = 0.45 + highlight*0.85 - b = 0.85 + highlight*0.98 + fluted := math.Sin(u*30.0+math.Sin(v*6.0-tSec*1.4)*0.8) * math.Cos(v*10.0-tSec*2.4) + highlight := math.Pow(math.Max(0, fluted), 4.0) + caustic := 0.22 * (0.5 + 0.5*math.Sin(v*18.0-tSec*3.6+u*9.0)) + r = 0.14 + highlight*0.68 + caustic*0.25 + g = 0.45 + highlight*0.82 + caustic*0.45 + b = 0.82 + highlight*0.96 + caustic*0.35 return math.Min(1, r), math.Min(1, g), math.Min(1, b) }, AudioGen: func(tSec float64) (mono, sub float64, pos [3]float64) { @@ -1250,12 +1302,17 @@ Description: "Synchronized neon green and cyan laser beams tracing digital countdown numerals directly onto front siding.", TargetSurface: "Front Exterior Facade", RenderPixel: func(u, v, tSec float64) (r, g, b float64) { - laserU := math.Exp(-math.Abs(u-0.5) * 80.0) - laserV := math.Exp(-math.Abs(v-0.5) * 80.0) - beam := math.Max(laserU, laserV) - r = beam * 0.1 + dx, dy := u-0.5, v-0.5 + ang := math.Atan2(dy, dx) + rad := math.Hypot(dx, dy) + fan1 := math.Pow(math.Max(0, math.Cos((ang-tSec*1.8)*4.0)), 14.0) + fan2 := math.Pow(math.Max(0, math.Cos((ang+tSec*1.3)*6.0)), 16.0) + ring := math.Exp(-math.Abs(math.Mod(rad*5.0-tSec*1.6+10.0, 1.0)-0.5) * 28.0) + pulse := 0.72 + 0.28*math.Sin(tSec*6.28) + beam := math.Min(1, (fan1+fan2*0.85+ring*0.65)*pulse) + r = beam*0.14 + fan2*0.35 g = beam * 1.0 - b = beam * 0.8 + b = beam*0.85 + ring*0.35 return math.Min(1, r), math.Min(1, g), math.Min(1, b) }, AudioGen: func(tSec float64) (mono, sub float64, pos [3]float64) { --- a/effect_browser_catalog326_windows.go +++ b/effect_browser_catalog326_windows.go @@ -149,11 +149,21 @@ return } func effectCategory326(tags string) string { - t := " " + strings.NewReplacer("-", " ", "/", " ").Replace(strings.ToLower(tags)) + " " + t := " " + strings.NewReplacer("-", " ", "/", " ", ":", " ", "(", " ", ")", " ").Replace(strings.ToLower(tags)) + " " for _, c := range []struct { label string terms []string - }{{"Botanical Motion",[]string{"botanical"}},{"Water & weather", []string{"water", "rain", "ocean", "snow", "cloud", "weather", "aquarium"}}, {"Fire & light", []string{"fire", "lava", "spark", "glow", "light", "laser"}}, {"Space & portals", []string{"space", "portal", "star", "cosmic"}}, {"Spooky & creatures", []string{"spooky", "halloween", "ghost", "bat", "creature"}}, {"Geometry & materials", []string{"geometry", "material", "grid", "glass", "metal"}}} { + }{ + {"Botanical Motion", []string{"botanical", "sandflora", "floral", "flower", "garden", "fern", "blossom", "petal"}}, + {"Christmas & Holiday", []string{"christmas", "xmas", "holiday", "santa", "winter", "frost", "reindeer", "nutcracker", "gingerbread", "garland", "ornament", "wreath", "nye", "festive", "celebration", "confetti", "fireworks", "sparkler"}}, + {"Water & weather", []string{"water", "rain", "ocean", "snow", "cloud", "weather", "aquarium", "reef", "caustic", "ripple", "wave", "storm", "lightning", "fog", "mist", "ice"}}, + {"Fire & light", []string{"fire", "lava", "spark", "glow", "light", "laser", "ember", "flame", "candle", "lantern", "aurora", "neon", "beam", "spotlight", "prism", "rainbow"}}, + {"Space & portals", []string{"space", "portal", "star", "cosmic", "galaxy", "nebula", "blackhole", "wormhole", "tunnel", "meteor", "comet", "moon", "eclipse", "singularity", "quantum"}}, + {"Spooky & creatures", []string{"spooky", "halloween", "ghost", "bat", "creature", "spider", "skull", "crow", "witch", "blood", "gore", "mansion", "crypt", "graveyard", "pumpkin", "haunted", "animal", "whale", "bird", "wolf", "dragon", "bug", "snake", "koi", "fish"}}, + {"Architecture & frames", []string{"frame", "smartframe", "mirror", "window", "door", "bezel", "outline", "architect", "column", "pillar", "brick", "stone", "marble", "cathedral", "molding", "temple", "shrine", "bookshelf", "facade"}}, + {"Music, retro & tech", []string{"music", "audio", "beat", "equalizer", "vu", "piano", "retro", "tech", "vhs", "glitch", "film", "matrix", "circuit", "cyber", "radar", "sonar", "clock", "arcade", "pixel", "digital", "code"}}, + {"Geometry & materials", []string{"geometry", "material", "grid", "glass", "metal", "chrome", "mercury", "gold", "brass", "crystal", "voronoi", "fractal", "kaleido", "honeycomb", "lattice", "fluid", "liquid", "ink", "smoke", "sand", "abstract", "optical", "depth", "relief", "physics", "cloth"}}, + } { for _, w := range c.terms { if strings.Contains(t, " "+w+" ") { return c.label