Skip to content

Commit

Permalink
Add feature to knock out highlights and reflections depending on pigm…
Browse files Browse the repository at this point in the history
…ent transparency.
  • Loading branch information
c-lipka committed Nov 19, 2016
1 parent 79ed353 commit e205d77
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 5 deletions.
4 changes: 4 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Prior to the release of 3.7.1, the following items still need urgent attention:
New Features
------------

- A new finish parameter, `use_alpha BOOL`, has been added. If set to `on`,
pigment transparency suppresses highlights and reflections. The default
setting is `off`.

- A new pattern, `potential`, has been added to define a pattern based on the
potential field of a blob or isosurface object.

Expand Down
2 changes: 1 addition & 1 deletion source/base/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#define OFFICIAL_VERSION_STRING "3.7.1"
#define OFFICIAL_VERSION_NUMBER 371

#define POV_RAY_PRERELEASE "alpha"
#define POV_RAY_PRERELEASE "x.knockout.8881807"

#if (POV_RAY_IS_AUTOBUILD == 1) && ((POV_RAY_IS_OFFICIAL == 1) || (POV_RAY_IS_SEMI_OFFICIAL == 1))
#ifdef POV_RAY_PRERELEASE
Expand Down
2 changes: 2 additions & 0 deletions source/core/material/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,8 @@ FINISH *Create_Finish()
New->SubsurfaceTranslucency.Clear();
New->SubsurfaceAnisotropy.Clear();

New->AlphaKnockout = false;

return(New);
}

Expand Down
1 change: 1 addition & 0 deletions source/core/material/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ struct Finish_Struct
SNGL Reflect_Metallic; // MBP
int Conserve_Energy; // added by NK Dec 19 1999
bool UseSubsurface; // whether to use subsurface light transport
bool AlphaKnockout; // whether pigment alpha knocks out finish effects
};


Expand Down
18 changes: 15 additions & 3 deletions source/core/render/trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,9 @@ void Trace::ComputeLightedTexture(MathColour& resultColour, ColourChannel& resul
else
att = layCol.Opacity();

if (layer->Finish->AlphaKnockout)
listWNRX->back().reflec *= att;

// now compute the BRDF or BSSRDF contribution
tmpCol.Clear();

Expand Down Expand Up @@ -964,7 +967,12 @@ void Trace::ComputeLightedTexture(MathColour& resultColour, ColourChannel& resul
// (We don't need to do this for (non-radiosity) rays during pretrace, as it does not affect radiosity sampling)
if(!ray.IsPretraceRay())
{
if((layer->Finish->Diffuse != 0.0) || (layer->Finish->DiffuseBack != 0.0) || (layer->Finish->Specular != 0.0) || (layer->Finish->Phong != 0.0))
if (((layer->Finish->Diffuse != 0.0) ||
(layer->Finish->DiffuseBack != 0.0) ||
(layer->Finish->Specular != 0.0) ||
(layer->Finish->Phong != 0.0)) &&
((!layer->Finish->AlphaKnockout) ||
(att != 0.0)))
{
MathColour classicContribution;

Expand Down Expand Up @@ -1643,18 +1651,22 @@ void Trace::ComputeOneDiffuseLight(const LightSource &lightsource, const Vector3
// surface-only diffuse term, they should use layered textures.
ComputeDiffuseColour(finish, lightsourceray.Direction, eye.Direction, layer_normal, tmpCol, lightcolour, layer_pigment_colour, relativeIor, attenuation, backside);

MathColour tempLightColour = (finish->AlphaKnockout ? lightcolour * attenuation : lightcolour);

// NK rad - don't compute highlights for radiosity gather rays, since this causes
// problems with colors being far too bright
// don't compute highlights for diffuse backside illumination
if((lightsource.Light_Type != FILL_LIGHT_SOURCE) && !eye.IsRadiosityRay() && !backside) // TODO FIXME radiosity - is this really the right way to do it (speaking of realism)?
{
if(finish->Phong > 0.0)
{
ComputePhongColour(finish, lightsourceray.Direction, eye.Direction, layer_normal, tmpCol, lightcolour, layer_pigment_colour, relativeIor);
ComputePhongColour (finish, lightsourceray.Direction, eye.Direction, layer_normal, tmpCol,
tempLightColour, layer_pigment_colour, relativeIor);
}

if(finish->Specular > 0.0)
ComputeSpecularColour(finish, lightsourceray.Direction, -eye.Direction, layer_normal, tmpCol, lightcolour, layer_pigment_colour, relativeIor);
ComputeSpecularColour (finish, lightsourceray.Direction, -eye.Direction, layer_normal, tmpCol,
tempLightColour, layer_pigment_colour, relativeIor);
}

if(finish->Irid > 0.0)
Expand Down
4 changes: 4 additions & 0 deletions source/parser/parser_materials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2632,6 +2632,10 @@ void Parser::Parse_Finish (FINISH **Finish_Ptr)
Parse_End();
END_CASE

CASE (USE_ALPHA_TOKEN)
New->AlphaKnockout = ((int) Allow_Float(1.0) != 0);
END_CASE

OTHERWISE
UNGET
EXIT
Expand Down
2 changes: 1 addition & 1 deletion unix/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.7.1-alpha
3.7.1-x.knockout.8881807

0 comments on commit e205d77

Please sign in to comment.