Skip to content

Commit e692c16

Browse files
committed
Merge branch 'feature/specular_knockout'
2 parents fd19745 + e205d77 commit e692c16

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

changes.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ Prior to the release of 3.7.1, the following items still need urgent attention:
4949
New Features
5050
------------
5151

52+
- A new finish parameter, `use_alpha`, has been added to suppress highlights
53+
and reflections depending on pigment transparency.
54+
5255
- Array elements no longer have to be of the same type.
5356

5457
- Support for variable-size arrays has been added.

source/core/material/texture.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,8 @@ FINISH *Create_Finish()
11871187
New->SubsurfaceTranslucency.Clear();
11881188
New->SubsurfaceAnisotropy.Clear();
11891189

1190+
New->AlphaKnockout = false;
1191+
11901192
return(New);
11911193
}
11921194

source/core/material/texture.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ struct Finish_Struct
132132
SNGL Reflect_Metallic; // MBP
133133
int Conserve_Energy; // added by NK Dec 19 1999
134134
bool UseSubsurface; // whether to use subsurface light transport
135+
bool AlphaKnockout; // whether pigment alpha knocks out finish effects
135136
};
136137

137138

source/core/render/trace.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,9 @@ void Trace::ComputeLightedTexture(MathColour& resultColour, ColourChannel& resul
858858
else
859859
att = layCol.Opacity();
860860

861+
if (layer->Finish->AlphaKnockout)
862+
listWNRX->back().reflec *= att;
863+
861864
// now compute the BRDF or BSSRDF contribution
862865
tmpCol.Clear();
863866

@@ -962,7 +965,12 @@ void Trace::ComputeLightedTexture(MathColour& resultColour, ColourChannel& resul
962965
// (We don't need to do this for (non-radiosity) rays during pretrace, as it does not affect radiosity sampling)
963966
if(!ray.IsPretraceRay())
964967
{
965-
if((layer->Finish->Diffuse != 0.0) || (layer->Finish->DiffuseBack != 0.0) || (layer->Finish->Specular != 0.0) || (layer->Finish->Phong != 0.0))
968+
if (((layer->Finish->Diffuse != 0.0) ||
969+
(layer->Finish->DiffuseBack != 0.0) ||
970+
(layer->Finish->Specular != 0.0) ||
971+
(layer->Finish->Phong != 0.0)) &&
972+
((!layer->Finish->AlphaKnockout) ||
973+
(att != 0.0)))
966974
{
967975
MathColour classicContribution;
968976

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

1652+
MathColour tempLightColour = (finish->AlphaKnockout ? lightcolour * attenuation : lightcolour);
1653+
16441654
// NK rad - don't compute highlights for radiosity gather rays, since this causes
16451655
// problems with colors being far too bright
16461656
// don't compute highlights for diffuse backside illumination
16471657
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)?
16481658
{
16491659
if(finish->Phong > 0.0)
16501660
{
1651-
ComputePhongColour(finish, lightsourceray.Direction, eye.Direction, layer_normal, tmpCol, lightcolour, layer_pigment_colour, relativeIor);
1661+
ComputePhongColour (finish, lightsourceray.Direction, eye.Direction, layer_normal, tmpCol,
1662+
tempLightColour, layer_pigment_colour, relativeIor);
16521663
}
16531664

16541665
if(finish->Specular > 0.0)
1655-
ComputeSpecularColour(finish, lightsourceray.Direction, -eye.Direction, layer_normal, tmpCol, lightcolour, layer_pigment_colour, relativeIor);
1666+
ComputeSpecularColour (finish, lightsourceray.Direction, -eye.Direction, layer_normal, tmpCol,
1667+
tempLightColour, layer_pigment_colour, relativeIor);
16561668
}
16571669

16581670
if(finish->Irid > 0.0)

source/parser/parser_materials.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,6 +2475,10 @@ void Parser::Parse_Finish (FINISH **Finish_Ptr)
24752475
Parse_End();
24762476
END_CASE
24772477

2478+
CASE (USE_ALPHA_TOKEN)
2479+
New->AlphaKnockout = ((int) Allow_Float(1.0) != 0);
2480+
END_CASE
2481+
24782482
OTHERWISE
24792483
UNGET
24802484
EXIT

0 commit comments

Comments
 (0)