Exemplo n.º 1
0
        private void CastShadow(SceneNodeBase sceneNodeBase, ShadowMappingCastShadowEventArgs arg)
        {
            if (sceneNodeBase != null)
            {
                var      node     = sceneNodeBase as ISupportShadowMapping;
                TwoFlags flags    = (node != null) ? node.EnableShadowMapping : TwoFlags.None;
                bool     before   = (node != null) && ((flags & TwoFlags.BeforeChildren) == TwoFlags.BeforeChildren);
                bool     children = (node == null) || ((flags & TwoFlags.Children) == TwoFlags.Children);

                if (before)
                {
                    flags  = node.EnableCastShadow;
                    before = (flags & TwoFlags.BeforeChildren) == TwoFlags.BeforeChildren;
                }

                if (children)
                {
                    flags    = (node != null) ? node.EnableCastShadow : TwoFlags.None;
                    children = (node == null) || ((flags & TwoFlags.Children) == TwoFlags.Children);
                }

                if (before)
                {
                    node.CastShadow(arg);
                }

                if (children)
                {
                    foreach (var item in sceneNodeBase.Children)
                    {
                        CastShadow(item, arg);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void CastShadow(ShadowMappingCastShadowEventArgs arg)
        {
            if (!this.IsInitialized)
            {
                this.Initialize();
            }

            LightBase light      = arg.Light;
            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();
        }
Exemplo n.º 3
0
        private void LightTheScene(LightBase light, Scene scene, ActionParams param)
        {
            // cast shadow from specified light.
            {
                this.lightEquipment.Begin(param.Viewport);

                var arg = new ShadowMappingCastShadowEventArgs(light);
                //this.colorMask.On();
                CastShadow(scene.RootNode, arg);
                //this.colorMask.Off();
                this.lightEquipment.End();
            }

            // light up the scene with specified light.
            {
                var arg = new ShadowMappingUnderLightEventArgs(param, scene.Camera, this.lightEquipment.BindingTexture, light);
                this.blend.On();
                RenderUnderLight(this.scene.RootNode, arg);
                this.blend.Off();
            }
        }