private void ShadowMapping(SceneNodeBase sceneElement, ShdowMappingEventArgs arg)
        {
            if (sceneElement != null)
            {
                var lightContainer = sceneElement as ILocalLightContainer;
                if (lightContainer != null)
                {
                    foreach (var light in lightContainer.LightList)
                    {
                        arg.CurrentLight = light;
                        light.Begin();
                        foreach (var child in sceneElement.Children)
                        {
                            this.CastShadow(child, arg);
                        }
                        light.End();
                        arg.CurrentLight = null;
                    }
                }

                foreach (var child in sceneElement.Children)
                {
                    this.ShadowMapping(child, arg);
                }
            }
        }
        /// <summary>
        /// Cast shadow.(Prepare shadow mapping texture)
        /// </summary>
        public override void Act()
        {
            GL.Instance.ClearColor(1, 1, 1, 1);
            GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);

            var arg = new ShdowMappingEventArgs();

            this.ShadowMapping(this.Scene.RootElement, arg);
        }
        private void CastShadow(SceneNodeBase sceneElement, ShdowMappingEventArgs arg)
        {
            if (sceneElement != null)
            {
                var renderable = sceneElement as IShadowMapping;
                if (renderable != null && renderable.EnableShadowMapping)
                {
                    renderable.CastShadow(arg);
                }

                foreach (var item in sceneElement.Children)
                {
                    CastShadow(item, arg);
                }
            }
        }
Example #4
0
        public void CastShadow(ShdowMappingEventArgs arg)
        {
            if (!this.IsInitialized)
            {
                this.Initialize();
            }

            LightBase light      = arg.CurrentLight;
            mat4      projection = light.GetProjectionMatrix();
            mat4      view       = light.GetViewMatrix();
            mat4      model      = this.GetModelMatrix();

            var           method  = this.RenderUnit.Methods[0]; // shadowmapBuilder
            ShaderProgram program = method.Program;

            program.SetUniform(mvpMatrix, projection * view * model);

            method.Render();
        }