protected override void BuildSphereAndGeometryNodes(ComponentManifest manifest, SceneNode parent)
        {
            Vector4 specColor = (Vector4)(manifest.Properties[ManifestKeys.MAT_SPEC_COLOR]);
            Effect.Parameters[EffectRegistry.MATERIAL_SPECULAR_COLOR_PARAM_NAME].SetValue(specColor);
            Effect.Parameters[EffectRegistry.TEXTURE_PARAM_NAME].SetValue(mTexture);

            float brightness = 1.0f;
            if (manifest.Properties.ContainsKey(ManifestKeys.BRIGHTNESS))
                brightness = (float)(manifest.Properties[ManifestKeys.BRIGHTNESS]);
            Effect.Parameters[EffectRegistry.BRIGHTNESS_PARAM_NAME].SetValue(brightness);

            float contrast = 1.0f;
            if (manifest.Properties.ContainsKey(ManifestKeys.CONTRAST))
                contrast = (float)(manifest.Properties[ManifestKeys.CONTRAST]);
            Effect.Parameters[EffectRegistry.CONTRAST_PARAM_NAME].SetValue(contrast);

            // First, add the effect's params to the EffectRegistry so the ParamSetter can retrieve them.
            EffectRegistry.Add(Effect, RenderOptions.RequiresHDRLighting | RenderOptions.RequiresShadowMap);

            // Create the default material
            EffectApplication defaultMaterial = new EffectApplication(Effect, RenderStatePresets.Default);
            defaultMaterial.AddParamSetter(new CommonParamSetter());
            defaultMaterial.AddParamSetter(new HDRLightParamSetter());
            defaultMaterial.AddParamSetter(new FogParamSetter());
            defaultMaterial.AddParamSetter(new ShadowParamSetter());

            RawGeometryNode geometry = null;
            ExplicitBoundingSphereNode meshBound = null;
            switch ((Shape)(manifest.Properties[ManifestKeys.SHAPE]))
            {
                case Shape.Box:
                    geometry = new RawGeometryNode(GeneratedGeometry.Box, defaultMaterial);
                    meshBound = new ExplicitBoundingSphereNode(GeneratedGeometry.BoxBound);
                    break;
                case Shape.Sphere:
                    geometry = new RawGeometryNode(GeneratedGeometry.Sphere, defaultMaterial);
                    meshBound = new ExplicitBoundingSphereNode(GeneratedGeometry.SphereBound);
                    break;
            }

            parent.AddChild(meshBound);
            meshBound.AddChild(geometry);

            // Create the ShadowMap material
            // Default to CastsShadow = true
            if (!manifest.Properties.ContainsKey(ManifestKeys.CASTS_SHADOW) || (bool)(manifest.Properties[ManifestKeys.CASTS_SHADOW]))
            {
                EffectApplication depthOnlyMaterial;
                depthOnlyMaterial = new EffectApplication(EffectRegistry.DepthOnlyFx, RenderStatePresets.Default);
                depthOnlyMaterial.AddParamSetter(new WorldViewProjParamSetter());
                geometry.AddMaterial(TraversalContext.MaterialFlags.ShadowMap, depthOnlyMaterial);
            }
            else
            {
                geometry.AddMaterial(TraversalContext.MaterialFlags.ShadowMap, null);
            }

            // If the GeometryNode requires additional materials, they would need to be added here.
        }
Beispiel #2
0
 public SceneGraphRoot(SceneResources sceneResources)
 {
     mRenderContext = new RenderContext(sceneResources);
     mDynamicRoot = new SceneNode();
     mStaticTreeRoot = null;
     mSkyboxRoot = new SceneNode();
     mTraversalData = new TraversalContext();
 }
        protected override void RemoveChild(SceneNode child)
        {
            base.RemoveChild(child);

            if (mChildren.Count == 0)
            {
                if (IsLeaf)
                {
                    Release();
                }
                else
                {
                    throw new InvalidOperationException("An ImplicitBoundingBoxNode that is not a leaf should never have fewer than two children.");
                }
            }
            else if (mChildren.Count == 1 && !IsLeaf)
            {
                mParent.AddChild(mChildren.Single());
                Release();
            }
            else
            {
                RecalculateBound();
            }
        }
        protected override void BuildSphereAndGeometryNodes(ComponentManifest manifest, SceneNode parent)
        {
            BoundingSphere bound = new BoundingSphere();
            bound.Center = Vector3.Zero;
            // TODO: P2: Magic number?
            bound.Radius = 120.0f;
            ExplicitBoundingSphereNode meshBound = new ExplicitBoundingSphereNode(bound);
            parent.AddChild(meshBound);

            // Create the default material
            EffectApplication defaultMaterial = new EffectApplication(mEffect, mSettings.RenderState);
            defaultMaterial.AddParamSetter(new ParticlesParamSetter(delegate() { return mCurrentTime; }));

            ParticleSystemGeometryNode geometry = new ParticleSystemGeometryNode(mParticleData, delegate() { mDrawCounter++; }, defaultMaterial);
            meshBound.AddChild(geometry);

            // It won't cast a shadow.
            geometry.AddMaterial(TraversalContext.MaterialFlags.ShadowMap, null);
        }
        protected override void BuildSphereAndGeometryNodes(ComponentManifest manifest, SceneNode parent)
        {
            foreach (ModelMesh mm in VisualModel.Meshes)
            {
                ExplicitBoundingSphereNode meshBound = new ExplicitBoundingSphereNode(mm.BoundingSphere);
                parent.AddChild(meshBound);

                foreach (ModelMeshPart mmp in mm.MeshParts)
                {
                    MaterialInfo mi = mmp.Tag as MaterialInfo;
                    if (mi == null)
                        throw new AssetFormatException("The VisualModel's ModelMeshParts do not contain the MaterialInfo in the Tag property.");

                    // First, add the effect's params to the EffectRegistry so the ParamSetter can retrieve them.
                    EffectRegistry.Add(mmp.Effect, mi.HandlingFlags);

                    // Create the default material
                    EffectApplication defaultMaterial = new EffectApplication(mmp.Effect, mi.RenderState);
                    defaultMaterial.AddParamSetter(new CommonParamSetter());
                    defaultMaterial.AddParamSetter(new FogParamSetter());

                    if ((mi.HandlingFlags & RenderOptions.RequiresHDRLighting) > 0)
                        defaultMaterial.AddParamSetter(new HDRLightParamSetter());

                    if ((mi.HandlingFlags & RenderOptions.RequiresSkeletalPose) > 0)
                        defaultMaterial.AddParamSetter(new SkinParamSetter());

                    if ((mi.HandlingFlags & RenderOptions.RequiresShadowMap) > 0)
                        defaultMaterial.AddParamSetter(new ShadowParamSetter());

                    if ((mi.HandlingFlags & RenderOptions.RequiresFringeMap) > 0)
                        defaultMaterial.AddParamSetter(new FringeMapParamSetter());

                    ModelGeometryNode geometry = new ModelGeometryNode(mmp, defaultMaterial);
                    meshBound.AddChild(geometry);

                    // Create the ShadowMap material
                    // Default to CastsShadow = true
                    if (!manifest.Properties.ContainsKey(ManifestKeys.CASTS_SHADOW) || (bool)(manifest.Properties[ManifestKeys.CASTS_SHADOW]))
                    {
                        EffectApplication depthOnlyMaterial;
                        if ((mi.HandlingFlags & RenderOptions.RequiresSkeletalPose) > 0)
                        {
                            depthOnlyMaterial = new EffectApplication(EffectRegistry.DepthOnlySkinFx, RenderStatePresets.Default);
                            depthOnlyMaterial.AddParamSetter(new SkinParamSetter());
                        }
                        else
                        {
                            depthOnlyMaterial = new EffectApplication(EffectRegistry.DepthOnlyFx, RenderStatePresets.Default);
                        }

                        depthOnlyMaterial.AddParamSetter(new WorldViewProjParamSetter());

                        geometry.AddMaterial(TraversalContext.MaterialFlags.ShadowMap, depthOnlyMaterial);
                    }
                    else
                    {
                        geometry.AddMaterial(TraversalContext.MaterialFlags.ShadowMap, null);
                    }

                    // If the GeometryNode requires additional materials, they would need to be added here.
                }
            }
        }
Beispiel #6
0
        public void InsertNode(SceneNode node, PartitionCategories category)
        {
            switch (category)
            {
                case PartitionCategories.Dynamic:
                    mDynamicRoot.AddChild(node);
                    break;
                case PartitionCategories.Static:
                    ImplicitBoundingBoxNode boxNode = node as ImplicitBoundingBoxNode;
                    if (boxNode == null)
                    {
                        boxNode = new ImplicitBoundingBoxNode(true);
                        boxNode.AddChild(node);
                        boxNode.RecalculateBound();
                    }

                    if (mStaticTreeRoot == null)
                    {
                        mStaticTreeRoot = boxNode;
                    }
                    else
                    {
                        mStaticTreeRoot.InsertNodeIntoBVH(boxNode);
                    }
                    break;
                case PartitionCategories.Skybox:
                    mSkyboxRoot.AddChild(node);
                    break;
            }
        }
Beispiel #7
0
 protected abstract void BuildSphereAndGeometryNodes(ComponentManifest manifest, SceneNode parent);
Beispiel #8
0
 public SceneNode(SceneNode orig)
 {
     mChildren = orig.mChildren;
     mParent = orig.mParent;
 }
Beispiel #9
0
 public virtual void AddChild(SceneNode child)
 {
     mChildren.Add(child);
     child.mParent = this;
 }
Beispiel #10
0
 public SceneNode()
 {
     mChildren = new List<SceneNode>();
     mParent = null;
 }
Beispiel #11
0
 protected virtual void RemoveChild(SceneNode child)
 {
     mChildren.Remove(child);
 }
 protected abstract void BuildSphereAndGeometryNodes(ComponentManifest manifest, SceneNode parent);
        protected override void BuildSphereAndGeometryNodes(ComponentManifest manifest, SceneNode parent)
        {
            BoundingSphere bound = new BoundingSphere();
            bound.Center = Vector3.Up;
            bound.Radius = SlagMath.SQRT_2 * 1.25f; // Billboards can be randomly enlarged and waving back and forth, so expand the bound by 25%.
            ExplicitBoundingSphereNode meshBound = new ExplicitBoundingSphereNode(bound);
            parent.AddChild(meshBound);

            // Create the default material
            EffectApplication defaultMaterial = new EffectApplication(Effect, Skelemator.RenderStatePresets.Default);
            defaultMaterial.AddParamSetter(new CommonParamSetter());
            defaultMaterial.AddParamSetter(new FogParamSetter());
            defaultMaterial.AddParamSetter(new BillboardParamSetter(true, delegate() { return mCurrentTime; }));
            EffectApplication defaultFringeMaterial = new EffectApplication(Effect, Skelemator.RenderStatePresets.AlphaBlendNPM);
            defaultFringeMaterial.AddParamSetter(new CommonParamSetter());
            defaultFringeMaterial.AddParamSetter(new FogParamSetter());
            defaultFringeMaterial.AddParamSetter(new BillboardParamSetter(false, delegate() { return mCurrentTime; }));

            AlphaCutoutGeometryNode geometry = new AlphaCutoutGeometryNode(mGeometry, defaultMaterial, defaultFringeMaterial);
            meshBound.AddChild(geometry);

            EffectApplication depthMaterial = new EffectApplication(mDepthOnlyEffect, Skelemator.RenderStatePresets.Default);
            depthMaterial.AddParamSetter(new CommonParamSetter());
            depthMaterial.AddParamSetter(new BillboardParamSetter(true, delegate() { return mCurrentTime; }));
            geometry.AddMaterial(TraversalContext.MaterialFlags.ShadowMap, null);
            geometry.AddFringeMaterial(TraversalContext.MaterialFlags.ShadowMap, null);
        }
Beispiel #14
0
        protected override void BuildSphereAndGeometryNodes(ComponentManifest manifest, SceneNode parent)
        {
            foreach (ModelMesh mm in VisualModel.Meshes)
            {
                ExplicitBoundingSphereNode meshBound = new ExplicitBoundingSphereNode(mm.BoundingSphere);
                parent.AddChild(meshBound);

                foreach (ModelMeshPart mmp in mm.MeshParts)
                {
                    MaterialInfo mi = mmp.Tag as MaterialInfo;
                    if (mi == null)
                    {
                        throw new AssetFormatException("The VisualModel's ModelMeshParts do not contain the MaterialInfo in the Tag property.");
                    }

                    // First, add the effect's params to the EffectRegistry so the ParamSetter can retrieve them.
                    EffectRegistry.Add(mmp.Effect, mi.HandlingFlags);

                    // Create the default material
                    EffectApplication defaultMaterial = new EffectApplication(mmp.Effect, mi.RenderState);
                    defaultMaterial.AddParamSetter(new CommonParamSetter());
                    defaultMaterial.AddParamSetter(new FogParamSetter());

                    if ((mi.HandlingFlags & RenderOptions.RequiresHDRLighting) > 0)
                    {
                        defaultMaterial.AddParamSetter(new HDRLightParamSetter());
                    }

                    if ((mi.HandlingFlags & RenderOptions.RequiresSkeletalPose) > 0)
                    {
                        defaultMaterial.AddParamSetter(new SkinParamSetter());
                    }

                    if ((mi.HandlingFlags & RenderOptions.RequiresShadowMap) > 0)
                    {
                        defaultMaterial.AddParamSetter(new ShadowParamSetter());
                    }

                    if ((mi.HandlingFlags & RenderOptions.RequiresFringeMap) > 0)
                    {
                        defaultMaterial.AddParamSetter(new FringeMapParamSetter());
                    }

                    ModelGeometryNode geometry = new ModelGeometryNode(mmp, defaultMaterial);
                    meshBound.AddChild(geometry);

                    // Create the ShadowMap material
                    // Default to CastsShadow = true
                    if (!manifest.Properties.ContainsKey(ManifestKeys.CASTS_SHADOW) || (bool)(manifest.Properties[ManifestKeys.CASTS_SHADOW]))
                    {
                        EffectApplication depthOnlyMaterial;
                        if ((mi.HandlingFlags & RenderOptions.RequiresSkeletalPose) > 0)
                        {
                            depthOnlyMaterial = new EffectApplication(EffectRegistry.DepthOnlySkinFx, RenderStatePresets.Default);
                            depthOnlyMaterial.AddParamSetter(new SkinParamSetter());
                        }
                        else
                        {
                            depthOnlyMaterial = new EffectApplication(EffectRegistry.DepthOnlyFx, RenderStatePresets.Default);
                        }

                        depthOnlyMaterial.AddParamSetter(new WorldViewProjParamSetter());

                        geometry.AddMaterial(TraversalContext.MaterialFlags.ShadowMap, depthOnlyMaterial);
                    }
                    else
                    {
                        geometry.AddMaterial(TraversalContext.MaterialFlags.ShadowMap, null);
                    }

                    // If the GeometryNode requires additional materials, they would need to be added here.
                }
            }
        }