private string AddFileToProject(string filename)
        {
            string openFile = Program.Instance.OpenFile;

            if (openFile != null)
            {
                string projectFolder = string.Concat(new FileInfo(openFile).DirectoryName, "\\");
                string newFileName   = new FileInfo(filename).Name;
                string copiedName    = string.Concat(projectFolder, newFileName);
                if (!File.Exists(copiedName))
                {
                    File.Copy(filename, copiedName);
                    if (filename.EndsWith(".x"))
                    {
                        XMesh mesh = new XMesh(filename);
                        for (int i = 0; i < mesh.NumberTextures; i++)
                        {
                            TextureBase texture = mesh.GetTexture(i);
                            if ((texture != null) && (!string.IsNullOrEmpty(texture.FileName)))
                            {
                                AddFileToProject(texture.FileName);
                            }
                        }
                        mesh.Dispose();
                    }
                }
                return(copiedName);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        /// <summary>
        /// Replaces a texture with a new one.
        /// </summary>
        /// <param name="oldTexture"></param>
        /// <param name="newTexture"></param>
        public bool ReplaceTexture(string oldTexture, string newTexture, bool update)
        {
            bool textureFound = false;

            if (meshTextures == null)
            {
                return(false);
            }
            for (int i = 0; i < meshTextures.Length; i++)
            {
                TextureBase texture = meshTextures[i];
                if (texture != null)
                {
                    if ((texture.FileName.ToLower().EndsWith(oldTexture.ToLower())) ||
                        (update && texture.FileName.LastIndexOf('\\') > 0 &&
                         newTexture.ToLower().EndsWith(texture.FileName.Substring(texture.FileName.LastIndexOf('\\') + 1).ToLower())))
                    {
                        try
                        {
                            textureFound = true;
                            texture.Dispose();
                            texture         = new TextureBase(newTexture);
                            meshTextures[i] = texture;
                        }
                        catch
                        {
                        }
                    }
                }
            }
            return(textureFound);
        }
예제 #3
0
        /// <summary>
        /// creates non-separable filter pass
        /// </summary>
        public static RenderPass CreateFilter(
			 string filterName,
			 string filterNamespace,
			 TextureBase source,
			 TextureBase result)
        {
            var viewport = ValueProvider.Create (() => new Vector2 (result.Width, result.Height));
            var uniformState = new UniformState ();
            uniformState.Set ("viewport_size", viewport);

            var _1stPass = CreateFullscreenQuad (filterName, filterNamespace, viewport,
            null
            ,
            window =>
            {
                GL.Clear (ClearBufferMask.ColorBufferBit);
                GL.Disable (EnableCap.DepthTest);
                GL.Disable (EnableCap.Blend);
            //pass state
            },
            new FramebufferBindingSet {{ "OUT_FragData_result", result }},
            uniformState,
            new TextureBindingSet {{ "source_texture", source }});
            return _1stPass;
        }
        /// <summary>
        /// given color and depth textures, render them.
        /// </summary>
        public static RenderPass CreateSolidBox(
			 TextureBase depth_texture,
			 BufferObject<Vector4> sprite_pos_buffer,
			 BufferObject<Vector4> sprite_color_buffer,
			 BufferObject<Vector4> sprite_dimensions_buffer,
			 BufferObject<Matrix4> sprite_rotation_local_buffer,
			 BufferObject<Matrix4> sprite_rotation_buffer,
			 IValueProvider<int> particles_count,
				IValueProvider<float> particle_scale_factor,
				IValueProvider<string> fragdepthroutine,
			 ModelViewProjectionParameters mvp
		)
        {
            var viewport = ValueProvider.Create (() => new Vector2 (depth_texture.Width, depth_texture.Height));
            var outputroutine = ValueProvider.Create (() => "SetOutputsNone");
            return CreateSolidBox
            (
                 new FramebufferBindingSet(
                  new DrawFramebufferBinding { Attachment = FramebufferAttachment.DepthAttachment, Texture = depth_texture }
                 ),
                 sprite_pos_buffer, sprite_color_buffer, sprite_dimensions_buffer, sprite_rotation_local_buffer, sprite_rotation_buffer,
                 viewport,
                 particles_count, particle_scale_factor, fragdepthroutine, outputroutine,
                 mvp,
                 null,
                 null
            );
        }
예제 #5
0
 /// <summary>
 ///     Sets the texture to the specified position.
 /// </summary>
 /// <param name="texture"></param>
 /// <param name="texturePos"></param>
 public void SetTexture(TextureBase texture, int texturePos)
 {
     Parent.NextTexture = texturePos + 1;
     GL.ActiveTexture(TextureUnit.Texture0 + texturePos);
     GL.BindTexture(texture.Target, texture);
     SetInt(texturePos);
 }
예제 #6
0
        /// <summary>
        /// Draws the specified texture.
        /// </summary>
        /// <param name="texture">The texture.</param>
        /// <param name="position">The position.</param>
        /// <param name="renderSize">Size of the render.</param>
        /// <param name="color">The color.</param>
        /// <param name="source">The source.</param>
        /// <param name="centerOrigin">if set to <c>true</c> [center origin].</param>
        public override void Draw(TextureBase texture, PointF position, Size renderSize, ColorW color, Rect source, bool centerOrigin)
        {
            testRectangle.X      = (int)position.X;
            testRectangle.Y      = (int)position.Y;
            testRectangle.Width  = (int)renderSize.Width;
            testRectangle.Height = (int)renderSize.Height;
            if (isClipped && !currentScissorRectangle.Intersects(testRectangle))
            {
                return;
            }

            sourceRect.X      = (int)source.X;
            sourceRect.Y      = (int)source.Y;
            sourceRect.Width  = (int)source.Width;
            sourceRect.Height = (int)source.Height;
            vecColor.A        = color.A;
            vecColor.R        = color.R;
            vecColor.G        = color.G;
            vecColor.B        = color.B;
            if (centerOrigin)
            {
                origin.X = testRectangle.Width / 2f;
                origin.Y = testRectangle.Height / 2f;
            }

            Texture2D native = texture.GetNativeTexture() as Texture2D;

            spriteBatch.Draw(native, testRectangle, sourceRect, vecColor, 0, origin);
        }
예제 #7
0
        //
        public static RenderPass CreateBlurFilter(
			 TextureBase source,
			 TextureBase interm,
			 TextureBase result)
        {
            return CreateSeparableFilter("blur", "RenderPassFactory", source, interm, result, null);
        }
예제 #8
0
        /// <summary>
        /// Clean up.
        /// </summary>
        public void Dispose()
        {
            foreach (Foliage fol in foliages)
            {
                owner.TransparentObjectManager.Objects.Remove(fol);
            }
            foliages.Clear();

            counter--;
            if (counter == 0)
            {
                if (foliageMesh != null)
                {
                    foliageMesh.Dispose();
                    foliageMesh = null;
                }
                if (trunkMesh != null)
                {
                    trunkMesh.Dispose();
                    trunkMesh = null;
                }
                if (foliageTexture != null)
                {
                    foliageTexture.Dispose();
                    foliageTexture = null;
                }
            }
        }
예제 #9
0
        public override void Compile(CompileParams data)
        {
            base.Compile(data);

            floorTexture    = data.RenderContext.CreateTexture2D(new Bitmap(Textures + "floor_color_map.jpg"), textureFilteringFunctionType.LinearMipmapLinear);
            lightMapTexture = data.RenderContext.CreateTexture2D(new Bitmap(Textures + "floor_light_map.jpg"), textureFilteringFunctionType.LinearMipmapLinear);
        }
예제 #10
0
        /// <summary>
        /// Draws the specified texture.
        /// </summary>
        /// <param name="texture">The texture.</param>
        /// <param name="position">The position.</param>
        /// <param name="renderSize">Size of the render.</param>
        /// <param name="color">The color.</param>
        /// <param name="source">The source.</param>
        /// <param name="centerOrigin">if set to <c>true</c> [center origin].</param>
        public override void Draw(TextureBase texture, PointF position, Size renderSize, ColorW color, Rect source, bool centerOrigin)
        {
            Rectangle testRectangle;

            testRectangle.X      = (int)position.X;
            testRectangle.Y      = (int)position.Y;
            testRectangle.Width  = (int)renderSize.Width;
            testRectangle.Height = (int)renderSize.Height;
            if (isClipped && !this.GraphicsDevice.ScissorRectangle.Intersects(testRectangle))
            {
                return;
            }

            this.Prepare(DrawState.Sprite);
            Rectangle sourceRect;

            sourceRect.X      = (int)source.X;
            sourceRect.Y      = (int)source.Y;
            sourceRect.Width  = (int)source.Width;
            sourceRect.Height = (int)source.Height;
            Color vecColor = new Color();

            vecColor.PackedValue = color.PackedValue;
            Texture2D native = texture.GetNativeTexture() as Texture2D;

            spriteBatch.Draw(native, testRectangle, sourceRect, vecColor, 0, Vector2.Zero, SpriteEffects.None, 0);
        }
예제 #11
0
        public static Sprite Create(
            ulong cameraGroup   = 0,
            Aspect aspect       = Aspect.Keep,
            bool horizontalFlip = false,
            bool verticalFlip   = false,
            Color?color         = null,
            int zOrder          = 0,
            Material material   = null,
            TextureBase texture = null,
            RectF?src           = null
            )
        {
            var elem = BoxUISystem.RentOrNull <Sprite>() ?? new Sprite();

            elem.cameraGroup_    = cameraGroup;
            elem.aspect_         = aspect;
            elem.horizontalFlip_ = horizontalFlip;
            elem.verticalFlip_   = verticalFlip;
            elem.color_          = color ?? new Color(255, 255, 255, 255);
            elem.zOrder_         = zOrder;
            elem.material_       = material;
            elem.texture_        = texture;
            elem.src_            = src ?? new RectF(Vector2FExt.Zero, texture?.Size.To2F() ?? Vector2FExt.Zero);
            return(elem);
        }
        public override void Draw(TextureBase texture, Renderer renderer, double elapsedGameTime, PointF position, Size renderSize, float opacity)
        {
            if (this.Resource == null)
            {
                return;
            }

            IList <TextureBlock> blocks;
            var boxOffset = this.GetBoxOffset();

            if (boxOffset >= 0)
            {
                blocks = this.Layout(this.Resource, new Point((int)renderSize.Width, (int)renderSize.Height), (int)boxOffset);
            }
            else //fallback
            {
                blocks = UIGraphics.LayoutTCB(this.Resource, new Point((int)renderSize.Width, (int)renderSize.Height));
            }

            foreach (var block in blocks)
            {
                if (block.Texture != null && block.Rectangle.Width > 0 && block.Rectangle.Height > 0)
                {
                    PointF pos   = new PointF(block.Rectangle.X + position.X, block.Rectangle.Y + position.Y);
                    Size   size  = new Size(block.Rectangle.Width, block.Rectangle.Height);
                    ColorW color = new ColorW(1f, 1f, 1f, this.Opacity);
                    renderer.Draw(block.Texture, pos, size, color, false);
                }
            }
        }
예제 #13
0
 /// <summary>
 ///     Sets the texture to the next possible position.
 /// </summary>
 /// <param name="texture"></param>
 public void SetTexture(TextureBase texture)
 {
     if (Parent != null)
     {
         SetTexture(texture, Parent.NextTexture);
     }
 }
예제 #14
0
 public void SetVariable(string variableName, TextureBase value)
 {
     if (effect != null)
     {
         effect.SetValue(variableName, value.Texture);
     }
 }
예제 #15
0
        public void setRenderToTexture(TextureBase texture, bool enableDepthAndStencil = false, int antiAlias = 0,
                                       int surfaceSelector = 0)
        {
            var texture2D = texture as Texture;

            if (texture2D == null)
            {
                throw new Exception("Invalid texture");
            }

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, mTextureFrameBufferId);
#if PLATFORM_MONOTOUCH
            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferSlot.ColorAttachment0, TextureTarget.Texture2D, texture.textureId, 0);
#else
            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, texture.textureId, 0);
#endif
            // setup viewport for render to texture
            // $$TODO figure out a way to invert the viewport vertically to account for GL's texture origin
            GL.Viewport(0, 0, texture2D.width, texture2D.height);

            // validate framebuffer status
            var code = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
            if (code != FramebufferErrorCode.FramebufferComplete)
            {
                throw new Exception("FrameBuffer status error:" + code);
            }

            // save texture we're rendering to
            mRenderToTexture = texture;
        }
        //computed world-space normal and clipping space depth (depth in range 0, 1)
        //where the result will be stored, results will be stored to the first component of the texture
        //how many samples will be used for occlusion estimation
        public static RenderPass CreateAoc(
		                                    TextureBase normalDepth,
		                                    TextureBase aoc,
		                                    IValueProvider<Matrix4> modelviewprojection,
		                                    IValueProvider<Matrix4> modelviewprojection_inv,
		                                    IValueProvider<Matrix4> projection,
		                                    IValueProvider<Matrix4> projection_inv,
		                                    AocParameters parameters)
        {
            return CreateAoc(
                             normalDepth,
                             aoc,
                             modelviewprojection,
                             modelviewprojection_inv,
                             projection,
                             projection_inv,
                             ValueProvider.Create (() => parameters.SamplesCount),
                             ValueProvider.Create (() => parameters.OccMaxDist),
                             ValueProvider.Create (() => parameters.OccPixmax),
                             ValueProvider.Create (() => parameters.OccPixmin),
                             ValueProvider.Create (() => parameters.OccMinSampleRatio),
                             ValueProvider.Create (() => parameters.OccConstantArea),
                             ValueProvider.Create (() => parameters.Strength),
                             ValueProvider.Create (() => parameters.Bias));
        }
예제 #17
0
        /// <summary>
        /// given color and depth textures, render them.
        /// </summary>
        public static RenderPass CreateRenderTextureToBuffer(
			 TextureBase source,
			 TextureBase depth_source,
			 IValueProvider<Vector2> viewportSize,
			 Action<GameWindow> beforeState,
			 Action<GameWindow> beforeRender,
			 params StatePart[] stateParts
		)
        {
            //TODO: BUG see System21.State.cs: line 351. Order of states has also some influence
            var states = new StatePart[]{
                new TextureBindingSet
                (
                 new TextureBinding { VariableName = "source_texture", Texture = source },
                 new TextureBinding { VariableName = "depth_texture", Texture = depth_source }
                )
            };

            states = stateParts.Concat(states).ToArray();

            return CreateFullscreenQuad
            (
                 "rendertexture", "RenderPassFactory",
                 viewportSize,
                 beforeState,
                 beforeRender,
                 states);
        }
        /*
        /// <summary>
        /// given color and depth textures, render them.
        /// </summary>
        public static RenderPass CreateSolidSphere
        (
             TextureBase normal_depth_target,
             TextureBase uv_colorindex_target,
             TextureBase depth_texture,
             BufferObject<Vector4> sprite_pos_buffer,
             BufferObject<Vector4> sprite_color_buffer,
             BufferObject<Vector4> sprite_dimensions_buffer,
             IValueProvider<int> particles_count,
             IValueProvider<float> particle_scale_factor,
             ModelViewProjectionParameters mvp,
             UniformState subroutineMapping,
             IEnumerable<Shader> subroutines
        )
        {
            var viewport = ValueProvider.Create (() => new Vector2 (depth_texture.Width, depth_texture.Height));
            var mode = ValueProvider.Create (() => 0);

            return CreateSolidSphere
            (
                 new FramebufferBindingSet(
                  new DrawFramebufferBinding { Attachment = FramebufferAttachment.DepthAttachment, Texture = depth_texture },
                  new DrawFramebufferBinding { VariableName = "Fragdata.uv_colorindex_none", Texture = uv_colorindex_target },
                  new DrawFramebufferBinding { VariableName = "Fragdata.normal_depth", Texture = normal_depth_target }
                 ),
                 sprite_pos_buffer, sprite_color_buffer, sprite_dimensions_buffer,
                 viewport,
                 particles_count, particle_scale_factor, mode,
                 mvp,
                 subroutineMapping,
                 subroutines
            );
        }*/
        /// <summary>
        /// given color and depth textures, render them.
        /// </summary>
        public static RenderPass CreateSolidSphere(
			 TextureBase normal_depth_target,
			 TextureBase uv_colorindex_target,
			 TextureBase depth_texture,
			 BufferObject<Vector4> sprite_pos_buffer,
			 BufferObject<Vector4> sprite_color_buffer,
			 BufferObject<Vector4> sprite_dimensions_buffer,
			 IValueProvider<int> particles_count,
			 IValueProvider<float> particle_scale_factor,
			 ModelViewProjectionParameters mvp
		)
        {
            var viewport = ValueProvider.Create (() => new Vector2 (depth_texture.Width, depth_texture.Height));
            var fragdepthroutine = ValueProvider.Create (() => "FragDepthDefault");
            var outputroutine = ValueProvider.Create (() => "SetOutputsDefault");

            return CreateSolidSphere
            (
                 new FramebufferBindingSet(
                  new DrawFramebufferBinding { Attachment = FramebufferAttachment.DepthAttachment, Texture = depth_texture },
                  new DrawFramebufferBinding { VariableName = "uv_colorindex_none", Texture = uv_colorindex_target },
                  new DrawFramebufferBinding { VariableName = "normal_depth", Texture = normal_depth_target }
                 ),
                 sprite_pos_buffer, sprite_color_buffer, sprite_dimensions_buffer,
                 viewport,
                 particles_count, particle_scale_factor, fragdepthroutine, outputroutine,
                 mvp,
                 null,
                 null
            );
        }
        //computed world-space normal and clipping space depth (depth in range 0, 1)
        //where the result will be stored, results will be stored to the first component of the texture
        //how many samples will be used for occlusion estimation
        public static RenderPass CreateAoc(
		                                    TextureBase normalDepth,
		                                    TextureBase aoc,
		                                    IValueProvider<Matrix4> modelviewprojection,
		                                    IValueProvider<Matrix4> modelviewprojection_inv,
		                                    IValueProvider<Matrix4> projection,
		                                    IValueProvider<Matrix4> projection_inv,
		                                    IValueProvider<int> samplesCount,
		                                    IValueProvider<float> occ_max_dist = null,
		                                    IValueProvider<float> occ_pixmax = null,
		                                    IValueProvider<float> occ_pixmin = null,
		                                    IValueProvider<float> occ_min_sample_ratio = null,
		                                    IValueProvider<bool> occ_constant_area = null,
		                                    IValueProvider<float> strength = null,
		                                    IValueProvider<float> bias = null)
        {
            var viewport = ValueProvider.Create (() => new Vector2 (aoc.Width, aoc.Height));
            //			var sampling_pattern = ValueProvider.Create
            //			(
            //				 () => MathHelper2.RandomVectorSet (256, new Vector2 (1, 1))
            //			);

            var current_pattern = MathHelper2.RandomVectorSet (256, new Vector2 (1, 1));
            var sampling_pattern = ValueProvider.Create
            (
                 () => current_pattern
            );

            var uniformState = new UniformState ();
            uniformState.Set ("viewport_size", viewport);
            uniformState.Set ("sampling_pattern", sampling_pattern);
            uniformState.Set ("sampling_pattern_len", samplesCount);

            uniformState.Set ("modelviewprojection_transform", modelviewprojection);
            uniformState.Set ("modelviewprojection_inv_transform", modelviewprojection_inv);
            uniformState.Set ("projection_transform", projection);
            uniformState.Set ("projection_inv_transform", projection_inv);

            uniformState.Set ("OCCLUDER_MAX_DISTANCE", occ_max_dist ?? ValueProvider.Create(35.0f));
            uniformState.Set ("PROJECTED_OCCLUDER_DISTANCE_MAX_SIZE", occ_pixmax ?? ValueProvider.Create(35.0f));
            uniformState.Set ("PROJECTED_OCCLUDER_DISTANCE_MIN_SIZE", occ_pixmin ?? ValueProvider.Create(2.0f));
            uniformState.Set ("MINIMAL_SAMPLES_COUNT_RATIO", occ_min_sample_ratio ?? ValueProvider.Create(0.1f));
            uniformState.Set ("USE_CONSTANT_OCCLUDER_PROJECTION", occ_constant_area ?? ValueProvider.Create(false));
            uniformState.Set ("AOC_STRENGTH", strength ?? ValueProvider.Create(2f));
            uniformState.Set ("AOC_BIAS", bias ?? ValueProvider.Create(-0.5f));

            return CreateFullscreenQuad (
                "aoc", "RenderPassFactory",
                viewport, null,
                window =>
                {
                    GL.Clear (ClearBufferMask.ColorBufferBit);
                    GL.Disable (EnableCap.DepthTest);
                    GL.Disable (EnableCap.Blend);
                },

                new FramebufferBindingSet{{ "OUT_FragData_aoc", aoc }},
                uniformState,
                new TextureBindingSet {{ "normaldepth_texture", normalDepth }});
        }
예제 #20
0
 public void SetVariable(EffectHandle variableHandle, TextureBase value)
 {
     if (effect != null)
     {
         effect.SetValue(variableHandle, value.Texture);
     }
 }
예제 #21
0
        public void CopyTexture(TextureBase dstResource, uint dstSubresource, uint dstX, uint dstY, uint dstZ, RenderTarget srcResource, uint srcSubresource)
        {
#if UNIT_TEST_COMPILANT
            throw new NotImplementedException("Unit tests, don't support methods calls. Only properties can be get or set.");
#else
            Internal_CopyTextureRegion3(unmanagedPtr, Object.GetUnmanagedPtr(dstResource), dstSubresource, dstX, dstY, dstZ, Object.GetUnmanagedPtr(srcResource), srcSubresource);
#endif
        }
예제 #22
0
파일: PPDDevice.cs 프로젝트: KHCmaster/PPD
 /// <summary>
 /// サーフェースをコピーします。
 /// </summary>
 /// <param name="src"></param>
 /// <param name="sourceRect"></param>
 /// <param name="dest"></param>
 /// <param name="destPoint"></param>
 internal override void StretchRectangle(TextureBase src, RawRectangle?sourceRect, TextureBase dest, RawPoint?destPoint)
 {
     device.UpdateSurface(
         ((Texture.DX9.Surface)src.Surface)._Surface,
         sourceRect,
         ((Texture.DX9.Surface)dest.Surface)._Surface,
         destPoint);
 }
예제 #23
0
 /// <summary>
 ///     Try to sets the texture at the specified position and tells the checkUniform, if worked or not.
 /// </summary>
 /// <param name="texture">The texture you want to add</param>
 /// <param name="pos">The position</param>
 /// <param name="checkUniform">The check uniform.</param>
 public void SetTexture(TextureBase texture, int pos, Uniform checkUniform)
 {
     checkUniform.SetBool(texture != null);
     if (texture != null)
     {
         SetTexture(texture);
     }
 }
예제 #24
0
 /// <summary>
 /// Clean up.
 /// </summary>
 public void Dispose()
 {
     if (textureBase != null)
     {
         textureBase.Dispose();
         textureBase = null;
     }
 }
예제 #25
0
파일: MoviePanel.cs 프로젝트: KHCmaster/PPD
            public void CreateThumb()
            {
                try
                {
                    TextureBase texture = movie.Texture;
                    if (texture != null)
                    {
                        var    bt     = new Bitmap(texture.ToStream());
                        Bitmap newbit = null;
                        if (aspectApplied)
                        {
                            if (movie.TrimmingData.Left < 0 || movie.TrimmingData.Top < 0 || movie.TrimmingData.Bottom < 0 || movie.TrimmingData.Right < 0)
                            {
                                newbit = bt.Clone(new System.Drawing.Rectangle(0, 0, bt.Width, bt.Height), bt.PixelFormat);
                                bt.Dispose();
                                bt = new Bitmap(480, 270);
                                var gra    = Graphics.FromImage(bt);
                                int width  = -(int)(movie.TrimmingData.GetLeftTrimming(movie.MovieWidth) + movie.TrimmingData.GetRightTrimming(movie.MovieWidth)) * bt.Width / 800,
                                    height = -(int)(movie.TrimmingData.GetTopTrimming(movie.MovieHeight) + movie.TrimmingData.GetBottomTrimming(movie.MovieHeight)) * bt.Height / 450;
                                gra.FillRectangle(Brushes.Black, new System.Drawing.Rectangle(0, 0, bt.Width, bt.Height));
                                gra.DrawImage(newbit, new System.Drawing.Rectangle(width / 2, height / 2, 480 - width, 270 - height), new System.Drawing.Rectangle(0, 0, newbit.Width, newbit.Height), GraphicsUnit.Pixel);
                                gra.Dispose();
                            }
                            else
                            {
                                newbit = bt.Clone(new System.Drawing.Rectangle((int)songInfo.TrimmingData.GetLeftTrimming(movie.MovieWidth),
                                                                               (int)songInfo.TrimmingData.GetTopTrimming(movie.MovieHeight),
                                                                               (int)(bt.Width - songInfo.TrimmingData.GetLeftTrimming(movie.MovieWidth) - songInfo.TrimmingData.GetRightTrimming(movie.MovieWidth)),
                                                                               (int)(bt.Height - songInfo.TrimmingData.GetTopTrimming(movie.MovieHeight) - songInfo.TrimmingData.GetTopTrimming(movie.MovieHeight))), bt.PixelFormat);
                                bt.Dispose();
                                bt = new Bitmap(newbit, 480, 270);
                            }
                        }
                        else
                        {
                            newbit = bt.Clone(new System.Drawing.Rectangle(0, 0, bt.Width, bt.Height), bt.PixelFormat);
                            bt.Dispose();
                            bt = new Bitmap(newbit, 480, 270);
                        }
                        newbit.Dispose();
                        if (movie.Rotated)
                        {
                            bt.RotateFlip(RotateFlipType.Rotate180FlipX);
                        }
                        bt.Save(Path.Combine(songInfo.DirectoryPath, "thumb.png"), System.Drawing.Imaging.ImageFormat.Png);

                        if (picture != null)
                        {
                            picture.UpdatePicture();
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Capture Error");
                }
            }
예제 #26
0
        public Terrain(Program owner)
        {
            vegetation = new Vegetation(owner);

            ground              = new GameObject();
            heightMap           = new Heightmap("data/text_height.png", 1000f, 100, 100);
            heightMap.MaxHeight = 100f;
            TerrainMesh sceneryMesh = new TerrainMesh(1.0f, heightMap);

            //sceneryMesh.Texture = new Bonsai.Objects.Textures.TextureBase("data\\grass.png");
            ground.Mesh = sceneryMesh;
            //ground.RotateXAngle = (float)Math.PI / 2;

            splatShader = new ShaderBase("splatting", "splatting3.fx");
            if (Framework.Instance.DeviceCaps.PixelShaderVersion.Major >= 3)
            {
                splatShader.SetTechnique("TextureSplatting_fx30");
            }
            else
            {
                splatShader.SetTechnique("TextureSplatting");
            }
            splatShader.SetVariable("matViewProj", ShaderBase.ShaderParameters.CameraProjection);
            splatShader.SetVariable("sunPosition", new Vector3(1, 1, 1));
            splatShader.SetVariable("underwater", 0.0f);
            splatShader.SetVariable("matWorld", ShaderBase.ShaderParameters.World);
            splatShader.SetVariable("matInvertTransposeWorld", ShaderBase.ShaderParameters.WorldInvertTranspose);
            splatShader.SetVariable("cameraPos", ShaderBase.ShaderParameters.CameraPosition);
            splatShader.SetVariable("nearRepeat", 64.0f);
            splatShader.SetVariable("farRepeat", 20.0f);
            splatShader.SetVariable("nearFactor2", 3.0f);
            splatShader.SetVariable("farFactor2", 2.0f);
            splatShader.SetVariable("nearFactor3", 3.0f);
            splatShader.SetVariable("farFactor3", 2.0f);
            splatShader.SetVariable("nearFactor4", 3.0f);
            splatShader.SetVariable("farFactor4", 2.0f);
            splatShader.SetVariable("blendSqDistance", 50f * 50f);
            splatShader.SetVariable("blendSqWidth", 1.0f / (200f * 200f));
            TextureBase normalMap       = new TextureBase("data/text_norm.png");
            TextureBase alphaMap        = new TextureBase("data/text.dds");
            TextureBase grassTexture    = new TextureBase("data/grass.png");
            TextureBase rockTexture     = new TextureBase("data/rock.png");
            TextureBase rockNormal      = new TextureBase("data/splat_rock_normal.jpg");
            TextureBase sandTexture     = new TextureBase("data/sand.png");
            TextureBase concreteTexture = new TextureBase("data/road.png");

            splatShader.SetVariable("NormalMapTexture", normalMap);
            splatShader.SetVariable("AlphaTexture", alphaMap);
            splatShader.SetVariable("DetailTexture1", grassTexture);
            splatShader.SetVariable("DetailTexture2", rockTexture);
            splatShader.SetVariable("DetailTexture2NormalMap", rockNormal);
            splatShader.SetVariable("DetailTexture3", sandTexture);
            splatShader.SetVariable("DetailTexture4", concreteTexture);

            ground.Shader = splatShader;
        }
예제 #27
0
        /// <summary>
        /// This method flushes all sampler state. Sampler state comes from two sources, the context.setTextureAt()
        /// and the Program3D's filtering parameters that are specified per tex instruction. Due to the way that GL works,
        /// the filtering parameters need to be associated with bound textures so that is performed here before drawing.
        /// </summary>
        private void flushSamplerState()
        {
            int sampler = 0;

            // loop until all dirty samplers have been processed
            while (mSamplerDirty != 0)
            {
                // determine if sampler is dirty
                if ((mSamplerDirty & (1 << sampler)) != 0)
                {
                    // activate texture unit for GL
                    GL.ActiveTexture(TextureUnit.Texture0 + sampler);

                    // get texture for sampler
                    TextureBase texture = mSamplerTextures[sampler];
                    if (texture != null)
                    {
                        // bind texture
                        GL.BindTexture(texture.textureTarget, texture.textureId);

                        // get sampler state from program
                        SamplerState state = mProgram.getSamplerState(sampler);
                        if (state != null)
                        {
                            var target = texture.textureTarget;
                            GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)state.MinFilter);
                            GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)state.MagFilter);
                            GL.TexParameter(target, TextureParameterName.TextureWrapS, (int)state.WrapModeS);
                            GL.TexParameter(target, TextureParameterName.TextureWrapT, (int)state.WrapModeT);
                            if (state.LodBias != 0.0)
                            {
                                throw new NotImplementedException("Lod bias setting not supported yet");
                            }
                        }
                        else
                        {
                            if (enableErrorChecking)
                            {
                                Console.WriteLine("warning: no sampler state found for sampler {0}", sampler);
                            }
                        }
                    }
                    else
                    {
                        // texture is null so unbind texture
                        GL.BindTexture(TextureTarget.Texture2D, 0);
                    }

                    // clear dirty bit
                    mSamplerDirty &= ~(1 << sampler);
                }

                // next sampler
                sampler++;
            }
        }
예제 #28
0
        /// <summary>Create new button instance</summary>
        public Picture(Dialog parent, string textureFile)
            : base(parent)
        {
            controlType  = ControlType.Picture;
            parentDialog = parent;

            isPressed   = false;
            textureBase = new TextureBase(textureFile);
            blendColor.Initialize(new ColorValue(1f, 1f, 1f, 1f), new ColorValue(1f, 1f, 1f, 1f), new ColorValue(0f, 0f, 0f, 0f));
        }
예제 #29
0
        private void SelTextureMipTrackBar_Scroll(object sender, EventArgs e)
        {
            var node = SelDrawableTexturesTreeView.SelectedNode;

            TextureBase texbase = node?.Tag as TextureBase;

            SelTextureMipLabel.Text = SelTextureMipTrackBar.Value.ToString();

            SelectTexture(texbase, true);
        }
예제 #30
0
 public SizeTexture(PPDDevice device)
 {
     this.device     = device;
     Texture         = ((Texture.DX9.TextureFactory)TextureFactoryManager.Factory).Create(device, Size, Size, 1, SharpDX.Direct3D9.Pool.Default, true);
     availableSpaces = new List <AvailableSpace>
     {
         new AvailableSpace(this, Point.Zero, new Size2(Size, Size))
     };
     onceUsedSpaces = new List <AvailableSpace>();
 }
예제 #31
0
        private void SelectTexture(TextureBase texbase, bool mipchange)
        {
            Texture tex    = texbase as Texture;
            YtdFile ytd    = null;
            string  errstr = string.Empty;

            if ((tex == null) && (texbase != null))
            {
                tex = TryGetTexture(texbase, out ytd, ref errstr);
            }
            if (tex != null)
            {
                currentTex = tex;
                int mip = 0;
                if (mipchange)
                {
                    mip = SelTextureMipTrackBar.Value;
                    if (mip >= tex.Levels)
                    {
                        mip = tex.Levels - 1;
                    }
                }
                else
                {
                    SelTextureMipTrackBar.Maximum = tex.Levels - 1;
                }
                DisplayTexture(tex, mip);


                //try get owner drawable to get the name for the dictionary textbox...
                object owner = null;
                if (Selection.Drawable != null)
                {
                    owner = Selection.Drawable.Owner;
                }
                YdrFile ydr = owner as YdrFile;
                YddFile ydd = owner as YddFile;
                YftFile yft = owner as YftFile;

                SelTextureNameTextBox.Text       = tex.Name;
                SelTextureDictionaryTextBox.Text = (ytd != null) ? ytd.Name : (ydr != null) ? ydr.Name : (ydd != null) ? ydd.Name : (yft != null) ? yft.Name : string.Empty;
                SaveTextureButton.Enabled        = true;
            }
            else
            {
                SelDrawableTexturePictureBox.Image = null;
                SelTextureNameTextBox.Text         = errstr;
                SelTextureDictionaryTextBox.Text   = string.Empty;
                SelTextureMipTrackBar.Value        = 0;
                SelTextureMipTrackBar.Maximum      = 0;
                SelTextureDimensionsLabel.Text     = "-";
                SaveTextureButton.Enabled          = false;
                currentTex = null;
            }
        }
예제 #32
0
        //
        public static RenderPass CreateBilateralFilter(
			 TextureBase source,
			 TextureBase interm,
			 TextureBase result,
			 IValueProvider<Vector4> k)
        {
            UniformState parameters = new UniformState();
            parameters.Set ("K", k);

            return CreateSeparableFilter("bilateralfilter", "RenderPassFactory", source, interm, result, parameters);
        }
예제 #33
0
        private void SelDrawableTexturesTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            SelDrawableTexturePropertyGrid.SelectedObject = e.Node?.Tag;

            TextureBase texbase = e.Node?.Tag as TextureBase;

            SelTextureMipTrackBar.Value = 0;
            SelTextureMipLabel.Text     = "0";

            SelectTexture(texbase, false);
        }
예제 #34
0
        public void OpenTexture(Stream data, string fname, Stream paletteData, TextureFormat format)
        {
            Bitmap textureBitmap;

            TextureBase texture = Texture.GetModule(format);

            texture.PaletteStream = paletteData;
            texture.Read(data, out textureBitmap);

            DisplayTexture(textureBitmap, fname, format);
        }
예제 #35
0
 private void SetTexturePrivate(string key, TextureBase value, bool assign)
 {
     if (key == null)
     {
         throw new ArgumentNullException(nameof(key), "引数がnullです");
     }
     if (assign)
     {
         textures[key] = value;
     }
     cbg_Material_SetTexture(selfPtr, key, value != null ? value.selfPtr : IntPtr.Zero);
 }
예제 #36
0
        public void setTextureAt(int sampler, TextureBase texture)
        {
            // see if texture changed
            if (mSamplerTextures[sampler] != texture)
            {
                // set sampler texture
                mSamplerTextures[sampler] = texture;

                // set flag indicating that this sampler is dirty
                mSamplerDirty |= (1 << sampler);
            }
        }
예제 #37
0
 private static void RenderImageButton(TextureBase image, Action onClick)
 {
     if (Engine.Tool.ImageButton(image,
                                 new Vector2F(80, 80),
                                 new Vector2F(0, 0),
                                 new Vector2F(1, 1),
                                 5,
                                 new Color(),
                                 new Color(255, 255, 255, 255)))
     {
         onClick();
     }
 }
예제 #38
0
 /// <summary>
 /// 指定した名前を持つ<see cref="TextureBase"/>のインスタンスを取得します。
 /// </summary>
 /// <param name="key">検索する<see cref="TextureBase"/>のインスタンスの名前</param>
 /// <exception cref="ArgumentNullException"><paramref name="key"/>がnull</exception>
 /// <returns><paramref name="key"/>を名前として持つ<see cref="TextureBase"/>のインスタンス</returns>
 public TextureBase GetTexture(string key)
 {
     if (key == null)
     {
         throw new ArgumentNullException(nameof(key), "引数がnullです");
     }
     if (!textures.TryGetValue(key, out var result))
     {
         var ret = cbg_Material_GetTexture(selfPtr, key);
         result = TextureBase.TryGetFromCache(ret);
     }
     return(result);
 }
예제 #39
0
        protected void AttachTexture(FramebufferAttachment attachmentTarget, TextureBase texture)
        {
            Bind(FramebufferTarget.Framebuffer);

            if (texture == null)
            {
                GL.FramebufferTexture(FramebufferTarget.Framebuffer, attachmentTarget, 0, 0);
                Debug.Assert(AttachedTextures.ContainsKey(attachmentTarget));
                AttachedTextures.Remove(attachmentTarget);
                return;
            }

            Debug.Assert(
                AttachedTextures.All(pair => pair.Value.Size == texture.Size),
                "All render target sizes for a framebuffer object must be equal.");
            Size = texture.Size;

            texture.Bind();

            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, attachmentTarget, texture.Target, texture.Handle, 0);
            AttachedTextures[attachmentTarget] = texture;
        }
예제 #40
0
        private void PrepareState()
        {
            if (m_Passes != null)
            {
                return;
            }

            unsafe
            {
                BeforeAATexture =
                new DataTexture<Vector4> {
                    Name = "BeforeAATexture",
                    InternalFormat = PixelInternalFormat.Rgba32f,
                    //Format = PixelFormat.DepthComponent,
                    Data2D = new Vector4[m_SolidModeTextureSize, m_SolidModeTextureSize],
                    Params = new TextureBase.Parameters
                    {
                        GenerateMipmap = false,
                        MinFilter = TextureMinFilter.Nearest,
                        MagFilter = TextureMagFilter.Nearest,
                }};

                AccumTexture =
                new DataTexture<Vector4> {
                    Name = "AccumTexture",
                    InternalFormat = PixelInternalFormat.Rgba32f,
                    Data2D = new Vector4[m_SolidModeTextureSize, m_SolidModeTextureSize],
                    Params = new TextureBase.Parameters
                    {
                        GenerateMipmap = false,
                        MinFilter = TextureMinFilter.Nearest,
                        MagFilter = TextureMagFilter.Nearest,
                    }};

                AATexture = new Texture
                {
                    Name = "AATexture",
                    InternalFormat = PixelInternalFormat.Rgba8,
                    Target = TextureTarget.Texture2D,
                    Width = m_SolidModeTextureSize,
                    Height = m_SolidModeTextureSize,
                    Params = new TextureBase.Parameters
                    {
                        //GenerateMipmap = true,
                        MinFilter = TextureMinFilter.Nearest,
                        MagFilter = TextureMagFilter.Nearest,
                    }
                };

                Depth_Texture =
                new DataTexture<float> {
                    Name = "Depth_Texture",
                    InternalFormat = PixelInternalFormat.DepthComponent32f,
                    Format = PixelFormat.DepthComponent,
                    Data2D = new float[m_SolidModeTextureSize, m_SolidModeTextureSize],
                    Params = new TextureBase.Parameters
                    {
                        GenerateMipmap = false,
                        MinFilter = TextureMinFilter.Nearest,
                        MagFilter = TextureMagFilter.Nearest,
                }};
            }

            var ortho = Matrix4.CreateOrthographic (1, 1, (float)NEAR, (float)FAR);

            m_Projection = new MatrixStack ().Push (ortho);
            m_TransformationStack = new MatrixStack ().Push (m_Projection);

            var frameCount = 1;
            m_UniformState = new UniformState
            {
                {"pRayMarchStepFactor", () => this.RayMarchStepFactor},
                {"k1", () => this.K1},
                {"k2", () => this.K2},
                {"k3", () => this.K3},
                {"k4", () => this.K4},
                {"time", () => this.Time},
                {"u_FrameCount", () => frameCount},
            };

            var workgroupSize = 8;
            var giPass = new SeparateProgramPass(
                "system6.globalillumination",
                window => { GLExtensions.DispatchCompute ((int)Math.Ceiling((float)Depth_Texture.Width/workgroupSize), (int)Math.Ceiling((float)Depth_Texture.Height/workgroupSize), 1); },
              new Program ("system6.gi")
                {
                    RenderPass.GetShaders ("system6", "gi", "compute")//.PrependText(namemodifier, scode),
                },
                new ImageBindingSet
                {
                    {"u_TargetDepth", () => Depth_Texture },
                    {"u_TargetColorLuma", () => BeforeAATexture },
                  {"u_TargetAccumLuma", () => AccumTexture },
                },
              m_UniformState);

            //var antialiasPass = RenderPassFactory.CreatePass( new Fxaa3Filter{ Source = BeforeAATexture, Target = AATexture});

            var finalRender = RenderPassFactory.CreateRenderTextureToBuffer
            (
                BeforeAATexture,
                Depth_Texture,
                ValueProvider.Create(() => m_Viewport),
                (window) =>
                {
                    SetCamera (window);
                },
                (window) =>
                {
                    GL.Clear (ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                    GL.Disable (EnableCap.DepthTest);
                    GL.Disable (EnableCap.Blend);
                    frameCount++;
                },
                FramebufferBindingSet.Default);

            m_Passes = new RenderPass[]{ giPass, /*antialiasPass, */finalRender };
            m_Manip = new OrbitManipulator (m_Projection);
            //m_Grid = new Grid (m_TransformationStack);

            m_TransformationStack.Push (m_Manip.RT);
            m_UniformState.Set ("modelview_transform", m_Manip.RT);
            m_UniformState.Set ("modelviewprojection_transform", m_TransformationStack);
            m_UniformState.Set ("projection_transform", m_Projection);
            m_UniformState.Set ("projection_inv_transform", new MatrixInversion(m_Projection));
            m_UniformState.Set ("modelview_inv_transform", new MatrixInversion(m_Manip.RT));
            m_UniformState.Set ("modelviewprojection_inv_transform", new MatrixInversion(m_TransformationStack));

            m_Manip.RT.PropertyChanged +=
            (s, args) => { frameCount = 0; };

            PrepareState ();
        }
예제 #41
0
        protected override void TextureSetup()
        {
            base.TextureSetup();

            NormalDepth_Texture_Unfiltered =
                new DataTexture<Vector4> {
                    Name = "NormalDepth_Texture_Unfiltered",
                    InternalFormat = PixelInternalFormat.Rgba32f,
                    //Format = PixelFormat.DepthComponent,
                    Data2D = new Vector4[SolidModeTextureSize, SolidModeTextureSize],
                    Params = new TextureBase.Parameters
                    {
                        GenerateMipmap = false,
                        MinFilter = TextureMinFilter.Nearest,
                        MagFilter = TextureMagFilter.Nearest,
                }};

            NormalDepth_Texture_H =
                new DataTexture<Vector4> {
                    Name = "NormalDepth_Texture_H",
                    InternalFormat = PixelInternalFormat.Rgba32f,
                    //Format = PixelFormat.DepthComponent,
                    Data2D = new Vector4[SolidModeTextureSize, SolidModeTextureSize],
                    Params = new TextureBase.Parameters
                    {
                        GenerateMipmap = false,
                        MinFilter = TextureMinFilter.Nearest,
                        MagFilter = TextureMagFilter.Nearest,
                }};
        }
예제 #42
0
        //
        private void PrepareTexture()
        {
            if(m_Texture == null)
            {
                m_Texture = new DataTexture<Vector3> {
                    Name = "custom_texture",
                    InternalFormat = PixelInternalFormat.Rgb,
                    Data2D = TestTexture(2, 2),
                    Params = new TextureBase.Parameters
                    {
                        GenerateMipmap = true,
                        MinFilter = TextureMinFilter.LinearMipmapLinear,
                        MagFilter = TextureMagFilter.Linear,
                    }};

                //m_Texture = opentk.Resources.Textures.FromVectors("", 100, 1, MathHelper2.RandomVectorSet(100, new Vector2d(1)));
              }

              if( m_Texture.Width != TextureResolution)
              {
                ((DataTexture<Vector3>)m_Texture).Data2D = TestTexture(TextureResolution, TextureResolution);
              }
        }
예제 #43
0
        /// <summary>
        /// create two passes in one compound pass. First pass has set "horizontal" uniform boolean to true,
        /// the second has it set to false.
        /// </summary>
        public static RenderPass CreateSeparableFilter(
			 string filterName,
			 string filterNamespace,
			 TextureBase source,
			 TextureBase interm,
			 TextureBase result,
			 UniformState parameters)
        {
            var viewport = ValueProvider.Create (() => new Vector2 (result.Width, result.Height));
            var horizontal = false;
            var uniformState = new UniformState ();
            uniformState.Set ("viewport_size", viewport);
            uniformState.Set ("horizontal", ValueProvider.Create (() => horizontal));

            parameters = parameters?? new UniformState();

            var _1stPass = CreateFullscreenQuad (filterName, filterNamespace, viewport,
            window =>
            {
                horizontal = false;
            }
            ,
            window =>
            {
                GL.Clear (ClearBufferMask.ColorBufferBit);
                GL.Disable (EnableCap.DepthTest);
                GL.Disable (EnableCap.Blend);
            //pass state
            },
            new FramebufferBindingSet {{ "OUT_FragData_result", interm }},
            uniformState,
            parameters,
            new TextureBindingSet {{ "source_texture", source }});

            var _2ndPass = CreateFullscreenQuad (filterName, filterNamespace, viewport,
            window =>
            {
                horizontal = true;
            }
            ,
            window =>
            {
                GL.Clear (ClearBufferMask.ColorBufferBit);
                GL.Disable (EnableCap.DepthTest);
                GL.Disable (EnableCap.Blend);
            //pass state
            },
            new FramebufferBindingSet {{ "OUT_FragData_result", result }},
            uniformState,
            parameters,
            new TextureBindingSet {{ "source_texture", interm }});

            return new CompoundRenderPass(_1stPass, _2ndPass);
        }
예제 #44
0
        protected virtual void TextureSetup()
        {
            //TEextures setup
            m_ParticleAttribute1_Texture =
                new DataTexture<Vector3> {
                    Name = "UV_ColorIndex_None_Texture",
                    InternalFormat = PixelInternalFormat.Rgba8,
                    Data2D = new Vector3[SolidModeTextureSize, SolidModeTextureSize],
                    Params = new TextureBase.Parameters
                    {
                        GenerateMipmap = false,
                        MinFilter = TextureMinFilter.Nearest,
                        MagFilter = TextureMagFilter.Nearest,
                }};

            AOC_Texture = new Texture
            {
                Name = "AOC_Texture",
                InternalFormat = PixelInternalFormat.R16f,
                Target = TextureTarget.Texture2D,
                Width = SsaoEffect.TextureSize,
                Height = SsaoEffect.TextureSize,
                Params = new TextureBase.Parameters
                {
                    //GenerateMipmap = true,
                    MinFilter = TextureMinFilter.Nearest,
                    MagFilter = TextureMagFilter.Nearest,
                }
            };

            AOC_Texture_Blurred_H = new Texture
            {
                Name = "AOC_Texture_HBLUR",
                InternalFormat = PixelInternalFormat.R16f,
                Target = TextureTarget.Texture2D,
                Width = SsaoEffect.TextureSize,
                Height = SsaoEffect.TextureSize,
                Params = new TextureBase.Parameters
                {
                    //GenerateMipmap = true,
                    MinFilter = TextureMinFilter.Nearest,
                    MagFilter = TextureMagFilter.Nearest,
                }
            };

            AOC_Texture_Blurred_HV = new Texture
            {
                Name = "AOC_Texture_HVBLUR",
                InternalFormat = PixelInternalFormat.R16f,
                Target = TextureTarget.Texture2D,
                Width = SsaoEffect.TextureSize,
                Height = SsaoEffect.TextureSize,
                Params = new TextureBase.Parameters
                {
                    GenerateMipmap = true,
                    MinFilter = TextureMinFilter.LinearMipmapLinear,
                    MagFilter = TextureMagFilter.Nearest,
                }
            };

            NormalDepth_Texture =
                new DataTexture<Vector4> {
                    Name = "NormalDepth_Texture",
                    InternalFormat = PixelInternalFormat.Rgba32f,
                    //Format = PixelFormat.DepthComponent,
                    Data2D = new Vector4[SolidModeTextureSize, SolidModeTextureSize],
                    Params = new TextureBase.Parameters
                    {
                        GenerateMipmap = false,
                        MinFilter = TextureMinFilter.Nearest,
                        MagFilter = TextureMagFilter.Nearest,
                }};

            Depth_Texture =
                new DataTexture<float> {
                    Name = "Depth_Texture",
                    InternalFormat = PixelInternalFormat.DepthComponent32f,
                    Format = PixelFormat.DepthComponent,
                    Data2D = new float[SolidModeTextureSize, SolidModeTextureSize],
                    Params = new TextureBase.Parameters
                    {
                        GenerateMipmap = false,
                        MinFilter = TextureMinFilter.Nearest,
                        MagFilter = TextureMagFilter.Nearest,
                }};

            BeforeAA_Texture =
                new DataTexture<Vector4> {
                    Name = "BeforeAA_Texture",
                    InternalFormat = PixelInternalFormat.Rgba8,
                    Data2D = new Vector4[SolidModeTextureSize, SolidModeTextureSize],
                    Params = new TextureBase.Parameters
                    {
                        GenerateMipmap = false,
                        MinFilter = TextureMinFilter.Linear,
                        MagFilter = TextureMagFilter.Linear,
                }};

            AA_Texture =
                new DataTexture<Vector4> {
                    Name = "AA_Texture",
                    InternalFormat = PixelInternalFormat.Rgba8,
                    Data2D = new Vector4[SolidModeTextureSize, SolidModeTextureSize],
                    Params = new TextureBase.Parameters
                    {
                        GenerateMipmap = false,
                        MinFilter = TextureMinFilter.Linear,
                        MagFilter = TextureMagFilter.Linear,
                }};

            Shadow_Texture =
                new DataTexture<float> {
                    Name = "Shadow_Texture",
                    InternalFormat = PixelInternalFormat.DepthComponent32f,
                    Format = PixelFormat.DepthComponent,
                    Data2D = new float[ShadowTextureSize, ShadowTextureSize],
                    Params = new TextureBase.Parameters
                    {
                        GenerateMipmap = true,
                        MinFilter = TextureMinFilter.LinearMipmapLinear,
                        MagFilter = TextureMagFilter.Linear,
                }};
        }
예제 #45
0
        private void PrepareState()
        {
            if (m_Passes != null)
            {
                return;
            }

            unsafe
            {
                AOC_Texture =
                new DataTexture<float> {
                    Name = "AOC_Texture",
                    InternalFormat = PixelInternalFormat.R8,
                    Data2D = new float[m_AocTextureSize, m_AocTextureSize],
                    Params = new TextureBase.Parameters
                    {
                        GenerateMipmap = true,
                        MinFilter = TextureMinFilter.LinearMipmapLinear,
                        MagFilter = TextureMagFilter.Linear,
                }};

                NormalDepth_Texture =
                new DataTexture<Vector4> {
                    Name = "NormalDepth_Texture",
                    InternalFormat = PixelInternalFormat.Rgba32f,
                    //Format = PixelFormat.DepthComponent,
                    Data2D = new Vector4[m_SolidModeTextureSize, m_SolidModeTextureSize],
                    Params = new TextureBase.Parameters
                    {
                        GenerateMipmap = false,
                        MinFilter = TextureMinFilter.Nearest,
                        MagFilter = TextureMagFilter.Nearest,
                }};

                Depth_Texture =
                new DataTexture<float> {
                    Name = "Depth_Texture",
                    InternalFormat = PixelInternalFormat.DepthComponent32f,
                    Format = PixelFormat.DepthComponent,
                    Data2D = new float[m_SolidModeTextureSize, m_SolidModeTextureSize],
                    Params = new TextureBase.Parameters
                    {
                        GenerateMipmap = false,
                        MinFilter = TextureMinFilter.Nearest,
                        MagFilter = TextureMagFilter.Nearest,
                }};
            }

            var ortho = Matrix4.CreateOrthographic (1, 1, (float)NEAR, (float)FAR);

            m_Projection = new MatrixStack ().Push (ortho);
            m_TransformationStack = new MatrixStack ().Push (m_Projection);

            m_UniformState = new UniformState
            {
                {"pRayMarchStepFactor", () => this.RayMarchStepFactor},
                {"k1", () => this.K1},
                {"k2", () => this.K2},
                {"k3", () => this.K3},
                {"k4", () => this.K4},
                {"time", () => this.Time},
            };

            /*//
            var firstPassSolid = RenderPassFactory.CreateFullscreenQuad
            (
                 "raymarch", "System5",
                 ValueProvider.Create(() => new Vector2(m_SolidModeTextureSize, m_SolidModeTextureSize)),
                 (window) =>
                 {
                    SetCamera (window);
                 },
                 (window) =>
                 {
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                    GL.Enable (EnableCap.DepthTest);
                    GL.DepthMask(true);
                    GL.DepthFunc (DepthFunction.Less);
                    GL.Disable (EnableCap.Blend);
                 },

                 //pass state
                 new FramebufferBindingSet
                 {
                   { FramebufferAttachment.DepthAttachment, Depth_Texture },
                   { "normal_depth", NormalDepth_Texture }
                 },
                 m_UniformState
            );*/

            var firstPassSolid = new SeparateProgramPass (
                "raymarch",
                (window) =>
                {
                    SetCamera (window);
                },
                (window) =>
                {
                    /*GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                    GL.Enable (EnableCap.DepthTest);
                    GL.DepthMask(true);
                    GL.DepthFunc (DepthFunction.Less);
                    GL.Disable (EnableCap.Blend);*/
                },
                x =>
                {
                    GLExtensions.DispatchCompute(m_SolidModeTextureSize/(4 * 8), m_SolidModeTextureSize/(4 * 8), 1);
                },
                RenderPass.GetShaders ("raymarch", "System5"),
                //pass state
                new ImageBindingSet
                {
                    { "u_NormalDepth", NormalDepth_Texture }
                },
                m_UniformState);

            AocParameters = new AocParameters
            {
                TextureSize = 512,
                OccConstantArea = false,
                OccMaxDist = 40,
                OccMinSampleRatio = 0.5f,
                OccPixmax = 100,
                OccPixmin = 2,
                SamplesCount = 32,
                Strength = 2.3f,
                Bias = 0.4f
            };

            var aocPassSolid = RenderPassFactory.CreateAoc
            (
                 NormalDepth_Texture,
                 AOC_Texture,
                 m_TransformationStack,
                 new MatrixInversion(m_TransformationStack),
                 m_Projection,
                 new MatrixInversion(m_Projection),
                 AocParameters
            );

            //
            var thirdPassSolid = RenderPassFactory.CreateFullscreenQuad
            (
                 "lighting", "System5",
                 ValueProvider.Create(() => m_Viewport),
                 (window) =>
                 {
                    SetCamera (window);
                 },
                 (window) =>
                 {
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                    GL.Enable (EnableCap.DepthTest);
                    GL.DepthMask(true);
                    GL.DepthFunc (DepthFunction.Less);
                    GL.Disable (EnableCap.Blend);
                 },
                //pass state
                 FramebufferBindingSet.Default,
                 m_UniformState,
                 new TextureBindingSet
                 {
                   {"normaldepth_texture", NormalDepth_Texture },
                   { "aoc_texture", AOC_Texture },
                 }
            );

            m_Passes = new RenderPass[]{ firstPassSolid, aocPassSolid, thirdPassSolid };
            m_Manip = new OrbitManipulator (m_Projection);
            //m_Grid = new Grid (m_TransformationStack);

            m_TransformationStack.Push (m_Manip.RT);
            m_UniformState.Set ("modelview_transform", m_Manip.RT);
            m_UniformState.Set ("modelviewprojection_transform", m_TransformationStack);
            m_UniformState.Set ("projection_transform", m_Projection);
            m_UniformState.Set ("projection_inv_transform", new MatrixInversion(m_Projection));
            m_UniformState.Set ("modelview_inv_transform", new MatrixInversion(m_Manip.RT));
            m_UniformState.Set ("modelviewprojection_inv_transform", new MatrixInversion(m_TransformationStack));

            PrepareState ();
        }
예제 #46
0
 public ColorRamp(string name, TextureBase texture)
 {
     Name = name;
     Texture = texture;
 }
예제 #47
0
        //
        public static RenderPass CreateFxaa3Filter(
			 TextureBase source,
			 TextureBase result)
        {
            return CreateFilter("fxaa3", "RenderPassFactory", source, result);
        }