Exemplo n.º 1
0
        public override void Load()
        {
            base.Load();

            skyboxEffect = EffectSystem.LoadEffect("SkyboxShader", GetDefaultCompilerParameters());
            parameters.Set(TexturingKeys.TextureCube0, skybox);
        }
Exemplo n.º 2
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            customEffect = EffectSystem.LoadEffect("CustomEffect");
            quad         = new PrimitiveQuad(GraphicsDevice, customEffect);
        }
Exemplo n.º 3
0
        public override void Start()
        {
            base.Start();

            paradoxTexture = Asset.Load <Texture>("LogoParadox");
            customEffect   = EffectSystem.LoadEffect("Effect").WaitForResult();
            quad           = new PrimitiveQuad(GraphicsDevice, customEffect);

            // set fixed parameters once
            quad.Parameters.Set(EffectKeys.Center, new Vector2(0.5f, 0.5f));
            quad.Parameters.Set(EffectKeys.Frequency, 40);
            quad.Parameters.Set(EffectKeys.Spread, 0.5f);
            quad.Parameters.Set(EffectKeys.Amplitude, 0.015f);
            quad.Parameters.Set(EffectKeys.InvAspectRatio, GraphicsDevice.BackBuffer.Height / (float)GraphicsDevice.BackBuffer.Width);

            // NOTE: Linear-Wrap sampling is not available for non-square non-power-of-two textures on opengl es 2.0
            samplingState = SamplerState.New(GraphicsDevice, new SamplerStateDescription(TextureFilter.Linear, TextureAddressMode.Clamp));

            // Add Effect rendering to the end of the pipeline
            var scene      = SceneSystem.SceneInstance.Scene;
            var compositor = ((SceneGraphicsCompositorLayers)scene.Settings.GraphicsCompositor);

            renderer = new SceneDelegateRenderer(RenderQuad);
            compositor.Master.Renderers.Add(renderer);
        }
Exemplo n.º 4
0
        public override void Load()
        {
            base.Load();

            skyboxEffect = EffectSystem.LoadEffect("SkyboxShader");
            skyboxEffect.Parameters.Set(TexturingKeys.TextureCube0, skybox);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Loads the effect.
        /// </summary>
        /// <param name="contentManager">The EffectSystem instance</param>
        /// <param name="file">The file.</param>
        /// <returns></returns>
        public override EffectBase LoadEffect(object contentManager, string file)
        {
            file = file.Replace("\\", "/");
            EffectSystem effectSystem = contentManager as EffectSystem;
            Effect       effect       = effectSystem.LoadEffect(file).WaitForResult();

            return(Engine.Instance.Renderer.CreateEffect(effect));
        }
Exemplo n.º 6
0
        void CreateDeviceObjects()
        {
            // set up a commandlist
            commandList = context.CommandList;

            // compile de shader
            imShader = new EffectInstance(effectSystem.LoadEffect("ImGuiShader").WaitForResult());
            imShader.UpdateEffect(device);

            var layout = new VertexDeclaration(
                VertexElement.Position <Vector2>(),
                VertexElement.TextureCoordinate <Vector2>(),
                VertexElement.Color(PixelFormat.R8G8B8A8_UNorm)
                );

            imVertLayout = layout;

            // de pipeline desc
            var pipeline = new PipelineStateDescription()
            {
                BlendState = BlendStates.NonPremultiplied,

                RasterizerState = new RasterizerStateDescription()
                {
                    CullMode  = CullMode.None,
                    DepthBias = 0,
                    FillMode  = FillMode.Solid,
                    MultisampleAntiAliasLine = false,
                    ScissorTestEnable        = true,
                    SlopeScaleDepthBias      = 0,
                },

                PrimitiveType     = PrimitiveType.TriangleList,
                InputElements     = imVertLayout.CreateInputElements(),
                DepthStencilState = DepthStencilStates.Default,

                EffectBytecode = imShader.Effect.Bytecode,
                RootSignature  = imShader.RootSignature,

                Output = new RenderOutputDescription(PixelFormat.R8G8B8A8_UNorm)
            };

            // finally set up the pipeline
            var pipelineState = PipelineState.New(device, ref pipeline);

            imPipeline = pipelineState;

            var is32Bits           = false;
            var indexBuffer        = Xenko.Graphics.Buffer.Index.New(device, INITIAL_INDEX_BUFFER_SIZE * sizeof(ushort), GraphicsResourceUsage.Dynamic);
            var indexBufferBinding = new IndexBufferBinding(indexBuffer, is32Bits, 0);

            indexBinding = indexBufferBinding;

            var vertexBuffer        = Xenko.Graphics.Buffer.Vertex.New(device, INITIAL_VERTEX_BUFFER_SIZE * imVertLayout.CalculateSize(), GraphicsResourceUsage.Dynamic);
            var vertexBufferBinding = new VertexBufferBinding(vertexBuffer, layout, 0);

            vertexBinding = vertexBufferBinding;
        }
Exemplo n.º 7
0
        public ShadowMapRenderer(IServiceRegistry services, RenderPipeline recursivePipeline) : base(services, recursivePipeline)
        {
            // Build blur effects for VSM
            var compilerParameters = GetDefaultCompilerParameters();

            vsmHorizontalBlur = EffectSystem.LoadEffect("HorizontalVsmBlur", compilerParameters);
            vsmVerticalBlur   = EffectSystem.LoadEffect("VerticalVsmBlur", compilerParameters);
            blurParameters    = new ParameterCollection();
        }
Exemplo n.º 8
0
        private Effect GetOrCreatePickingSpriteEffect()
        {
            if (pickingSpriteEffect == null)
            {
                pickingSpriteEffect = EffectSystem.LoadEffect("SpritePicking").WaitForResult();
            }

            return(pickingSpriteEffect);
        }
Exemplo n.º 9
0
        private Effect GetOrCreateSelectedSpriteEffect()
        {
            if (selectedSpriteEffect == null)
            {
                selectedSpriteEffect = EffectSystem.LoadEffect("SelectedSprite").WaitForResult();
            }

            return(selectedSpriteEffect);
        }
Exemplo n.º 10
0
        public override void Load()
        {
            var desc = new BlendStateDescription(Blend.One, Blend.SourceAlpha);

            desc.RenderTargets[0].AlphaSourceBlend      = Blend.Zero;
            desc.RenderTargets[0].AlphaDestinationBlend = Blend.One;
            blendState = BlendState.New(GraphicsDevice, desc);

            effect          = EffectSystem.LoadEffect("AtmosphereLighting");
            Pass.StartPass += Render;
        }
Exemplo n.º 11
0
            public EffectInstance GetOrCreateAlphaCutoffSpriteEffect(EffectSystem effectSystem)
            {
                if (alphaCutoffEffect != null)
                {
                    return(alphaCutoffEffect);
                }

                alphaCutoffEffect = new EffectInstance(effectSystem.LoadEffect("SpriteAlphaCutoffEffect").WaitForResult());
                alphaCutoffEffect.Parameters.Set(SpriteBaseKeys.ColorIsSRgb, isSrgb);

                return(alphaCutoffEffect);
            }
Exemplo n.º 12
0
        private void CreateDeviceObjects()
        {
            var commandList = Game.GraphicsContext.CommandList;

            var shader = new EffectInstance(EffectSystem.LoadEffect("MultiMeshShader").WaitForResult());

            shader.UpdateEffect(GraphicsDevice);
            streamShader = shader;

            var outputDesc = new RenderOutputDescription(GraphicsDevice.Presenter.BackBuffer.Format);

            outputDesc.CaptureState(commandList);

            var pipeline = new PipelineStateDescription()
            {
                /* TODO: do we need all these? */
                BlendState        = BlendStates.Default,
                RasterizerState   = RasterizerStateDescription.Default,
                DepthStencilState = DepthStencilStates.None,
                Output            = outputDesc,

                PrimitiveType  = PrimitiveType.TriangleList,
                InputElements  = VertexType.Layout.CreateInputElements(),
                EffectBytecode = shader.Effect.Bytecode,
                RootSignature  = shader.RootSignature,
            };

            var newPipelineState = PipelineState.New(GraphicsDevice, ref pipeline);

            pipelineState = newPipelineState;

            var streamBuffer = Xenko.Graphics.Buffer.New <VertexType>(
                GraphicsDevice,
                INITIAL_INSTANCE_COUNT,
                BufferFlags.VertexBuffer | BufferFlags.StreamOutput
                );

            streamOutBufferBinding = new VertexBufferBinding(streamBuffer, VertexType.Layout, streamBuffer.ElementCount);

            transformBuffer = Xenko.Graphics.Buffer.Structured.New <Matrix>(
                GraphicsDevice,
                INITIAL_INSTANCE_COUNT,
                isUnorderedAccess: true
                );

            colorBuffer = Xenko.Graphics.Buffer.Structured.New <Color4>(
                GraphicsDevice,
                INITIAL_INSTANCE_COUNT,
                isUnorderedAccess: true
                );
        }
Exemplo n.º 13
0
        public AtmosphereBuilder(GraphicsDevice device, EffectSystem effectSystem)
        {
            blendState = BlendState.New(device, new BlendStateDescription(Blend.One, Blend.One)).DisposeBy(this);

            Data = new AtmosphereData(device, new AtmosphereSettings());

            // TODO: Use max precision temporary textures

            /*
             *          var intermediateTransmittanceDesc = Data.Transmittance.Description;
             *          intermediateTransmittanceDesc.Format = PixelFormat.R32G32B32A32_Float;
             *          var intermediateIrradianceDesc = Data.Irradiance.Description;
             *          intermediateIrradianceDesc.Format = PixelFormat.R32G32B32A32_Float;
             *          var intermediateInscatterDesc = Data.Inscatter.Description;
             *          intermediateInscatterDesc.Format = PixelFormat.R32G32B32A32_Float;
             *
             *          var intermediateTransmittance = Texture2D.New(device, intermediateTransmittanceDesc).DisposeBy(this);
             *          var intermediateIrradiance = Texture3D.New(device, intermediateIrradianceDesc).DisposeBy(this);
             *          var intermediateInscatter = Texture3D.New(device, intermediateInscatterDesc).DisposeBy(this);
             */

            deltaE  = Texture.New(device, Data.Irradiance.Description).DisposeBy(this);
            deltaSM = Texture.New(device, Data.Inscatter.Description).DisposeBy(this);
            deltaSR = Texture.New(device, Data.Inscatter.Description).DisposeBy(this);
            deltaJ  = Texture.New(device, Data.Inscatter.Description).DisposeBy(this);

            computeTransmittance      = effectSystem.LoadEffect("ComputeTransmittance");
            computeSingleIrradiance   = effectSystem.LoadEffect("SingleIrradiance");
            copySingleInscatter       = effectSystem.LoadEffect("CopySingleInscatter");
            computeSingleInscatter    = effectSystem.LoadEffect("SingleInscatter");
            computeOutscatter         = effectSystem.LoadEffect("Outscatter");
            computeMultipleIrradiance = effectSystem.LoadEffect("MultipleIrradiance");
            computeMultipleInscatter  = effectSystem.LoadEffect("MultipleInscatter");
            copyMultipleInscatter     = effectSystem.LoadEffect("CopyMultipleInscatter");
            copySlice = effectSystem.LoadEffect("CopySlice");

            parameters.Set(AtmospherePrecomputationKeys.DeltaSR, deltaSR);
            parameters.Set(AtmospherePrecomputationKeys.DeltaSM, deltaSM);
            parameters.Set(AtmospherePrecomputationKeys.DeltaE, deltaE);
            parameters.Set(AtmospherePrecomputationKeys.DeltaJ, deltaJ);
        }
Exemplo n.º 14
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            cubemapSpriteEffect = EffectSystem.LoadEffect("CubemapSprite").WaitForResult();

            drawEffectContext = RenderContext.GetShared(Services);
            lamberFilter      = new LambertianPrefilteringSH(drawEffectContext);
            renderSHEffect    = new SphericalHarmonicsRendererEffect();
            renderSHEffect.Initialize(drawEffectContext);

            spriteBatch      = new SpriteBatch(GraphicsDevice);
            inputCubemap     = Asset.Load <Texture>("CubeMap");
            outputCubemap    = Texture.NewCube(GraphicsDevice, 256, 1, PixelFormat.R8G8B8A8_UNorm, TextureFlags.RenderTarget | TextureFlags.ShaderResource).DisposeBy(this);
            displayedCubemap = outputCubemap;
        }
Exemplo n.º 15
0
        /// <inheritdoc/>
        public override void Load()
        {
            base.Load();

            // Create necessary objects
            if (IBLRenderTarget == null)
            {
                IBLRenderTarget = Texture.New2D(GraphicsDevice, readOnlyDepthBuffer.Width, readOnlyDepthBuffer.Height, PixelFormat.R16G16B16A16_Float, TextureFlags.ShaderResource | TextureFlags.RenderTarget);
            }

            cubemapMesh = GeometricPrimitive.Cube.New(GraphicsDevice);

            var blendStateDescr = new BlendStateDescription()
            {
                RenderTargets = new[]
                {
                    new BlendStateRenderTargetDescription()
                    {
                        BlendEnable           = true,
                        ColorSourceBlend      = Blend.SourceAlpha,
                        ColorDestinationBlend = Blend.One,
                        ColorBlendFunction    = BlendFunction.Add,
                        AlphaSourceBlend      = Blend.One,
                        AlphaDestinationBlend = Blend.One,
                        AlphaBlendFunction    = BlendFunction.Add,
                        ColorWriteChannels    = ColorWriteChannels.All
                    }
                }
            };

            IBLBlendState = BlendState.New(GraphicsDevice, blendStateDescr);

            // depth state to test z-fail of backfaces
            IBLDepthStencilState = DepthStencilState.New(GraphicsDevice, new DepthStencilStateDescription(true, false)
            {
                StencilEnable       = false,
                DepthBufferFunction = CompareFunction.GreaterEqual,
            });

            // effect
            IBLEffect = EffectSystem.LoadEffect(specularEffectName);

            parameters = new ParameterCollection();
            parameters.Set(RenderTargetKeys.DepthStencilSource, readOnlyDepthBuffer);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Gets the SDF font effect.
        /// </summary>
        /// <returns></returns>
        public override EffectBase GetSDFFontEffect()
        {
            if (sdfFontEffect == null)
            {
                Effect effect = effectSystem.LoadEffect("SDFFontShader").WaitForResult();
                if (effect != null)
                {
                    ParameterCollection parameters = new ParameterCollection();
                    parameters.Set <Color4>(SDFFontShaderKeys.TintColor, Color4.White);
                    parameters.Set <Color4>(SDFFontShaderKeys.BorderColor, Color4.Black);
                    parameters.Set <float>(SDFFontShaderKeys.BorderThickness, 0f);

                    sdfFontEffect = new XenkoEffect(effect, parameters);
                }
            }

            return(sdfFontEffect);
        }
Exemplo n.º 17
0
        private void RenderCubeMap()
        {
            if (displayedViews == null || spriteBatch == null)
            {
                return;
            }

            spriteEffect = EffectSystem.LoadEffect("SpriteEffect").WaitForResult();

            var size = new Vector2(screenSize.X / 3f, screenSize.Y / 4f);

            spriteBatch.Begin(SpriteSortMode.Texture, spriteEffect);
            spriteBatch.Draw(displayedViews[1], new RectangleF(0, size.Y, size.X, size.Y), Color.White);
            spriteBatch.Draw(displayedViews[2], new RectangleF(size.X, 0f, size.X, size.Y), Color.White);
            spriteBatch.Draw(displayedViews[4], new RectangleF(size.X, size.Y, size.X, size.Y), Color.White);
            spriteBatch.Draw(displayedViews[3], new RectangleF(size.X, 2f * size.Y, size.X, size.Y), Color.White);
            spriteBatch.Draw(displayedViews[5], new RectangleF(size.X, 3f * size.Y, size.X, size.Y), null, Color.White, 0f, Vector2.Zero, SpriteEffects.FlipVertically);
            spriteBatch.Draw(displayedViews[0], new RectangleF(2f * size.X, size.Y, size.X, size.Y), Color.White);
            spriteBatch.End();
        }
Exemplo n.º 18
0
        /// <inheritdoc/>
        public override void Load()
        {
            base.Load();

            useMultipleRenderTargets = GraphicsDevice.Features.Profile >= GraphicsProfile.Level_10_0;

            for (var maxBlendCount = 2; maxBlendCount < 5; ++maxBlendCount)
            {
                var compilerParameter      = new CompilerParameters();
                var compilerParameterChild = new ShaderMixinParameters[maxBlendCount];
                for (var i = 0; i < maxBlendCount; ++i)
                {
                    var param = new ShaderMixinParameters();
                    param.Add(CubemapBlendRenderer.CubemapKey, GetTextureCubeKey(i));
                    compilerParameterChild[i] = param;
                }
                compilerParameter.Set(CubemapBlendRenderer.Cubemaps, compilerParameterChild);
                compilerParameter.Set(CubemapBlendRenderer.CubemapCount, maxBlendCount);
                compilerParameter.Set(CubemapBlendRenderer.UseMultipleRenderTargets, useMultipleRenderTargets);
                cubemapBlendEffects.Add(maxBlendCount, EffectSystem.LoadEffect("CubemapBlendEffect", compilerParameter));
            }
        }
Exemplo n.º 19
0
        protected override void InitializeCore()
        {
            base.InitializeCore();

            customEffect         = EffectSystem.LoadEffect("Effect").WaitForResult();
            customEffectInstance = new EffectInstance(customEffect);

            spriteBatch = new SpriteBatch(GraphicsDevice)
            {
                VirtualResolution = new Vector3(1)
            };

            // set fixed parameters once
            customEffectInstance.Parameters.Set(TexturingKeys.Sampler, samplerState);
            customEffectInstance.Parameters.Set(EffectKeys.Center, new Vector2(0.5f, 0.5f));
            customEffectInstance.Parameters.Set(EffectKeys.Frequency, 40);
            customEffectInstance.Parameters.Set(EffectKeys.Spread, 0.5f);
            customEffectInstance.Parameters.Set(EffectKeys.Amplitude, 0.015f);
            customEffectInstance.Parameters.Set(EffectKeys.InvAspectRatio, GraphicsDevice.Presenter.BackBuffer.Height / (float)GraphicsDevice.Presenter.BackBuffer.Width);

            samplerState = SamplerState.New(GraphicsDevice, new SamplerStateDescription(TextureFilter.Linear, TextureAddressMode.Clamp));
        }
Exemplo n.º 20
0
        private void RenderCubeMap(RenderDrawContext context)
        {
            if (displayedViews == null || spriteBatch == null)
            {
                return;
            }

            spriteEffect = new EffectInstance(EffectSystem.LoadEffect("SpriteEffect").WaitForResult());

            var size = new Vector2(screenSize.X / 3f, screenSize.Y / 4f);

            context.CommandList.SetRenderTargetAndViewport(null, GraphicsDevice.Presenter.BackBuffer);
            context.CommandList.Clear(GraphicsDevice.Presenter.BackBuffer, Color.Green);

            spriteBatch.Begin(GraphicsContext, SpriteSortMode.Texture, spriteEffect);
            spriteBatch.Draw(displayedViews[1], new RectangleF(0, size.Y, size.X, size.Y), Color.White);
            spriteBatch.Draw(displayedViews[2], new RectangleF(size.X, 0f, size.X, size.Y), Color.White);
            spriteBatch.Draw(displayedViews[4], new RectangleF(size.X, size.Y, size.X, size.Y), Color.White);
            spriteBatch.Draw(displayedViews[3], new RectangleF(size.X, 2f * size.Y, size.X, size.Y), Color.White);
            spriteBatch.Draw(displayedViews[5], new RectangleF(size.X, 3f * size.Y, size.X, size.Y), null, Color.White, 0f, Vector2.Zero, SpriteEffects.FlipVertically);
            spriteBatch.Draw(displayedViews[0], new RectangleF(2f * size.X, size.Y, size.X, size.Y), Color.White);
            spriteBatch.End();
        }
Exemplo n.º 21
0
        protected Graphics.Effect ComputeMeshFallbackEffect(RenderObject renderObject, [NotNull] RenderEffect renderEffect, RenderEffectState renderEffectState)
        {
            try
            {
                var renderMesh = (RenderMesh)renderObject;

                bool hasDiffuseMap    = renderMesh.MaterialPass.Parameters.ContainsKey(MaterialKeys.DiffuseMap);
                var  fallbackMaterial = hasDiffuseMap
                    ? fallbackTextureMaterial
                    : fallbackColorMaterial;

                // High priority
                var compilerParameters = new CompilerParameters {
                    EffectParameters = { TaskPriority = -1 }
                };

                // Support skinning
                if (renderMesh.Mesh.Skinning != null && renderMesh.Mesh.Skinning.Bones.Length <= 56)
                {
                    compilerParameters.Set(MaterialKeys.HasSkinningPosition, renderMesh.Mesh.Parameters.Get(MaterialKeys.HasSkinningPosition));
                    compilerParameters.Set(MaterialKeys.HasSkinningNormal, renderMesh.Mesh.Parameters.Get(MaterialKeys.HasSkinningNormal));
                    compilerParameters.Set(MaterialKeys.HasSkinningTangent, renderMesh.Mesh.Parameters.Get(MaterialKeys.HasSkinningTangent));

                    compilerParameters.Set(MaterialKeys.SkinningMaxBones, 56);
                }

                // Set material permutations
                compilerParameters.Set(MaterialKeys.PixelStageSurfaceShaders, fallbackMaterial.Passes[0].Parameters.Get(MaterialKeys.PixelStageSurfaceShaders));
                compilerParameters.Set(MaterialKeys.PixelStageStreamInitializer, fallbackMaterial.Passes[0].Parameters.Get(MaterialKeys.PixelStageStreamInitializer));

                // Set lighting permutations (use custom white light, since this effect will not be processed by the lighting render feature)
                compilerParameters.Set(LightingKeys.EnvironmentLights, new ShaderSourceCollection {
                    new ShaderClassSource("LightConstantWhite")
                });

                // Initialize parameters with material ones (need a CopyTo?)
                renderEffect.FallbackParameters = new ParameterCollection(renderMesh.MaterialPass.Parameters);

                // Don't show selection wireframe/highlights as compiling
                var ignoreState = renderEffect.EffectSelector.EffectName.EndsWith(".Wireframe") || renderEffect.EffectSelector.EffectName.EndsWith(".Highlight") ||
                                  renderEffect.EffectSelector.EffectName.EndsWith(".Picking");

                // Also set a value so that we know something is loading (green glowing FX) or error (red glowing FX)
                if (!ignoreState)
                {
                    if (renderEffectState == RenderEffectState.Compiling)
                    {
                        compilerParameters.Set(SceneEditorParameters.IsEffectCompiling, true);
                    }
                    else if (renderEffectState == RenderEffectState.Error)
                    {
                        compilerParameters.Set(SceneEditorParameters.IsEffectError, true);
                    }
                }

                if (renderEffectState == RenderEffectState.Error)
                {
                    // Retry every few seconds
                    renderEffect.RetryTime = DateTime.UtcNow + TimeSpan.FromSeconds(5);
                }

                return(EffectSystem.LoadEffect(renderEffect.EffectSelector.EffectName, compilerParameters).WaitForResult());
            }
            catch
            {
                // TODO: Log or rethrow?
                renderEffect.State = RenderEffectState.Error;
                return(null);
            }
        }
Exemplo n.º 22
0
 public EffectInstance GetOrCreatePickingSpriteEffect(EffectSystem effectSystem)
 {
     return(pickingEffect ?? (pickingEffect = new EffectInstance(effectSystem.LoadEffect("SpritePicking").WaitForResult())));
 }
 public EffectInstance GetOrCreatePickingSpriteEffect(EffectSystem effectSystem)
 {
     return pickingEffect ?? (pickingEffect = new EffectInstance(effectSystem.LoadEffect("SpritePicking").WaitForResult()));
 }
Exemplo n.º 24
0
 public ShadowMapRenderer(IServiceRegistry services, RenderPipeline recursivePipeline) : base(services, recursivePipeline)
 {
     // Build blur effects for VSM
     vsmHorizontalBlur = EffectSystem.LoadEffect("HorizontalVsmBlur");
     vsmVerticalBlur   = EffectSystem.LoadEffect("VerticalVsmBlur");
 }