Skip to content

Commit

Permalink
Updated volume rendering. RGB rendering problem persists.
Browse files Browse the repository at this point in the history
  • Loading branch information
enigmahe committed Jun 25, 2024
1 parent 528f395 commit 44cfed2
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 17 deletions.
3 changes: 2 additions & 1 deletion bxdf/setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pybind11.setup_helpers import Pybind11Extension
from setuptools import setup
import platform

__version__ = "0.2.0"
cxx_std=11
Expand All @@ -9,7 +10,7 @@
["vol_loader/vol2numpy.cpp"],
# Example: passing in the version to the compiled code
define_macros = [('VERSION_INFO', __version__)],
extra_compile_args= ['-g', '-O2', '-fopenmp'],
extra_compile_args= ['-g', '-O3' if platform.system() == "Linux" else '-O2', '-fopenmp'],
),
]

Expand Down
2 changes: 0 additions & 2 deletions bxdf/vol_loader/vol2numpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ bool readVolumeData(const std::string& filename, VolumeData& volume) {
return false;
}

printf("Channel: %d\n", volume.channels);

file.seekg(24, std::ios::cur); // Skip the bounding box

int numVoxels = volume.xres * volume.yres * volume.zres * volume.channels;
Expand Down
7 changes: 3 additions & 4 deletions bxdf/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ def __init__(self, elem: xet.Element):
if self.type_id == GridVolume_np.MONO:
self.density_grid *= self.density_scaling[0]
else:
print(f"Shape: {self.density_grid.shape}, {self.density_scaling}")
self.density_grid *= self.density_scaling

def assign_transform(self, trans_r, trans_t, trans_s):
Expand Down Expand Up @@ -153,7 +152,8 @@ def export(self):
return GridVolume(_type = 0)
aabb_mini, aabb_maxi = self.get_aabb()
maj = self.density_grid.max(axis = (0, 1, 2))
majorant = vec3(maj) if self.type_id == GridVolume_np.RGB else vec3([maj, maj, maj])
majorant = vec3(maj) if self.type_id == GridVolume_np.RGB else vec3([maj, maj, maj])
CONSOLE.log(f"Majorant: {majorant}. PDF: {majorant / majorant.sum()}")
# the shape of density grid: (zres, yres, xres, channels)
return GridVolume(
_type = self.type_id,
Expand Down Expand Up @@ -344,7 +344,7 @@ def sample_distance_delta_tracking_3d(self, grid: ti.template(), ray_ol: vec3, r

@ti.func
def eval_tr_ratio_tracking_3d(self, grid: ti.template(), ray_ol: vec3, ray_dl: vec3, near_far: vec2) -> vec3:
Tr = ONES_V3
Tr = ONES_V3
if self._type:
# Step 1: choose one element according to the majorant
maj = 1.0
Expand All @@ -356,7 +356,6 @@ def eval_tr_ratio_tracking_3d(self, grid: ti.template(), ray_ol: vec3, ray_dl: v
else:
maj = self.majorant[2]
inv_maj = 1.0 / maj

t = near_far[0]
while True:
dist = -ti.log(1.0 - ti.random(float)) * inv_maj
Expand Down
2 changes: 0 additions & 2 deletions emitters/abtract_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ def sample_hit(

if ti.static(HEMISPHERE_SAMPLE_SPHERE):
to_hit = (hit_pos - center).normalized()
# the pdf here can be viewed as being both both sa & area measure
# since for a unit sphere, different unit solid angle extends to the same amount of area
local_dir, pdf = uniform_sphere()
normal, _ = delocalize_rotate(to_hit, local_dir)
ret_pos = center + normal * radius
Expand Down
2 changes: 0 additions & 2 deletions renderer/vpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def __init__(self,
):
super().__init__(emitters, array_info, objects, prop, bvh_delay)
self.has_volume = False
self.volume = None
if prop["volume"]:
CONSOLE.log("Loading Grid Volume ...")
volume = GridVolume_np(prop["volume"][0])
Expand All @@ -49,7 +48,6 @@ def __init__(self,
self.volume = volume.export()
CONSOLE.log(f"Grid volume loaded: {volume}")
else:
self.volume = GridVolume_np(None).export()
self.density_grid = ti.field(float, (1, 1, 1))
self.world_scattering = self.world.medium._type >= 0

Expand Down
18 changes: 16 additions & 2 deletions scenes/cbox/cbox-rgbvol.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,26 @@
<rgb name="par" value="0.7"/>
<bool name="mono2rgb" value="true"/>

<transform name="toWorld">
<translate x="0.5" y="-0.6" z="2.4"/>
<rotate type="euler" r="20" p="0.0" y="90"/>
<scale x="0.01" y="0.035" z="0.02"/>
</transform>
</volume>

<!-- <volume name="janga" type="rgb" phase_type="hg">
<string name="density_grid" path="./scenes/volume/embergen_dust_devil_tornado_a_50-256-256-256.vol"/>
<rgb name="albedo" value="#F8F8F8"/>
<rgb name="density_scaling" value="10.0"/>
<rgb name="par" value="0.7"/>
<bool name="mono2rgb" value="true"/>
<transform name="toWorld">
<translate x="0.6" y="0.0" z="1.3"/>
<rotate type="euler" r="0" p="0.0" y="0"/>
<scale x="0.03" y="0.03" z="0.03"/>
<scale x="0.02" y="0.02" z="0.01"/>
</transform>
</volume>
</volume> -->

<world name="yes!">
<rgb name="skybox" value="0.0"/>
Expand Down
2 changes: 1 addition & 1 deletion scenes/csphere/balls-mono.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<rgb name="k_s" value="0.0"/>
</brdf>

<bsdf type="lambertian" id="glass">
<bsdf type="det-refraction" id="glass">
<rgb name="k_d" value="#FAFAFA"/>
<medium type="transparent">
<rgb name="u_a" value="0.0"/>
Expand Down
6 changes: 4 additions & 2 deletions tracer/path_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import sys
sys.path.append("..")

import tqdm
import numpy as np
import taichi as ti
import taichi.math as tm
Expand All @@ -22,6 +21,7 @@

from bxdf.brdf import BRDF
from bxdf.bsdf import BSDF, BSDF_np
from bxdf.volume import GridVolume_np
from bxdf.texture import Texture, Texture_np
from parsers.opts import get_options
from parsers.obj_desc import ObjDescriptor
Expand All @@ -31,7 +31,7 @@
from sampler.general_sampling import *
from utils.tools import TicToc
from tracer.interaction import Interaction
from tracer.ti_bvh import LinearBVH, LinearNode, export_python_bvh
from tracer.ti_bvh import LinearBVH, LinearNode

from rich.console import Console
CONSOLE = Console(width = 128)
Expand Down Expand Up @@ -90,6 +90,8 @@ def __init__(self,
# maybe we should opt for environment map (env lighting)
self.roughness_map = Texture.field() # TODO: this is useless for now

self.volume = GridVolume_np(None).export()

ti.root.dense(ti.i, self.src_num).place(self.src_field) # Light source Taichi storage
self.obj_nodes = ti.root.bitmasked(ti.i, self.num_objects)
self.obj_nodes.place(self.brdf_field) # BRDF Taichi storage
Expand Down
3 changes: 2 additions & 1 deletion tracer/setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pybind11.setup_helpers import Pybind11Extension
from setuptools import setup
import platform

__version__ = "0.1.0"
cxx_std=11
Expand All @@ -9,7 +10,7 @@
["bvh/bvh.cpp"],
# Example: passing in the version to the compiled code
define_macros = [('VERSION_INFO', __version__)],
extra_compile_args= ['-g', '-O2'],
extra_compile_args= ['-g', '-O3' if platform.system() == "Linux" else '-O2'],
),
]

Expand Down

0 comments on commit 44cfed2

Please sign in to comment.