Skip to content

Commit

Permalink
Cycles ShaderNetworkAlgo : Remove custom unnormalized light support
Browse files Browse the repository at this point in the history
Instead rely on Cycles' inbuilt support
  • Loading branch information
murraystevenson committed Sep 27, 2024
1 parent b6a8190 commit 2a3eba1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 46 deletions.
2 changes: 2 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ Fixes
- RenderPassEditor :
- Fixed history window to update on context changes, for example, when the current frame is changed.
- Fixed invalid `scene:path` context variables created by the history window. [^1]
- Cycles : Fixed issue where scaling unnormalized quad and disk lights would not affect their brightness.

Breaking Changes
----------------

- IECoreArnold : Added `messageContext` argument to `NodeAlgo::Converter` and `NodeAlgo::MotionConverter`.
- Instancer : Renamed `encapsulateInstanceGroups` plug to `encapsulate`. Encapsulation now produces a single capsule at the `.../instances` location, instead of capsules at each `.../instances/<prototypeName>` location.
- Cycles : Removed custom handling of unnormalized lights. We now rely on Cycles' inbuilt behaviour which results in a brightness difference for unnormalized point, spot and disk lights.

[^1]: To be omitted from 1.5.0.0 release notes.

Expand Down
48 changes: 2 additions & 46 deletions src/GafferCycles/IECoreCyclesPreview/ShaderNetworkAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,13 @@ T parameterValue( const IECore::CompoundDataMap &parameters, const IECore::Inter

// Cycles lights just have a single `strength` parameter which
// we want to present as separate "virtual" parameters for
// intensity, color, exposure and normalize. We calculate un-normalized
// lights by multiplying the surface area of the light source.
// intensity, color, exposure.
bool contributesToLightStrength( InternedString parameterName )
{
return
parameterName == "intensity" ||
parameterName == "color" ||
parameterName == "exposure" ||
parameterName == "normalize"
parameterName == "exposure"
;
}

Expand All @@ -387,48 +385,6 @@ Imath::Color3f constantLightStrength( const IECoreScene::ShaderNetwork *light )
// you'd want to texture that.
strength *= powf( 2.0f, parameterValue<float>( lightShader->parameters(), "exposure", 0.0f ) );

// Cycles has normalized lights as a default, we can emulate un-normalized lights
// with a bit of surface area size calculation onto the strength parameter.
/// \todo I think we should move normalization into Cycles itself -
/// https://developer.blender.org/D16838
if( !parameterValue<bool>( lightShader->parameters(), "normalize", true ) )
{
if( lightShader->getName() == "distant_light" )
{
const float angle = IECore::degreesToRadians( parameterValue<float>( lightShader->parameters(), "angle", 0.0f ) ) / 2.0f;
const float radius = tanf( angle );
const float area = M_PI_F * radius * radius;
if( area > 0.0f )
{
strength *= area;
}
}
else if( lightShader->getName() == "background_light" )
{
// Do nothing.
}
else if(
lightShader->getName() == "quad_light" ||
lightShader->getName() == "portal"
)
{
const float width = parameterValue( lightShader->parameters(), "width", 1.0f );
const float height = parameterValue( lightShader->parameters(), "height", 1.0f );
strength *= width * height;
}
else if( lightShader->getName() == "disk_light" )
{
const float width = parameterValue( lightShader->parameters(), "width", 2.0f ) * 0.5f;
const float height = parameterValue( lightShader->parameters(), "height", 2.0f ) * 0.5f;
strength *= M_PI * width * height;
}
else // Point or spot light.
{
const float size = parameterValue( lightShader->parameters(), "size", 1.0f ) * 0.5f;
strength *= M_PI * size * size * 4.0f;
}
}

return strength;;
}

Expand Down

0 comments on commit 2a3eba1

Please sign in to comment.