diff --git a/lib/mayaHydra/hydraExtensions/adapters/directionalLightAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/directionalLightAdapter.cpp index 4b56274957..6096f223c7 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/directionalLightAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/directionalLightAdapter.cpp @@ -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 diff --git a/lib/mayaHydra/hydraExtensions/adapters/lightAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/lightAdapter.cpp index 96fa2aea20..7c3536b19e 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/lightAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/lightAdapter.cpp @@ -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); diff --git a/lib/mayaHydra/mayaPlugin/renderOverride.cpp b/lib/mayaHydra/mayaPlugin/renderOverride.cpp index 2dc442469a..85af353e5b 100644 --- a/lib/mayaHydra/mayaPlugin/renderOverride.cpp +++ b/lib/mayaHydra/mayaPlugin/renderOverride.cpp @@ -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(