implemented msaa
This commit is contained in:
parent
554fa84a0a
commit
17b212acba
3 changed files with 21 additions and 14 deletions
|
@ -22,20 +22,22 @@ func mix(src, dest color.Color) color.RGBA {
|
|||
b1 := float64(ib1) / 65535.0
|
||||
a1 := float64(ia1) / 65535.0
|
||||
|
||||
ir2, ig2, ib2, _ := dest.RGBA()
|
||||
ir2, ig2, ib2, ia2 := dest.RGBA()
|
||||
r2 := float64(ir2) / 65535.0
|
||||
g2 := float64(ig2) / 65535.0
|
||||
b2 := float64(ib2) / 65535.0
|
||||
a2 := float64(ia2) / 65535.0
|
||||
|
||||
r := (r1-r2)*a1 + r2
|
||||
g := (g1-g2)*a1 + g2
|
||||
b := (b1-b2)*a1 + b2
|
||||
a := math.Max((a1-a2)*a1+a2, a2)
|
||||
|
||||
return color.RGBA{
|
||||
R: uint8(math.Round(r * 255.0)),
|
||||
G: uint8(math.Round(g * 255.0)),
|
||||
B: uint8(math.Round(b * 255.0)),
|
||||
A: 255,
|
||||
A: uint8(math.Round(a * 255.0)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
type SoftwareBackend struct {
|
||||
Image *image.RGBA
|
||||
|
||||
// MSAA int
|
||||
MSAA int
|
||||
|
||||
clip *image.Alpha
|
||||
mask *image.Alpha
|
||||
|
|
|
@ -172,7 +172,7 @@ func (b *SoftwareBackend) fillTriangleMSAA(tri [][2]float64, msaaLevel int, msaa
|
|||
sx := float64(x) + msaaStep*0.5
|
||||
for stepx := 0; stepx <= msaaLevel; stepx++ {
|
||||
if sx >= l[stepy] && sx < r[stepy] {
|
||||
msaaPixels = append(msaaPixels, msaaPixel{ix: x, iy: y, fx: sx, fy: sy})
|
||||
msaaPixels = addMSAAPixel(msaaPixels, msaaPixel{ix: x, iy: y, fx: sx, fy: sy})
|
||||
}
|
||||
sx += msaaStep
|
||||
}
|
||||
|
@ -184,6 +184,15 @@ func (b *SoftwareBackend) fillTriangleMSAA(tri [][2]float64, msaaLevel int, msaa
|
|||
return msaaPixels
|
||||
}
|
||||
|
||||
func addMSAAPixel(msaaPixels []msaaPixel, px msaaPixel) []msaaPixel {
|
||||
for _, px2 := range msaaPixels {
|
||||
if px == px2 {
|
||||
return msaaPixels
|
||||
}
|
||||
}
|
||||
return append(msaaPixels, px)
|
||||
}
|
||||
|
||||
func quadArea(quad [4][2]float64) float64 {
|
||||
leftv := [2]float64{quad[1][0] - quad[0][0], quad[1][1] - quad[0][1]}
|
||||
topv := [2]float64{quad[3][0] - quad[0][0], quad[3][1] - quad[0][1]}
|
||||
|
@ -329,10 +338,7 @@ func (b *SoftwareBackend) fillTrianglesMSAA(pts [][2]float64, msaaLevel int, fn
|
|||
continue
|
||||
}
|
||||
|
||||
col := fn(px.fx, px.fy)
|
||||
if col.A == 0 {
|
||||
return
|
||||
}
|
||||
col := fn(px2.fx, px2.fy)
|
||||
mr += int(col.R)
|
||||
mg += int(col.G)
|
||||
mb += int(col.B)
|
||||
|
@ -348,14 +354,13 @@ func (b *SoftwareBackend) fillTrianglesMSAA(pts [][2]float64, msaaLevel int, fn
|
|||
A: uint8(ma / samples),
|
||||
}
|
||||
b.Image.SetRGBA(px.ix, px.iy, mix(combined, b.Image.RGBAAt(px.ix, px.iy)))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (b *SoftwareBackend) fillTriangles(pts [][2]float64, fn func(x, y float64) color.RGBA) {
|
||||
// if b.MSAA > 0 {
|
||||
// b.fillTrianglesMSAA(pts, b.MSAA, fn)
|
||||
// } else {
|
||||
if b.MSAA > 0 {
|
||||
b.fillTrianglesMSAA(pts, b.MSAA, fn)
|
||||
} else {
|
||||
b.fillTrianglesNoAA(pts, fn)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue