Example #1
0
        //----------------------------------------------------------------------------
        //----------------------------------------------------------------------------
        private void Render(List <RenderData> renderList)
        {
            foreach (RenderData data in renderList)
            {
                if (data.Model != null)
                {
                    Model           model      = data.Model;
                    AnimationPlayer animPlayer = data.AnimPlayer;

                    if (data.RenderCallback != null)
                    {
                        data.RenderCallback(data.Model);
                        return;
                    }
                    // Copy any parent transforms.
                    //Matrix[] a44Bones = null;

                    //if(animPlayer != null)
                    //    a44Bones = animPlayer.GetSkinTransforms();

                    Matrix[] transforms = new Matrix[model.Bones.Count];
                    ICamera  camera     = EngineServices.GetSystem <IGameSystems>().Camera;
                    LightRig lightRig   = EngineServices.GetSystem <IGameSystems>().LightRig;

                    model.CopyAbsoluteBoneTransformsTo(transforms);

                    // Draw the model. A model can have multiple meshes, so loop.
                    foreach (ModelMesh mesh in model.Meshes)
                    {
                        // This is where the mesh orientation is set, as well
                        // as our camera and projection.
                        foreach (BasicEffect effect in mesh.Effects)
                        {
                            //Matrix.CreateFromQuaternion()
                            effect.EnableDefaultLighting();
                            effect.World      = transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(data.Position) * Matrix.CreateFromQuaternion(data.Orientation);
                            effect.Projection = camera.ProjectionMatrix;
                            effect.View       = camera.ViewMatrix;

                            //SetLightingData(lightRig, effect);

                            //foreach (EffectTechnique technique in effect.Techniques)
                            //{
                            //if (a44Bones != null) effect.Parameters["Bones"].SetValue(a44Bones);


                            //effect.Parameters["Projection"].SetValue(camera.ProjectionMatrix);
                            //effect.Parameters["View"].SetValue(camera.ViewMatrix);
                            //}
                        }
                        // Draw the mesh, using the effects set above.
                        mesh.Draw();
                    }
                }
            }
        }
Example #2
0
 void OnEnable()
 {
     targetLightRig = (LightRig)serializedObject.targetObject;
     targetLightRig.FillLists();
     lightTargetParametersList = serializedObject.FindProperty("lightTargetParametersList");
     ifocus     = serializedObject.FindProperty("focus");
     lightCount = lightTargetParametersList.arraySize;
     if (ifocus.intValue != -1)
     {
         changeFocus();
     }
 }
Example #3
0
        //----------------------------------------------------------------------------
        //----------------------------------------------------------------------------
        private void SetLightingData(LightRig lightRig, Effect effect)
        {
            if (lightRig.LightCount > 0)
            {
                //This assert is in here to ensure we don't overflow the array in the shader.
                Debug.Assert(lightRig.LightCount < 8);

                //we set this so we know how many lights to process in the shaders
                effect.Parameters["nLightCount"].SetValue(lightRig.LightCount);

                for (int nIndex = 0; nIndex < lightRig.LightCount; ++nIndex)
                {
                    Light           light       = lightRig.Lights[nIndex];
                    EffectParameter effectParam = effect.Parameters["Lights"].Elements[nIndex];
                    effectParam.StructureMembers["Position"].SetValue(light.Position);
                    effectParam.StructureMembers["Target"].SetValue(light.Target);
                    effectParam.StructureMembers["Direction"].SetValue(light.Direction);
                    //effectParam.StructureMembers["Colour"].SetValue(light.Colour);
                    effectParam.StructureMembers["Intensity"].SetValue(light.Intensity);
                    effectParam.StructureMembers["OuterRadius"].SetValue(light.OuterRadius);
                    effectParam.StructureMembers["InnerRadius"].SetValue(light.InnerRadius);
                }
            }
        }
Example #4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here

            // Add objects and lights to the ObjectManager and LightManager
            // respectively. The ObjectManager accepts objects in several forms:
            //
            //   -As SceneObjects, which can be dynamic (movable) or static and are
            //    created from XNA Models or custom vertex / index buffer.
            //
            //   -As XNA Models, which can only be static.
            //

            voxelManager.AddVoxelType("Models/cobblestone", 10000);
            voxelManager.FinishInit(Content, GraphicsDevice, sceneInterface);

            //Window.Title = Window.Title + " - Instanced Object Count: " + (instancesPerContainerObject * containerObjects.Length);

            // LightRigs contain many lights and light groups.
            LightRig rig = new LightRig();

            // Ambient lights uniformly illuminate the scene.
            AmbientLight ambientlight = new AmbientLight();
            ambientlight.Enabled = true;
            ambientlight.DiffuseColor = new Vector3(0.8f, 0.98f, 0.99f);
            ambientlight.Intensity = 0.5f;

            // Directional lights illuminate the scene from a specific direction, similar to sunlight.
            DirectionalLight sunlight = new DirectionalLight();
            sunlight.Enabled = true;
            sunlight.DiffuseColor = new Vector3(1.0f, 0.97f, 0.77f);
            sunlight.Intensity = 2.6f;
            sunlight.Direction = new Vector3(-0.60f, -0.73f, -0.32f);
            sunlight.ShadowType = ShadowType.AllObjects;
            sunlight.ShadowQuality = 1.0f;
            sunlight.ShadowPrimaryBias = 1.0f;
            sunlight.ShadowSecondaryBias = 0.04f;

            DirectionalLight sunlightB = new DirectionalLight();
            sunlightB.Enabled = true;
            sunlightB.DiffuseColor = new Vector3(0.0f, 0.97f, 0.77f);
            sunlightB.Intensity = 2.6f;
            sunlightB.Direction = new Vector3(0.60f, -0.73f, -0.32f);
            sunlightB.ShadowType = ShadowType.AllObjects;
            sunlightB.ShadowQuality = 1.0f;
            sunlightB.ShadowPrimaryBias = 1.0f;
            sunlightB.ShadowSecondaryBias = 0.04f;

            // Add the lights to a group.
            LightGroup group = new LightGroup();
            group.Add(ambientlight);
            group.Add(sunlight);
            group.Add(sunlightB);

            // Add the group to the light rig and commit the changes.
            rig.LightGroups.Add(group);
            rig.CommitChanges();

            // Submit the light rig to the light manager.
            sceneInterface.LightManager.Submit(rig);

            // Setup the scene settings.
            environment = new SceneEnvironment();
            environment.VisibleDistance = 250;
            environment.FogEnabled = true;
            environment.FogColor = new Vector3(0.5f, 0.5f, 0.5f);
            environment.FogStartDistance = 200;
            environment.FogEndDistance = 250;
            environment.ShadowFadeStartDistance = 200;
            environment.ShadowFadeEndDistance = 250;
            environment.ShadowCasterDistance = 250;

            // Apply the user preferences (example - not required).
            sceneInterface.ApplyPreferences(preferences);
        }