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__
|
|
|
|
|
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 20:39:14 +02:00
|
|
|
#include "util/util_types.h"
|
|
|
|
#include "kernel/kernel_types.h"
|
2013-08-14 06:51:18 +00:00
|
|
|
|
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();
|
2017-11-01 21:07:15 +01:00
|
|
|
OSL::ClosureParam *closure_bsdf_transparent_params();
|
2018-02-08 16:14:04 +01:00
|
|
|
OSL::ClosureParam *closure_bssrdf_params();
|
2017-11-01 21:07:15 +01:00
|
|
|
OSL::ClosureParam *closure_absorption_params();
|
|
|
|
OSL::ClosureParam *closure_henyey_greenstein_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 22:56:43 +02: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();
|
2017-04-18 11:43:09 +02:00
|
|
|
OSL::ClosureParam *closure_bsdf_microfacet_ggx_fresnel_params();
|
|
|
|
OSL::ClosureParam *closure_bsdf_microfacet_ggx_aniso_fresnel_params();
|
|
|
|
OSL::ClosureParam *closure_bsdf_microfacet_multi_ggx_fresnel_params();
|
|
|
|
OSL::ClosureParam *closure_bsdf_microfacet_multi_ggx_glass_fresnel_params();
|
|
|
|
OSL::ClosureParam *closure_bsdf_microfacet_multi_ggx_aniso_fresnel_params();
|
|
|
|
OSL::ClosureParam *closure_bsdf_principled_clearcoat_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);
|
2017-11-01 21:07:15 +01:00
|
|
|
void closure_bsdf_transparent_prepare(OSL::RendererServices *, int id, void *data);
|
2018-02-08 16:14:04 +01:00
|
|
|
void closure_bssrdf_prepare(OSL::RendererServices *, int id, void *data);
|
2017-11-01 21:07:15 +01:00
|
|
|
void closure_absorption_prepare(OSL::RendererServices *, int id, void *data);
|
|
|
|
void closure_henyey_greenstein_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 22:56:43 +02: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);
|
2017-04-18 11:43:09 +02:00
|
|
|
void closure_bsdf_microfacet_ggx_fresnel_prepare(OSL::RendererServices *, int id, void *data);
|
|
|
|
void closure_bsdf_microfacet_ggx_aniso_fresnel_prepare(OSL::RendererServices *, int id, void *data);
|
|
|
|
void closure_bsdf_microfacet_multi_ggx_fresnel_prepare(OSL::RendererServices *, int id, void *data);
|
|
|
|
void closure_bsdf_microfacet_multi_ggx_glass_fresnel_prepare(OSL::RendererServices *, int id, void *data);
|
|
|
|
void closure_bsdf_microfacet_multi_ggx_aniso_fresnel_prepare(OSL::RendererServices *, int id, void *data);
|
|
|
|
void closure_bsdf_principled_clearcoat_prepare(OSL::RendererServices *, int id, void *data);
|
2012-11-06 19:59:02 +00:00
|
|
|
|
2013-11-29 02:09:24 +01: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 02:09:24 +01: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 22:17:27 +02: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 02:09:24 +01:00
|
|
|
/* Closure */
|
|
|
|
|
|
|
|
class CClosurePrimitive {
|
|
|
|
public:
|
2016-07-25 03:03:23 +02:00
|
|
|
virtual void setup(ShaderData *sd, int path_flag, float3 weight) = 0;
|
2015-09-23 12:23:37 +05:00
|
|
|
|
|
|
|
OSL::ustring label;
|
2013-11-29 02:09:24 +01:00
|
|
|
};
|
|
|
|
|
2012-10-20 12:18:00 +00:00
|
|
|
/* BSDF */
|
|
|
|
|
2013-11-29 02:09:24 +01:00
|
|
|
class CBSDFClosure : public CClosurePrimitive {
|
2012-10-20 12:18:00 +00:00
|
|
|
public:
|
2016-07-25 03:03:23 +02:00
|
|
|
bool skip(const ShaderData *sd, int path_flag, int scattering);
|
2012-10-20 12:18:00 +00:00
|
|
|
};
|
|
|
|
|
2016-07-25 03:03:23 +02: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 03:03:23 +02:00
|
|
|
structname params; \
|
|
|
|
float3 unused; \
|
2013-11-29 17:17:00 +01:00
|
|
|
\
|
2016-07-25 03:03:23 +02:00
|
|
|
void setup(ShaderData *sd, int path_flag, float3 weight) \
|
2012-10-20 12:18:00 +00:00
|
|
|
{ \
|
2016-07-25 03:03:23 +02: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 12:23:37 +05:00
|
|
|
CLOSURE_STRING_KEYPARAM(Upper##Closure, label, "label"), \
|
2016-02-03 12:17:39 +01:00
|
|
|
CLOSURE_FINISH_PARAM(Upper##Closure) \
|
2012-10-20 12:18:00 +00:00
|
|
|
}; \
|
|
|
|
return params; \
|
|
|
|
} \
|
|
|
|
\
|
2013-11-29 02:09:24 +01:00
|
|
|
CCLOSURE_PREPARE_STATIC(bsdf_##lower##_prepare, Upper##Closure)
|
2012-10-20 12:18:00 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* __OSL_CLOSURES_H__ */
|
|
|
|
|