Lux measurement using Irradiance feature

Use this forum for general user support and related questions.
Forum rules
Please upload a testscene that allows developers to reproduce the problem, and attach some images.
pro
Posts: 23
Joined: Wed Dec 12, 2018 7:48 am

Re: Lux measurement using Irradiance feature

Post by pro »

Dade wrote: Thu Jan 03, 2019 10:09 am ... getting as input a text file with a generic list of rays to trace ...
I am continuing with the work - I recently looked into the code of existing camera types, and I would like to ask you the following questions:
1. How to construct text file with a generic list of rays to trace and set it as an input to this new type of camera?
2. What are the further steps in development of this new type of camera - Are there also any templates / code pieces that I could reuse from other camera types to create that one?
3. Could you please suggest which specific files should I look into more precisely (to gain a better understanding of how the whole mechanism, that will use that camera, works), or just shortly describe the big picture of a mechanism (with related filenames)?
4. How hard would it be to also add this feature to Blender API?

Thank you very much in advance for your time answering my questions!
User avatar
Dade
Developer
Developer
Posts: 5672
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: Lux measurement using Irradiance feature

Post by Dade »

pro wrote: Mon Jan 21, 2019 9:07 am I am continuing with the work - I recently looked into the code of existing camera types, and I would like to ask you the following questions:
1. How to construct text file with a generic list of rays to trace and set it as an input to this new type of camera?
The code for parsing camera properties (and allocating a new camera object) is here: https://github.com/LuxCoreRender/LuxCor ... a.cpp#L164

You can add there the code for parsing a new type of camera. You can have a new camera property with the name of text file to read. The camera definition could look like:

Code: Select all

scene.camera.type = probes
scene.camera.file = probes.txt
pro wrote: Mon Jan 21, 2019 9:07 am 2. What are the further steps in development of this new type of camera - Are there also any templates / code pieces that I could reuse from other camera types to create that one?
You can look into the code of other camera types to check how they work: https://github.com/LuxCoreRender/LuxCor ... lg/cameras

Something like orthographic camera, for instance.
pro wrote: Mon Jan 21, 2019 9:07 am 3. Could you please suggest which specific files should I look into more precisely (to gain a better understanding of how the whole mechanism, that will use that camera, works), or just shortly describe the big picture of a mechanism (with related filenames)?
Basically, the path tracing rendering code uses a single Camera method, Camera::GenerateRay(): https://github.com/LuxCoreRender/LuxCor ... r.cpp#L309

Camera::GenerateRay() returns the ray to trace given the coordinate of a sample on the image plane and few random variables. I assume, in your case the ray will be starting from one of the "probe" points and sampling the hemisphere. The pixel will tell which probe to use so each pixel of the rendered image will give you the probe value.

The support for BiDirectional path tracing is far more complex and I doubt it is doable without knowing how BiDir works.
pro wrote: Mon Jan 21, 2019 9:07 am 4. How hard would it be to also add this feature to Blender API?
B.Y.O.B. is the one able to answer this question.
Support LuxCoreRender project with salts and bounties
User avatar
B.Y.O.B.
Developer
Developer
Posts: 4146
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Lux measurement using Irradiance feature

Post by B.Y.O.B. »

pro wrote: Mon Jan 21, 2019 9:07 am 4. How hard would it be to also add this feature to Blender API?
What exactly needs to be done from the Blender side?
Create a list of points on the surface of a mesh, and write it to a text file? Or something else?
pro
Posts: 23
Joined: Wed Dec 12, 2018 7:48 am

Re: Lux measurement using Irradiance feature

Post by pro »

B.Y.O.B. wrote: Mon Jan 21, 2019 11:25 am What exactly needs to be done from the Blender side?
Create a list of points on the surface of a mesh, and write it to a text file? Or something else?
For a given mesh (visible inside a camera's view), values of illuminance (measured in lux) should be returned for chosen points on that surface. Now I'm not sure how is it with the time complexity, values for the majority of the points on the surface would be prefered (It would be great if the result could look similar to the output obtained by "Irradiance" feature). If the least is not possible, also values for N points would be good for the beginning.
User avatar
Dade
Developer
Developer
Posts: 5672
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: Lux measurement using Irradiance feature

Post by Dade »

Pro, you may be attacking a problem that is too complex to solve for someone without internal knowledge of how LuxCore and BlendLuxCore work. I propose you to attack the problem from a different angle: you could do (small) rendering using environment camera to render the radiance received by a probe.

This is the rendering of from a point on the floor of a test scene using environment camera:

hemi.jpg

Each pixel of the upper half of the image is the radiance received by the hemisphere over the probe. It can be transformed in irradiance or whatever you want. You can also just render only the upper half of the image using border rendering (in order to cut in half the rendering times).

The HUGE advantage of this solution would be to have to work over LuxCore API in Python. It is orders of magnitude simpler than having to work in C++ inside LuxCore, it would work with GPUs too, etc.

You would have only to write a script reading a scene and a text file with the list of points to probe and it would have only to do a rendering for each probe. It could be also implemented in Blender as a tool (as second step).
Support LuxCoreRender project with salts and bounties
pro
Posts: 23
Joined: Wed Dec 12, 2018 7:48 am

Re: Lux measurement using Irradiance feature

Post by pro »

Thanks for this idea! If I understand it correctly, my python code should look something like this, written in pseudo-code (please correct me if I'm wrong):

Code: Select all

# PSEUDO CODE for BlenderPY API
camera = Camera("panoramic")
render = Render()
# Set boundaries
render.border_min_y = 0.5  #border rendering
render.border_max_y = 1
render.set_aov = lux (where lux is defined as lumen/m^2)

P = chosen plane
probe_points = chosen points on P

for probe_point in probe_points:
	camera.location = probe_point.location	
	# Align z axis of the camera with respect to planes normal
	camera.local_z_axis = the same direction as normal vector of P in probe_point
	lux_value_in_probe_point = somehow a summation (?) of values of rendered pixels from the upper half of render
Related to C++ code and this solution:
Dade wrote: Tue Jan 22, 2019 7:41 pm Each pixel of the upper half of the image is the radiance received by the hemisphere over the probe. It can be transformed in irradiance or whatever you want.
To transform it to lux value, I would still need to implement the new camera type, derived from panoramic in C++, if I understood correctly?

Would be the final value simply the summation of all pixel values on my "lux" AOV?
Last edited by pro on Mon Jan 28, 2019 10:10 am, edited 3 times in total.
User avatar
B.Y.O.B.
Developer
Developer
Posts: 4146
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Lux measurement using Irradiance feature

Post by B.Y.O.B. »

pro wrote: Wed Jan 23, 2019 8:13 am

Code: Select all

camera.border_rendering(only upper half)
In Blender, the border is not a property of the camera, but of scene.render: https://docs.blender.org/api/2.79/bpy.t ... rder_max_x
pro wrote: Wed Jan 23, 2019 8:13 am

Code: Select all

camera.measure_unit = lux (where lux defined as lumen/m^2)
This is not necessary.
pro
Posts: 23
Joined: Wed Dec 12, 2018 7:48 am

Re: Lux measurement using Irradiance feature

Post by pro »

B.Y.O.B. wrote: Wed Jan 23, 2019 9:46 am In Blender, the border is not a property of the camera, but of scene.render: https://docs.blender.org/api/2.79/bpy.t ... rder_max_x
Thank you for comments - excuse me for not being that accurate with pseudocode before (I updated it now according to your suggestions). I hope that now I correctly described the general Dade's idea, he had in mind in his last described approach :?:
User avatar
Dade
Developer
Developer
Posts: 5672
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: Lux measurement using Irradiance feature

Post by Dade »

pro wrote: Wed Jan 23, 2019 10:46 am I hope that now I correctly described the general Dade's idea, he had in mind in his last described approach :?:
Yes, for instance irradiance on a probe is just: Average(<upper half pixel value> * Dot(<probe normal>, <pixel hemispherical direction>) / PI)
Support LuxCoreRender project with salts and bounties
pro
Posts: 23
Joined: Wed Dec 12, 2018 7:48 am

Re: Lux measurement using Irradiance feature

Post by pro »

Dade wrote: Fri Jan 25, 2019 2:23 pm Yes, for instance irradiance on a probe is just: Average(<upper half pixel value> * Dot(<probe normal>, <pixel hemispherical direction>) / PI)
Thank you for your reply! I would like to discuss another idea I was thining about recently, but I'm not sure if it's attainable.
1. Would it be possible to somehow just modify the irradiance logic in C++ and recompile, such that it would measure lux? I would find that kind of solution great, since everything is already integrated in Blender and the result is a "heatmap" (also possible to draw contours) instead of outputing values on n probe points? Excuse me for the possible misconceptions..
2. In which file could I find the low level "formula" that calculates value for already implemented irradiance - is it implemented in "engines" src for each engine or somewhere else? I think I have found a part of the logic inside pathoclbase_funcs.cl:

Code: Select all

	const float weight = misEnabled ? PowerHeuristic(directLightSamplingPdfW, bsdfPdfW) : 1.f;
	const float3 lightRadiance = VLOAD3F(info->lightRadiance.c);
	VSTORE3F(bsdfEval * (weight * factor) * lightRadiance, info->lightRadiance.c);
#if defined(PARAM_FILM_CHANNELS_HAS_IRRADIANCE)
	VSTORE3F(factor * lightRadiance, info->lightIrradiance.c);
#endif
3. My guess was that PowerHeuristic gives Watts in equation irradiance=lm/W, and I would need to somehow get only lm from this part of the code and devide by area, to obtain lm/m²=lux. Is that the place where the code could be manipulated to obtain lux?
Thanks for your time answering my question!
Post Reply