Skip to content

Commit

Permalink
Cycles : Added light-linking, as well as some tweaks to CyclesMeshLig…
Browse files Browse the repository at this point in the history
…ht so it can participate in linking.
  • Loading branch information
boberfly committed Dec 29, 2023
1 parent 10c881c commit b44fc2e
Show file tree
Hide file tree
Showing 5 changed files with 868 additions and 113 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Features
--------

- DeepSlice : Added a new node for clipping out part of an image based on depth.
- Cycles : Added support for light-linking.

Improvements
------------
Expand Down
10 changes: 0 additions & 10 deletions python/GafferCyclesTest/InteractiveCyclesRenderTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ def testAddAndRemoveOutput( self ) :

pass

@unittest.skip( "Light linking not supported" )
def testLightLinking( self ) :

pass

@unittest.skip( "Light linking not supported" )
def testHideLinkedLight( self ) :

pass

def _createConstantShader( self ) :

shader = GafferCycles.CyclesShader()
Expand Down
30 changes: 28 additions & 2 deletions python/GafferCyclesUI/CyclesMeshLightUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def __shaderMetadata( plug, name ) :
"description",
"""
Turns mesh primitives into Cycles mesh lights by assigning
an emission shader, turning off all visibility except for camera rays,
and adding the meshes to the default lights set.
an emission shader and adding the meshes to the default lights set.
""",

plugs = {
Expand All @@ -64,6 +63,8 @@ def __shaderMetadata( plug, name ) :
rays.
""",

"nameValuePlugPlugValueWidget:ignoreNamePlug", True,

],

"lightGroup" : [
Expand All @@ -73,6 +74,31 @@ def __shaderMetadata( plug, name ) :
The light group that the mesh light will contribute to.
""",

"nameValuePlugPlugValueWidget:ignoreNamePlug", True,

],

"emissionSamplingMethod" : [

"description",
"""
Sampling strategy for emissive surfaces.
""",

"nameValuePlugPlugValueWidget:ignoreNamePlug", True,

],

"emissionSamplingMethod.value" : [

"preset:None", "none",
"preset:Auto", "auto",
"preset:Front", "front",
"preset:Back", "back",
"preset:Front-Back", "front_back",

"plugValueWidget:type", "GafferUI.PresetsPlugValueWidget",

],

"parameters" : [
Expand Down
37 changes: 20 additions & 17 deletions src/GafferCycles/CyclesMeshLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,13 @@ CyclesMeshLight::CyclesMeshLight( const std::string &name )
: GafferScene::FilteredSceneProcessor( name, IECore::PathMatcher::NoMatch )
{

// CyclesAttributesNode. This hides the objects from the majority
// of ray types, since we don't want to add the poor sampling of the
// object on top of the nice sampling of the light. The only visibility
// option we don't turn off is camera visibility - instead we promote
// so the user can decide whether or not the mesh should be visible in
// the render.

CyclesAttributesPtr attributes = new CyclesAttributes( "__attributes" );
attributes->inPlug()->setInput( inPlug() );
attributes->filterPlug()->setInput( filterPlug() );
for( NameValuePlug::Iterator it( attributes->attributesPlug() ); !it.done(); ++it )
{
if( boost::ends_with( (*it)->getName().string(), "Visibility" ) && (*it)->getName() != "cameraVisibility" )
{
(*it)->enabledPlug()->setValue( true );
(*it)->valuePlug<BoolPlug>()->setValue( false );
}
}

addChild( attributes );

// Camera visibility

Plug *internalCameraVisibilityPlug = attributes->attributesPlug()->getChild<Plug>( "cameraVisibility" );
PlugPtr cameraVisibilityPlug = internalCameraVisibilityPlug->createCounterpart( "cameraVisibility", Plug::In );
addChild( cameraVisibilityPlug );
Expand All @@ -90,6 +76,13 @@ CyclesMeshLight::CyclesMeshLight( const std::string &name )
addChild( lightGroupPlug );
internalLightGroupPlug->setInput( lightGroupPlug );

// Emission sampling method

Plug *internalEmissionSamplingMethodPlug = attributes->attributesPlug()->getChild<Plug>( "emissionSamplingMethod" );
PlugPtr emissionSamplingMethodPlug = internalEmissionSamplingMethodPlug->createCounterpart( "emissionSamplingMethod", Plug::In );
addChild( emissionSamplingMethodPlug );
internalEmissionSamplingMethodPlug->setInput( emissionSamplingMethodPlug );

// Shader node. This loads the Cycles emission shader.

CyclesShaderPtr shader = new CyclesShader( "__shader" );
Expand All @@ -115,13 +108,23 @@ CyclesMeshLight::CyclesMeshLight( const std::string &name )
shaderAssignment->shaderPlug()->setInput( shader->outPlug() );
addChild( shaderAssignment );

// Set node. This adds the objects into the __lights set,
// so they will be output correctly to the renderer.

SetPtr set = new Set( "__set" );
set->inPlug()->setInput( shaderAssignment->outPlug() );
set->filterPlug()->setInput( filterPlug() );
set->namePlug()->setValue( "__lights" );
set->modePlug()->setValue( Set::Add );
addChild( set );

// Default lights Set node.

BoolPlugPtr defaultLightPlug = new BoolPlug( "defaultLight", Plug::In, true );
addChild( defaultLightPlug );

SetPtr defaultLightsSet = new Set( "__defaultLightsSet" );
defaultLightsSet->inPlug()->setInput( shaderAssignment->outPlug() );
defaultLightsSet->inPlug()->setInput( set->outPlug() );
defaultLightsSet->filterPlug()->setInput( filterPlug() );
defaultLightsSet->enabledPlug()->setInput( defaultLightPlug.get() );
defaultLightsSet->namePlug()->setValue( "defaultLights" );
Expand Down
Loading

0 comments on commit b44fc2e

Please sign in to comment.