public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters) { gameWindow = (iPhoneOSGameView)Description.DeviceWindowHandle.NativeHandle; device.InitDefaultRenderTarget(presentationParameters); backBuffer = device.DefaultRenderTarget; DepthStencilBuffer = device.windowProvidedDepthTexture; }
public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters) { gameWindow = (iPhoneOSGameView)Description.DeviceWindowHandle.NativeHandle; device.InitDefaultRenderTarget(presentationParameters); backBuffer = Texture.New2D(device, Description.BackBufferWidth, Description.BackBufferHeight, presentationParameters.BackBufferFormat, TextureFlags.RenderTarget | TextureFlags.ShaderResource); }
/// <summary> /// Initializes a new instance of the <see cref="ComputeTextureColor" /> class. /// </summary> /// <param name="texture">The texture.</param> /// <param name="texcoordIndex">Index of the texcoord.</param> /// <param name="scale">The scale.</param> /// <param name="offset">The offset.</param> protected ComputeTextureBase(Texture texture, TextureCoordinate texcoordIndex, Vector2 scale, Vector2 offset) { Texture = texture; TexcoordIndex = texcoordIndex; Sampler = new ComputeColorParameterSampler(); Scale = scale; Offset = offset; Key = null; }
/// <summary> /// Creates a <see cref="Sprite"/> having the provided texture and name. /// The region size is initialized with the whole size of the texture. /// </summary> /// <param name="fragmentName">The name of the sprite</param> /// <param name="texture">The texture to use as texture</param> public Sprite(string fragmentName, Texture texture) { Name = fragmentName; IsTransparent = true; Texture = texture; if(texture != null) Region = new Rectangle(0, 0, texture.ViewWidth, texture.ViewHeight); }
public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters) { device.InitDefaultRenderTarget(Description); //backBuffer = device.DefaultRenderTarget; // TODO: Review Depth buffer creation for both Android and iOS //DepthStencilBuffer = device.windowProvidedDepthTexture; backBuffer = Texture.New2D(device, Description.BackBufferWidth, Description.BackBufferHeight, presentationParameters.BackBufferFormat, TextureFlags.RenderTarget | TextureFlags.ShaderResource); }
public ShadowMapAtlasTexture(Texture texture, int textureId) { if (texture == null) throw new ArgumentNullException("texture"); Texture = texture; Clear(Texture.Width, Texture.Height); Width = texture.Width; Height = texture.Height; RenderFrame = RenderFrame.FromTexture((Texture)null, texture); Id = textureId; }
/// <summary> /// Sets an input texture /// </summary> /// <param name="slot">The slot.</param> /// <param name="texture">The texture.</param> public void SetInput(int slot, Texture texture) { if (slot < 0 || slot >= inputTextures.Length) throw new ArgumentOutOfRangeException("slot", "slot must be in the range [0, 128["); inputTextures[slot] = texture; if (slot > maxInputTextureIndex) { maxInputTextureIndex = slot; } }
public static Material NewDiffuseOnly(Texture diffuseTexture) { return New( new MaterialDescriptor() { Attributes = { Diffuse = new MaterialDiffuseMapFeature(new ComputeTextureColor(diffuseTexture)), DiffuseModel = new MaterialDiffuseLambertModelFeature(), } }); }
/// <summary> /// Creates a image fragment having the provided color/alpha textures and name. /// The region size is initialized with the whole size of the texture. /// </summary> /// <param name="fragmentName">Name of the fragment</param> /// <param name="color">The texture to use as color</param> /// <param name="alpha">the texture to use as alpha</param> public ImageFragment(string fragmentName, Texture color, Texture alpha) { Name = fragmentName; IsTransparent = true; Texture = color; TextureAlpha = alpha; var referenceTexture = color ?? alpha; if(referenceTexture != null) RegionInternal = new Rectangle(0, 0, referenceTexture.ViewWidth, referenceTexture.ViewHeight); }
/// <summary> /// Creates a <see cref="Sprite"/> having the provided texture and name. /// The region size is initialized with the whole size of the texture. /// </summary> /// <param name="fragmentName">The name of the sprite</param> /// <param name="texture">The texture to use as texture</param> public Sprite(string fragmentName, Texture texture) { Name = fragmentName; PixelsPerUnit = new Vector2(DefaultPixelsPerUnit); IsTransparent = true; Texture = texture; if (texture != null) { Region = new Rectangle(0, 0, texture.ViewWidth, texture.ViewHeight); Center = new Vector2(Region.Width/2, Region.Height/2); } }
public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters) { PresentInterval = presentationParameters.PresentationInterval; // Initialize the swap chain swapChain = CreateSwapChain(); backBuffer = new Texture(device).InitializeFrom(swapChain.GetBackBuffer<SharpDX.Direct3D11.Texture2D>(0), Description.BackBufferFormat.IsSRgb()); // Reload should get backbuffer from swapchain as well //backBufferTexture.Reload = graphicsResource => ((Texture)graphicsResource).Recreate(swapChain.GetBackBuffer<SharpDX.Direct3D11.Texture>(0)); }
public override void Start() { // create the ball sprite. var virtualResolution = new Vector3(GraphicsDevice.BackBuffer.Width, GraphicsDevice.BackBuffer.Height, 1); spriteBatch = new SpriteBatch(GraphicsDevice) { VirtualResolution = virtualResolution }; sphere = Asset.Load<Texture>("sphere"); // Initialize ball's state related variables. resolution = new Vector2(virtualResolution.X, virtualResolution.Y); ballHalfSize = new Vector2(SphereWidth / 2, SphereHeight / 2); ballPosition = resolution / 2; ballSpeed = new Vector2(600, -400); // Add Graphics Layer var scene = SceneSystem.SceneInstance.Scene; var compositor = ((SceneGraphicsCompositorLayers)scene.Settings.GraphicsCompositor); compositor.Master.Renderers.Add(delegateRenderer = new SceneDelegateRenderer(RenderSpheres)); }
protected override void InitializeCore() { base.InitializeCore(); LuminanceLogEffect = ToLoadAndUnload(new LuminanceLogEffect()); // Create 1x1 texture luminance1x1 = Texture.New2D(GraphicsDevice, 1, 1, 1, luminanceFormat, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this); // Use a multiscaler multiScaler = ToLoadAndUnload(new ImageMultiScaler()); // Readback is always going to be done on the 1x1 texture readback = ToLoadAndUnload(readback); // Blur used before upscaling blur = ToLoadAndUnload(new GaussianBlur()); blur.Radius = 4; }
protected override async Task LoadContent() { await base.LoadContent(); // sets the virtual resolution areaSize = new Vector2(GraphicsDevice.BackBuffer.Width, GraphicsDevice.BackBuffer.Height); // Creates the camera CameraComponent.UseCustomProjectionMatrix = true; CameraComponent.ProjectionMatrix = SpriteBatch.CalculateDefaultProjection(new Vector3(areaSize, 200)); // Load assets groundSprites = Asset.Load<SpriteGroup>("GroundSprite"); ballSprite1 = Asset.Load<Texture>("Sphere1"); ballSprite2 = Asset.Load<Texture>("Sphere2"); ball = Asset.Load<Entity>("Ball"); // create fore/background entities foreground = new Entity(); background = new Entity(); foreground.Add(new SpriteComponent { SpriteProvider = new SpriteFromSpriteGroup { SpriteGroup = groundSprites }, CurrentFrame = 1 }); background.Add(new SpriteComponent { SpriteProvider = new SpriteFromSpriteGroup { SpriteGroup = groundSprites }, CurrentFrame = 0 }); Scene.AddChild(ball); Scene.AddChild(foreground); Scene.AddChild(background); spriteComponent = ball.Get(SpriteComponent.Key); transfoComponent = ball.Get(TransformComponent.Key); transfoComponent.Position.X = areaSize.X / 2; transfoComponent.Position.Y = areaSize.Y / 2; var decorationScalings = new Vector3(areaSize.X, areaSize.Y, 1); background.Get(TransformComponent.Key).Scale = decorationScalings; foreground.Get(TransformComponent.Key).Scale = decorationScalings; background.Get(TransformComponent.Key).Position = new Vector3(0, 0, -1); foreground.Get(TransformComponent.Key).Position = new Vector3(0, areaSize.Y, 1); SpriteAnimation.Play(spriteComponent, 0, spriteComponent.SpriteProvider.SpritesCount-1, AnimationRepeatMode.LoopInfinite, 30); }
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); }
public override async Task Execute() { if (_tile == null) { _tile = await _unicodeFontFactory.GetTextAsync<Texture>(0, "This is a test of the emergency openuo system.", 1); } await Script.NextFrame(); }
public LuminanceResult(float averageLuminance, Texture localTexture) : this() { AverageLuminance = averageLuminance; LocalTexture = localTexture; }
protected override void DrawCore(RenderContext context) { var input = GetInput(0); var output = GetOutput(0); if (FadeOutSpeed == 0f) { // Nothing to do if (input != output) { GraphicsDevice.Copy(input, output); } return; } if (input == output) { var newInput = NewScopedRenderTarget2D(input.Description); GraphicsDevice.Copy(input, newInput); input = newInput; } // Check we have a render target to hold the persistence over a few frames if (persistenceTexture == null || persistenceTexture.Description != output.Description) { // We need to re-allocate the texture if (persistenceTexture != null) { Context.Allocator.ReleaseReference(persistenceTexture); } persistenceTexture = Context.Allocator.GetTemporaryTexture2D(output.Description); // Initializes to black GraphicsDevice.Clear(persistenceTexture, Color.Black); } var accumulationPersistence = NewScopedRenderTarget2D(persistenceTexture.Description); // For persistence, we combine the current brightness with the one of the previous frames. bloomAfterimageShader.Parameters.Set(BloomAfterimageShaderKeys.FadeOutSpeed, FadeOutSpeed); bloomAfterimageShader.Parameters.Set(BloomAfterimageShaderKeys.Sensitivity, Sensitivity / 100f); bloomAfterimageShader.SetInput(0, input); bloomAfterimageShader.SetInput(1, persistenceTexture); bloomAfterimageShader.SetOutput(accumulationPersistence); bloomAfterimageShader.Draw("Afterimage persistence accumulation"); // Keep the final brightness buffer for the following frames GraphicsDevice.Copy(accumulationPersistence, persistenceTexture); // Merge persistence and current bloom into the final result bloomAfterimageCombineShader.SetInput(0, input); bloomAfterimageCombineShader.SetInput(1, persistenceTexture); bloomAfterimageCombineShader.SetOutput(output); bloomAfterimageCombineShader.Draw("Afterimage persistence combine"); }
protected override Task LoadContent() { // Load the fonts spriteFont11 = Asset.Load<SpriteFont>("Arial"); // load the round texture roundTexture = Asset.Load<Texture>("round"); // create the SpriteBatch used to render them spriteBatch = new SpriteBatch(GraphicsDevice); // initialize parameters textHeight = spriteFont11.MeasureString(KeyboardSessionString).Y; screenSize = new Vector2(GraphicsDevice.BackBuffer.Width, GraphicsDevice.BackBuffer.Height); roundTextureSize = new Vector2(roundTexture.Width, roundTexture.Height); // activate the gesture recognitions Input.ActivatedGestures.Add(new GestureConfigDrag()); Input.ActivatedGestures.Add(new GestureConfigFlick()); Input.ActivatedGestures.Add(new GestureConfigLongPress()); Input.ActivatedGestures.Add(new GestureConfigComposite()); Input.ActivatedGestures.Add(new GestureConfigTap()); // add a task to the task scheduler that will be executed asynchronously Script.AddTask(UpdateInputStates); return Task.FromResult(0); }
public void SetShadowMapShaderData(int index, ILightShadowMapShaderData shaderData) { var singleLightData = (LightDirectionalShadowMapShaderData)shaderData; var splits = singleLightData.CascadeSplits; var matrices = singleLightData.WorldToShadowCascadeUV; int splitIndex = index * cascadeCount; for (int i = 0; i < splits.Length; i++) { cascadeSplits[splitIndex + i] = splits[i]; worldToShadowCascadeUV[splitIndex + i] = matrices[i]; } depthBiases[index] = singleLightData.DepthBias; offsetScales[index] = singleLightData.OffsetScale; // TODO: should be setup just once at creation time if (index == 0) { shadowMapTexture = singleLightData.Texture; if (shadowMapTexture != null) { shadowMapTextureSize = new Vector2(shadowMapTexture.Width, shadowMapTexture.Height); shadowMapTextureTexelSize = 1.0f / shadowMapTextureSize; } } }
/// <summary> /// Initializes a new instance of the <see cref="ComputeTextureColor" /> class. /// </summary> /// <param name="texture">The texture.</param> /// <param name="texcoordIndex">Index of the texcoord.</param> /// <param name="scale">The scale.</param> /// <param name="offset">The offset.</param> public ComputeTextureScalar(Texture texture, TextureCoordinate texcoordIndex, Vector2 scale, Vector2 offset) : base(texture, texcoordIndex, scale, offset) { Channel = TextureChannel.R; }
/// <summary> /// Create an instance of <see cref="Sprite"/> from the provided <see cref="Texture"/>. /// A unique Id is set as name and the <see cref="Region"/> is initialized to the size of the whole texture. /// </summary> /// <param name="texture">The texture to use as texture</param> public Sprite(Texture texture) : this(Guid.NewGuid().ToString(), texture) { }
/// <summary> /// Initializes a new instance of the <see cref="ComputeTextureColor"/> class. /// </summary> /// <param name="texture">The texture.</param> public ComputeTextureColor(Texture texture) : base(texture, TextureCoordinate.Texcoord0, Vector2.One, Vector2.Zero) { }
public ParameterKey<Texture> GetTextureKey(Texture texture, ParameterKey<Texture> key, Color? defaultTextureValue = null) { var textureKey = (ParameterKey<Texture>)GetParameterKey(key); if (texture != null) { Parameters.Set(textureKey, texture); } else if (defaultTextureValue != null && Assets != null) { texture = GenerateTextureFromColor(defaultTextureValue.Value); Parameters.Set(textureKey, texture); } return textureKey; }
/// <summary> /// Draws a quad with a texture. This Draw method is using a simple pixel shader that is sampling the texture. /// </summary> /// <param name="texture">The texture to draw.</param> /// <param name="samplerState">State of the sampler. If null, default sampler is <see cref="SamplerStateFactory.LinearClamp" />.</param> /// <param name="color">The color.</param> /// <param name="applyEffectStates">The flag to apply effect states.</param> /// <exception cref="System.ArgumentException">Expecting a Texture;texture</exception> public void Draw(Texture texture, SamplerState samplerState, Color4 color, bool applyEffectStates = false) { // Make sure that we are using our vertex shader parameters.Set(SpriteEffectKeys.Color, color); parameters.Set(TexturingKeys.Texture0, texture); parameters.Set(TexturingKeys.Sampler, samplerState ?? GraphicsDevice.SamplerStates.LinearClamp); simpleEffect.Apply(GraphicsDevice, parameterCollectionGroup, applyEffectStates); Draw(); // TODO ADD QUICK UNBIND FOR SRV //GraphicsDevice.Context.PixelShader.SetShaderResource(0, null); }
/// <summary> /// Initializes a new instance of the <see cref="ComputeTextureColor" /> class. /// </summary> /// <param name="texture">The texture.</param> /// <param name="texcoordIndex">Index of the texcoord.</param> /// <param name="scale">The scale.</param> /// <param name="offset">The offset.</param> public ComputeTextureColor(Texture texture, TextureCoordinate texcoordIndex, Vector2 scale, Vector2 offset) : base(texture, texcoordIndex, scale, offset) { }
/// <summary> /// Provides a color buffer and a depth buffer to apply the depth-of-field to. /// </summary> /// <param name="colorBuffer">A color buffer to process.</param> /// <param name="depthBuffer">The depth buffer corresponding to the color buffer provided.</param> public void SetColorDepthInput(Texture colorBuffer, Texture depthBuffer) { SetInput(0, colorBuffer); SetInput(1, depthBuffer); }
protected override void InitializeCore() { base.InitializeCore(); coclinearDepthMapEffect = ToLoadAndUnload(new ImageEffectShader("CoCLinearDepthShader")); combineLevelsEffect = ToLoadAndUnload(new ImageEffectShader("CombineLevelsFromCoCEffect")); combineLevelsFrontEffect = ToLoadAndUnload(new ImageEffectShader("CombineFrontCoCEffect")); textureScaler = ToLoadAndUnload(new ImageScaler()); cocMapBlur = ToLoadAndUnload(new CoCMapBlur()); thresholdAlphaCoC = ToLoadAndUnload(new ImageEffectShader("ThresholdAlphaCoC")); thresholdAlphaCoCFront = ToLoadAndUnload(new ImageEffectShader("ThresholdAlphaCoCFront")); pointDepthShader = ToLoadAndUnload(new ImageEffectShader("PointDepth")); depthReadBack = ToLoadAndUnload(new ImageReadback<Half>(Context)); depthCenter1x1 = Texture.New2D(GraphicsDevice, 1, 1, 1, PixelFormat.R16_Float, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this); depthReadBack.SetInput(depthCenter1x1); }
private void SetSpriteImage(Texture texture) { spriteComponent.SpriteProvider = new SpriteFromTexture { Texture = texture, IsTransparent = true }; }
/// <summary> /// Draws a quad with a texture. This Draw method is using the current effect bound to this instance. /// </summary> /// <param name="texture">The texture.</param> /// <param name="applyEffectStates">The flag to apply effect states.</param> public void Draw(Texture texture, bool applyEffectStates = false) { Draw(texture, null, Color.White, applyEffectStates); }
/// <summary> /// Clears a texture with unordered access. /// </summary> /// <param name="texture">The texture with unordered access.</param> /// <param name="value">Set this value for the whole buffer.</param> public void Clear(Texture texture, int value) { throw new NotImplementedException(); }