<commit_before>﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="DirectionalLight3D.cs" company="Helix Toolkit">
//   Copyright (c) 2014 Helix Toolkit contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace HelixToolkit.Wpf.SharpDX
{
    using HelixToolkit.Wpf.SharpDX.Extensions;

    public sealed class DirectionalLight3D : Light3D
    {
        public DirectionalLight3D()
        {
            this.Color = global::SharpDX.Color.White;
            this.LightType = LightType.Directional;
        }

        protected override bool OnAttach(IRenderHost host)
        {
            /// --- attach
            if (base.OnAttach(host))
            {

                /// --- light constant params            
                this.vLightDir = this.effect.GetVariableByName("vLightDir").AsVector();
                this.vLightColor = this.effect.GetVariableByName("vLightColor").AsVector();
                this.iLightType = this.effect.GetVariableByName("iLightType").AsScalar();

                /// --- Set light type
                Light3DSceneShared.LightTypes[lightIndex] = (int)this.LightType;

                /// --- flush
                //this.Device.ImmediateContext.Flush();
                return true;
            }
            else
            {
                return false;
            }
        }

        protected override void OnDetach()
        {
            Disposer.RemoveAndDispose(ref this.vLightDir);
            Disposer.RemoveAndDispose(ref this.vLightColor);
            Disposer.RemoveAndDispose(ref this.iLightType);
            base.OnDetach();
        }

        protected override bool CanRender(RenderContext context)
        {
            var manager = renderHost.RenderTechniquesManager;
            if (base.CanRender(context))
            {
                if (renderHost.RenderTechnique == manager.RenderTechniques.Get(DeferredRenderTechniqueNames.Deferred) ||
                    renderHost.RenderTechnique == manager.RenderTechniques.Get(DeferredRenderTechniqueNames.GBuffer))
                {
                    return false;
                }
                return true;
            }
            return false;
        }
        protected override void OnRender(RenderContext context)
        {
            if (this.IsRendering)
            {
                /// --- set lighting parameters

                Light3DSceneShared.LightColors[lightIndex] = this.Color;
            }
            else
            {
                // --- turn-off the light
                Light3DSceneShared.LightColors[lightIndex] = new global::SharpDX.Color4(0, 0, 0, 0);
            }

            /// --- set lighting parameters
            Light3DSceneShared.LightDirections[lightIndex] = -this.Direction.ToVector4();

            /// --- update lighting variables               
            this.vLightDir.Set(Light3DSceneShared.LightDirections);
            this.vLightColor.Set(Light3DSceneShared.LightColors);
            this.iLightType.Set(Light3DSceneShared.LightTypes);


            /// --- if shadow-map enabled
            if (this.renderHost.IsShadowMapEnabled)
            {
                /// update shader
                this.mLightView.SetMatrix(Light3DSceneShared.LightViewMatrices);
                this.mLightProj.SetMatrix(Light3DSceneShared.LightProjMatrices);
            }
        }
    }
}
<commit_msg>Fix canrender=false but still rendering issue.<commit_after>﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="DirectionalLight3D.cs" company="Helix Toolkit">
//   Copyright (c) 2014 Helix Toolkit contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace HelixToolkit.Wpf.SharpDX
{
    using HelixToolkit.Wpf.SharpDX.Extensions;

    public sealed class DirectionalLight3D : Light3D
    {
        public DirectionalLight3D()
        {
            this.Color = global::SharpDX.Color.White;
            this.LightType = LightType.Directional;
        }

        protected override bool OnAttach(IRenderHost host)
        {
            /// --- attach
            if (base.OnAttach(host))
            {

                /// --- light constant params            
                this.vLightDir = this.effect.GetVariableByName("vLightDir").AsVector();
                this.vLightColor = this.effect.GetVariableByName("vLightColor").AsVector();
                this.iLightType = this.effect.GetVariableByName("iLightType").AsScalar();

                /// --- Set light type
                Light3DSceneShared.LightTypes[lightIndex] = (int)this.LightType;

                /// --- flush
                //this.Device.ImmediateContext.Flush();
                return true;
            }
            else
            {
                return false;
            }
        }

        protected override void OnDetach()
        {
            Disposer.RemoveAndDispose(ref this.vLightDir);
            Disposer.RemoveAndDispose(ref this.vLightColor);
            Disposer.RemoveAndDispose(ref this.iLightType);
            base.OnDetach();
        }

        protected override bool CanRender(RenderContext context)
        {
            var manager = renderHost.RenderTechniquesManager;
            if (base.CanRender(context))
            {
                if (renderHost.RenderTechnique == manager.RenderTechniques.Get(DeferredRenderTechniqueNames.Deferred) ||
                    renderHost.RenderTechnique == manager.RenderTechniques.Get(DeferredRenderTechniqueNames.GBuffer))
                {
                    return false;
                }
                return true;
            }
            else
            {
                Light3DSceneShared.LightColors[lightIndex] = new global::SharpDX.Color4(0, 0, 0, 0);
            }
            return false;
        }
        protected override void OnRender(RenderContext context)
        {
            if (this.IsRendering)
            {
                /// --- set lighting parameters

                Light3DSceneShared.LightColors[lightIndex] = this.Color;
            }
            else
            {
                // --- turn-off the light
                Light3DSceneShared.LightColors[lightIndex] = new global::SharpDX.Color4(0, 0, 0, 0);
            }

            /// --- set lighting parameters
            Light3DSceneShared.LightDirections[lightIndex] = -this.Direction.ToVector4();

            /// --- update lighting variables               
            this.vLightDir.Set(Light3DSceneShared.LightDirections);
            this.vLightColor.Set(Light3DSceneShared.LightColors);
            this.iLightType.Set(Light3DSceneShared.LightTypes);


            /// --- if shadow-map enabled
            if (this.renderHost.IsShadowMapEnabled)
            {
                /// update shader
                this.mLightView.SetMatrix(Light3DSceneShared.LightViewMatrices);
                this.mLightProj.SetMatrix(Light3DSceneShared.LightProjMatrices);
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.14888503137935638, 'fraction_numerical': 0.006943517158499132, 'mean_word_length': 1.2445310158825291, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5012753', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1729, 'n_words': 272}