2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "device/device.h"
|
2020-03-19 08:33:03 +00:00
|
|
|
#include "render/buffers.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
|
|
|
|
#include "util/util_foreach.h"
|
|
|
|
#include "util/util_hash.h"
|
|
|
|
#include "util/util_math.h"
|
|
|
|
#include "util/util_opengl.h"
|
|
|
|
#include "util/util_time.h"
|
|
|
|
#include "util/util_types.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
/* Buffer Params */
|
|
|
|
|
|
|
|
BufferParams::BufferParams()
|
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
width = 0;
|
|
|
|
height = 0;
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
full_x = 0;
|
|
|
|
full_y = 0;
|
|
|
|
full_width = 0;
|
|
|
|
full_height = 0;
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
denoising_data_pass = false;
|
|
|
|
denoising_clean_pass = false;
|
|
|
|
denoising_prefiltered_pass = false;
|
2020-01-31 14:23:17 +00:00
|
|
|
|
|
|
|
Pass::add(PASS_COMBINED, passes);
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void BufferParams::get_offset_stride(int &offset, int &stride)
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
offset = -(full_x + full_y * width);
|
|
|
|
stride = width;
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
bool BufferParams::modified(const BufferParams ¶ms)
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
return !(full_x == params.full_x && full_y == params.full_y && width == params.width &&
|
|
|
|
height == params.height && full_width == params.full_width &&
|
2019-12-11 17:11:46 +00:00
|
|
|
full_height == params.full_height && Pass::equals(passes, params.passes) &&
|
|
|
|
denoising_data_pass == params.denoising_data_pass &&
|
|
|
|
denoising_clean_pass == params.denoising_clean_pass &&
|
|
|
|
denoising_prefiltered_pass == params.denoising_prefiltered_pass);
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int BufferParams::get_passes_size()
|
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
int size = 0;
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
for (size_t i = 0; i < passes.size(); i++)
|
|
|
|
size += passes[i].components;
|
2017-05-07 12:40:58 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
if (denoising_data_pass) {
|
|
|
|
size += DENOISING_PASS_SIZE_BASE;
|
|
|
|
if (denoising_clean_pass)
|
|
|
|
size += DENOISING_PASS_SIZE_CLEAN;
|
|
|
|
if (denoising_prefiltered_pass)
|
|
|
|
size += DENOISING_PASS_SIZE_PREFILTERED;
|
|
|
|
}
|
2017-05-07 12:40:58 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
return align_up(size, 4);
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
}
|
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
int BufferParams::get_denoising_offset()
|
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
int offset = 0;
|
2017-05-07 12:40:58 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
for (size_t i = 0; i < passes.size(); i++)
|
|
|
|
offset += passes[i].components;
|
2017-05-07 12:40:58 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
return offset;
|
2017-05-07 12:40:58 +00:00
|
|
|
}
|
|
|
|
|
2019-02-06 11:42:10 +00:00
|
|
|
int BufferParams::get_denoising_prefiltered_offset()
|
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(denoising_prefiltered_pass);
|
2019-02-06 11:42:10 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
int offset = get_denoising_offset();
|
2019-02-06 11:42:10 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
offset += DENOISING_PASS_SIZE_BASE;
|
|
|
|
if (denoising_clean_pass) {
|
|
|
|
offset += DENOISING_PASS_SIZE_CLEAN;
|
|
|
|
}
|
2019-02-06 11:42:10 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
return offset;
|
2019-02-06 11:42:10 +00:00
|
|
|
}
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* Render Buffer Task */
|
|
|
|
|
|
|
|
RenderTile::RenderTile()
|
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
w = 0;
|
|
|
|
h = 0;
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
sample = 0;
|
|
|
|
start_sample = 0;
|
|
|
|
num_samples = 0;
|
|
|
|
resolution = 0;
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
offset = 0;
|
|
|
|
stride = 0;
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
buffer = 0;
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
buffers = NULL;
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Render Buffers */
|
|
|
|
|
2017-10-20 21:31:13 +00:00
|
|
|
RenderBuffers::RenderBuffers(Device *device)
|
2019-04-17 04:17:24 +00:00
|
|
|
: buffer(device, "RenderBuffers", MEM_READ_WRITE),
|
|
|
|
map_neighbor_copied(false),
|
|
|
|
render_time(0.0f)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderBuffers::~RenderBuffers()
|
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
buffer.free();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void RenderBuffers::reset(BufferParams ¶ms_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
params = params_;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
/* re-allocate buffer */
|
2020-02-11 15:30:01 +00:00
|
|
|
buffer.alloc(params.width * params.get_passes_size(), params.height);
|
2019-04-17 04:17:24 +00:00
|
|
|
buffer.zero_to_device();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
void RenderBuffers::zero()
|
2017-09-27 01:53:03 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
buffer.zero_to_device();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
bool RenderBuffers::copy_from_device()
|
2011-08-28 13:55:59 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
if (!buffer.device_pointer)
|
|
|
|
return false;
|
2011-08-28 13:55:59 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
buffer.copy_from_device(0, params.width * params.get_passes_size(), params.height);
|
2017-05-07 12:40:58 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
return true;
|
2017-05-07 12:40:58 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
bool RenderBuffers::get_denoising_pass_rect(
|
|
|
|
int type, float exposure, int sample, int components, float *pixels)
|
2017-05-07 12:40:58 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
if (buffer.data() == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
float scale = 1.0f;
|
|
|
|
float alpha_scale = 1.0f / sample;
|
|
|
|
if (type == DENOISING_PASS_PREFILTERED_COLOR || type == DENOISING_PASS_CLEAN ||
|
|
|
|
type == DENOISING_PASS_PREFILTERED_INTENSITY) {
|
|
|
|
scale *= exposure;
|
|
|
|
}
|
|
|
|
else if (type == DENOISING_PASS_PREFILTERED_VARIANCE) {
|
|
|
|
scale *= exposure * exposure * (sample - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int offset;
|
|
|
|
if (type == DENOISING_PASS_CLEAN) {
|
|
|
|
/* The clean pass isn't changed by prefiltering, so we use the original one there. */
|
|
|
|
offset = type + params.get_denoising_offset();
|
|
|
|
scale /= sample;
|
|
|
|
}
|
2019-12-11 17:11:46 +00:00
|
|
|
else if (params.denoising_prefiltered_pass) {
|
|
|
|
offset = type + params.get_denoising_prefiltered_offset();
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-12-11 17:11:46 +00:00
|
|
|
switch (type) {
|
|
|
|
case DENOISING_PASS_PREFILTERED_DEPTH:
|
|
|
|
offset = params.get_denoising_offset() + DENOISING_PASS_DEPTH;
|
|
|
|
break;
|
|
|
|
case DENOISING_PASS_PREFILTERED_NORMAL:
|
|
|
|
offset = params.get_denoising_offset() + DENOISING_PASS_NORMAL;
|
|
|
|
break;
|
|
|
|
case DENOISING_PASS_PREFILTERED_ALBEDO:
|
|
|
|
offset = params.get_denoising_offset() + DENOISING_PASS_ALBEDO;
|
|
|
|
break;
|
|
|
|
case DENOISING_PASS_PREFILTERED_COLOR:
|
|
|
|
/* If we're not saving the prefiltering result, return the original noisy pass. */
|
|
|
|
offset = params.get_denoising_offset() + DENOISING_PASS_COLOR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
scale /= sample;
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int pass_stride = params.get_passes_size();
|
|
|
|
int size = params.width * params.height;
|
|
|
|
|
|
|
|
float *in = buffer.data() + offset;
|
|
|
|
|
|
|
|
if (components == 1) {
|
|
|
|
for (int i = 0; i < size; i++, in += pass_stride, pixels++) {
|
|
|
|
pixels[0] = in[0] * scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (components == 3) {
|
|
|
|
for (int i = 0; i < size; i++, in += pass_stride, pixels += 3) {
|
|
|
|
pixels[0] = in[0] * scale;
|
|
|
|
pixels[1] = in[1] * scale;
|
|
|
|
pixels[2] = in[2] * scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (components == 4) {
|
|
|
|
/* Since the alpha channel is not involved in denoising, output the Combined alpha channel. */
|
|
|
|
assert(params.passes[0].type == PASS_COMBINED);
|
|
|
|
float *in_combined = buffer.data();
|
|
|
|
|
|
|
|
for (int i = 0; i < size; i++, in += pass_stride, in_combined += pass_stride, pixels += 4) {
|
2019-05-31 20:38:50 +00:00
|
|
|
float3 val = make_float3(in[0], in[1], in[2]);
|
|
|
|
if (type == DENOISING_PASS_PREFILTERED_COLOR && params.denoising_prefiltered_pass) {
|
|
|
|
/* Remove highlight compression from the image. */
|
|
|
|
val = color_highlight_uncompress(val);
|
|
|
|
}
|
|
|
|
pixels[0] = val.x * scale;
|
|
|
|
pixels[1] = val.y * scale;
|
|
|
|
pixels[2] = val.z * scale;
|
2019-04-17 04:17:24 +00:00
|
|
|
pixels[3] = saturate(in_combined[3] * alpha_scale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
bool RenderBuffers::get_pass_rect(
|
2019-12-04 18:57:28 +00:00
|
|
|
const string &name, float exposure, int sample, int components, float *pixels)
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
if (buffer.data() == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-06 21:19:01 +00:00
|
|
|
float *sample_count = NULL;
|
|
|
|
if (name == "Combined") {
|
|
|
|
int sample_offset = 0;
|
|
|
|
for (size_t j = 0; j < params.passes.size(); j++) {
|
|
|
|
Pass &pass = params.passes[j];
|
|
|
|
if (pass.type != PASS_SAMPLE_COUNT) {
|
|
|
|
sample_offset += pass.components;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sample_count = buffer.data() + sample_offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
int pass_offset = 0;
|
|
|
|
|
|
|
|
for (size_t j = 0; j < params.passes.size(); j++) {
|
|
|
|
Pass &pass = params.passes[j];
|
|
|
|
|
2019-12-04 18:57:28 +00:00
|
|
|
/* Pass is identified by both type and name, multiple of the same type
|
|
|
|
* may exist with a different name. */
|
|
|
|
if (pass.name != name) {
|
2019-04-17 04:17:24 +00:00
|
|
|
pass_offset += pass.components;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-12-04 18:57:28 +00:00
|
|
|
PassType type = pass.type;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
|
|
|
float *in = buffer.data() + pass_offset;
|
|
|
|
int pass_stride = params.get_passes_size();
|
|
|
|
|
2020-04-06 21:19:01 +00:00
|
|
|
float scale = (pass.filter) ? 1.0f / (float)sample : 1.0f;
|
|
|
|
float scale_exposure = (pass.exposure) ? scale * exposure : scale;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
|
|
|
int size = params.width * params.height;
|
|
|
|
|
|
|
|
if (components == 1 && type == PASS_RENDER_TIME) {
|
|
|
|
/* Render time is not stored by kernel, but measured per tile. */
|
|
|
|
float val = (float)(1000.0 * render_time / (params.width * params.height * sample));
|
|
|
|
for (int i = 0; i < size; i++, pixels++) {
|
|
|
|
pixels[0] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (components == 1) {
|
|
|
|
assert(pass.components == components);
|
|
|
|
|
|
|
|
/* Scalar */
|
|
|
|
if (type == PASS_DEPTH) {
|
|
|
|
for (int i = 0; i < size; i++, in += pass_stride, pixels++) {
|
|
|
|
float f = *in;
|
2020-04-06 21:19:01 +00:00
|
|
|
pixels[0] = (f == 0.0f) ? 1e10f : f * scale_exposure;
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == PASS_MIST) {
|
|
|
|
for (int i = 0; i < size; i++, in += pass_stride, pixels++) {
|
2020-04-06 21:19:01 +00:00
|
|
|
float f = *in;
|
|
|
|
pixels[0] = saturate(f * scale_exposure);
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-04 13:00:26 +00:00
|
|
|
#ifdef WITH_CYCLES_DEBUG
|
2019-04-17 04:17:24 +00:00
|
|
|
else if (type == PASS_BVH_TRAVERSED_NODES || type == PASS_BVH_TRAVERSED_INSTANCES ||
|
|
|
|
type == PASS_BVH_INTERSECTIONS || type == PASS_RAY_BOUNCES) {
|
|
|
|
for (int i = 0; i < size; i++, in += pass_stride, pixels++) {
|
2020-04-06 21:19:01 +00:00
|
|
|
float f = *in;
|
2019-04-17 04:17:24 +00:00
|
|
|
pixels[0] = f * scale;
|
|
|
|
}
|
|
|
|
}
|
2014-10-04 13:00:26 +00:00
|
|
|
#endif
|
2019-04-17 04:17:24 +00:00
|
|
|
else {
|
|
|
|
for (int i = 0; i < size; i++, in += pass_stride, pixels++) {
|
2020-04-06 21:19:01 +00:00
|
|
|
float f = *in;
|
|
|
|
pixels[0] = f * scale_exposure;
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (components == 3) {
|
|
|
|
assert(pass.components == 4);
|
|
|
|
|
|
|
|
/* RGBA */
|
|
|
|
if (type == PASS_SHADOW) {
|
|
|
|
for (int i = 0; i < size; i++, in += pass_stride, pixels += 3) {
|
|
|
|
float4 f = make_float4(in[0], in[1], in[2], in[3]);
|
|
|
|
float invw = (f.w > 0.0f) ? 1.0f / f.w : 1.0f;
|
|
|
|
|
|
|
|
pixels[0] = f.x * invw;
|
|
|
|
pixels[1] = f.y * invw;
|
|
|
|
pixels[2] = f.z * invw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pass.divide_type != PASS_NONE) {
|
|
|
|
/* RGB lighting passes that need to divide out color */
|
|
|
|
pass_offset = 0;
|
|
|
|
for (size_t k = 0; k < params.passes.size(); k++) {
|
|
|
|
Pass &color_pass = params.passes[k];
|
|
|
|
if (color_pass.type == pass.divide_type)
|
|
|
|
break;
|
|
|
|
pass_offset += color_pass.components;
|
|
|
|
}
|
|
|
|
|
|
|
|
float *in_divide = buffer.data() + pass_offset;
|
|
|
|
|
|
|
|
for (int i = 0; i < size; i++, in += pass_stride, in_divide += pass_stride, pixels += 3) {
|
|
|
|
float3 f = make_float3(in[0], in[1], in[2]);
|
|
|
|
float3 f_divide = make_float3(in_divide[0], in_divide[1], in_divide[2]);
|
|
|
|
|
2020-04-06 21:19:01 +00:00
|
|
|
f = safe_divide_even_color(f * exposure, f_divide);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
|
|
|
pixels[0] = f.x;
|
|
|
|
pixels[1] = f.y;
|
|
|
|
pixels[2] = f.z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* RGB/vector */
|
|
|
|
for (int i = 0; i < size; i++, in += pass_stride, pixels += 3) {
|
2020-04-06 21:19:01 +00:00
|
|
|
float3 f = make_float3(in[0], in[1], in[2]);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
|
|
|
pixels[0] = f.x * scale_exposure;
|
|
|
|
pixels[1] = f.y * scale_exposure;
|
|
|
|
pixels[2] = f.z * scale_exposure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (components == 4) {
|
|
|
|
assert(pass.components == components);
|
|
|
|
|
|
|
|
/* RGBA */
|
|
|
|
if (type == PASS_SHADOW) {
|
|
|
|
for (int i = 0; i < size; i++, in += pass_stride, pixels += 4) {
|
|
|
|
float4 f = make_float4(in[0], in[1], in[2], in[3]);
|
|
|
|
float invw = (f.w > 0.0f) ? 1.0f / f.w : 1.0f;
|
|
|
|
|
|
|
|
pixels[0] = f.x * invw;
|
|
|
|
pixels[1] = f.y * invw;
|
|
|
|
pixels[2] = f.z * invw;
|
|
|
|
pixels[3] = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == PASS_MOTION) {
|
|
|
|
/* need to normalize by number of samples accumulated for motion */
|
|
|
|
pass_offset = 0;
|
|
|
|
for (size_t k = 0; k < params.passes.size(); k++) {
|
|
|
|
Pass &color_pass = params.passes[k];
|
|
|
|
if (color_pass.type == PASS_MOTION_WEIGHT)
|
|
|
|
break;
|
|
|
|
pass_offset += color_pass.components;
|
|
|
|
}
|
|
|
|
|
|
|
|
float *in_weight = buffer.data() + pass_offset;
|
|
|
|
|
|
|
|
for (int i = 0; i < size; i++, in += pass_stride, in_weight += pass_stride, pixels += 4) {
|
|
|
|
float4 f = make_float4(in[0], in[1], in[2], in[3]);
|
|
|
|
float w = in_weight[0];
|
|
|
|
float invw = (w > 0.0f) ? 1.0f / w : 0.0f;
|
|
|
|
|
|
|
|
pixels[0] = f.x * invw;
|
|
|
|
pixels[1] = f.y * invw;
|
|
|
|
pixels[2] = f.z * invw;
|
|
|
|
pixels[3] = f.w * invw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == PASS_CRYPTOMATTE) {
|
|
|
|
for (int i = 0; i < size; i++, in += pass_stride, pixels += 4) {
|
2020-04-06 21:19:01 +00:00
|
|
|
float4 f = make_float4(in[0], in[1], in[2], in[3]);
|
2019-04-17 04:17:24 +00:00
|
|
|
/* x and z contain integer IDs, don't rescale them.
|
|
|
|
y and w contain matte weights, they get scaled. */
|
|
|
|
pixels[0] = f.x;
|
|
|
|
pixels[1] = f.y * scale;
|
|
|
|
pixels[2] = f.z;
|
|
|
|
pixels[3] = f.w * scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (int i = 0; i < size; i++, in += pass_stride, pixels += 4) {
|
2020-04-06 21:19:01 +00:00
|
|
|
if (sample_count && sample_count[i * pass_stride] < 0.0f) {
|
|
|
|
scale = (pass.filter) ? -1.0f / (sample_count[i * pass_stride]) : 1.0f;
|
|
|
|
scale_exposure = (pass.exposure) ? scale * exposure : scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
float4 f = make_float4(in[0], in[1], in[2], in[3]);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
|
|
|
pixels[0] = f.x * scale_exposure;
|
|
|
|
pixels[1] = f.y * scale_exposure;
|
|
|
|
pixels[2] = f.z * scale_exposure;
|
|
|
|
|
|
|
|
/* clamp since alpha might be > 1.0 due to russian roulette */
|
|
|
|
pixels[3] = saturate(f.w * scale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2011-08-28 13:55:59 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Display Buffer */
|
|
|
|
|
2017-10-20 21:31:13 +00:00
|
|
|
DisplayBuffer::DisplayBuffer(Device *device, bool linear)
|
2019-04-17 04:17:24 +00:00
|
|
|
: draw_width(0),
|
|
|
|
draw_height(0),
|
|
|
|
transparent(true), /* todo: determine from background */
|
|
|
|
half_float(linear),
|
|
|
|
rgba_byte(device, "display buffer byte"),
|
|
|
|
rgba_half(device, "display buffer half")
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DisplayBuffer::~DisplayBuffer()
|
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
rgba_byte.free();
|
|
|
|
rgba_half.free();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void DisplayBuffer::reset(BufferParams ¶ms_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
draw_width = 0;
|
|
|
|
draw_height = 0;
|
|
|
|
|
|
|
|
params = params_;
|
|
|
|
|
|
|
|
/* allocate display pixels */
|
|
|
|
if (half_float) {
|
|
|
|
rgba_half.alloc_to_device(params.width, params.height);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rgba_byte.alloc_to_device(params.width, params.height);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2011-12-20 12:25:37 +00:00
|
|
|
void DisplayBuffer::draw_set(int width, int height)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
assert(width <= params.width && height <= params.height);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
draw_width = width;
|
|
|
|
draw_height = height;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
void DisplayBuffer::draw(Device *device, const DeviceDrawParams &draw_params)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
if (draw_width != 0 && draw_height != 0) {
|
|
|
|
device_memory &rgba = (half_float) ? (device_memory &)rgba_half : (device_memory &)rgba_byte;
|
|
|
|
|
|
|
|
device->draw_pixels(rgba,
|
|
|
|
0,
|
|
|
|
draw_width,
|
|
|
|
draw_height,
|
|
|
|
params.width,
|
|
|
|
params.height,
|
|
|
|
params.full_x,
|
|
|
|
params.full_y,
|
|
|
|
params.full_width,
|
|
|
|
params.full_height,
|
|
|
|
transparent,
|
|
|
|
draw_params);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DisplayBuffer::draw_ready()
|
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
return (draw_width != 0 && draw_height != 0);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|