Esempio n. 1
0
        /// <summary>
        /// Clones a <see cref="ModelComponent"/>s <see cref="Material"/> if required;
        /// </summary>
        /// <param name="modelComponent"></param>
        /// <param name="materialIndex"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">If <paramref name="modelComponent"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="materialIndex"/> is less than 0 or greater than <see cref="ModelComponent.GetMaterialCount"/> and not in <see cref="ModelComponent.Materials"/>.</exception>
        private static Material GetMaterialCopy(this ModelComponent modelComponent, int materialIndex)
        {
            if (modelComponent == null)
            {
                throw new ArgumentNullException(nameof(modelComponent));
            }

            if (!IsValidMaterialIndex(modelComponent, materialIndex))
            {
                throw new ArgumentOutOfRangeException(nameof(materialIndex));
            }

            var material = modelComponent.GetMaterial(materialIndex);

            if (material is ModelComponentMaterialCopy copy && copy.ModelComponent == modelComponent)
            {
                return(material);
            }

            var materialCopy = new ModelComponentMaterialCopy()
            {
                ModelComponent = modelComponent,
            };

            MaterialExtensions.CopyProperties(material, materialCopy);

            modelComponent.Materials[materialIndex] = materialCopy;

            return(materialCopy);
        }
Esempio n. 2
0
        public override void Update()
        {
            return;

            Entity entity   = null;
            var    newModel = entity.Get <ModelComponent>();

            //if (_selectedModel != newModel) _selectedModel?.Materials
            if (newModel != null && _selectedModel != newModel && EffectMaterial != null)
            {
                _selectedModel = newModel;

                for (int i = 0; i < _selectedModel.GetMaterialCount(); i++)
                {
                    //Remove the effect render pass from that other material
                    //TODO: This will lead to issues when the model has multiple materials
                    effectRenderPass.Material.Passes.Remove(effectRenderPass);

                    //Clone the material
                    var clonedMaterial = CloneMaterial(_selectedModel.GetMaterial(i));
                    //Layers ~= render passes
                    //Add the effect render pass to the material
                    clonedMaterial.Passes.Add(
                        effectRenderPass
                        );

                    /*
                     * var clonedPass1 = new MaterialPass(effectMaterial.Passes[0].Parameters);
                     * clonedPass1.HasTransparency = pass.HasTransparency;
                     * clonedPass1.BlendState = pass.BlendState;
                     * clonedPass1.IsLightDependent = pass.IsLightDependent;
                     *
                     * clone.Passes.Add(clonedPass1);
                     */

                    /*var parCol = new ParameterCollection();
                     * //parCol.Set(MaterialKeys.PixelStageSurfaceShaders, (SiliconStudio.Xenko.Shaders.ShaderClassSource)"hi");
                     * parCol.Set(MaterialKeys.DiffuseValue, Color4.White);
                     * clonedMaterial.Passes.Add(new MaterialPass(parCol)
                     *      {
                     *      HasTransparency = true,
                     *      BlendState = new BlendStateDescription(Blend.One, Blend.Zero),
                     *      IsLightDependent = true
                     * });*/

                    //Override the default materials
                    _selectedModel.Materials[i] = clonedMaterial;
                }
            }
        }
Esempio n. 3
0
        public override void Update()
        {
            phase = (float)Game.UpdateTime.Total.TotalSeconds * RotationSpeed;
            var rotate = Quaternion.RotationAxis(upAxis, (float)Math.PI * 2.0f * phase);

            Entity.Transform.Rotation = originalRotation * rotate;

            var material = VentLightModelComponent.GetMaterial(0);

            foreach (var pass in material.Passes)
            {
                pass.Parameters.Set(ComputeColorTextureScrollParamKeys.Offset, new Vector2(phase, 0.0f));
                pass.Parameters.Set(ComputeColorTextureScrollParamKeys.MyTexture, LightTexture);
            }
        }
Esempio n. 4
0
        private void InitializeFogTileSpace()
        {
            if (!Enable)
            {
                return;
            }

            fogMap           = new FogTile[Convert.ToInt32((Rows / Scale) * (Columns / Scale))];
            State            = new ConcurrentDictionary <Vector2, bool>();
            fogVisibilityMap = new ConcurrentDictionary <Vector2, FastList <Vector2> >();
            simulation       = this.GetSimulation();
            subscribers      = new FastList <Entity>();

            StartOffset *= Scale;

            // Generate master fog map
            var fogMapIndex = 0;

            for (var x = 0; x < Columns / Scale; x++)
            {
                for (var z = 0; z < Rows / Scale; z++)
                {
                    var coord = new Vector2(x, z);

                    var fogTileEntity = Tile.Instantiate().First();
                    fogTileEntity.Transform.Position = new Vector3(x * Scale + StartOffset,
                                                                   Entity.Transform.Position.Y, z * Scale + StartOffset);
                    fogTileEntity.Transform.Scale = Vector3.One * Scale;

                    var fogTile = new FogTile(this, Game.UpdateTime, coord);
                    fogTileEntity.Add(fogTile);

                    fogMap[fogMapIndex] = fogTile;
                    fogMapIndex++;
                    State.TryAdd(coord, false);
                    fogVisibilityMap.TryAdd(coord, new FastList <Vector2>());
                    Entity.AddChild(fogTileEntity);
                }
            }

            // Update visibility map for every point on the grid
            foreach (var fogTile in fogMap)
            {
                fogTile.Entity.Transform.GetWorldTransformation(out positionRecycler, out _, out _);
                fogVisibilityMap[fogTile.Coord].Add(fogTile.Coord);

                for (float i = 0; i <= 360; i += Sweep)
                {
                    targetRecycler = new Vector3(positionRecycler.X + (Vision * 2) * (float)Math.Cos(i), positionRecycler.Y,
                                                 positionRecycler.Z + (Vision * 2) * (float)Math.Sin(i));

                    nextTileRecycler = false;

                    foreach (var hitResult in simulation.RaycastPenetrating(positionRecycler, targetRecycler)
                             .OrderBy(result => Vector3.Distance(positionRecycler, result.Point)))
                    {
                        if (nextTileRecycler && hitResult.Collider.CollisionGroup == CollisionFilterGroups.CustomFilter10)
                        {
                            coordRecycler = hitResult.Collider.Entity.Get <FogTile>().Coord;
                            if (!fogVisibilityMap[fogTile.Coord].Contains(coordRecycler))
                            {
                                fogVisibilityMap[fogTile.Coord].Add(coordRecycler);
                            }
                            break;
                        }

                        if (hitResult.Collider.CollisionGroup == CollisionFilterGroups.StaticFilter)
                        {
                            nextTileRecycler = true;
                            continue;
                        }

                        if (Vector3.Distance(positionRecycler, hitResult.Point) > Vision)
                        {
                            continue;
                        }

                        if (hitResult.Collider.CollisionGroup == CollisionFilterGroups.CustomFilter10)
                        {
                            coordRecycler = hitResult.Collider.Entity.Get <FogTile>().Coord;
                            if (!fogVisibilityMap[fogTile.Coord].Contains(coordRecycler))
                            {
                                fogVisibilityMap[fogTile.Coord].Add(coordRecycler);
                            }
                        }
                    }
                }
            }

            shaderParamsPre = FogOfWarPre.GetMaterial(0)?.Passes[0]?.Parameters;
            shaderParamsPre?.Set(FogOfWarTileShaderKeys.Rows, Rows / Scale);
            shaderParamsPre?.Set(FogOfWarTileShaderKeys.Scale, Scale);
            shaderParamsPre?.Set(FogOfWarTileShaderKeys.FogMap, fogMap.Select(a => a.Visibility).ToArray());

            shaderParamsPost = FogOfWarPost.GetMaterial(0)?.Passes[0]?.Parameters;
            shaderParamsPost?.Set(FogOfWarDirectionalShaderKeys.FogOpacity, Opacity);

            // Disable all fog tile colliders
            foreach (var fogTile in fogMap)
            {
                SceneSystem.SceneInstance.Remove(fogTile.Entity);
            }
        }