Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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.
        }
Ejemplo n.º 4
0
        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.
        }
        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);
        }
Ejemplo n.º 6
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.
                }
            }
        }
        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);
        }
Ejemplo n.º 8
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.
                }
            }
        }