Ejemplo n.º 1
0
        public static ShaderClassSource GenerateTextureLayer(string vfsOutputPath, string sourceTextureFile, int textureUVSetIndex, Vector2 textureUVscaling,
                                                             ref int textureCount, ParameterKey <Texture> surfaceMaterialKey, Mesh meshData, Logger logger)
        {
            ParameterKey <Texture> parameterKey;

            var url = vfsOutputPath + "_" + Path.GetFileNameWithoutExtension(sourceTextureFile);

            if (File.Exists(sourceTextureFile))
            {
                if (logger != null)
                {
                    logger.Warning($"The texture '{sourceTextureFile}' referenced in the mesh material can not be found on the system. Loading will probably fail at run time.", CallerInfo.Get());
                }
            }

            parameterKey = ParameterKeys.IndexedKey(surfaceMaterialKey, textureCount++);
            var uvSetName = "TEXCOORD";

            if (textureUVSetIndex != 0)
            {
                uvSetName += textureUVSetIndex;
            }
            //albedoMaterial->Add(gcnew ShaderClassSource("TextureStream", uvSetName, "TEXTEST" + uvSetIndex));
            var uvScaling          = textureUVscaling;
            var textureName        = parameterKey.Name;
            var needScaling        = uvScaling != Vector2.One;
            var currentComposition = needScaling
                ? new ShaderClassSource("ComputeColorTextureRepeat", textureName, uvSetName, "float2(" + uvScaling.X + ", " + uvScaling.Y + ")")
            : new ShaderClassSource("ComputeColorTexture", textureName, uvSetName);

            return(currentComposition);
        }
Ejemplo n.º 2
0
        // [ParadoxScript]
        public static async Task LoadCave(EngineContext engineContext, Entity animationEntity)
        {
            // Setup "fake" directional light for outdoor so that normal maps stand out.
            var outdoorLight = new DirectionalLight {
                LightDirection = new Vector3(-2.0f, -1.0f, -1.0f)
            };
            //outdoor.Permutations.Set(LightingPermutation.Key, new LightingPermutation { Lights = { outdoorLight } });
            //outdoor.Permutations.Set(LightingPermutation.Key, new LightingPermutation { Lights = { outdoorLight } });

            var effectMagma = engineContext.RenderContext.Effects.First(x => x.Name == "Magma");

            effectMagma.Parameters.AddSources(engineContext.DataContext.RenderPassPlugins.TryGetValue("NoisePlugin").Parameters);

            //var assetManager = new AssetManager(new ContentSerializerContextGenerator(engineContext.VirtualFileSystem, engineContext.PackageManager, ParameterContainerExtensions.DefaultSceneSerializer));
            var caveEntityPrefab1 = await engineContext.AssetManager.LoadAsync <Entity>("/global_data/gdc_demo/bg/bg1.hotei#");

            var caveEntityPrefab2 = await engineContext.AssetManager.LoadAsync <Entity>("/global_data/gdc_demo/bg/bg2.hotei#");

            var caveEntity1 = Prefab.Clone(caveEntityPrefab1);
            var caveEntity2 = Prefab.Clone(caveEntityPrefab2);

            SkyBoxPlugin skyBoxPlugin;

            if (engineContext.DataContext.RenderPassPlugins.TryGetValueCast("SkyBoxPlugin", out skyBoxPlugin))
            {
                var skyBoxTexture = (Texture2D)await engineContext.AssetManager.LoadAsync <Texture>("/global_data/gdc_demo/bg/GDC2012_map_sky.dds");

                skyBoxPlugin.Texture = skyBoxTexture;
            }

            var magmaTexturePaths = new[]
            {
                "/global_data/gdc_demo/bg/GDC2012_map_maguma_04.dds",
                "/global_data/gdc_demo/bg/GDC2012_map_maguma_05.dds",
                "/global_data/gdc_demo/bg/GDC2012_map_maguma_06.dds",

                "/global_data/gdc_demo/bg/GDC2012_map_maguma_00.dds",
                "/global_data/gdc_demo/bg/GDC2012_map_maguma_01.dds",
                "/global_data/gdc_demo/bg/GDC2012_map_maguma_02.dds",
                "/global_data/gdc_demo/bg/GDC2012_map_maguma_03.dds",
                "/global_data/gdc_demo/bg/GDC2012_map_maguma_noise_00.dds",
                "/global_data/gdc_demo/bg/GDC2012_map_maguma_noise_01.dds",
                "/global_data/gdc_demo/bg/GDC2012_map_maguma_normals.dds",
            };
            var magmaTextures = new Texture2D[magmaTexturePaths.Length];

            for (int i = 0; i < magmaTextures.Length; i++)
            {
                magmaTextures[i] = (Texture2D)await engineContext.AssetManager.LoadAsync <Texture>(magmaTexturePaths[i]);
            }

            var lightVectors = new[]
            {
                new Vector3(-1.0f, 0.3f, -1.0f),
                new Vector3(1.0f, 0.0f, -1.0f),
                new Vector3(1.0f, 0.0f, -1.0f),
            };


            var random     = new Random(0);
            int planeIndex = 0;

            foreach (var entity in ParameterContainerExtensions.CollectEntityTree(caveEntity1))
            {
                var meshComponent = entity.Get(ModelComponent.Key);
                if (meshComponent == null)
                {
                    continue;
                }

                // Setup textures for magma
                if (entity.Name.StartsWith("maguma_"))
                {
                    meshComponent.MeshParameters.Set(LightKeys.LightDirection, lightVectors[planeIndex]);
                    meshComponent.MeshParameters.Set(ParameterKeys.IndexedKey(TexturingKeys.Texture0, 1), magmaTextures[planeIndex]);
                    planeIndex++;
                    for (int i = 3; i < magmaTextures.Length; i++)
                    {
                        meshComponent.MeshParameters.Set(ParameterKeys.IndexedKey(TexturingKeys.Texture0, i - 1), magmaTextures[i]);
                    }


                    foreach (var effectMesh in meshComponent.SubMeshes)
                    {
                        effectMesh.EffectData.Name = "Magma";
                    }

                    // Attach a bullet particle emitter to the magma
                    var emitter = new BulletParticleEmitterComponent()
                    {
                        //Count = 4096,
                        Count       = 16384,
                        Description = new BulletEmitterDescription()
                        {
                            Target     = new Vector3(-3016.261f, -70.52288f, 800.8788f),
                            BulletSize = 4.0f,
                            //MaxTimeTarget = 1000.0f + 5000.0f * (float)random.NextDouble(),
                            VelocityUp     = new Vector3(0, 0, 200),
                            MaxTimeUp      = 5000.0f,
                            MaxTimeTarget  = 20000.0f,
                            VelocityTarget = 200.0f,
                            Opacity        = 1.0f,
                            //DistanceDragonRepulse = 1200.0f,
                            //DecayDragonRepulse = 70.0f,
                            DistanceDragonRepulse = 600.0f,
                            DecayDragonRepulse    = 70.0f,
                            VelocityRepulse       = 200.0f,
                        },
                        RootAnimation = animationEntity,
                    };
                    emitter.OnAddToSystem(engineContext.EntityManager, engineContext.RenderContext);
                    emitter.OnUpdateData();
                    entity.Set(ParticleEmitterComponent.Key, emitter);
                }

                foreach (var effectMesh in meshComponent.SubMeshes)
                {
                    effectMesh.Parameters.Set(ParameterKeys.IndexedKey(TexturingKeys.DiffuseTexture, 3), (Texture2D)await engineContext.AssetManager.LoadAsync <Texture>("/global_data/gdc_demo/bg/GDC2012_map_dis_ao.dds"));
                }
            }

            await engineContext.EntityManager.AddEntityAsync(caveEntity1);

            await engineContext.EntityManager.AddEntityAsync(caveEntity2);

            foreach (var entity in ParameterContainerExtensions.CollectEntityTree(caveEntity1).Concat(ParameterContainerExtensions.CollectEntityTree(caveEntity2)))
            {
                var meshComponent = entity.Get(ModelComponent.Key);
                if (meshComponent == null)
                {
                    continue;
                }

                foreach (var effectMesh in meshComponent.InstantiatedSubMeshes)
                {
                    effectMesh.Value.Parameters.Set(MaterialKeys.SpecularIntensity, 2.0f);
                    effectMesh.Value.Parameters.Set(MaterialKeys.SpecularPower, 0.1f);
                }
            }
        }