Browse Source

refactor: инкапсуляция рендера в Multicore

master
exepirit 6 months ago
parent
commit
d0131004f9
Signed by: exepirit GPG Key ID: 7F96A965465257B9
  1. 8
      cmd/sphere/main.go
  2. 9
      pkg/render/multicore.go
  3. 5
      tests/integration/render/multicore_test.go

8
cmd/sphere/main.go

@ -21,16 +21,12 @@ func writeImage(filename string, img output.DataWriter) error {
}
func main() {
/*renderer := render.Default{
renderer := render.NewMulticore(render.Default{
CameraPos: geometry.NewVector3(0, 1.75, 0),
Shadow: lighting.SoftShadow{
Softness: 32,
},
}*/
shading := lighting.SoftShadow{
Softness: 32,
}
renderer := render.NewMulticore(geometry.NewVector3(0, 1.75, 0), shading, 32)
}, 32)
image := output.NewPPM(640, 360)
function := func(p geometry.Vector3) float64 {

9
pkg/render/multicore.go

@ -5,8 +5,6 @@ import (
"runtime"
"sync"
"git.0x73.ru/exepirit/sdf/pkg/geometry"
"git.0x73.ru/exepirit/sdf/pkg/lighting"
"git.0x73.ru/exepirit/sdf/pkg/output"
)
@ -16,12 +14,9 @@ type Multicore struct {
currentX, currentY int
}
func NewMulticore(cameraPos geometry.Vector3, shadow lighting.ShadowCalc, segmentSize int) Multicore {
func NewMulticore(innerRender Default, segmentSize int) Multicore {
return Multicore{
Default: Default{
CameraPos: cameraPos,
Shadow: shadow,
},
Default: innerRender,
segmentSize: segmentSize,
}
}

5
tests/integration/render/multicore_test.go

@ -24,7 +24,10 @@ func Test_MulticoreRender_SimpleScene_RenderWithSegmentSize(t *testing.T) {
scene := makeSimpleScene()
for _, segmentSize := range segmentSizes {
t.Run(fmt.Sprintf("render with segment size %d", segmentSize), func(t *testing.T) {
renderer := render.NewMulticore(geometry.NewVector3(0, 0, 0), lighting.HardShadow{}, segmentSize)
renderer := render.NewMulticore(render.Default{
CameraPos: geometry.NewVector3(0, 0, 0),
Shadow: lighting.HardShadow{},
}, segmentSize)
started := time.Now()
renderer.Render(image, scene)

Loading…
Cancel
Save