DepthImageArray returns the float values from the last GrabDepthImage call automatically handles down-sampling from multisampling.
()
| 362 | // DepthImageArray returns the float values from the last GrabDepthImage call |
| 363 | // automatically handles down-sampling from multisampling. |
| 364 | func (rp *Render) DepthImageArray() ([]float32, error) { |
| 365 | if rp.GrabDepth.Host == vk.NullBuffer { |
| 366 | err := errors.New("DepthImageArray: No GrabDepth.Host buffer -- must call GrabDepthImage") |
| 367 | if Debug { |
| 368 | log.Println(err) |
| 369 | } |
| 370 | return nil, err |
| 371 | } |
| 372 | sz := rp.Format.Size |
| 373 | fsz := sz.X * sz.Y |
| 374 | ary := make([]float32, fsz) |
| 375 | fp := (*[ByteCopyMemoryLimit]float32)(rp.GrabDepth.HostPtr)[0:fsz] |
| 376 | copy(ary, fp) |
| 377 | // note: you cannot specify a greater width than actual width |
| 378 | // and resolving depth images GPU-side is not exactly clear: |
| 379 | // https://community.khronos.org/t/how-to-resolve-multi-sampled-depth-images/7584 |
| 380 | // https://www.reddit.com/r/vulkan/comments/rpeywp/is_it_possible_to_resolve_a_depth_msaa_buffer/ |
| 381 | // furthermore, the function for resolving the multiple samples is not obvious either -- average |
| 382 | // is implemented below: |
| 383 | // for y := 0; y < sz.Y; y++ { |
| 384 | // for x := 0; x < sz.X; x++ { |
| 385 | // sum := float32(0) |
| 386 | // for ys := 0; ys < ns2; ys++ { |
| 387 | // for xs := 0; xs < ns2; xs++ { |
| 388 | // si := (y*ns2+ys)*sz.X*ns2 + x*ns2 + xs |
| 389 | // sum += fp[si] |
| 390 | // } |
| 391 | // } |
| 392 | // di := y*sz.X + x |
| 393 | // ary[di] = sum / float32(nsamp) |
| 394 | // } |
| 395 | // } |
| 396 | return ary, nil |
| 397 | } |
no test coverage detected