/// <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) { TransformState transformState = (TransformState)sceneCtx.GraphicsStateStack.Current[TransformState.StateSetIndex]; LightsState.LightSpot light = new LightsState.LightSpot(); SetLightParameters(sceneCtx, light); Matrix4x4f worldModel = transformState.ModelView; Matrix3x3f normalMatrix = new Matrix3x3f(worldModel, 3, 3).Inverse.Transposed; light.Direction = (normalMatrix * (Vertex3f)Direction).Normalized; light.Position = (Vertex3f)(worldModel * Vertex3f.Zero); light.AttenuationFactors = AttenuationFactors; light.FallOff = new Vertex2f((float)Math.Cos(Angle.ToRadians(FalloffAngle)), FalloffExponent); // Shadow mapping if (_ShadowMap != null) { // Determined later: light.ShadowMapIndex light.ShadowMapMvp = _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) { 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(SceneGraphContext sceneCtx) { LightsState.LightSpot light = new LightsState.LightSpot(); SetLightParameters(sceneCtx, light); light.FallOff = new Vertex2f(FalloffAngle, FalloffExponent); return(light); }