Skip to content

Instantly share code, notes, and snippets.

@Opioid
Opioid / aces.py
Last active April 25, 2021 08:39
sRGB to ACEScg
import numpy as np
# Formula from: http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
def rgb_to_xyz(r, g, b, w):
xyz_r = np.array([r[0] / r[1], 1, (1 - r[0] - r[1]) / r[1]])
xyz_g = np.array([g[0] / g[1], 1, (1 - g[0] - g[1]) / g[1]])
xyz_b = np.array([b[0] / b[1], 1, (1 - b[0] - b[1]) / b[1]])
xyz_w = np.array([w[0] / w[1], 1, (1 - w[0] - w[1]) / w[1]])
s = xyz_w * np.linalg.inv(np.matrix([xyz_r, xyz_g, xyz_b]))
@Opioid
Opioid / decomposition_tracking.cpp
Last active July 13, 2018 19:51
Understanding decomposition tracking
void decomposition_tracking(const Ray& ray, const Material& material, float& t_out, float3& transmittance) {
auto const cm = material.control_medium();
float const rc = rng_.random_float();
float const t_c = ray.min_t - std::log(1.f - rc) / cm.minorant_mu_t;
if (t_c > ray.max_t) {
t_out = ray.max_t;
transmittance = float3(1.f);
return;
@Opioid
Opioid / spectral_tracking.cpp
Last active March 19, 2018 12:08
Debugging spectral tracking
float3 direct_light(const Ray& ray, const float3& p) {
// return lighting at this point...
}
float3 spectral_tracking(const Ray& ray, const Material& material, float3& transmittance) {
const float d = ray.max_t - ray.min_t;
float3 w(1.f);
float t = 0.f;
@Opioid
Opioid / delta_tracking.cpp
Last active March 3, 2018 22:42
Comparing delta-tracking with tracking on homogeneous media
float3 direct_light(const float3& position) {
// direct light inside volume including phase function and beam transmittance
}
float3 homogeneous2(const Ray& ray, float3& transmittance) {
float3 radiance(0.f);
if (Algorithm::Tracking == algorithm) {
const float3 sigma_a = material.absorption(float3::identity());
@Opioid
Opioid / tracking.cpp
Created February 15, 2018 17:29
Comparing homogeneous single scattering algorithms from pixar course notes
float3 direct_light(const float3& position) {
// direct light inside volume including phase function and beam transmittance
}
float3 homogeneous(const Ray& ray, float3& transmittance) {
float3 radiance(0.f);
const float3 extinction = sigma_a + sigma_s;
const float3 scattering_albedo = sigma_s / extinction;