General baking questions

Discussion related to the LuxCore functionality, implementations and API.
Post Reply
Silverlan
Posts: 7
Joined: Tue Feb 09, 2021 7:54 am

General baking questions

Post by Silverlan »

Hello!

I'm trying to get accustomed to how baking works in LuxCoreRender, however there are a few points I'm a little confused about:
1) I've tried baking the lightmaps for the bake demo scene (https://github.com/LuxCoreRender/LuxCor ... r-bake.cfg) using luxcoreconsole.
The scene has both a film output and a bake output defined:

Code: Select all

film.outputs.0.type = "RGBA_IMAGEPIPELINE"
film.outputs.0.filename = "RGBA_IMAGEPIPELINE_0.png"
film.outputs.0.index = "0"

bake.maps.0.type = "LIGHTMAP"
bake.maps.0.filename = "1398588469529680.exr"
The bake output file looks correct:
Image
But what exactly is the purpose of the film output in this case? It looks completely different and it places everything weirdly into a corner of the image:
Image

2) I want the lightmaps with the original, unmodified HDR colors, i.e. no gamma correction, no tone-mapping, etc. So, I've tried this configuration with just NOP in the image pipeline:

Code: Select all

renderengine.type = "BAKECPU"
sampler.type = "SOBOL"
film.filter.type = "BLACKMANHARRIS"
film.filter.width = 4
film.width = 1024
film.height = 1024
batch.haltspp = 512
batch.haltnoisethreshold = 0.03
film.outputs.0.type = "RGBA"
film.outputs.0.filename = "RGBA_0.exr"
film.outputs.0.index = "0"
film.imagepipelines.0.0.type = "NOP"
bake.minmapautosize = 256
bake.maxmapautosize = 512
bake.powerof2autosize.enable = 1
bake.maps.0.type = "LIGHTMAP"
bake.maps.0.filename = "1398588469529680.exr"
bake.maps.0.imagepipelineindex = 0
bake.maps.0.autosize.enabled = 1
bake.maps.0.uvindex = 0
bake.maps.0.objectnames = "1398588469529680"
scene.file = "scene.scn"
However, this just causes LuxCoreRender to crash in "CUDADevice::EnqueueWriteBuffer":
Image

If I also add a linear tonemap with a scale of 1 (which should be equivalent to NOP if I'm understanding it correctly), it works:

Code: Select all

renderengine.type = "BAKECPU"
sampler.type = "SOBOL"
film.filter.type = "BLACKMANHARRIS"
film.filter.width = 4
film.width = 1024
film.height = 1024
batch.haltspp = 512
batch.haltnoisethreshold = 0.03
film.outputs.0.type = "RGBA"
film.outputs.0.filename = "RGBA_0.exr"
film.outputs.0.index = "0"
film.imagepipelines.0.0.type = "NOP"
film.imagepipelines.0.1.type = "TONEMAP_LINEAR"
film.imagepipelines.0.1.scale = "1"
bake.minmapautosize = 256
bake.maxmapautosize = 512
bake.powerof2autosize.enable = 1
bake.maps.0.type = "LIGHTMAP"
bake.maps.0.filename = "1398588469529680.exr"
bake.maps.0.imagepipelineindex = 0
bake.maps.0.autosize.enabled = 1
bake.maps.0.uvindex = 0
bake.maps.0.objectnames = "1398588469529680"
scene.file = "scene.scn"
Is this a bug, or am I missing something?

3) I want to do my own post-processing, so instead of saving the image data to a file, I'd just like to copy it to a buffer instead. For regular non-bake renders, I can just use film.GetOutput<float>(...) (instead of film.SaveOutputs()) and it works just fine:

Code: Select all

// Save the rendered image
// session->GetFilm().SaveOutputs();
auto &film = session->GetFilm();
std::vector<float> data {};
data.resize(film.GetWidth() *film.GetHeight() *4);
session->GetFilm().GetOutput<float>(luxcore::Film::FilmOutputType::OUTPUT_RGBA,data.data());
stbi_write_hdr("bake.hdr",film.GetWidth(),film.GetHeight(),4,data.data());
However, if I do that for baking, the result is similar to the film output, where everything is squeezed into a corner:
Image

Is there some way to get the same data that is used for the actual bake outputs without having to save it to a file and then re-reading it?
User avatar
Dade
Developer
Developer
Posts: 5672
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: General baking questions

Post by Dade »

Silverlan wrote: Tue Feb 16, 2021 9:29 am But what exactly is the purpose of the film output in this case? It looks completely different and it places everything weirdly into a corner of the image:
It is there to just provide some visual feedback of the ongoing rendering when using LuxCoreUI.
Silverlan wrote: Tue Feb 16, 2021 9:29 am Is this a bug, or am I missing something?
It looks like a bug when using NOP image pipeline plugin with CUDA, I have to check. As work around you can force the image pipeline to run on CPU and there should be no problem.
Silverlan wrote: Tue Feb 16, 2021 9:29 am Is there some way to get the same data that is used for the actual bake outputs without having to save it to a file and then re-reading it?
No, it wasn't really intended to be originally used from the API. You have no information when one baked map is ready (when you are rendering multiple maps) so you can only render a single map per session and you can crop the output you receive with GetOutput<float>(): the baked map is just placed in the upper left corner of the film.
Support LuxCoreRender project with salts and bounties
Silverlan
Posts: 7
Joined: Tue Feb 09, 2021 7:54 am

Re: General baking questions

Post by Silverlan »

Dade wrote: Tue Feb 16, 2021 11:37 am It looks like a bug when using NOP image pipeline plugin with CUDA, I have to check. As work around you can force the image pipeline to run on CPU and there should be no problem.
Am I correct in assuming that linear tonemap with a scale of 1 is equivalent to NOP?
Dade wrote: Tue Feb 16, 2021 11:37 am It looks like a bug when using NOP image pipeline plugin with CUDA, I have to check. As work around you can force the image pipeline to run on CPU and there should be no problem.
Setting

Code: Select all

film.opencl.enable = "0"
still causes it to crash when using NOP with nothing else. Is that how you would disable CUDA? I can't actually find any option particular to CUDA.

Also, I'm not sure if I'm misconfiguring something, but the results I'm getting from the BAKECPU render engine look very different compared to normal renders.
I've set up a small example scene here: https://pragma-engine.com/share/luxcore_bake_test.zip
It includes two configurations:
• render-image.cfg: Regular render using PATHOCL render engine

Code: Select all

renderengine.type = "PATHOCL"
sampler.type = "SOBOL"
batch.halttime = 4320000
context.cuda.optix.enable = "1"
film.opencl.enable = "0"
film.opencl.platform = "-1"
film.opencl.device = "-1"
batch.haltspp = 20
film.spp = 20
film.width = 1920
film.height = 1080
film.outputs.0.type = "RGBA"
film.outputs.0.filename = "output.exr"
film.outputs.0.filesafe = "0"
film.outputs.0.index = "0"
film.outputs.1.type = "ALBEDO"
film.outputs.1.filename = "albedo.exr"
film.outputs.1.filesafe = "0"
film.outputs.2.type = "AVG_SHADING_NORMAL"
film.outputs.2.filename = "normal.exr"
film.outputs.2.filesafe = "0"
scene.file = "scene.scn"
• bake.cfg: Bake render using BAKECPU render engine

Code: Select all

renderengine.type = "BAKECPU"
sampler.type = "SOBOL"
batch.halttime = 4320000
context.cuda.optix.enable = "1"
film.opencl.enable = "0"
film.opencl.platform = "-1"
film.opencl.device = "-1"
bake.minmapautosize = 256
bake.maxmapautosize = 512
bake.powerof2autosize.enable = 0
bake.maps.0.type = "LIGHTMAP"
bake.maps.0.filename = "lightmap_atlas.exr"
bake.maps.0.imagepipelineindex = 0
bake.maps.0.autosize.enabled = 0
bake.maps.0.uvindex = 1
bake.maps.0.width = 1024
bake.maps.0.height = 1024
bake.maps.0.objectnames = "0_0" "0_1" "0_2" "0_3" "0_4" "0_5" "0_6" "0_7" "0_8" "0_9" "0_10" "0_11" "0_12" "0_13" "0_14" "0_15" "0_16"
film.filter.type = "BLACKMANHARRIS"
film.filter.width = 4
batch.haltnoisethreshold = 0.03
batch.haltspp = 200
film.spp = 200
film.imagepipelines.0.0.type = "TONEMAP_LINEAR"
film.imagepipelines.0.0.scale = "1"
film.outputs.0.type = "RGBA"
film.outputs.0.filename = "RGBA_0.exr"
film.outputs.0.filesafe = "0"
film.outputs.0.index = "0"
scene.file = "scene.scn"
Both use the same scene file, i.e. lights, objects, meshes, etc. are all identical. This is the result from the render-image.cfg:
Image

And this is the result using the bake.cfg:
Image

The lightmap UVs cover the entire scene, but for whatever reason everything just comes out as extremely dark and noisy (even at a high sample count, but that's presumably because it's just so dark).
What could cause this difference between the renders?

// Edit:
So it looks like the reason for the dark lighting is the linear tone-mapping I used as a work-around for the NOP issue:

Code: Select all

film.imagepipelines.0.0.type = "TONEMAP_LINEAR"
film.imagepipelines.0.0.scale = "1"
I don't really understand why though. The wiki page for tone-mapping (https://wiki.luxcorerender.org/ImagePip ... Tonemapper) states:

Code: Select all

Linear Tonemapper
Simply multiplies all pixels in the image with the scale value.
But if that's the case, a scale value of 1 should not affect the image, right?

// Edit:
I'm a little confused, I was under the impression that the "RGB" and "RGBA" output types (as opposed to "RGB_IMAGEPIPELINE" and "RGBA_IMAGEPIPELINE") do not get affected by the image pipeline. Yet when I add something to the pipeline, it does affect the image:

Code: Select all

renderengine.type = "PATHOCL"
sampler.type = "SOBOL"
batch.halttime = 4320000
context.cuda.optix.enable = "1"
film.opencl.enable = "0"
film.opencl.platform = "-1"
film.opencl.device = "-1"
batch.haltspp = 20
film.spp = 20
film.width = 1920
film.height = 1080
film.outputs.0.type = "RGBA"
film.outputs.0.filename = "output.exr"
film.outputs.0.filesafe = "0"
film.outputs.0.index = "0"
film.outputs.1.type = "ALBEDO"
film.outputs.1.filename = "albedo.exr"
film.outputs.1.filesafe = "0"
film.outputs.2.type = "AVG_SHADING_NORMAL"
film.outputs.2.filename = "normal.exr"
film.outputs.2.filesafe = "0"
scene.file = "scene.scn"
film.imagepipelines.0.0.type = "TONEMAP_LINEAR"
film.imagepipelines.0.0.scale = "1"
WITHOUT the tonemap linear:
Image

WITH tonemap linear:
Image

Is this always the case, or just when using the luxcoreui program?
User avatar
Dade
Developer
Developer
Posts: 5672
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: General baking questions

Post by Dade »

Silverlan wrote: Wed Feb 17, 2021 1:58 pm Am I correct in assuming that linear tonemap with a scale of 1 is equivalent to NOP?
Yes for any practical purpose aside from some side effect, performance difference and the fact that "x * 1.f" may be not always exactly equal to "x" with 32bit floating point numbers.
Silverlan wrote: Wed Feb 17, 2021 1:58 pm Setting

Code: Select all

film.opencl.enable = "0"
still causes it to crash when using NOP with nothing else. Is that how you would disable CUDA?
Yes anyway I should have fixed the problem with the NOP plugin in the latest source.
Silverlan wrote: Wed Feb 17, 2021 1:58 pm Is this always the case, or just when using the luxcoreui program?
If you don't define any image pipe line, LuxCore uses a default one: https://github.com/LuxCoreRender/LuxCor ... s.cpp#L141 (AutoLinear + Gamma correction)

Linear scale between [0.0, 1.0] while AutoLinear between [0.0, <Max. image color>]. This may explain what you are observing. It is also true for any LuxCore API application (LuxCoreUI or not).
Support LuxCoreRender project with salts and bounties
User avatar
Dade
Developer
Developer
Posts: 5672
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: General baking questions

Post by Dade »

Silverlan wrote: Wed Feb 17, 2021 1:58 pm // Edit:
I'm a little confused, I was under the impression that the "RGB" and "RGBA" output types (as opposed to "RGB_IMAGEPIPELINE" and "RGBA_IMAGEPIPELINE") do not get affected by the image pipeline.
Yes, "RGB" and "RGBA" are the raw HDR rendering (i.e. the input of the image pipeline while *_IMAGEPIPELINE are the output).
Support LuxCoreRender project with salts and bounties
Post Reply