Skip to content

Commit

Permalink
HYDRA-500 : Fix directional and default lights not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
lanierd-adsk committed Nov 9, 2023
1 parent d78bd1b commit ee77196
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ class MayaHydraDirectionalLightAdapter : public MayaHydraLightAdapter

void _CalculateLightParams(GlfSimpleLight& light) override
{
//To simulate a directional light which has no actual position, but doesn't seem to be supported in hydra, we set a position very very far
//so it looks like a directional light.
// Directional lights point toward -Z, but we need the opposite
// for the position so the light acts as a directional light.
const auto direction = GfVec4f(0.0, 0.0, 1.0, 0.0) * GetTransform();
static const double farfarAway {1.0e15};//we use a point on the Z axis far far away
const GfVec4d direction = farfarAway * GetTransform().GetRow(2);//Equivalent to GfVec4d(0.0, 0.0, farfarAway, 0.0) * GetTransform();
light.SetHasShadow(true);
light.SetPosition({ direction[0], direction[1], direction[2], 0.0f });
light.SetPosition({ (float)direction[0], (float)direction[1], (float)direction[2], 0.0f });
}

VtValue Get(const TfToken& key) override
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaHydra/hydraExtensions/adapters/lightAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ VtValue MayaHydraLightAdapter::Get(const TfToken& key)
GetGfMatrixFromMaya(GetDagPath().inclusiveMatrixInverse()));
#else
light.SetTransform(
GetGfMatrixFromMaya(GetDagPath().inclusiveMatrix()));
GetGfMatrixFromMaya(inclusiveMatrix));
#endif
_CalculateLightParams(light);
return VtValue(light);
Expand Down
9 changes: 7 additions & 2 deletions lib/mayaHydra/mayaPlugin/renderOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,15 @@ void MtohRenderOverride::_DetectMayaDefaultLighting(const MHWRender::MDrawContex
considerAllSceneLights);

if (hasDirection && !hasPosition) {

//To simulate a directional light which has no actual position, but doesn't seem to be supported in hydra, we set a position very very far
//so it looks like a directional light.
static const float farfarAway {1.0e15f};//we use a point on the Z axis far far away

// Note for devs : if you update more parameters in the default light, don't forget
// to update MtohDefaultLightDelegate::SetDefaultLight currently there are only 3 :
// to update MtohDefaultLightDelegate::SetDefaultLight and MayaHydraSceneIndex::SetDefaultLight, currently there are only 3 :
// position, diffuse, specular
_defaultLight.SetPosition({ -direction.x, -direction.y, -direction.z, 0.0f });
_defaultLight.SetPosition({ -farfarAway*direction.x, -farfarAway*direction.y, -farfarAway*direction.z, 0.0f });
_defaultLight.SetDiffuse(
{ intensity * color.r, intensity * color.g, intensity * color.b, 1.0f });
_defaultLight.SetSpecular(
Expand Down

0 comments on commit ee77196

Please sign in to comment.