/// <summary> /// Create the corresponding <see cref="LightsState.Light"/> for this object. /// </summary> /// <returns> /// It returns the <see cref="LightsState.Light"/> equivalent to this SceneObjectLight. /// </returns> public override LightsState.Light ToLight(GraphicsContext ctx, SceneGraphContext sceneCtx) { TransformStateBase transformState = (TransformStateBase)sceneCtx.GraphicsStateStack.Current[TransformStateBase.StateSetIndex]; LightsState.LightSpot light = new LightsState.LightSpot(); SetLightParameters(sceneCtx, light); IModelMatrix worldModel = transformState.LocalModelView; IMatrix3x3 normalMatrix = worldModel.GetComplementMatrix(3, 3).GetInverseMatrix().Transpose(); light.Direction = ((Vertex3f)normalMatrix.Multiply((Vertex3f)Direction)).Normalized; light.Position = (Vertex3f)worldModel.Multiply(Vertex3f.Zero); light.AttenuationFactors = AttenuationFactors; light.FallOff = new Vertex2f((float)Math.Cos(Angle.ToRadians(FalloffAngle)), FalloffExponent); // Shadow mapping if (_ShadowMap != null && _ShadowViewMatrix != null) { // Determined later: light.ShadowMapIndex light.ShadowMapMvp.Set(_ShadowViewMatrix); light.ShadowMap2D = _ShadowMap; } else { light.ShadowMapIndex = -1; light.ShadowMap2D = null; } return(light); }
/// <summary> /// Create the corresponding <see cref="LightsState.Light"/> for this object. /// </summary> /// <returns> /// It returns the <see cref="LightsState.Light"/> equivalent to this SceneObjectLight. /// </returns> public override LightsState.Light ToLight(GraphicsContext ctx, SceneGraphContext sceneCtx) { LightsState.LightDirectional light = new LightsState.LightDirectional(); SetLightParameters(sceneCtx, light); TransformStateBase transformState = (TransformStateBase)sceneCtx.GraphicsStateStack.Current[TransformStateBase.StateSetIndex]; IMatrix3x3 normalMatrix = transformState.NormalMatrix; light.Direction = ((Vertex3f)normalMatrix.Multiply((Vertex3f)Direction)).Normalized; light.HalfVector = (Vertex3f.UnitZ + light.Direction).Normalized; return(light); }
/// <summary> /// Create the corresponding <see cref="LightsState.Light"/> for this object. /// </summary> /// <returns> /// It returns the <see cref="LightsState.Light"/> equivalent to this SceneObjectLight. /// </returns> public override LightsState.Light ToLight(SceneGraphContext sceneCtx) { LightsState.LightDirectional light = new LightsState.LightDirectional(); SetLightParameters(sceneCtx, light); // Note: avoiding to invert the view matrix twice IMatrix3x3 normalMatrix = sceneCtx.CurrentView.LocalModel.GetComplementMatrix(3, 3).Transpose(); light.Direction = ((Vertex3f)normalMatrix.Multiply((Vertex3f)Direction)).Normalized; light.HalfVector = (Vertex3f.UnitZ + light.Direction).Normalized; return(light); }