|
49 | 49 | #include "pxr/usd/usd/schemaRegistry.h" |
50 | 50 | #endif |
51 | 51 |
|
| 52 | +#include "boost/algorithm/string/predicate.hpp" |
52 | 53 | #include "boost/algorithm/string/replace.hpp" |
53 | 54 | #include "boost/pointer_cast.hpp" |
54 | 55 |
|
@@ -391,22 +392,28 @@ IECoreScene::ShaderNetworkPtr IECoreUSD::ShaderAlgo::readShaderNetwork( const px |
391 | 392 | IECoreScene::ShaderNetworkPtr result = new IECoreScene::ShaderNetwork(); |
392 | 393 | IECoreScene::ShaderNetwork::Parameter outputHandle = readShaderNetworkWalk( usdSource.GetPrim().GetParent().GetPath(), usdSource.GetOutput( usdSourceName ), *result ); |
393 | 394 |
|
394 | | - // For the output shader, set the type to "ai:surface" if it is "ai:shader". |
395 | | - // This is complete nonsense - there is nothing to suggest that this shader is |
396 | | - // of type surface - it could be a simple texture or noise, or even a |
397 | | - // displacement or volume shader. |
| 395 | + // If the output shader has type "ai:shader" then set its type to |
| 396 | + // "ai:surface" or "ai:light" as appropriate. This is just a heuristic, |
| 397 | + // needed because we don't write the type out in `writeShaderNetwork()`. |
| 398 | + // It's fragile because it is possible to assign `ai:shader` types as |
| 399 | + // displacements or volumes as well as surfaces. But in the majority of |
| 400 | + // cases this allows us to round-trip shader assignments as required by |
| 401 | + // Gaffer's conventions. |
398 | 402 | // |
399 | | - // But arbitrarily setting the type on the output to "ai:surface" matches our |
400 | | - // current Gaffer convention, so it allows round-tripping. |
401 | | - // In the long run, the fact this is working at all appears to indicate that we |
402 | | - // don't use the suffix of the shader type for anything, and we should just set |
403 | | - // everything to prefix:shader ( aside from lights, which are a bit of a |
404 | | - // different question ) |
| 403 | + /// \todo In the long run, we want to stop relying on shader types |
| 404 | + /// completely. |
405 | 405 | const IECoreScene::Shader *outputShader = result->getShader( outputHandle.shader ); |
406 | 406 | if( outputShader->getType() == "ai:shader" ) |
407 | 407 | { |
408 | 408 | IECoreScene::ShaderPtr o = outputShader->copy(); |
409 | | - o->setType( "ai:surface" ); |
| 409 | + if( boost::ends_with( outputShader->getName(), "_light" ) ) |
| 410 | + { |
| 411 | + o->setType( "ai:light" ); |
| 412 | + } |
| 413 | + else |
| 414 | + { |
| 415 | + o->setType( "ai:surface" ); |
| 416 | + } |
410 | 417 | result->setShader( outputHandle.shader, std::move( o ) ); |
411 | 418 | } |
412 | 419 |
|
|
0 commit comments