tylermorganwall / rayvertex

3D Software Rasterizer for R
https://www.rayvertex.com
65 stars 2 forks source link

Dark spots in raster #1

Closed gdagstn closed 3 years ago

gdagstn commented 3 years ago

Hi!

Thanks for the great package.

I am trying to replicate my brain rendering workflow, porting from rayrender to rayvertex, and something weird happened: some dark spots appear in some parts of the image.

See video:

https://user-images.githubusercontent.com/21171362/121120034-580ab380-c84f-11eb-801c-4cb14758ee90.mp4

The code I use for this is pretty simple, as every shape is loaded as a mesh3d_mesh in the scene and the scene frames are rendered in parallel (takes 2 minutes to render 90 frames)

vb.center = c(254, 160, -220)
dist.from = 1350

steps = 180
steps.x = dist.from * 2 * cos(seq(0, 360, length.out = steps) * pi/180)
steps.z = dist.from * 2 * sin(seq(0, 360, length.out = steps) * pi/180)

scene = mesh3d_mesh(meshlist[[1]])

for(i in names(meshlist)) {
    mesh.material = paste0("#", structures.available$color_hex_triplet[structures.available$id == i])
    scene <- add_shape(scene, 
                       shape = mesh3d_mesh(meshlist[[i]], 
                       material = material_list(diffuse = mesh.material)))
    }

plan(multiprocess, workers = 13) 

future.apply::future_lapply(1:90, function(j) {
  options(cores = 4)
  rasterize_scene(scene = scene,
               lookat = vb.center,
               lookfrom = c(steps.x[j*2], 50, steps.z[j*2]),
               width = 1080,
               height = 1080,
               light_info = directional_light(c(steps.x[j*2], 50, steps.z[j*2]), 
                                                                color = "white", 
                                                                intensity = 0.8),
               background = "white",
               parallel = TRUE, 
               filename=glue::glue("./raster/brainmov_rast_{j}"))
            },
    future.seed = TRUE)

A similar workflow in rayrender has no such issue.

Any idea if I'm doing something wrong/need to change arguments?

tylermorganwall commented 3 years ago

Can you provide the mesh data? It looks like there's something unique going on with the mesh that's causing the black spots. Pathtracing is a bit more forgiving of mesh issues, which is why it they might not have appeared in rayrender.

gdagstn commented 3 years ago

You can find the meshlist object here!

tylermorganwall commented 3 years ago

Great, thanks! Do you have the structures.available data as well for the color? Also, the camera angles I get when I run your code aren't the same in the image—everything is rotated and the mesh is centered at c(-268.5, -235.5, 155.0).

If you can find a specific frame j with the black spots and provide the above, I should be able to determine the cause.

gdagstn commented 3 years ago

Really sorry about that - I had exported the list before rotating and smoothing the meshes.

You can find both the correct mesh list and the structures data frame here.

The offending frames in the video I made are for j = 1:53 and 87:90.

Thanks!

tylermorganwall commented 3 years ago

Oh, that's shadow acne. Hard to completely avoid in rasterization when using shadow maps. Since the light is parallel to the camera, you don't need shadow maps, so turn them off by setting shadow_map = FALSE in rasterize_scene(). Should fix your issue.