internal DepthStencilBuffer(GraphicsDevice device, Texture2D depthTexture, bool isReadOnly) : base(device)
        {
            DescriptionInternal = depthTexture.Description;
            depthTexture.AddReferenceInternal();
            Texture = depthTexture;

            resourceId = Texture.ResourceId;

            if (Description.Format == PixelFormat.D24_UNorm_S8_UInt ||
                Description.Format == PixelFormat.D32_Float_S8X24_UInt)
            {
                IsDepthBuffer = true;
                IsStencilBuffer = true;
            }
            else if (Description.Format == PixelFormat.D32_Float || 
                     Description.Format == PixelFormat.D16_UNorm)
            {
                IsDepthBuffer = true;
                IsStencilBuffer = false;
            }
            else 
                throw new NotSupportedException("The provided depth stencil format is currently not supported"); // implement composition for other formats


#if !SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES
            if (isReadOnly)
            {
                if (device.versionMajor < 4)
                {
                    needReadOnlySynchronization = true;
                    throw new NotImplementedException();
                }
            }
#endif
        }
Exemplo n.º 2
0
        public override void Load()
        {
            base.Load();

            if (OfflineCompilation)
                return;

            // Declare post render pass
            PostPass = new RenderPass("PostPass").KeepAliveBy(ActiveObjects);
            RenderPass.AddPass(PostPass);


            var depthStencilTexture = Texture.New2D(GraphicsDevice, AtlasSize, AtlasSize, PixelFormat.D32_Float, TextureFlags.DepthStencil | TextureFlags.ShaderResource).KeepAliveBy(ActiveObjects);
            var depthStencilBuffer = depthStencilTexture.ToDepthStencilBuffer(false);
            ShadowMapDepth = depthStencilBuffer;

            //MainTargetPlugin.Parameters.Set(ShadowMapKeys.Texture0, ShadowMapDepth);

            // Setup clear of this target
            var renderTargetPlugin = new RenderTargetsPlugin
                {
                    Services = Services,
                    EnableClearDepth = true,
                    EnableSetTargets = false,
                    RenderPass = RenderPass,
                    RenderTarget = null,
                    DepthStencil = depthStencilBuffer,
                };
            renderTargetPlugin.Apply();

            // Use Default ZTest for GBuffer
            depthStencilStateZStandard = DepthStencilState.New(GraphicsDevice, new DepthStencilStateDescription().Default()).KeepAliveBy(ActiveObjects);
            depthStencilStateZStandard.Name = "ZStandard";

            Parameters.Set(EffectPlugin.DepthStencilStateKey, depthStencilStateZStandard);

            casterRasterizerState = RasterizerState.New(GraphicsDevice, new RasterizerStateDescription(CullMode.Back)).KeepAliveBy(ActiveObjects);

            // Variance Shadow Mapping
            // Create the blur temporary texture
            var shadowMapTextureDesc = ShadowMapDepth.Description;
            var shadowMapBlurH = Texture.New2D(GraphicsDevice, shadowMapTextureDesc.Width, shadowMapTextureDesc.Height, PixelFormat.R32G32_Float, TextureFlags.ShaderResource | TextureFlags.RenderTarget).KeepAliveBy(ActiveObjects);
            var shadowMapBlurV = Texture.New2D(GraphicsDevice, shadowMapTextureDesc.Width, shadowMapTextureDesc.Height, PixelFormat.R32G32_Float, TextureFlags.ShaderResource | TextureFlags.RenderTarget).KeepAliveBy(ActiveObjects);

            Texture2D textureSourceH = ShadowMapDepth.Texture;
            Texture2D textureSourceV = shadowMapBlurH;
            RenderTarget renderTargetH = shadowMapBlurH.ToRenderTarget();
            RenderTarget renderTargetV = shadowMapBlurV.ToRenderTarget();

            var blurQuadMesh = new EffectMesh[2];
            for (int j = 0; j < BlurCount; j++)
            {
                for (int i = 0; i < 2; ++i)
                {
                    blurQuadMesh[i] = new EffectMesh(j > 0 ? blurEffects[1] : blurEffects[i]).KeepAliveBy(ActiveObjects);
                    blurQuadMesh[i].Parameters.Set(PostEffectBlurKeys.Coefficients, new[] { 0.2270270270f, 0.3162162162f, 0.3162162162f, 0.0702702703f, 0.0702702703f });
                    var unit = i == 0 ? Vector2.UnitX : Vector2.UnitY;
                    blurQuadMesh[i].Parameters.Set(PostEffectBlurKeys.Offsets, new[] { Vector2.Zero, unit * -1.3846153846f, unit * +1.3846153846f, unit * -3.2307692308f, unit * +3.2307692308f });

                    PostPass.AddPass(blurQuadMesh[i].EffectPass);

                    RenderSystem.GlobalMeshes.AddMesh(blurQuadMesh[i]);
                }

                blurQuadMesh[0].Parameters.Set(TexturingKeys.Texture0, textureSourceH);
                blurQuadMesh[1].Parameters.Set(TexturingKeys.Texture0, textureSourceV);
                blurQuadMesh[0].Parameters.Set(RenderTargetKeys.RenderTarget, renderTargetH);
                blurQuadMesh[1].Parameters.Set(RenderTargetKeys.RenderTarget, renderTargetV);

                textureSourceH = shadowMapBlurV;
                textureSourceV = shadowMapBlurH;
            }

            ShadowMapVsm = shadowMapBlurV;

            // Final texture for VSM is result of blur
            //MainTargetPlugin.Parameters.Set(ShadowMapKeys.Texture0, shadowMapBlurV);
        }
Exemplo n.º 3
0
        // [XenkoScript]
        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);
                }
            }
        }
Exemplo n.º 4
0
 internal DepthStencilBuffer(GraphicsDevice device, Texture2D depthTexture, bool isReadOnly) : base(device)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 5
0
 protected internal Texture2D(GraphicsDevice device, Texture2D texture) : base(device, texture)
 {
 }