2011-04-27 11:58:34 +00:00
|
|
|
/*
|
|
|
|
* Adapted from Open Shading Language with this license:
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Modifications Copyright 2011, Blender Foundation.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* * Neither the name of Sony Pictures Imageworks nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __OSL_CLOSURES_H__
|
|
|
|
#define __OSL_CLOSURES_H__
|
|
|
|
|
2013-08-14 06:51:18 +00:00
|
|
|
#include "util_types.h"
|
|
|
|
#include "kernel_types.h"
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
#include <OSL/oslclosure.h>
|
|
|
|
#include <OSL/oslexec.h>
|
|
|
|
#include <OSL/genclosure.h>
|
|
|
|
|
2012-10-20 12:18:00 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-06 16:28:02 +00:00
|
|
|
OSL::ClosureParam *closure_emission_params();
|
|
|
|
OSL::ClosureParam *closure_background_params();
|
|
|
|
OSL::ClosureParam *closure_holdout_params();
|
2012-11-06 19:59:02 +00:00
|
|
|
OSL::ClosureParam *closure_ambient_occlusion_params();
|
2012-12-11 14:39:41 +00:00
|
|
|
OSL::ClosureParam *closure_bsdf_diffuse_ramp_params();
|
2012-12-19 21:17:16 +00:00
|
|
|
OSL::ClosureParam *closure_bsdf_phong_ramp_params();
|
2013-08-18 14:15:57 +00:00
|
|
|
OSL::ClosureParam *closure_bssrdf_cubic_params();
|
|
|
|
OSL::ClosureParam *closure_bssrdf_gaussian_params();
|
2016-02-03 22:34:49 +00:00
|
|
|
OSL::ClosureParam *closure_bssrdf_burley_params();
|
2013-12-28 00:54:44 +00:00
|
|
|
OSL::ClosureParam *closure_henyey_greenstein_volume_params();
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 20:56:43 +00:00
|
|
|
OSL::ClosureParam *closure_bsdf_microfacet_multi_ggx_params();
|
|
|
|
OSL::ClosureParam *closure_bsdf_microfacet_multi_ggx_glass_params();
|
|
|
|
OSL::ClosureParam *closure_bsdf_microfacet_multi_ggx_aniso_params();
|
2012-10-20 12:18:00 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void closure_emission_prepare(OSL::RendererServices *, int id, void *data);
|
|
|
|
void closure_background_prepare(OSL::RendererServices *, int id, void *data);
|
|
|
|
void closure_holdout_prepare(OSL::RendererServices *, int id, void *data);
|
2012-11-06 19:59:02 +00:00
|
|
|
void closure_ambient_occlusion_prepare(OSL::RendererServices *, int id, void *data);
|
2012-12-11 14:39:41 +00:00
|
|
|
void closure_bsdf_diffuse_ramp_prepare(OSL::RendererServices *, int id, void *data);
|
2012-12-19 21:17:16 +00:00
|
|
|
void closure_bsdf_phong_ramp_prepare(OSL::RendererServices *, int id, void *data);
|
2013-08-18 14:15:57 +00:00
|
|
|
void closure_bssrdf_cubic_prepare(OSL::RendererServices *, int id, void *data);
|
|
|
|
void closure_bssrdf_gaussian_prepare(OSL::RendererServices *, int id, void *data);
|
2016-02-03 22:34:49 +00:00
|
|
|
void closure_bssrdf_burley_prepare(OSL::RendererServices *, int id, void *data);
|
2013-12-28 00:54:44 +00:00
|
|
|
void closure_henyey_greenstein_volume_prepare(OSL::RendererServices *, int id, void *data);
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 20:56:43 +00:00
|
|
|
void closure_bsdf_microfacet_multi_ggx_prepare(OSL::RendererServices *, int id, void *data);
|
|
|
|
void closure_bsdf_microfacet_multi_ggx_glass_prepare(OSL::RendererServices *, int id, void *data);
|
|
|
|
void closure_bsdf_microfacet_multi_ggx_aniso_prepare(OSL::RendererServices *, int id, void *data);
|
2012-11-06 19:59:02 +00:00
|
|
|
|
2013-11-29 01:09:24 +00:00
|
|
|
#define CCLOSURE_PREPARE(name, classname) \
|
2011-04-27 11:58:34 +00:00
|
|
|
void name(RendererServices *, int id, void *data) \
|
|
|
|
{ \
|
|
|
|
memset(data, 0, sizeof(classname)); \
|
|
|
|
new (data) classname(); \
|
|
|
|
}
|
|
|
|
|
2013-11-29 01:09:24 +00:00
|
|
|
#define CCLOSURE_PREPARE_STATIC(name, classname) static CCLOSURE_PREPARE(name, classname)
|
2012-11-21 13:41:47 +00:00
|
|
|
|
2012-12-15 10:18:42 +00:00
|
|
|
#define CLOSURE_FLOAT3_PARAM(st, fld) \
|
2015-08-12 20:17:27 +00:00
|
|
|
{ TypeDesc::TypeVector, (int)reckless_offsetof(st, fld), NULL, sizeof(OSL::Vec3) }
|
2012-12-15 10:18:42 +00:00
|
|
|
|
|
|
|
#define TO_VEC3(v) OSL::Vec3(v.x, v.y, v.z)
|
|
|
|
#define TO_COLOR3(v) OSL::Color3(v.x, v.y, v.z)
|
2012-10-20 12:18:00 +00:00
|
|
|
#define TO_FLOAT3(v) make_float3(v[0], v[1], v[2])
|
|
|
|
|
2013-11-29 01:09:24 +00:00
|
|
|
/* Closure */
|
|
|
|
|
|
|
|
class CClosurePrimitive {
|
|
|
|
public:
|
2016-07-25 01:03:23 +00:00
|
|
|
virtual void setup(ShaderData *sd, int path_flag, float3 weight) = 0;
|
2015-09-23 07:23:37 +00:00
|
|
|
|
|
|
|
OSL::ustring label;
|
2013-11-29 01:09:24 +00:00
|
|
|
};
|
|
|
|
|
2012-10-20 12:18:00 +00:00
|
|
|
/* BSDF */
|
|
|
|
|
2013-11-29 01:09:24 +00:00
|
|
|
class CBSDFClosure : public CClosurePrimitive {
|
2012-10-20 12:18:00 +00:00
|
|
|
public:
|
2016-07-25 01:03:23 +00:00
|
|
|
bool skip(const ShaderData *sd, int path_flag, int scattering);
|
2012-10-20 12:18:00 +00:00
|
|
|
};
|
|
|
|
|
2016-07-25 01:03:23 +00:00
|
|
|
#define BSDF_CLOSURE_CLASS_BEGIN(Upper, lower, structname, TYPE) \
|
2012-10-20 12:18:00 +00:00
|
|
|
\
|
|
|
|
class Upper##Closure : public CBSDFClosure { \
|
|
|
|
public: \
|
2016-07-25 01:03:23 +00:00
|
|
|
structname params; \
|
|
|
|
float3 unused; \
|
2013-11-29 16:17:00 +00:00
|
|
|
\
|
2016-07-25 01:03:23 +00:00
|
|
|
void setup(ShaderData *sd, int path_flag, float3 weight) \
|
2012-10-20 12:18:00 +00:00
|
|
|
{ \
|
2016-07-25 01:03:23 +00:00
|
|
|
if(!skip(sd, path_flag, TYPE)) { \
|
|
|
|
structname *bsdf = (structname*)bsdf_alloc_osl(sd, sizeof(structname), weight, ¶ms); \
|
|
|
|
sd->flag |= (bsdf) ? bsdf_##lower##_setup(bsdf) : 0; \
|
|
|
|
} \
|
2012-10-20 12:18:00 +00:00
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
\
|
2012-11-21 13:41:47 +00:00
|
|
|
static ClosureParam *bsdf_##lower##_params() \
|
2012-10-20 12:18:00 +00:00
|
|
|
{ \
|
|
|
|
static ClosureParam params[] = {
|
|
|
|
|
|
|
|
/* parameters */
|
|
|
|
|
|
|
|
#define BSDF_CLOSURE_CLASS_END(Upper, lower) \
|
2015-09-23 07:23:37 +00:00
|
|
|
CLOSURE_STRING_KEYPARAM(Upper##Closure, label, "label"), \
|
2016-02-03 11:17:39 +00:00
|
|
|
CLOSURE_FINISH_PARAM(Upper##Closure) \
|
2012-10-20 12:18:00 +00:00
|
|
|
}; \
|
|
|
|
return params; \
|
|
|
|
} \
|
|
|
|
\
|
2013-11-29 01:09:24 +00:00
|
|
|
CCLOSURE_PREPARE_STATIC(bsdf_##lower##_prepare, Upper##Closure)
|
2012-10-20 12:18:00 +00:00
|
|
|
|
2013-12-28 00:54:44 +00:00
|
|
|
/* Volume */
|
|
|
|
|
2016-07-25 01:03:23 +00:00
|
|
|
#define VOLUME_CLOSURE_CLASS_BEGIN(Upper, lower, structname, TYPE) \
|
2013-12-28 00:54:44 +00:00
|
|
|
\
|
2016-07-25 01:03:23 +00:00
|
|
|
class Upper##Closure : public CBSDFClosure { \
|
2013-12-28 00:54:44 +00:00
|
|
|
public: \
|
2016-07-25 01:03:23 +00:00
|
|
|
structname params; \
|
2013-12-28 00:54:44 +00:00
|
|
|
\
|
2016-07-25 01:03:23 +00:00
|
|
|
void setup(ShaderData *sd, int path_flag, float3 weight) \
|
2013-12-28 00:54:44 +00:00
|
|
|
{ \
|
2016-07-25 01:03:23 +00:00
|
|
|
structname *volume = (structname*)bsdf_alloc_osl(sd, sizeof(structname), weight, ¶ms); \
|
|
|
|
sd->flag |= (volume) ? volume_##lower##_setup(volume) : 0; \
|
2013-12-28 00:54:44 +00:00
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
static ClosureParam *volume_##lower##_params() \
|
|
|
|
{ \
|
|
|
|
static ClosureParam params[] = {
|
|
|
|
|
|
|
|
/* parameters */
|
|
|
|
|
|
|
|
#define VOLUME_CLOSURE_CLASS_END(Upper, lower) \
|
2015-09-23 07:23:37 +00:00
|
|
|
CLOSURE_STRING_KEYPARAM(Upper##Closure, label, "label"), \
|
2016-02-03 11:17:39 +00:00
|
|
|
CLOSURE_FINISH_PARAM(Upper##Closure) \
|
2013-12-28 00:54:44 +00:00
|
|
|
}; \
|
|
|
|
return params; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
CCLOSURE_PREPARE_STATIC(volume_##lower##_prepare, Upper##Closure)
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* __OSL_CLOSURES_H__ */
|
|
|
|
|