I am writing postprocessing script to the cycles rendering.

Can I somehow track the whole lightpath of a single pixel from the camera to the origin of the light? For example the I have 3 lamps(A, B, C) and an environment map in my scene. I want to know that pixel (200,100) is in 30% made from light of lamp A and in 70% from lamp B.(some of render samples came across one, some across another) And pixel (300, 200) reflects the environment map’s coordinate (2000,1000). Is there any way to extract the information about from where the light comes, maybe at least from single render sample?(since in one sample each pixel should reflect/refract only one light source) If so, at which level I should integrate with blender? Python scripting is ok or do I need to recompile some parts of cycles?

My final point is to find origin of each light path and track how the object interacts with environment.

  • $\begingroup$ What have you tried so far? That sounds like waay to much info to extract from an already heavy and slow process that is rendering. I'm not a coder or anything, but I'm not sure there is any way to access that type for information directly, and certainly not from a final rendered image as far as I know. $\endgroup$ – Duarte Farrajota Ramos Oct 10 '17 at 3:40
  • $\begingroup$ @DuarteFarrajotaRamos I am doing something like diffraction/reflection mask which will be applicable to already rendered images(as an extension for photoshop, krita, gimp etc - it will allow you to place for example glass on an image without rendering it again). I have already made algorithm which applies this mask on image, but have to make all masks manually, so I want to make cycles extension which will export image to my format. So I have done another part of my program and I am just starting with blender part(and gathering information how to do it the most efficiently before I start) $\endgroup$ – Krzysztof Sroga Oct 10 '17 at 8:33

Rendering doesn't work like that. Tracking only 1 light path would give a very bad representation of the scene and would be inaccurate.

Each pixel is an origin for infinite amount of light paths leading into different light sources, each bounce determined by probability. Rendering infinite samples is not doable, so the more samples (light paths traced), the better the image (better representing the scene).

There are 2 approaches you can go:

  • Render the image in N-dimensional color space, N being the number of light sources, each light-source being monochromatic only. Render as many samples as you can. Each pixel's color will exactly correspond with what light influenced it.

    My guess is you will have to compile your own Cycles for this.

  • Render the image multiple times, one light source at a time. This can be scripted with python, or even done by animating the lights and rendering N-frames long animation, where N is number of lights. Each frame will be an exact map of how that light influences the scene.

  • $\begingroup$ I know that. But if so, I can gather more samples(one by one using script) and make average of them(In fact I am only looking for the most common one and the scenes are quite simple - only single object per one render) Thank you for your first approach, it looks quite good, but takes a lot of effort. The second one on the other hand unfortunately doesn't allow me to detect from which place of environment map the light comes. $\endgroup$ – Krzysztof Sroga Oct 9 '17 at 20:25
  • $\begingroup$ @wefhy Then render a colorful image and assign each point of environment different color: similar how UV space looks like: i.stack.imgur.com/CpO0n.png. $\endgroup$ – Jaroslav Jerryno Novotny Oct 9 '17 at 20:33
  • $\begingroup$ Thanks, great idea :) although it works only for grayscale objects, I think, I'll be able to somehow solve it with multiple renders :) It's very helpful, I'll use this idea in my project. One, last thing, but it's additional - do you maybe have an idea how to deal with bluring objects(for example refractive with roughness)? Can I somehow determine the blur radius? If I solve this last thing, I'll be ready to work on this project. $\endgroup$ – Krzysztof Sroga Oct 9 '17 at 20:46
  • $\begingroup$ @wefhy You will have to know the distance between the rough surface and the thing that is reflected/refracted on that surface. The blur amount is dependent on the distance. Other than that you can use image morphology to determine the amount of blur (or also the direction if it is motion blur) with doing Fourier transform and looking into the frequency spectrum of images:image.slidesharecdn.com/… $\endgroup$ – Jaroslav Jerryno Novotny Oct 9 '17 at 21:28
  • $\begingroup$ Ok, that sounds at least doable. I think I'll focus on only the first part for now and then think about bluring a bit more. I still don't get how to make that spectrum neither how to use it to determine bluriness. If I get it right, on this pass I disable difraction (set IOR to 1) and then analyze how the image behind is blured. Or just how is roughsess-on blured in comparison to roughness-off? $\endgroup$ – Krzysztof Sroga Oct 10 '17 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.