Skip to content

Commit

Permalink
Reverted remove ashikmin closure. stdosl.h formatting changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
est77 committed Nov 16, 2015
1 parent ee29cb0 commit 4f1357f
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 39 deletions.
44 changes: 44 additions & 0 deletions src/appleseed/renderer/kernel/shading/closures.cpp
Expand Up @@ -67,6 +67,17 @@ namespace

struct EmptyClosureParams {};

struct AshikhminShirleyBRDFClosureParams
{
OSL::Vec3 N;
OSL::Vec3 T;
OSL::Color3 rd;
OSL::Color3 rg;
float nu;
float nv;
float fr;
};

struct DebugClosureParams
{
OSL::ustring tag;
Expand Down Expand Up @@ -273,6 +284,30 @@ void CompositeSurfaceClosure::process_closure_tree(

switch (c->id)
{
case AshikhminShirleyID:
{
const AshikhminShirleyBRDFClosureParams* p =
reinterpret_cast<const AshikhminShirleyBRDFClosureParams*>(c->data());

AshikhminBRDFInputValues values;
values.m_rd = Color3f(p->rd);
values.m_rd_multiplier = 1.0;
values.m_rg = Color3f(p->rg);
values.m_rg_multiplier = 1.0;
values.m_nu = max(p->nu, 0.01f);
values.m_nv = max(p->nv, 0.01f);
values.m_fr_multiplier = p->fr;

add_closure<AshikhminBRDFInputValues>(
static_cast<ClosureID>(c->id),
original_shading_basis,
w,
Vector3d(p->N),
Vector3d(p->T),
values);
}
break;

case DisneyID:
{
const DisneyBRDFClosureParams* p =
Expand Down Expand Up @@ -890,6 +925,15 @@ void register_appleseed_closures(OSL::ShadingSystem& shading_system)

static const BuiltinClosures builtins[] =
{
{ "as_ashikhmin_shirley", AshikhminShirleyID, { CLOSURE_VECTOR_PARAM(AshikhminShirleyBRDFClosureParams, N),
CLOSURE_VECTOR_PARAM(AshikhminShirleyBRDFClosureParams, T),
CLOSURE_COLOR_PARAM(AshikhminShirleyBRDFClosureParams, rd),
CLOSURE_COLOR_PARAM(AshikhminShirleyBRDFClosureParams, rg),
CLOSURE_FLOAT_PARAM(AshikhminShirleyBRDFClosureParams, nu),
CLOSURE_FLOAT_PARAM(AshikhminShirleyBRDFClosureParams, nv),
CLOSURE_FLOAT_PARAM(AshikhminShirleyBRDFClosureParams, fr),
CLOSURE_FINISH_PARAM(AshikhminShirleyBRDFClosureParams) } },

{ "as_disney", DisneyID, { CLOSURE_VECTOR_PARAM(DisneyBRDFClosureParams, N),
CLOSURE_VECTOR_PARAM(DisneyBRDFClosureParams, T),
CLOSURE_COLOR_PARAM(DisneyBRDFClosureParams, base_color),
Expand Down
3 changes: 3 additions & 0 deletions src/appleseed/renderer/kernel/shading/closures.h
Expand Up @@ -32,6 +32,7 @@
// appleseed.renderer headers.
#include "renderer/modeling/bsdf/osl/oslmicrofacetbrdf.h"
#include "renderer/modeling/bsdf/osl/oslmicrofacetbtdf.h"
#include "renderer/modeling/bsdf/ashikhminbrdf.h"
#include "renderer/modeling/bsdf/diffusebtdf.h"
#include "renderer/modeling/bsdf/disneybrdf.h"
#include "renderer/modeling/bsdf/orennayarbrdf.h"
Expand Down Expand Up @@ -88,6 +89,7 @@ namespace renderer
enum ClosureID
{
// BSDF closures.
AshikhminShirleyID,
DisneyID,
OrenNayarID,
ReflectionID,
Expand Down Expand Up @@ -138,6 +140,7 @@ class APPLESEED_ALIGN(16) CompositeClosure

protected:
typedef boost::mpl::vector<
AshikhminBRDFInputValues,
DiffuseBTDFInputValues,
DipoleBSSRDFInputValues,
DisneyBRDFInputValues,
Expand Down
81 changes: 53 additions & 28 deletions src/appleseed/renderer/kernel/shading/stdosl.h.in
Expand Up @@ -482,34 +482,28 @@ string concat (string a, string b, string c, string d, string e, string f) {
// Closures
/*************************************************************/

/******************/
/***************************************/
// diffuse
/******************/
/***************************************/

closure color oren_nayar(normal N, float roughness) BUILTIN;

closure color translucent(normal N) BUILTIN;

closure color as_sheen(normal N) BUILTIN;

// for compat with the spec.
closure color diffuse(normal N)
{
return oren_nayar(N, 0);
}


/******************/
/***************************************/
// specular
/******************/
/***************************************/

closure color reflection(normal N) BUILTIN;
closure color refraction(normal N, float eta) BUILTIN;


/******************/
/***************************************/
// glossy
/******************/
/***************************************/

closure color microfacet(
string distribution,
Expand All @@ -531,9 +525,9 @@ closure color microfacet(
}


/******************/
/***************************************/
// subsurface
/******************/
/***************************************/

closure color as_subsurface(
string profile,
Expand All @@ -553,16 +547,20 @@ closure color as_subsurface(
return as_subsurface(profile, N, rd, dmfp, eta, 0.0);
}

// for compat with the spec.
closure color subsurface(float eta, float g, color mfp, color albedo)
{
return as_subsurface("better_dipole", N, albedo, mfp, eta, g);
}

/***************************************/
// composite closures
/***************************************/

/******************/
// uber-closures
/******************/
closure color as_ashikhmin_shirley(
normal N, // normal
vector T, // tangent
color rd, // diffuse reflectance of the substrate
color rg, // glossy reflectance at normal incidence
float nu, // Phong-like exponent in first tangent direction
float nv, // Phong-like exponent in second tangent direction
float fr // Fresnel multiplier
) BUILTIN;

closure color as_disney(
normal N,
Expand All @@ -580,24 +578,51 @@ closure color as_disney(
float clearcoat_gloss) BUILTIN;


/******************/
/***************************************/
// emission
/******************/
/***************************************/

closure color emission() BUILTIN;


/******************/
/***************************************/
// compatibility with the OSL spec
/***************************************/

closure color diffuse(normal N)
{
return oren_nayar(N, 0);
}

closure color phong(normal N, float exponent)
{
return as_ashikhmin_shirley(
N,
vector(0),
color(0),
color(1),
exponent,
exponent,
1.0);
}

closure color subsurface(float eta, float g, color mfp, color albedo)
{
return as_subsurface("better_dipole", N, albedo, mfp, eta, g);
}


/***************************************/
// misc
/******************/
/***************************************/

closure color background() BUILTIN;
closure color transparent() BUILTIN;


/******************/
/***************************************/
// unsupported
/******************/
/***************************************/

closure color debug(string tag) BUILTIN;
closure color holdout() BUILTIN;
Expand Down
12 changes: 1 addition & 11 deletions src/appleseed/renderer/modeling/bsdf/ashikhminbrdf.cpp
Expand Up @@ -34,7 +34,6 @@
#include "renderer/kernel/lighting/scatteringmode.h"
#include "renderer/modeling/bsdf/bsdf.h"
#include "renderer/modeling/bsdf/bsdfwrapper.h"
#include "renderer/modeling/input/inputarray.h"

// appleseed.foundation headers.
#include "foundation/math/sampling/mappings.h"
Expand Down Expand Up @@ -379,16 +378,7 @@ namespace
}

private:
APPLESEED_DECLARE_INPUT_VALUES(InputValues)
{
Spectrum m_rd; // diffuse reflectance of the substrate
double m_rd_multiplier; // diffuse reflectance multiplier
Spectrum m_rg; // glossy reflectance at normal incidence
double m_rg_multiplier; // glossy reflectance multiplier
double m_fr_multiplier; // Fresnel multiplier
double m_nu; // Phong-like exponent in first tangent direction
double m_nv; // Phong-like exponent in second tangent direction
};
typedef AshikhminBRDFInputValues InputValues;

// Precomputed reflectance-related values.
struct RVal
Expand Down
17 changes: 17 additions & 0 deletions src/appleseed/renderer/modeling/bsdf/ashikhminbrdf.h
Expand Up @@ -33,6 +33,7 @@
// appleseed.renderer headers.
#include "renderer/global/globaltypes.h"
#include "renderer/modeling/bsdf/ibsdffactory.h"
#include "renderer/modeling/input/inputarray.h"

// appleseed.foundation headers.
#include "foundation/platform/compiler.h"
Expand All @@ -50,6 +51,22 @@ namespace renderer { class ParamArray; }
namespace renderer
{

//
// Ashikhmin-Shirley BRDF input values.
//

APPLESEED_DECLARE_INPUT_VALUES(AshikhminBRDFInputValues)
{
Spectrum m_rd; // diffuse reflectance of the substrate
double m_rd_multiplier; // diffuse reflectance multiplier
Spectrum m_rg; // glossy reflectance at normal incidence
double m_rg_multiplier; // glossy reflectance multiplier
double m_fr_multiplier; // Fresnel multiplier
double m_nu; // Phong-like exponent in first tangent direction
double m_nv; // Phong-like exponent in second tangent direction
};


//
// Ashikhmin-Shirley BRDF factory.
//
Expand Down
8 changes: 8 additions & 0 deletions src/appleseed/renderer/modeling/bsdf/osl/oslbsdf.cpp
Expand Up @@ -83,6 +83,13 @@ namespace
{
memset(m_all_bsdfs, 0, sizeof(BSDF*) * NumClosuresIDs);

m_ashikhmin_shirley_brdf =
AshikhminBRDFFactory().create(
"ashikhmin_brdf",
ParamArray());

m_all_bsdfs[AshikhminShirleyID] = m_ashikhmin_shirley_brdf.get();

m_diffuse_btdf =
create_and_register_bsdf(
TranslucentID,
Expand Down Expand Up @@ -319,6 +326,7 @@ namespace
}

private:
auto_release_ptr<BSDF> m_ashikhmin_shirley_brdf;
auto_release_ptr<BSDF> m_diffuse_btdf;
auto_release_ptr<BSDF> m_disney_brdf;
auto_release_ptr<BSDF> m_microfacet_beckmann_brdf;
Expand Down

0 comments on commit 4f1357f

Please sign in to comment.