Skip to content

Commit

Permalink
Safeguard Lommel-Seeliger and Oren-Nayar related code with preprocess…
Browse files Browse the repository at this point in the history
…or flags.
  • Loading branch information
c-lipka committed Jan 20, 2019
1 parent dd851ba commit fc2e8be
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 6 deletions.
2 changes: 1 addition & 1 deletion source/base/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
/// where `N` is a serial number starting at 1 in each phase, `TIME` is the number of minutes
/// since 2000-01-01 00:00, and `FEATURE` is an arbitrary alphanumeric moniker for a particular
/// experimental feature.
#define POV_RAY_PRERELEASE "x.diffuse.10021406"
#define POV_RAY_PRERELEASE "x.diffuse.10021912"

#if defined(DOXYGEN) && !defined(POV_RAY_PRERELEASE)
// Work around doxygen being unable to document undefined macros.
Expand Down
14 changes: 14 additions & 0 deletions source/core/configcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@
///
/// @{

/// @def POV_EXPERIMENTAL_LOMMEL_SEELIGER
/// Whether experimental Lommel-Seeliger diffuse reflection should be enabled.
///
#ifndef POV_EXPERIMENTAL_LOMMEL_SEELIGER
#define POV_EXPERIMENTAL_LOMMEL_SEELIGER 1
#endif

/// @def POV_EXPERIMENTAL_OREN_NAYAR
/// Whether experimental Oren-Nayar diffuse reflection should be enabled.
///
#ifndef POV_EXPERIMENTAL_OREN_NAYAR
#define POV_EXPERIMENTAL_OREN_NAYAR 1
#endif

//******************************************************************************
///
/// @name PooledSimpleVector Sizes
Expand Down
4 changes: 4 additions & 0 deletions source/core/material/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,13 @@ FINISH *Create_Finish()
#endif
New->DiffuseAlbedoAdjust = 1.0;
New->DiffuseAlbedoAdjustRad = 1.0;
#if POV_EXPERIMENTAL_LOMMEL_SEELIGER
New->LommelSeeligerWeight = 0.0;
#endif
#if POV_EXPERIMENTAL_OREN_NAYAR
New->OrenNayarA = 1.0;
New->OrenNayarB = 0.0;
#endif
New->Phong = 0.0;
New->Phong_Size = 40.0;
New->Specular = 0.0;
Expand Down
12 changes: 12 additions & 0 deletions source/core/material/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ struct Finish_Struct
#endif
SNGL DiffuseAlbedoAdjust, DiffuseAlbedoAdjustRad;

#if POV_EXPERIMENTAL_LOMMEL_SEELIGER

/// How much of the diffuse contribution should be computed using the Lommel-Seeliger model.
///
/// By default, POV-Ray uses a Lambertian-based diffuse reflectivity model. While this model is useful for
Expand All @@ -122,6 +124,10 @@ struct Finish_Struct
/// is frequently used.
SNGL LommelSeeligerWeight;

#endif

#if POV_EXPERIMENTAL_OREN_NAYAR

/// @name Oren-Nayar diffuse model parameters.
///
/// By default, POV-Ray uses a Lambertian-based diffuse reflectivity model. While this model is useful for
Expand All @@ -137,6 +143,8 @@ struct Finish_Struct
/// Factor B of the simplified Oren-Nayar model, defaulting to 0.0 for the Lambertian model.
SNGL OrenNayarB;

#endif

/// @}

SNGL Specular, Roughness;
Expand All @@ -155,6 +163,8 @@ struct Finish_Struct
bool UseSubsurface; // whether to use subsurface light transport
bool AlphaKnockout; // whether pigment alpha knocks out finish effects

#if POV_EXPERIMENTAL_OREN_NAYAR

void SetOrenNayarSigma(double sigma)
{
SetOrenNayarSigmaSqr(sigma*sigma);
Expand All @@ -164,6 +174,8 @@ struct Finish_Struct
OrenNayarA = 1.0 - 0.50 * sigmaSqr / (sigmaSqr + 0.57);
OrenNayarB = 0.45 * sigmaSqr / (sigmaSqr + 0.09);
}

#endif
};


Expand Down
13 changes: 12 additions & 1 deletion source/core/render/trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2444,9 +2444,17 @@ void Trace::ComputeDiffuseColour(const FINISH *finish, const Vector3d& lightDire
else
intensity = cos_in;

if (finish->Fresnel || (finish->LommelSeeligerWeight != 0.0) || (finish->OrenNayarB != 0.0))
bool needCosOut = finish->Fresnel;
#if POV_EXPERIMENTAL_LOMMEL_SEELIGER
needCosOut = needCosOut || (finish->LommelSeeligerWeight != 0.0);
#endif
#if POV_EXPERIMENTAL_OREN_NAYAR
needCosOut = needCosOut || (finish->OrenNayarB != 0.0);
#endif
if (needCosOut)
cos_out = fabs(dot(layer_normal, eyeDirection));

#if POV_EXPERIMENTAL_OREN_NAYAR
if (finish->OrenNayarA != 1.0)
intensity *= finish->OrenNayarA;
if (finish->OrenNayarB != 0.0)
Expand All @@ -2460,12 +2468,15 @@ void Trace::ComputeDiffuseColour(const FINISH *finish, const Vector3d& lightDire
double beta = min(theta_in, theta_out);
intensity += finish->OrenNayarB * cos_in * max(0.0,cos_phi) * sin(alpha) * tan(beta);
}
#endif

#if POV_EXPERIMENTAL_LOMMEL_SEELIGER
if (finish->LommelSeeligerWeight != 0.0)
{
intensity *= (1.0 - finish->LommelSeeligerWeight);
intensity += finish->LommelSeeligerWeight * cos_in / (cos_in + cos_out);
}
#endif

intensity *= diffuse * attenuation;

Expand Down
4 changes: 4 additions & 0 deletions source/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,14 @@ void Parser::Run()

if(mExperimentalFlags.backsideIllumination) featureList.push_back("backside illumination");
if(mExperimentalFlags.functionHf) featureList.push_back("function '.hf'");
#if POV_EXPERIMENTAL_LOMMEL_SEELIGER
if(mExperimentalFlags.lommelSeeliger) featureList.push_back("Lommel-Seeliger diffuse model");
#endif
if(mExperimentalFlags.meshCamera) featureList.push_back("mesh camera");
if(mExperimentalFlags.objImport) featureList.push_back("wavefront obj import");
#if POV_EXPERIMENTAL_OREN_NAYAR
if(mExperimentalFlags.orenNayar) featureList.push_back("Oren-Nayar diffuse model");
#endif
if(mExperimentalFlags.slopeAltitude) featureList.push_back("slope pattern altitude");
if(mExperimentalFlags.spline) featureList.push_back("spline");
if(mExperimentalFlags.subsurface) featureList.push_back("subsurface light transport");
Expand Down
8 changes: 8 additions & 0 deletions source/parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,14 @@ struct ExperimentalFlags
{
bool backsideIllumination : 1;
bool functionHf : 1;
#if POV_EXPERIMENTAL_LOMMEL_SEELIGER
bool lommelSeeliger : 1;
#endif
bool meshCamera : 1;
bool objImport : 1;
#if POV_EXPERIMENTAL_OREN_NAYAR
bool orenNayar : 1;
#endif
bool slopeAltitude : 1;
bool spline : 1;
bool subsurface : 1;
Expand All @@ -170,10 +174,14 @@ struct ExperimentalFlags
ExperimentalFlags() :
backsideIllumination(false),
functionHf(false),
#if POV_EXPERIMENTAL_LOMMEL_SEELIGER
lommelSeeliger(false),
#endif
meshCamera(false),
objImport(false),
#if POV_EXPERIMENTAL_OREN_NAYAR
orenNayar(false),
#endif
slopeAltitude(false),
spline(false),
subsurface(false),
Expand Down
20 changes: 16 additions & 4 deletions source/parser/parser_materials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2313,17 +2313,21 @@ void Parser::Parse_Finish (FINISH **Finish_Ptr)
mExperimentalFlags.backsideIllumination = true;
END_CASE

#if POV_EXPERIMENTAL_LOMMEL_SEELIGER
CASE (LOMMEL_SEELIGER_TOKEN)
New->LommelSeeligerWeight = Parse_Float ();
mExperimentalFlags.lommelSeeliger = true;
END_CASE
#endif

#if POV_EXPERIMENTAL_OREN_NAYAR
CASE (OREN_NAYAR_TOKEN)
New->SetOrenNayarSigma(Parse_Float ());
mExperimentalFlags.orenNayar = true;
PossibleError("Parameterization of the Oren-Nayar diffuse model has not been finalized yet."
" Expect future versions of POV-Ray to render this scene differently without warning.");
END_CASE
#endif

CASE (REFLECTION_TOKEN)
{
Expand Down Expand Up @@ -2542,21 +2546,25 @@ void Parser::Parse_Finish (FINISH **Finish_Ptr)
END_EXPECT /* End of finish_mods */
#endif

if ((New->OrenNayarA != 1.0) || (New->OrenNayarB != 0.0))
#if POV_EXPERIMENTAL_LOMMEL_SEELIGER
if (New->LommelSeeligerWeight != 0.0)
{
if (New->Fresnel)
PossibleError("Finish-level 'fresnel' keyword found in combination with the Oren-Nayar diffuse model."
PossibleError("Finish-level 'fresnel' keyword found in combination with the Lommel-Seeliger diffuse model."
" The interaction of these features has not been finalized yet, and is known to be bogus."
" Expect future versions of POV-Ray to render this scene differently without warning.");
}
#endif

if (New->LommelSeeligerWeight != 0.0)
#if POV_EXPERIMENTAL_OREN_NAYAR
if ((New->OrenNayarA != 1.0) || (New->OrenNayarB != 0.0))
{
if (New->Fresnel)
PossibleError("Finish-level 'fresnel' keyword found in combination with the Lommel-Seeliger diffuse model."
PossibleError("Finish-level 'fresnel' keyword found in combination with the Oren-Nayar diffuse model."
" The interaction of these features has not been finalized yet, and is known to be bogus."
" Expect future versions of POV-Ray to render this scene differently without warning.");
}
#endif

if ((sceneData->EffectiveLanguageVersion() >= 370) && ambientSet)
{
Expand Down Expand Up @@ -2584,15 +2592,19 @@ void Parser::Parse_Finish (FINISH **Finish_Ptr)
// so that a user-specified value of 1.0 corresponds to a
// backscattering of 100% of the incoming light
double EffectiveBihemisphericalReflectance = 2.0 / (New->Brilliance + 1.0);
#if POV_EXPERIMENTAL_OREN_NAYAR
if (New->OrenNayarA != 1.0)
EffectiveBihemisphericalReflectance *= New->OrenNayarA;
if (New->OrenNayarB != 0.0)
EffectiveBihemisphericalReflectance += New->OrenNayarB * (2.0/3.0 - (64.0/45.0)*(1.0/M_PI));
#endif
#if POV_EXPERIMENTAL_LOMMEL_SEELIGER
if (New->LommelSeeligerWeight != 0.0)
{
EffectiveBihemisphericalReflectance *= (1.0 - New->LommelSeeligerWeight);
EffectiveBihemisphericalReflectance += New->LommelSeeligerWeight * ((8.0 * (1.0-log(2.0))) / 3.0);
}
#endif
if (diffuseAdjust)
{
New->DiffuseAlbedoAdjust = 1.0 / EffectiveBihemisphericalReflectance;
Expand Down
4 changes: 4 additions & 0 deletions source/parser/reservedwords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ const RESERVED_WORD Reserved_Words[] = {
{ LOCAL_TOKEN, "local" },
{ LOCATION_TOKEN, "location" },
{ LOG_TOKEN, "log" },
#if POV_EXPERIMENTAL_LOMMEL_SEELIGER
{ LOMMEL_SEELIGER_TOKEN, "lommel_seeliger "},
#endif
{ LOOK_AT_TOKEN, "look_at" },
{ LOOKS_LIKE_TOKEN, "looks_like" },
{ LOW_ERROR_FACTOR_TOKEN, "low_error_factor" },
Expand Down Expand Up @@ -380,7 +382,9 @@ const RESERVED_WORD Reserved_Words[] = {
{ ONION_TOKEN, "onion" },
{ OPEN_TOKEN, "open" },
{ OPTIONAL_TOKEN, "optional" },
#if POV_EXPERIMENTAL_OREN_NAYAR
{ OREN_NAYAR_TOKEN, "oren_nayar "},
#endif
{ ORIENT_TOKEN, "orient" },
{ ORIENTATION_TOKEN, "orientation" },
{ ORTHOGRAPHIC_TOKEN, "orthographic" },
Expand Down
4 changes: 4 additions & 0 deletions source/parser/reservedwords.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,9 @@ enum TokenId : int
LOAD_FILE_TOKEN,
LOCAL_TOKEN,
LOCATION_TOKEN,
#if POV_EXPERIMENTAL_LOMMEL_SEELIGER
LOMMEL_SEELIGER_TOKEN,
#endif
LOOK_AT_TOKEN,
LOOKS_LIKE_TOKEN,
LOW_ERROR_FACTOR_TOKEN,
Expand Down Expand Up @@ -527,7 +529,9 @@ enum TokenId : int
ONION_TOKEN,
OPEN_TOKEN,
OPTIONAL_TOKEN,
#if POV_EXPERIMENTAL_OREN_NAYAR
OREN_NAYAR_TOKEN,
#endif
ORIENT_TOKEN,
ORIENTATION_TOKEN,
ORTHOGRAPHIC_TOKEN,
Expand Down

0 comments on commit fc2e8be

Please sign in to comment.