forked from bartvdbraak/blender
Cycles: Generate OSL closures using macros and a template file
This has the advantage of being able to use information about the existing OSL closures in various places without code duplication. In addition, the setup code for all closures was moved to standalone functions to avoid usage of virtual function calls in preparation for GPU support. This patch was split from D15902. Differential Revision: https://developer.blender.org/D15917
This commit is contained in:
parent
ef7c9e793e
commit
8611c37f97
@ -273,5 +273,5 @@ StatementMacros:
|
||||
- PyObject_VAR_HEAD
|
||||
- ccl_gpu_kernel_postfix
|
||||
|
||||
MacroBlockBegin: "^BSDF_CLOSURE_CLASS_BEGIN$"
|
||||
MacroBlockEnd: "^BSDF_CLOSURE_CLASS_END$"
|
||||
MacroBlockBegin: "^OSL_CLOSURE_STRUCT_BEGIN$"
|
||||
MacroBlockEnd: "^OSL_CLOSURE_STRUCT_END$"
|
||||
|
@ -59,39 +59,10 @@ ccl_device_inline ccl_private ShaderClosure *bsdf_alloc(ccl_private ShaderData *
|
||||
* we will not allocate new closure. */
|
||||
if (sample_weight >= CLOSURE_WEIGHT_CUTOFF) {
|
||||
ccl_private ShaderClosure *sc = closure_alloc(sd, size, CLOSURE_NONE_ID, weight);
|
||||
if (sc == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sc->sample_weight = sample_weight;
|
||||
|
||||
return sc;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef __OSL__
|
||||
ccl_device_inline ShaderClosure *bsdf_alloc_osl(ShaderData *sd,
|
||||
int size,
|
||||
Spectrum weight,
|
||||
void *data)
|
||||
{
|
||||
kernel_assert(isfinite_safe(weight));
|
||||
|
||||
const float sample_weight = fabsf(average(weight));
|
||||
|
||||
/* Use comparison this way to help dealing with non-finite weight: if the average is not finite
|
||||
* we will not allocate new closure. */
|
||||
if (sample_weight >= CLOSURE_WEIGHT_CUTOFF) {
|
||||
ShaderClosure *sc = closure_alloc(sd, size, CLOSURE_NONE_ID, weight);
|
||||
if (!sc) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy((void *)sc, data, size);
|
||||
|
||||
sc->weight = weight;
|
||||
sc->sample_weight = sample_weight;
|
||||
|
||||
return sc;
|
||||
@ -99,6 +70,5 @@ ccl_device_inline ShaderClosure *bsdf_alloc_osl(ShaderData *sd,
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
CCL_NAMESPACE_END
|
||||
|
@ -10,18 +10,14 @@ set(INC_SYS
|
||||
)
|
||||
|
||||
set(SRC
|
||||
background.cpp
|
||||
bsdf_diffuse_ramp.cpp
|
||||
bsdf_phong_ramp.cpp
|
||||
emissive.cpp
|
||||
bssrdf.cpp
|
||||
closures.cpp
|
||||
services.cpp
|
||||
shader.cpp
|
||||
)
|
||||
|
||||
set(HEADER_SRC
|
||||
closures.h
|
||||
closures_setup.h
|
||||
closures_template.h
|
||||
globals.h
|
||||
services.h
|
||||
shader.h
|
||||
|
@ -1,77 +0,0 @@
|
||||
/* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Adapted from Open Shading Language
|
||||
* Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Modifications Copyright 2011-2022 Blender Foundation. */
|
||||
|
||||
#include <OpenImageIO/fmath.h>
|
||||
|
||||
#include <OSL/genclosure.h>
|
||||
|
||||
#include "kernel/osl/closures.h"
|
||||
|
||||
// clang-format off
|
||||
#include "kernel/device/cpu/compat.h"
|
||||
#include "kernel/device/cpu/globals.h"
|
||||
|
||||
#include "kernel/closure/alloc.h"
|
||||
#include "kernel/closure/emissive.h"
|
||||
|
||||
#include "kernel/util/color.h"
|
||||
// clang-format on
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
using namespace OSL;
|
||||
|
||||
/// Generic background closure
|
||||
///
|
||||
/// We only have a background closure for the shaders
|
||||
/// to return a color in background shaders. No methods,
|
||||
/// only the weight is taking into account
|
||||
///
|
||||
class GenericBackgroundClosure : public CClosurePrimitive {
|
||||
public:
|
||||
void setup(ShaderData *sd, uint32_t /* path_flag */, float3 weight)
|
||||
{
|
||||
background_setup(sd, rgb_to_spectrum(weight));
|
||||
}
|
||||
};
|
||||
|
||||
/// Holdout closure
|
||||
///
|
||||
/// This will be used by the shader to mark the
|
||||
/// amount of holdout for the current shading
|
||||
/// point. No parameters, only the weight will be
|
||||
/// used
|
||||
///
|
||||
class HoldoutClosure : CClosurePrimitive {
|
||||
public:
|
||||
void setup(ShaderData *sd, uint32_t /* path_flag */, float3 weight)
|
||||
{
|
||||
closure_alloc(sd, sizeof(ShaderClosure), CLOSURE_HOLDOUT_ID, rgb_to_spectrum(weight));
|
||||
sd->flag |= SD_HOLDOUT;
|
||||
}
|
||||
};
|
||||
|
||||
ClosureParam *closure_background_params()
|
||||
{
|
||||
static ClosureParam params[] = {
|
||||
CLOSURE_STRING_KEYPARAM(GenericBackgroundClosure, label, "label"),
|
||||
CLOSURE_FINISH_PARAM(GenericBackgroundClosure)};
|
||||
return params;
|
||||
}
|
||||
|
||||
CCLOSURE_PREPARE(closure_background_prepare, GenericBackgroundClosure)
|
||||
|
||||
ClosureParam *closure_holdout_params()
|
||||
{
|
||||
static ClosureParam params[] = {CLOSURE_FINISH_PARAM(HoldoutClosure)};
|
||||
return params;
|
||||
}
|
||||
|
||||
CCLOSURE_PREPARE(closure_holdout_prepare, HoldoutClosure)
|
||||
|
||||
CCL_NAMESPACE_END
|
@ -1,68 +0,0 @@
|
||||
/* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Adapted from Open Shading Language
|
||||
* Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Modifications Copyright 2011-2022 Blender Foundation. */
|
||||
|
||||
#include <OpenImageIO/fmath.h>
|
||||
|
||||
#include <OSL/genclosure.h>
|
||||
|
||||
#include "kernel/device/cpu/compat.h"
|
||||
#include "kernel/osl/closures.h"
|
||||
|
||||
// clang-format off
|
||||
#include "kernel/device/cpu/compat.h"
|
||||
#include "kernel/device/cpu/globals.h"
|
||||
|
||||
#include "kernel/types.h"
|
||||
#include "kernel/closure/alloc.h"
|
||||
#include "kernel/closure/bsdf_diffuse_ramp.h"
|
||||
#include "kernel/closure/bsdf_util.h"
|
||||
|
||||
#include "kernel/util/color.h"
|
||||
// clang-format on
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
using namespace OSL;
|
||||
|
||||
class DiffuseRampClosure : public CBSDFClosure {
|
||||
public:
|
||||
DiffuseRampBsdf params;
|
||||
Color3 colors[8];
|
||||
|
||||
void setup(ShaderData *sd, uint32_t /* path_flag */, float3 weight)
|
||||
{
|
||||
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
|
||||
|
||||
DiffuseRampBsdf *bsdf = (DiffuseRampBsdf *)bsdf_alloc_osl(
|
||||
sd, sizeof(DiffuseRampBsdf), rgb_to_spectrum(weight), ¶ms);
|
||||
|
||||
if (bsdf) {
|
||||
bsdf->colors = (float3 *)closure_alloc_extra(sd, sizeof(float3) * 8);
|
||||
|
||||
if (bsdf->colors) {
|
||||
for (int i = 0; i < 8; i++)
|
||||
bsdf->colors[i] = TO_FLOAT3(colors[i]);
|
||||
|
||||
sd->flag |= bsdf_diffuse_ramp_setup(bsdf);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ClosureParam *closure_bsdf_diffuse_ramp_params()
|
||||
{
|
||||
static ClosureParam params[] = {CLOSURE_FLOAT3_PARAM(DiffuseRampClosure, params.N),
|
||||
CLOSURE_COLOR_ARRAY_PARAM(DiffuseRampClosure, colors, 8),
|
||||
CLOSURE_STRING_KEYPARAM(DiffuseRampClosure, label, "label"),
|
||||
CLOSURE_FINISH_PARAM(DiffuseRampClosure)};
|
||||
return params;
|
||||
}
|
||||
|
||||
CCLOSURE_PREPARE(closure_bsdf_diffuse_ramp_prepare, DiffuseRampClosure)
|
||||
|
||||
CCL_NAMESPACE_END
|
@ -1,69 +0,0 @@
|
||||
/* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Adapted from Open Shading Language
|
||||
* Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Modifications Copyright 2011-2022 Blender Foundation. */
|
||||
|
||||
#include <OpenImageIO/fmath.h>
|
||||
|
||||
#include <OSL/genclosure.h>
|
||||
|
||||
#include "kernel/device/cpu/compat.h"
|
||||
#include "kernel/osl/closures.h"
|
||||
|
||||
// clang-format off
|
||||
#include "kernel/device/cpu/compat.h"
|
||||
#include "kernel/device/cpu/globals.h"
|
||||
|
||||
#include "kernel/types.h"
|
||||
#include "kernel/closure/alloc.h"
|
||||
#include "kernel/closure/bsdf_phong_ramp.h"
|
||||
#include "kernel/closure/bsdf_util.h"
|
||||
|
||||
#include "kernel/util/color.h"
|
||||
// clang-format on
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
using namespace OSL;
|
||||
|
||||
class PhongRampClosure : public CBSDFClosure {
|
||||
public:
|
||||
PhongRampBsdf params;
|
||||
Color3 colors[8];
|
||||
|
||||
void setup(ShaderData *sd, uint32_t /* path_flag */, float3 weight)
|
||||
{
|
||||
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
|
||||
|
||||
PhongRampBsdf *bsdf = (PhongRampBsdf *)bsdf_alloc_osl(
|
||||
sd, sizeof(PhongRampBsdf), rgb_to_spectrum(weight), ¶ms);
|
||||
|
||||
if (bsdf) {
|
||||
bsdf->colors = (float3 *)closure_alloc_extra(sd, sizeof(float3) * 8);
|
||||
|
||||
if (bsdf->colors) {
|
||||
for (int i = 0; i < 8; i++)
|
||||
bsdf->colors[i] = TO_FLOAT3(colors[i]);
|
||||
|
||||
sd->flag |= bsdf_phong_ramp_setup(bsdf);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ClosureParam *closure_bsdf_phong_ramp_params()
|
||||
{
|
||||
static ClosureParam params[] = {CLOSURE_FLOAT3_PARAM(PhongRampClosure, params.N),
|
||||
CLOSURE_FLOAT_PARAM(PhongRampClosure, params.exponent),
|
||||
CLOSURE_COLOR_ARRAY_PARAM(PhongRampClosure, colors, 8),
|
||||
CLOSURE_STRING_KEYPARAM(PhongRampClosure, label, "label"),
|
||||
CLOSURE_FINISH_PARAM(PhongRampClosure)};
|
||||
return params;
|
||||
}
|
||||
|
||||
CCLOSURE_PREPARE(closure_bsdf_phong_ramp_prepare, PhongRampClosure)
|
||||
|
||||
CCL_NAMESPACE_END
|
@ -1,105 +0,0 @@
|
||||
/* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Adapted from Open Shading Language
|
||||
* Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Modifications Copyright 2011-2022 Blender Foundation. */
|
||||
|
||||
#include <OSL/genclosure.h>
|
||||
|
||||
#include "kernel/device/cpu/compat.h"
|
||||
#include "kernel/osl/closures.h"
|
||||
|
||||
// clang-format off
|
||||
#include "kernel/device/cpu/compat.h"
|
||||
#include "kernel/device/cpu/globals.h"
|
||||
|
||||
#include "kernel/types.h"
|
||||
|
||||
#include "kernel/closure/alloc.h"
|
||||
#include "kernel/closure/bsdf_util.h"
|
||||
#include "kernel/closure/bsdf_diffuse.h"
|
||||
#include "kernel/closure/bsdf_principled_diffuse.h"
|
||||
#include "kernel/closure/bssrdf.h"
|
||||
|
||||
#include "kernel/util/color.h"
|
||||
// clang-format on
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
using namespace OSL;
|
||||
|
||||
static ustring u_burley("burley");
|
||||
static ustring u_random_walk_fixed_radius("random_walk_fixed_radius");
|
||||
static ustring u_random_walk("random_walk");
|
||||
|
||||
class CBSSRDFClosure : public CClosurePrimitive {
|
||||
public:
|
||||
Bssrdf params;
|
||||
float ior;
|
||||
ustring method;
|
||||
|
||||
CBSSRDFClosure()
|
||||
{
|
||||
params.roughness = FLT_MAX;
|
||||
params.anisotropy = 1.0f;
|
||||
ior = 1.4f;
|
||||
}
|
||||
|
||||
void setup(ShaderData *sd, uint32_t path_flag, float3 weight)
|
||||
{
|
||||
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N);
|
||||
|
||||
if (method == u_burley) {
|
||||
alloc(sd, path_flag, weight, CLOSURE_BSSRDF_BURLEY_ID);
|
||||
}
|
||||
else if (method == u_random_walk_fixed_radius) {
|
||||
alloc(sd, path_flag, weight, CLOSURE_BSSRDF_RANDOM_WALK_FIXED_RADIUS_ID);
|
||||
}
|
||||
else if (method == u_random_walk) {
|
||||
alloc(sd, path_flag, weight, CLOSURE_BSSRDF_RANDOM_WALK_ID);
|
||||
}
|
||||
}
|
||||
|
||||
void alloc(ShaderData *sd, uint32_t path_flag, float3 weight, ClosureType type)
|
||||
{
|
||||
Bssrdf *bssrdf = bssrdf_alloc(sd, rgb_to_spectrum(weight));
|
||||
|
||||
if (bssrdf) {
|
||||
/* disable in case of diffuse ancestor, can't see it well then and
|
||||
* adds considerably noise due to probabilities of continuing path
|
||||
* getting lower and lower */
|
||||
if (path_flag & PATH_RAY_DIFFUSE_ANCESTOR) {
|
||||
params.radius = zero_spectrum();
|
||||
}
|
||||
|
||||
/* create one closure per color channel */
|
||||
bssrdf->radius = params.radius;
|
||||
bssrdf->albedo = params.albedo;
|
||||
bssrdf->N = params.N;
|
||||
bssrdf->roughness = params.roughness;
|
||||
bssrdf->anisotropy = clamp(params.anisotropy, 0.0f, 0.9f);
|
||||
sd->flag |= bssrdf_setup(sd, bssrdf, (ClosureType)type, clamp(ior, 1.01f, 3.8f));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ClosureParam *closure_bssrdf_params()
|
||||
{
|
||||
static ClosureParam params[] = {
|
||||
CLOSURE_STRING_PARAM(CBSSRDFClosure, method),
|
||||
CLOSURE_FLOAT3_PARAM(CBSSRDFClosure, params.N),
|
||||
CLOSURE_FLOAT3_PARAM(CBSSRDFClosure, params.radius),
|
||||
CLOSURE_FLOAT3_PARAM(CBSSRDFClosure, params.albedo),
|
||||
CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, params.roughness, "roughness"),
|
||||
CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, ior, "ior"),
|
||||
CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, params.anisotropy, "anisotropy"),
|
||||
CLOSURE_STRING_KEYPARAM(CBSSRDFClosure, label, "label"),
|
||||
CLOSURE_FINISH_PARAM(CBSSRDFClosure)};
|
||||
return params;
|
||||
}
|
||||
|
||||
CCLOSURE_PREPARE(closure_bssrdf_prepare, CBSSRDFClosure)
|
||||
|
||||
CCL_NAMESPACE_END
|
File diff suppressed because it is too large
Load Diff
@ -1,142 +0,0 @@
|
||||
/* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Adapted from Open Shading Language
|
||||
* Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Modifications Copyright 2011-2022 Blender Foundation. */
|
||||
|
||||
#ifndef __OSL_CLOSURES_H__
|
||||
#define __OSL_CLOSURES_H__
|
||||
|
||||
#include "kernel/types.h"
|
||||
#include "util/types.h"
|
||||
|
||||
#include <OSL/genclosure.h>
|
||||
#include <OSL/oslclosure.h>
|
||||
#include <OSL/oslexec.h>
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
OSL::ClosureParam *closure_emission_params();
|
||||
OSL::ClosureParam *closure_background_params();
|
||||
OSL::ClosureParam *closure_holdout_params();
|
||||
OSL::ClosureParam *closure_bsdf_diffuse_ramp_params();
|
||||
OSL::ClosureParam *closure_bsdf_phong_ramp_params();
|
||||
OSL::ClosureParam *closure_bsdf_transparent_params();
|
||||
OSL::ClosureParam *closure_bssrdf_params();
|
||||
OSL::ClosureParam *closure_absorption_params();
|
||||
OSL::ClosureParam *closure_henyey_greenstein_params();
|
||||
OSL::ClosureParam *closure_bsdf_microfacet_params();
|
||||
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();
|
||||
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();
|
||||
|
||||
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);
|
||||
void closure_bsdf_diffuse_ramp_prepare(OSL::RendererServices *, int id, void *data);
|
||||
void closure_bsdf_phong_ramp_prepare(OSL::RendererServices *, int id, void *data);
|
||||
void closure_bsdf_transparent_prepare(OSL::RendererServices *, int id, void *data);
|
||||
void closure_bssrdf_prepare(OSL::RendererServices *, int id, void *data);
|
||||
void closure_absorption_prepare(OSL::RendererServices *, int id, void *data);
|
||||
void closure_henyey_greenstein_prepare(OSL::RendererServices *, int id, void *data);
|
||||
void closure_bsdf_microfacet_prepare(OSL::RendererServices *, int id, void *data);
|
||||
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);
|
||||
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);
|
||||
void closure_bsdf_principled_hair_prepare(OSL::RendererServices *, int id, void *data);
|
||||
|
||||
#define CCLOSURE_PREPARE(name, classname) \
|
||||
void name(RendererServices *, int id, void *data) \
|
||||
{ \
|
||||
memset(data, 0, sizeof(classname)); \
|
||||
new (data) classname(); \
|
||||
}
|
||||
|
||||
#define CCLOSURE_PREPARE_STATIC(name, classname) static CCLOSURE_PREPARE(name, classname)
|
||||
|
||||
#define CLOSURE_FLOAT3_PARAM(st, fld) \
|
||||
{ \
|
||||
TypeDesc::TypeVector, (int)reckless_offsetof(st, fld), NULL, sizeof(OSL::Vec3) \
|
||||
}
|
||||
|
||||
#define BSDF_CLOSURE_FLOAT_PARAM(st, fld) CLOSURE_FLOAT_PARAM(st, fld),
|
||||
#define BSDF_CLOSURE_FLOAT3_PARAM(st, fld) CLOSURE_FLOAT3_PARAM(st, fld),
|
||||
|
||||
#define TO_VEC3(v) OSL::Vec3(v.x, v.y, v.z)
|
||||
#define TO_COLOR3(v) OSL::Color3(v.x, v.y, v.z)
|
||||
#define TO_FLOAT3(v) make_float3(v[0], v[1], v[2])
|
||||
|
||||
/* Closure */
|
||||
|
||||
class CClosurePrimitive {
|
||||
public:
|
||||
virtual void setup(ShaderData *sd, uint32_t path_flag, float3 weight) = 0;
|
||||
|
||||
OSL::ustring label;
|
||||
};
|
||||
|
||||
/* BSDF */
|
||||
|
||||
class CBSDFClosure : public CClosurePrimitive {
|
||||
public:
|
||||
bool skip(const ShaderData *sd, uint32_t path_flag, int scattering);
|
||||
};
|
||||
|
||||
#define BSDF_CLOSURE_CLASS_BEGIN(Upper, lower, structname, TYPE) \
|
||||
\
|
||||
class Upper##Closure : public CBSDFClosure { \
|
||||
public: \
|
||||
structname params; \
|
||||
float3 unused; \
|
||||
\
|
||||
void setup(ShaderData *sd, uint32_t path_flag, float3 weight) \
|
||||
{ \
|
||||
if (!skip(sd, path_flag, TYPE)) { \
|
||||
params.N = ensure_valid_reflection(sd->Ng, sd->I, params.N); \
|
||||
structname *bsdf = (structname *)bsdf_alloc_osl( \
|
||||
sd, sizeof(structname), rgb_to_spectrum(weight), ¶ms); \
|
||||
sd->flag |= (bsdf) ? bsdf_##lower##_setup(bsdf) : 0; \
|
||||
} \
|
||||
} \
|
||||
}; \
|
||||
\
|
||||
static ClosureParam *bsdf_##lower##_params() \
|
||||
{ \
|
||||
static ClosureParam params[] = {
|
||||
|
||||
/* parameters */
|
||||
|
||||
#define BSDF_CLOSURE_CLASS_END(Upper, lower) \
|
||||
CLOSURE_STRING_KEYPARAM(Upper##Closure, label, "label"), CLOSURE_FINISH_PARAM(Upper##Closure) \
|
||||
} \
|
||||
; \
|
||||
return params; \
|
||||
} \
|
||||
\
|
||||
CCLOSURE_PREPARE_STATIC(bsdf_##lower##_prepare, Upper##Closure)
|
||||
|
||||
CCL_NAMESPACE_END
|
||||
|
||||
#endif /* __OSL_CLOSURES_H__ */
|
1166
intern/cycles/kernel/osl/closures_setup.h
Normal file
1166
intern/cycles/kernel/osl/closures_setup.h
Normal file
File diff suppressed because it is too large
Load Diff
258
intern/cycles/kernel/osl/closures_template.h
Normal file
258
intern/cycles/kernel/osl/closures_template.h
Normal file
@ -0,0 +1,258 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0
|
||||
* Copyright 2011-2022 Blender Foundation */
|
||||
|
||||
#ifndef OSL_CLOSURE_STRUCT_BEGIN
|
||||
# define OSL_CLOSURE_STRUCT_BEGIN(Upper, lower)
|
||||
#endif
|
||||
#ifndef OSL_CLOSURE_STRUCT_END
|
||||
# define OSL_CLOSURE_STRUCT_END(Upper, lower)
|
||||
#endif
|
||||
#ifndef OSL_CLOSURE_STRUCT_MEMBER
|
||||
# define OSL_CLOSURE_STRUCT_MEMBER(Upper, TYPE, type, name, key)
|
||||
#endif
|
||||
#ifndef OSL_CLOSURE_STRUCT_ARRAY_MEMBER
|
||||
# define OSL_CLOSURE_STRUCT_ARRAY_MEMBER(Upper, TYPE, type, name, key, size)
|
||||
#endif
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(Diffuse, diffuse)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(Diffuse, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(Diffuse, diffuse)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(OrenNayar, oren_nayar)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(OrenNayar, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(OrenNayar, FLOAT, float, roughness, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(OrenNayar, oren_nayar)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(Translucent, translucent)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(Translucent, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(Translucent, translucent)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(Reflection, reflection)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(Reflection, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(Reflection, reflection)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(Refraction, refraction)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(Refraction, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(Refraction, FLOAT, float, ior, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(Refraction, refraction)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(Transparent, transparent)
|
||||
OSL_CLOSURE_STRUCT_END(Transparent, transparent)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(Microfacet, microfacet)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(Microfacet, STRING, ustring, distribution, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(Microfacet, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(Microfacet, VECTOR, packed_float3, T, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(Microfacet, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(Microfacet, FLOAT, float, alpha_y, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(Microfacet, FLOAT, float, ior, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(Microfacet, INT, int, refract, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(Microfacet, microfacet)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(MicrofacetGGXIsotropic, microfacet_ggx)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXIsotropic, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXIsotropic, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(MicrofacetGGXIsotropic, microfacet_ggx)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(MicrofacetGGX, microfacet_ggx_aniso)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGX, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGX, VECTOR, packed_float3, T, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGX, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGX, FLOAT, float, alpha_y, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(MicrofacetGGX, microfacet_ggx_aniso)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(MicrofacetGGXRefraction, microfacet_ggx_refraction)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXRefraction, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXRefraction, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXRefraction, FLOAT, float, ior, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(MicrofacetGGXRefraction, microfacet_ggx_refraction)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(MicrofacetMultiGGX, microfacet_multi_ggx)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGX, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGX, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGX, VECTOR, packed_float3, color, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(MicrofacetMultiGGX, microfacet_multi_ggx)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(MicrofacetMultiGGXGlass, microfacet_multi_ggx_glass)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXGlass, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXGlass, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXGlass, FLOAT, float, ior, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXGlass, VECTOR, packed_float3, color, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(MicrofacetMultiGGXGlass, microfacet_multi_ggx_glass)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(MicrofacetMultiGGXAniso, microfacet_multi_ggx_aniso)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXAniso, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXAniso, VECTOR, packed_float3, T, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXAniso, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXAniso, FLOAT, float, alpha_y, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXAniso, VECTOR, packed_float3, color, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(MicrofacetMultiGGXAniso, microfacet_multi_ggx_aniso)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(MicrofacetGGXFresnel, microfacet_ggx_fresnel)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXFresnel, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXFresnel, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXFresnel, FLOAT, float, ior, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXFresnel, VECTOR, packed_float3, color, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXFresnel, VECTOR, packed_float3, cspec0, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(MicrofacetGGXFresnel, microfacet_ggx_fresnel)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(MicrofacetGGXAnisoFresnel, microfacet_ggx_aniso_fresnel)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXAnisoFresnel, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXAnisoFresnel, VECTOR, packed_float3, T, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXAnisoFresnel, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXAnisoFresnel, FLOAT, float, alpha_y, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXAnisoFresnel, FLOAT, float, ior, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXAnisoFresnel, VECTOR, packed_float3, color, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetGGXAnisoFresnel, VECTOR, packed_float3, cspec0, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(MicrofacetGGXAnisoFresnel, microfacet_ggx_aniso_fresnel)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(MicrofacetMultiGGXFresnel, microfacet_multi_ggx_fresnel)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXFresnel, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXFresnel, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXFresnel, FLOAT, float, ior, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXFresnel, VECTOR, packed_float3, color, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXFresnel, VECTOR, packed_float3, cspec0, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(MicrofacetMultiGGXFresnel, microfacet_multi_ggx_fresnel)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(MicrofacetMultiGGXGlassFresnel, microfacet_multi_ggx_glass_fresnel)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXGlassFresnel, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXGlassFresnel, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXGlassFresnel, FLOAT, float, ior, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXGlassFresnel, VECTOR, packed_float3, color, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXGlassFresnel, VECTOR, packed_float3, cspec0, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(MicrofacetMultiGGXGlassFresnel, microfacet_multi_ggx_glass_fresnel)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(MicrofacetMultiGGXAnisoFresnel, microfacet_multi_ggx_aniso_fresnel)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXAnisoFresnel, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXAnisoFresnel, VECTOR, packed_float3, T, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXAnisoFresnel, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXAnisoFresnel, FLOAT, float, alpha_y, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXAnisoFresnel, FLOAT, float, ior, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXAnisoFresnel, VECTOR, packed_float3, color, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetMultiGGXAnisoFresnel, VECTOR, packed_float3, cspec0, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(MicrofacetMultiGGXAnisoFresnel, microfacet_multi_ggx_aniso_fresnel)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(MicrofacetBeckmannIsotropic, microfacet_beckmann)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetBeckmannIsotropic, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetBeckmannIsotropic, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(MicrofacetBeckmannIsotropic, microfacet_beckmann)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(MicrofacetBeckmann, microfacet_beckmann_aniso)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetBeckmann, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetBeckmann, VECTOR, packed_float3, T, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetBeckmann, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetBeckmann, FLOAT, float, alpha_y, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(MicrofacetBeckmann, microfacet_beckmann_aniso)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(MicrofacetBeckmannRefraction, microfacet_beckmann_refraction)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetBeckmannRefraction, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetBeckmannRefraction, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(MicrofacetBeckmannRefraction, FLOAT, float, ior, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(MicrofacetBeckmannRefraction, microfacet_beckmann_refraction)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(AshikhminShirley, ashikhmin_shirley)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(AshikhminShirley, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(AshikhminShirley, VECTOR, packed_float3, T, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(AshikhminShirley, FLOAT, float, alpha_x, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(AshikhminShirley, FLOAT, float, alpha_y, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(AshikhminShirley, ashikhmin_shirley)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(AshikhminVelvet, ashikhmin_velvet)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(AshikhminVelvet, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(AshikhminVelvet, FLOAT, float, sigma, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(AshikhminVelvet, ashikhmin_velvet)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(DiffuseToon, diffuse_toon)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(DiffuseToon, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(DiffuseToon, FLOAT, float, size, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(DiffuseToon, FLOAT, float, smooth, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(DiffuseToon, diffuse_toon)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(GlossyToon, glossy_toon)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(GlossyToon, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(GlossyToon, FLOAT, float, size, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(GlossyToon, FLOAT, float, smooth, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(GlossyToon, glossy_toon)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(PrincipledDiffuse, principled_diffuse)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(PrincipledDiffuse, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(PrincipledDiffuse, FLOAT, float, roughness, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(PrincipledDiffuse, principled_diffuse)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(PrincipledSheen, principled_sheen)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(PrincipledSheen, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(PrincipledSheen, principled_sheen)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(PrincipledClearcoat, principled_clearcoat)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(PrincipledClearcoat, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(PrincipledClearcoat, FLOAT, float, clearcoat, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(PrincipledClearcoat, FLOAT, float, clearcoat_roughness, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(PrincipledClearcoat, principled_clearcoat)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(GenericEmissive, emission)
|
||||
OSL_CLOSURE_STRUCT_END(GenericEmissive, emission)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(GenericBackground, background)
|
||||
OSL_CLOSURE_STRUCT_END(GenericBackground, background)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(Holdout, holdout)
|
||||
OSL_CLOSURE_STRUCT_END(Holdout, holdout)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(DiffuseRamp, diffuse_ramp)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(DiffuseRamp, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_ARRAY_MEMBER(DiffuseRamp, COLOR, packed_float3, colors, NULL, 8)
|
||||
OSL_CLOSURE_STRUCT_END(DiffuseRamp, diffuse_ramp)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(PhongRamp, phong_ramp)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(PhongRamp, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(PhongRamp, FLOAT, float, exponent, NULL)
|
||||
OSL_CLOSURE_STRUCT_ARRAY_MEMBER(PhongRamp, COLOR, packed_float3, colors, NULL, 8)
|
||||
OSL_CLOSURE_STRUCT_END(PhongRamp, phong_ramp)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(BSSRDF, bssrdf)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(BSSRDF, STRING, ustring, method, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(BSSRDF, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(BSSRDF, VECTOR, packed_float3, radius, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(BSSRDF, VECTOR, packed_float3, albedo, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(BSSRDF, FLOAT, float, roughness, "roughness")
|
||||
OSL_CLOSURE_STRUCT_MEMBER(BSSRDF, FLOAT, float, ior, "ior")
|
||||
OSL_CLOSURE_STRUCT_MEMBER(BSSRDF, FLOAT, float, anisotropy, "anisotropy")
|
||||
OSL_CLOSURE_STRUCT_END(BSSRDF, bssrdf)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(HairReflection, hair_reflection)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(HairReflection, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(HairReflection, FLOAT, float, roughness1, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(HairReflection, FLOAT, float, roughness2, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(HairReflection, VECTOR, packed_float3, T, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(HairReflection, FLOAT, float, offset, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(HairReflection, hair_reflection)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(HairTransmission, hair_transmission)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(HairTransmission, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(HairTransmission, FLOAT, float, roughness1, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(HairTransmission, FLOAT, float, roughness2, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(HairReflection, VECTOR, packed_float3, T, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(HairReflection, FLOAT, float, offset, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(HairTransmission, hair_transmission)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(PrincipledHair, principled_hair)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(PrincipledHair, VECTOR, packed_float3, N, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(PrincipledHair, VECTOR, packed_float3, sigma, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(PrincipledHair, FLOAT, float, v, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(PrincipledHair, FLOAT, float, s, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(PrincipledHair, FLOAT, float, m0_roughness, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(PrincipledHair, FLOAT, float, alpha, NULL)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(PrincipledHair, FLOAT, float, eta, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(PrincipledHair, principled_hair)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(VolumeAbsorption, absorption)
|
||||
OSL_CLOSURE_STRUCT_END(VolumeAbsorption, absorption)
|
||||
|
||||
OSL_CLOSURE_STRUCT_BEGIN(VolumeHenyeyGreenstein, henyey_greenstein)
|
||||
OSL_CLOSURE_STRUCT_MEMBER(VolumeHenyeyGreenstein, FLOAT, float, g, NULL)
|
||||
OSL_CLOSURE_STRUCT_END(VolumeHenyeyGreenstein, henyey_greenstein)
|
||||
|
||||
#undef OSL_CLOSURE_STRUCT_BEGIN
|
||||
#undef OSL_CLOSURE_STRUCT_END
|
||||
#undef OSL_CLOSURE_STRUCT_MEMBER
|
||||
#undef OSL_CLOSURE_STRUCT_ARRAY_MEMBER
|
@ -1,54 +0,0 @@
|
||||
/* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Adapted from Open Shading Language
|
||||
* Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Modifications Copyright 2011-2022 Blender Foundation. */
|
||||
|
||||
#include <OpenImageIO/fmath.h>
|
||||
|
||||
#include <OSL/genclosure.h>
|
||||
|
||||
#include "kernel/osl/closures.h"
|
||||
|
||||
// clang-format off
|
||||
#include "kernel/device/cpu/compat.h"
|
||||
#include "kernel/device/cpu/globals.h"
|
||||
|
||||
#include "kernel/types.h"
|
||||
#include "kernel/closure/alloc.h"
|
||||
#include "kernel/closure/emissive.h"
|
||||
|
||||
#include "kernel/util/color.h"
|
||||
// clang-format on
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
using namespace OSL;
|
||||
|
||||
/// Variable cone emissive closure
|
||||
///
|
||||
/// This primitive emits in a cone having a configurable
|
||||
/// penumbra area where the light decays to 0 reaching the
|
||||
/// outer_angle limit. It can also behave as a lambertian emitter
|
||||
/// if the provided angles are PI/2, which is the default
|
||||
///
|
||||
class GenericEmissiveClosure : public CClosurePrimitive {
|
||||
public:
|
||||
void setup(ShaderData *sd, uint32_t /* path_flag */, float3 weight)
|
||||
{
|
||||
emission_setup(sd, rgb_to_spectrum(weight));
|
||||
}
|
||||
};
|
||||
|
||||
ClosureParam *closure_emission_params()
|
||||
{
|
||||
static ClosureParam params[] = {CLOSURE_STRING_KEYPARAM(GenericEmissiveClosure, label, "label"),
|
||||
CLOSURE_FINISH_PARAM(GenericEmissiveClosure)};
|
||||
return params;
|
||||
}
|
||||
|
||||
CCLOSURE_PREPARE(closure_emission_prepare, GenericEmissiveClosure)
|
||||
|
||||
CCL_NAMESPACE_END
|
@ -18,7 +18,6 @@
|
||||
#include "scene/pointcloud.h"
|
||||
#include "scene/scene.h"
|
||||
|
||||
#include "kernel/osl/closures.h"
|
||||
#include "kernel/osl/globals.h"
|
||||
#include "kernel/osl/services.h"
|
||||
#include "kernel/osl/shader.h"
|
||||
@ -1605,8 +1604,8 @@ bool OSLRenderServices::trace(TraceOpt &options,
|
||||
/* setup ray */
|
||||
Ray ray;
|
||||
|
||||
ray.P = TO_FLOAT3(P);
|
||||
ray.D = TO_FLOAT3(R);
|
||||
ray.P = make_float3(P.x, P.y, P.z);
|
||||
ray.D = make_float3(R.x, R.y, R.z);
|
||||
ray.tmin = 0.0f;
|
||||
ray.tmax = (options.maxdist == 1.0e30f) ? FLT_MAX : options.maxdist - options.mindist;
|
||||
ray.time = sd->time;
|
||||
@ -1629,12 +1628,12 @@ bool OSLRenderServices::trace(TraceOpt &options,
|
||||
|
||||
/* ray differentials */
|
||||
differential3 dP;
|
||||
dP.dx = TO_FLOAT3(dPdx);
|
||||
dP.dy = TO_FLOAT3(dPdy);
|
||||
dP.dx = make_float3(dPdx.x, dPdx.y, dPdx.z);
|
||||
dP.dy = make_float3(dPdy.x, dPdy.y, dPdy.z);
|
||||
ray.dP = differential_make_compact(dP);
|
||||
differential3 dD;
|
||||
dD.dx = TO_FLOAT3(dRdx);
|
||||
dD.dy = TO_FLOAT3(dRdy);
|
||||
dD.dx = make_float3(dRdx.x, dRdx.y, dRdx.z);
|
||||
dD.dy = make_float3(dRdy.x, dRdy.y, dRdy.z);
|
||||
ray.dD = differential_make_compact(dD);
|
||||
|
||||
/* allocate trace data */
|
||||
|
@ -76,6 +76,8 @@ class OSLRenderServices : public OSL::RendererServices {
|
||||
OSLRenderServices(OSL::TextureSystem *texture_system);
|
||||
~OSLRenderServices();
|
||||
|
||||
static void register_closures(OSL::ShadingSystem *ss);
|
||||
|
||||
bool get_matrix(OSL::ShaderGlobals *sg,
|
||||
OSL::Matrix44 &result,
|
||||
OSL::TransformationPtr xform,
|
||||
|
@ -13,14 +13,19 @@
|
||||
|
||||
#include "kernel/integrator/state.h"
|
||||
|
||||
#include "kernel/osl/closures.h"
|
||||
#include "kernel/osl/globals.h"
|
||||
#include "kernel/osl/services.h"
|
||||
#include "kernel/osl/shader.h"
|
||||
|
||||
#include "kernel/osl/types.h"
|
||||
#include "kernel/osl/closures_setup.h"
|
||||
|
||||
#include "kernel/util/differential.h"
|
||||
// clang-format on
|
||||
|
||||
#define TO_VEC3(v) OSL::Vec3(v.x, v.y, v.z)
|
||||
#define TO_FLOAT3(v) make_float3(v[0], v[1], v[2])
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
/* Threads */
|
||||
@ -133,7 +138,8 @@ static void shaderdata_to_shaderglobals(const KernelGlobalsCPU *kg,
|
||||
|
||||
/* Surface */
|
||||
|
||||
static void flatten_surface_closure_tree(ShaderData *sd,
|
||||
static void flatten_surface_closure_tree(const KernelGlobalsCPU *kg,
|
||||
ShaderData *sd,
|
||||
uint32_t path_flag,
|
||||
const OSL::ClosureColor *closure,
|
||||
float3 weight = make_float3(1.0f, 1.0f, 1.0f))
|
||||
@ -144,27 +150,30 @@ static void flatten_surface_closure_tree(ShaderData *sd,
|
||||
switch (closure->id) {
|
||||
case OSL::ClosureColor::MUL: {
|
||||
OSL::ClosureMul *mul = (OSL::ClosureMul *)closure;
|
||||
flatten_surface_closure_tree(sd, path_flag, mul->closure, TO_FLOAT3(mul->weight) * weight);
|
||||
flatten_surface_closure_tree(kg, sd, path_flag, mul->closure, TO_FLOAT3(mul->weight) * weight);
|
||||
break;
|
||||
}
|
||||
case OSL::ClosureColor::ADD: {
|
||||
OSL::ClosureAdd *add = (OSL::ClosureAdd *)closure;
|
||||
flatten_surface_closure_tree(sd, path_flag, add->closureA, weight);
|
||||
flatten_surface_closure_tree(sd, path_flag, add->closureB, weight);
|
||||
flatten_surface_closure_tree(kg, sd, path_flag, add->closureA, weight);
|
||||
flatten_surface_closure_tree(kg, sd, path_flag, add->closureB, weight);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
OSL::ClosureComponent *comp = (OSL::ClosureComponent *)closure;
|
||||
CClosurePrimitive *prim = (CClosurePrimitive *)comp->data();
|
||||
|
||||
if (prim) {
|
||||
#ifdef OSL_SUPPORTS_WEIGHTED_CLOSURE_COMPONENTS
|
||||
weight = weight * TO_FLOAT3(comp->w);
|
||||
#endif
|
||||
prim->setup(sd, path_flag, weight);
|
||||
}
|
||||
#define OSL_CLOSURE_STRUCT_BEGIN(Upper, lower) \
|
||||
case OSL_CLOSURE_##Upper##_ID: { \
|
||||
const OSL::ClosureComponent *comp = \
|
||||
reinterpret_cast<const OSL::ClosureComponent *>(closure); \
|
||||
weight *= TO_FLOAT3(comp->w); \
|
||||
osl_closure_##lower##_setup(kg, \
|
||||
sd, \
|
||||
path_flag, \
|
||||
weight, \
|
||||
reinterpret_cast<const Upper##Closure *>(comp + 1)); \
|
||||
break; \
|
||||
}
|
||||
#include "closures_template.h"
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,12 +247,13 @@ void OSLShader::eval_surface(const KernelGlobalsCPU *kg,
|
||||
|
||||
/* flatten closure tree */
|
||||
if (globals->Ci)
|
||||
flatten_surface_closure_tree(sd, path_flag, globals->Ci);
|
||||
flatten_surface_closure_tree(kg, sd, path_flag, globals->Ci);
|
||||
}
|
||||
|
||||
/* Background */
|
||||
|
||||
static void flatten_background_closure_tree(ShaderData *sd,
|
||||
static void flatten_background_closure_tree(const KernelGlobalsCPU *kg,
|
||||
ShaderData *sd,
|
||||
const OSL::ClosureColor *closure,
|
||||
float3 weight = make_float3(1.0f, 1.0f, 1.0f))
|
||||
{
|
||||
@ -254,28 +264,27 @@ static void flatten_background_closure_tree(ShaderData *sd,
|
||||
switch (closure->id) {
|
||||
case OSL::ClosureColor::MUL: {
|
||||
OSL::ClosureMul *mul = (OSL::ClosureMul *)closure;
|
||||
flatten_background_closure_tree(sd, mul->closure, weight * TO_FLOAT3(mul->weight));
|
||||
flatten_background_closure_tree(kg, sd, mul->closure, weight * TO_FLOAT3(mul->weight));
|
||||
break;
|
||||
}
|
||||
case OSL::ClosureColor::ADD: {
|
||||
OSL::ClosureAdd *add = (OSL::ClosureAdd *)closure;
|
||||
|
||||
flatten_background_closure_tree(sd, add->closureA, weight);
|
||||
flatten_background_closure_tree(sd, add->closureB, weight);
|
||||
flatten_background_closure_tree(kg, sd, add->closureA, weight);
|
||||
flatten_background_closure_tree(kg, sd, add->closureB, weight);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
OSL::ClosureComponent *comp = (OSL::ClosureComponent *)closure;
|
||||
CClosurePrimitive *prim = (CClosurePrimitive *)comp->data();
|
||||
|
||||
if (prim) {
|
||||
#ifdef OSL_SUPPORTS_WEIGHTED_CLOSURE_COMPONENTS
|
||||
weight = weight * TO_FLOAT3(comp->w);
|
||||
#endif
|
||||
prim->setup(sd, 0, weight);
|
||||
}
|
||||
#define OSL_CLOSURE_STRUCT_BEGIN(Upper, lower) \
|
||||
case OSL_CLOSURE_##Upper##_ID: { \
|
||||
const OSL::ClosureComponent *comp = reinterpret_cast<const OSL::ClosureComponent *>(closure); \
|
||||
weight *= TO_FLOAT3(comp->w); \
|
||||
osl_closure_##lower##_setup( \
|
||||
kg, sd, 0, weight, reinterpret_cast<const Upper##Closure *>(comp + 1)); \
|
||||
break; \
|
||||
}
|
||||
#include "closures_template.h"
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -299,12 +308,13 @@ void OSLShader::eval_background(const KernelGlobalsCPU *kg,
|
||||
|
||||
/* return background color immediately */
|
||||
if (globals->Ci)
|
||||
flatten_background_closure_tree(sd, globals->Ci);
|
||||
flatten_background_closure_tree(kg, sd, globals->Ci);
|
||||
}
|
||||
|
||||
/* Volume */
|
||||
|
||||
static void flatten_volume_closure_tree(ShaderData *sd,
|
||||
static void flatten_volume_closure_tree(const KernelGlobalsCPU *kg,
|
||||
ShaderData *sd,
|
||||
const OSL::ClosureColor *closure,
|
||||
float3 weight = make_float3(1.0f, 1.0f, 1.0f))
|
||||
{
|
||||
@ -314,26 +324,26 @@ static void flatten_volume_closure_tree(ShaderData *sd,
|
||||
switch (closure->id) {
|
||||
case OSL::ClosureColor::MUL: {
|
||||
OSL::ClosureMul *mul = (OSL::ClosureMul *)closure;
|
||||
flatten_volume_closure_tree(sd, mul->closure, TO_FLOAT3(mul->weight) * weight);
|
||||
flatten_volume_closure_tree(kg, sd, mul->closure, TO_FLOAT3(mul->weight) * weight);
|
||||
break;
|
||||
}
|
||||
case OSL::ClosureColor::ADD: {
|
||||
OSL::ClosureAdd *add = (OSL::ClosureAdd *)closure;
|
||||
flatten_volume_closure_tree(sd, add->closureA, weight);
|
||||
flatten_volume_closure_tree(sd, add->closureB, weight);
|
||||
flatten_volume_closure_tree(kg, sd, add->closureA, weight);
|
||||
flatten_volume_closure_tree(kg, sd, add->closureB, weight);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
OSL::ClosureComponent *comp = (OSL::ClosureComponent *)closure;
|
||||
CClosurePrimitive *prim = (CClosurePrimitive *)comp->data();
|
||||
|
||||
if (prim) {
|
||||
#ifdef OSL_SUPPORTS_WEIGHTED_CLOSURE_COMPONENTS
|
||||
weight = weight * TO_FLOAT3(comp->w);
|
||||
#endif
|
||||
prim->setup(sd, 0, weight);
|
||||
}
|
||||
}
|
||||
#define OSL_CLOSURE_STRUCT_BEGIN(Upper, lower) \
|
||||
case OSL_CLOSURE_##Upper##_ID: { \
|
||||
const OSL::ClosureComponent *comp = reinterpret_cast<const OSL::ClosureComponent *>(closure); \
|
||||
weight *= TO_FLOAT3(comp->w); \
|
||||
osl_closure_##lower##_setup( \
|
||||
kg, sd, 0, weight, reinterpret_cast<const Upper##Closure *>(comp + 1)); \
|
||||
break; \
|
||||
}
|
||||
#include "closures_template.h"
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -358,7 +368,7 @@ void OSLShader::eval_volume(const KernelGlobalsCPU *kg,
|
||||
|
||||
/* flatten closure tree */
|
||||
if (globals->Ci)
|
||||
flatten_volume_closure_tree(sd, globals->Ci);
|
||||
flatten_volume_closure_tree(kg, sd, globals->Ci);
|
||||
}
|
||||
|
||||
/* Displacement */
|
||||
|
@ -33,9 +33,6 @@ struct OSLShadingSystem;
|
||||
|
||||
class OSLShader {
|
||||
public:
|
||||
/* init */
|
||||
static void register_closures(OSLShadingSystem *ss);
|
||||
|
||||
/* per thread data */
|
||||
static void thread_init(KernelGlobalsCPU *kg, OSLGlobals *osl_globals);
|
||||
static void thread_free(KernelGlobalsCPU *kg);
|
||||
|
21
intern/cycles/kernel/osl/types.h
Normal file
21
intern/cycles/kernel/osl/types.h
Normal file
@ -0,0 +1,21 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0
|
||||
* Copyright 2011-2022 Blender Foundation */
|
||||
|
||||
#pragma once
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
/* Closure */
|
||||
|
||||
enum ClosureTypeOSL {
|
||||
OSL_CLOSURE_MUL_ID = -1,
|
||||
OSL_CLOSURE_ADD_ID = -2,
|
||||
|
||||
OSL_CLOSURE_NONE_ID = 0,
|
||||
|
||||
#define OSL_CLOSURE_STRUCT_BEGIN(Upper, lower) OSL_CLOSURE_##Upper##_ID,
|
||||
#include "closures_template.h"
|
||||
};
|
||||
|
||||
|
||||
CCL_NAMESPACE_END
|
@ -298,7 +298,7 @@ void OSLShaderManager::shading_system_init()
|
||||
const int nraytypes = sizeof(raytypes) / sizeof(raytypes[0]);
|
||||
ss_shared->attribute("raytypes", TypeDesc(TypeDesc::STRING, nraytypes), raytypes);
|
||||
|
||||
OSLShader::register_closures((OSLShadingSystem *)ss_shared);
|
||||
OSLRenderServices::register_closures(ss_shared);
|
||||
|
||||
loaded_shaders.clear();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user