From 44cfed20de8d97ef5c8f34843eb13e972e6cd7d5 Mon Sep 17 00:00:00 2001 From: enigmahe Date: Tue, 25 Jun 2024 14:44:47 +0800 Subject: [PATCH] Updated volume rendering. RGB rendering problem persists. --- bxdf/setup.py | 3 ++- bxdf/vol_loader/vol2numpy.cpp | 2 -- bxdf/volume.py | 7 +++---- emitters/abtract_source.py | 2 -- renderer/vpt.py | 2 -- scenes/cbox/cbox-rgbvol.xml | 18 ++++++++++++++++-- scenes/csphere/balls-mono.xml | 2 +- tracer/path_tracer.py | 6 ++++-- tracer/setup.py | 3 ++- 9 files changed, 28 insertions(+), 17 deletions(-) diff --git a/bxdf/setup.py b/bxdf/setup.py index 811d065..8b222fe 100644 --- a/bxdf/setup.py +++ b/bxdf/setup.py @@ -1,5 +1,6 @@ from pybind11.setup_helpers import Pybind11Extension from setuptools import setup +import platform __version__ = "0.2.0" cxx_std=11 @@ -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'], ), ] diff --git a/bxdf/vol_loader/vol2numpy.cpp b/bxdf/vol_loader/vol2numpy.cpp index 029f84a..7a6747a 100644 --- a/bxdf/vol_loader/vol2numpy.cpp +++ b/bxdf/vol_loader/vol2numpy.cpp @@ -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; diff --git a/bxdf/volume.py b/bxdf/volume.py index 40fc562..d494135 100644 --- a/bxdf/volume.py +++ b/bxdf/volume.py @@ -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): @@ -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, @@ -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 @@ -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 diff --git a/emitters/abtract_source.py b/emitters/abtract_source.py index 761dda0..720733c 100644 --- a/emitters/abtract_source.py +++ b/emitters/abtract_source.py @@ -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 diff --git a/renderer/vpt.py b/renderer/vpt.py index e37136e..91f298d 100644 --- a/renderer/vpt.py +++ b/renderer/vpt.py @@ -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]) @@ -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 diff --git a/scenes/cbox/cbox-rgbvol.xml b/scenes/cbox/cbox-rgbvol.xml index e502c90..ac31562 100644 --- a/scenes/cbox/cbox-rgbvol.xml +++ b/scenes/cbox/cbox-rgbvol.xml @@ -117,12 +117,26 @@ + + + + + + + + diff --git a/scenes/csphere/balls-mono.xml b/scenes/csphere/balls-mono.xml index 8a8a410..cdbd0f6 100644 --- a/scenes/csphere/balls-mono.xml +++ b/scenes/csphere/balls-mono.xml @@ -78,7 +78,7 @@ - + diff --git a/tracer/path_tracer.py b/tracer/path_tracer.py index db05d63..4b15140 100644 --- a/tracer/path_tracer.py +++ b/tracer/path_tracer.py @@ -9,7 +9,6 @@ import sys sys.path.append("..") -import tqdm import numpy as np import taichi as ti import taichi.math as tm @@ -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 @@ -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) @@ -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 diff --git a/tracer/setup.py b/tracer/setup.py index 4950aca..0646bf6 100644 --- a/tracer/setup.py +++ b/tracer/setup.py @@ -1,5 +1,6 @@ from pybind11.setup_helpers import Pybind11Extension from setuptools import setup +import platform __version__ = "0.1.0" cxx_std=11 @@ -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'], ), ]