mitsuba-renderer / mitsuba3

Mitsuba 3: A Retargetable Forward and Inverse Renderer
https://www.mitsuba-renderer.org/
Other
2.1k stars 246 forks source link

The problem of obtaining the BSDF at the intersection #1204

Closed ioissss closed 5 months ago

ioissss commented 5 months ago

I'm writing my own Integrator, inheriting from mitsuba.SamplingIntegrator, rewriting the sample(self,scene,sampler,ray,medium=None,active=True) function in it, and my sample() function is as follows:

def sample(self,scene,sampler,ray,medium=None,active=True):
        L = mi.Color3f(0.0) #initialize radiance
        si = scene.ray_intersect(ray,active=active) #intersection
        active &= si.is_valid()
        # NEE
        ctx = mi.BSDFContext()
        ctx.type_mask = mi.BSDFFlags.All
        ctx.mode = mi.TransportMode.Radiance
        bsdf = si.bsdf()
        emitter_sample,emitter_weight = scene.sample_emitter_direction(si,sampler.next_2d(),test_visibility=True,active=active)
        data = np.array(bsdf.eval(ctx,si,emitter_sample.d))
        np.savetxt('./output.txt',data,fmt="%.3f")
        #if si is a emitter
        L += si.emitter(scene).eval(si)
        L += emitter_weight*bsdf.eval(ctx,si,emitter_sample.d)
        return [L,active,[]] 

Running this code, I get the following results: image There's a big part that's black.

I checked the running result of ’bsdf.eval(ctx,si,emitter_sample.d)‘ and found that most of them are (0.0, 0.0, 0.0), print(bsdf) can be found that there are many of them are None. the scenario that I used is the tutorial cbox.xml. I didn't find any examples related to rewriting Integrator in the tutorials, where can I find such examples, the API documentation describes it very briefly, where can I find examples of usage of related functions

ioissss commented 5 months ago

I visualized the intersection of bsdf.eval() value, found that the problem appeared in the bsdf value of the evaluation, each intersection at the evaluation of the bsdf value after visualization is as follows: image I don't know why I'm getting this error, is there something wrong with the emitter_sample.d ? I've always assumed that emitter_sample.d is pointing from the intersection point to the light source and is located in the world coordinate system, the code is """ bsdf = si.bsdf() emitter_sample,emitter_weight = scene.sample_emitter_direction(si,sampler.next_2d(),test_visibility=True,active=active)

L += emitter_weight*bsdf.eval(mi.BSDFContext(),si,emitter_sample.d) """

njroussel commented 5 months ago

When opening an issue please follow the pre-filled template :warning:

I'll move this to a discussion thread for now, it seems more appropriate.