def test_rgb_arithmetic(self): code = """ tmp = p1 + p2 p3 = tmp p4 = 2 * p3 p5 = p3 * 2.66 """ p1 = RGBArg('p1', RGBSpectrum(0.36, 0.85, 0.14)) p2 = RGBArg('p2', RGBSpectrum(0.22, 0.11, 0.58)) p3 = RGBArg('p3', RGBSpectrum(0.0, 0.0, 0.0)) p4 = RGBArg('p4', RGBSpectrum(0.0, 0.0, 0.0)) p5 = RGBArg('p5', RGBSpectrum(0.0, 0.0, 0.0)) shader = Shader(code=code, args=[p1, p2, p3, p4, p5]) shader.compile() shader.prepare([Runtime()]) shader.execute() v = shader.get_value('p3') self.assertAlmostEqual(v.r, 0.36 + 0.22) self.assertAlmostEqual(v.g, 0.85 + 0.11) self.assertAlmostEqual(v.b, 0.14 + 0.58) v = shader.get_value('p4') self.assertAlmostEqual(v.r, (0.36 + 0.22) * 2, places=6) self.assertAlmostEqual(v.g, (0.85 + 0.11) * 2, places=6) self.assertAlmostEqual(v.b, (0.14 + 0.58) * 2, places=6) v = shader.get_value('p5') self.assertAlmostEqual(v.r, (0.36 + 0.22) * 2.66, places=6) self.assertAlmostEqual(v.g, (0.85 + 0.11) * 2.66, places=6) self.assertAlmostEqual(v.b, (0.14 + 0.58) * 2.66, places=6)
def test_assign_rgb_spectrum(self): code = """ p2 = p1 """ p1 = RGBArg('p1', RGBSpectrum(0.36, 0.85, 0.14)) p2 = RGBArg('p2', RGBSpectrum(0.0, 0.0, 0.0)) shader = Shader(code=code, args=[p1, p2]) shader.compile() shader.prepare([Runtime()]) shader.execute() v = shader.get_value('p2') self.assertAlmostEqual(v.r, 0.36) self.assertAlmostEqual(v.g, 0.85) self.assertAlmostEqual(v.b, 0.14)
def test_rgb_spectrum(self): code = """ spec2 = Spectrum(spec, 0.23) """ spec = RGBArg('spec', RGBSpectrum(0.2, 0.3, 0.4)) spec2 = RGBArg('spec2', RGBSpectrum(0.0, 0.0, 0.0)) shader = Shader(code=code, args=[spec, spec2]) shader.compile() runtime = Runtime() shader.prepare([runtime]) shader.execute() val = shader.get_value('spec2') self.assertAlmostEqual(val.r, 0.23) self.assertAlmostEqual(val.g, 0.23) self.assertAlmostEqual(val.b, 0.23)
def rgb_to_vec_shader(): code = """ return float3(rgb[0], rgb[1], rgb[2]) """ rgb = RGBArg('rgb', RGBSpectrum(0.0, 0.0, 0.0)) shader = Shader(code=code, name='spectrum_to_vec', func_args=[rgb], is_func=True) return shader
def lum_rgb_shader(): code = """ return rgb[0] * 0.212671 + rgb[1] * 0.715160 + rgb[2] * 0.072169 """ rgb = RGBArg('rgb', RGBSpectrum(0.0, 0.0, 0.0)) shader = Shader(code=code, name='lumminance', func_args=[rgb], is_func=True) return shader
def test_rgb_lum(self): shader = lum_rgb_shader() shader.compile() runtime = Runtime() shader.prepare([runtime]) code = """ rez = lumminance(r1) """ s = RGBArg('r1', RGBSpectrum(0.2, 0.3, 0.4)) rez = FloatArg('rez', 0.0) shader2 = Shader(code=code, args=[rez, s]) shader2.compile([shader]) shader2.prepare([runtime]) shader2.execute() lum = 0.2 * 0.212671 + 0.3 * 0.715160 + 0.4 * 0.072169 val = shader2.get_value('rez') self.assertAlmostEqual(lum, val)
def test_rgb_spec_to_vec(self): shader = rgb_to_vec_shader() shader.compile() runtime = Runtime() shader.prepare([runtime]) code = """ rez = spectrum_to_vec(r1) """ s = RGBArg('r1', RGBSpectrum(0.2, 0.3, 0.4)) rez = Vec3Arg('rez', Vector3(0.0, 0.0, 0.0)) shader2 = Shader(code=code, args=[rez, s]) shader2.compile([shader]) shader2.prepare([runtime]) shader2.execute() val = shader2.get_value('rez') self.assertAlmostEqual(val.x, 0.2) self.assertAlmostEqual(val.y, 0.3) self.assertAlmostEqual(val.z, 0.4)
def test_rgb_lambertian(self): register_rgb_shadepoint() mat = Material() r = RGBSpectrum(0.0, 0.0, 0.0) mat.load('lambertian', r) mat.compile() runtime = Runtime() mat.prepare([runtime]) ptrs = mat.bsdf.get_ptrs() code = """ hp = HitPoint() sp = ShadePoint() material_reflectance(hp, sp, ptr_func) rez = sp.material_reflectance """ ptr_func = PointerArg('ptr_func', ptrs[0]) rez = RGBArg('rez', RGBSpectrum(0.0, 0.0, 0.0)) shader = Shader(code=code, args=[ptr_func, rez]) shader.compile() shader.prepare([runtime]) shader.execute() print(shader.get_value('rez'))