voxcity.simulator_gpu.core¶
Shared core utilities for simulator_gpu.
Vector and ray utilities using Taichi for GPU acceleration. Based on ray-tracing-one-weekend-taichi patterns.
GPU Optimization Notes: - All functions use @ti.func for GPU inlining - Branchless operations preferred where possible - Memory coalescing friendly access patterns - done-flag pattern for early termination (reduces warp divergence)
Attributes¶
Classes¶
Functions¶
|
Normalize a vector. |
|
Normalize a vector with safety check for zero-length. |
|
Dot product of two vectors. |
|
Cross product of two vectors. |
|
Reflect vector v around normal n. |
|
Get point along ray at parameter t. |
|
Compute squared length of vector (avoids sqrt). |
|
Compute squared distance between two points (avoids sqrt). |
|
Branchless minimum of three values. |
|
Branchless maximum of three values. |
|
Clamp value to range [lo, hi]. |
|
Generate random point in unit sphere. |
|
Generate random vector in hemisphere around normal. |
|
Generate random vector with cosine-weighted distribution in hemisphere. |
|
Convert spherical coordinates to Cartesian unit vector. |
|
Convert Cartesian unit vector to spherical coordinates. |
|
Rotate vector around an axis by a given angle using Rodrigues' rotation formula. |
|
Build orthonormal basis for a face with given normal. |
Module Contents¶
- voxcity.simulator_gpu.core.Vector3¶
- voxcity.simulator_gpu.core.Point3¶
- voxcity.simulator_gpu.core.Color3¶
- voxcity.simulator_gpu.core.PI = 3.141592653589793¶
- voxcity.simulator_gpu.core.TWO_PI = 6.283185307179586¶
- voxcity.simulator_gpu.core.HALF_PI = 1.5707963267948966¶
- voxcity.simulator_gpu.core.DEG_TO_RAD = 0.017453292519943295¶
- voxcity.simulator_gpu.core.RAD_TO_DEG = 57.29577951308232¶
- voxcity.simulator_gpu.core.SOLAR_CONSTANT = 1361.0¶
- voxcity.simulator_gpu.core.EXT_COEF = 0.6¶
- voxcity.simulator_gpu.core.MIN_STABLE_COSZEN = 0.0262¶
- voxcity.simulator_gpu.core.GPU_BLOCK_SIZE = 256¶
- voxcity.simulator_gpu.core.normalize_safe(v: Vector3) Vector3¶
Normalize a vector with safety check for zero-length.
- voxcity.simulator_gpu.core.reflect(v: Vector3, n: Vector3) Vector3¶
Reflect vector v around normal n.
- voxcity.simulator_gpu.core.ray_at(origin: Point3, direction: Vector3, t: taichi.f32) Point3¶
Get point along ray at parameter t.
- voxcity.simulator_gpu.core.length_squared(v: Vector3) taichi.f32¶
Compute squared length of vector (avoids sqrt).
- voxcity.simulator_gpu.core.distance_squared(p1: Point3, p2: Point3) taichi.f32¶
Compute squared distance between two points (avoids sqrt).
- voxcity.simulator_gpu.core.min3(a: taichi.f32, b: taichi.f32, c: taichi.f32) taichi.f32¶
Branchless minimum of three values.
- voxcity.simulator_gpu.core.max3(a: taichi.f32, b: taichi.f32, c: taichi.f32) taichi.f32¶
Branchless maximum of three values.
- voxcity.simulator_gpu.core.clamp(x: taichi.f32, lo: taichi.f32, hi: taichi.f32) taichi.f32¶
Clamp value to range [lo, hi].
- voxcity.simulator_gpu.core.random_in_hemisphere(normal: Vector3) Vector3¶
Generate random vector in hemisphere around normal.
- voxcity.simulator_gpu.core.random_cosine_hemisphere(normal: Vector3) Vector3¶
Generate random vector with cosine-weighted distribution in hemisphere. Used for diffuse radiation sampling.
- voxcity.simulator_gpu.core.spherical_to_cartesian(azimuth: taichi.f32, elevation: taichi.f32) Vector3¶
Convert spherical coordinates to Cartesian unit vector.
- Parameters:
azimuth – Angle from north (y-axis), clockwise, in radians
elevation – Angle from horizontal, in radians (0 = horizontal, pi/2 = zenith)
- Returns:
Unit vector (x, y, z) where z is vertical (up)
- voxcity.simulator_gpu.core.cartesian_to_spherical(v: Vector3) taichi.math.vec2¶
Convert Cartesian unit vector to spherical coordinates.
- Returns:
vec2(azimuth, elevation) in radians
- voxcity.simulator_gpu.core.rotate_vector_axis_angle(vec: Vector3, axis: Vector3, angle: taichi.f32) Vector3¶
Rotate vector around an axis by a given angle using Rodrigues’ rotation formula.
- Parameters:
vec – Vector to rotate
axis – Rotation axis (will be normalized)
angle – Rotation angle in radians
- Returns:
Rotated vector