Skip to content

Instantly share code, notes, and snippets.

@arpit15
Last active March 26, 2020 14:32
Show Gist options
  • Save arpit15/57297b0dc124622045aaeec8864b7cf1 to your computer and use it in GitHub Desktop.
Save arpit15/57297b0dc124622045aaeec8864b7cf1 to your computer and use it in GitHub Desktop.
import mitsuba
import enoki as ek
import numpy as np
from math import radians, cos
from mitsuba.core import Point3f, warp, Ray3f, AnimatedTransform
from mitsuba.core.math import Pi
from mitsuba.render import (DirectionSample3f, Emitter,
SurfaceInteraction3f, EmitterFlags,
Texture)
class MyPointEmitter(Emitter):
"""docstring for MyPointEmitter"""
def __init__(self, props):
# super(MyPointEmitter, props).__init__(props)
Emitter.__init__(self, props)
# print(self.m_world_transform)
self.m_intensity = props['intensity'] # assumption that a texture is returned
self.m_intensity = Texture.D65(1)
print(self.m_intensity.class_().name())
self.m_needs_sample_3 = False
self.m_flags = +EmitterFlags.DeltaPosition
# should ideally be inherited from cpp parent class
self.m_world_transform = AnimatedTransform(props["to_world"])
def sample_ray(self, time,
sample1, # wavelength
sample2, # pos
sample3, # dir
active):
wavelengths, spec_weight = self.m_intensity.sample(SurfaceInteraction3f(), np.arange(sample1), active)
trafo = self.m_world_transform.eval(ref.time)
ray = Ray3f(trafo*Point3f(0), warp.square_to_uniform_sphere(sample3),
time, wavelengths)
print(spec_weight.class_().name())
return (ray, spec_weight*4.0*Pi)
def sample_direction(self, ref, sample, active):
trafo = self.m_world_transform.eval(ref.time, active)
ds = DirectionSample3f()
ds.p = trafo.translation()
ds.n = 0
ds.uv = 0
ds.time = ref.time
ds.pdf = 1
ds.delta = True
ds.d = ds.p - ref.p
ds.dist = ek.norm(ds.d)
inv_dist = ek.rcp(ds.dist)
ds.d *= inv_dist
si = SurfaceInteraction3f()
si.wavelengths = ref.wavelengths
spec = self.m_intensity.eval(si, active)*(inv_dist*inv_dist)
# print(spec.class_().name())
return (ds, spec)
def pdf_direction(self, ref, ds, active):
return 0
def eval(self, si, active):
return 0
def bbox(self):
return self.m_world_transform.translation_bounds()
def to_string(self):
mystr = "MyPointLight\n"
mystr.append(" world_transform" + self.m_world_transform.to_string())
mystr.append(" intensity" + self.m_intensity + "\n")
return mystr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment