/// <summary>The draw function.</summary> public override void Draw() { base.Draw(); float alpha = Tween( FadeCompletion ); TRS pos = new TRS( Director.Instance.CurrentScene.Camera.CalcBounds() ); TRS uv = TRS.Quad0_1; Director.Instance.SpriteRenderer.DefaultShader.SetUVTransform( ref GameEngine2D.Base.Math.UV_TransformIdentity ); { Director.Instance.GL.SetBlendMode( BlendMode.None); Vector4 color = new Vector4( 1.0f - alpha ); Director.Instance.SpriteRenderer.DefaultShader.SetColor( ref color ); Director.Instance.SpriteRenderer.BeginSprites( m_previous_scene_render, 1 ); Director.Instance.SpriteRenderer.AddSprite( ref pos, ref uv ); Director.Instance.SpriteRenderer.EndSprites(); } { Director.Instance.GL.SetBlendMode( BlendMode.Additive ); Vector4 color = new Vector4( alpha ); Director.Instance.SpriteRenderer.DefaultShader.SetColor( ref color ); Director.Instance.SpriteRenderer.BeginSprites( m_next_scene_render, 1 ); Director.Instance.SpriteRenderer.AddSprite( ref pos, ref uv ); Director.Instance.SpriteRenderer.EndSprites(); } }
// float VertexZ; /// <summary>RawSpriteTile constructor.</summary> public RawSpriteTile( TRS positioning, Vector2i tile_index, bool flipu=false, bool flipv=false ) { Quad = positioning; TileIndex2D = tile_index; FlipU = flipu; FlipV = flipv; // VertexZ = vertexz; }
public RawSpriteTile CreateRawSpriteTile(String path, Int32 u, Int32 v, TRS trs) { if (String.IsNullOrWhiteSpace(path)) throw new ArgumentException(); if (!TextureAssetsByUsers.ContainsKey(path)) throw new ArgumentException("Unknown texture asset: " + path); TextureInfo ti = GetTextureInfo(path); RawSpriteTile s = new RawSpriteTile(trs, new Vector2i(u, v)); s.Quad.S = new Vector2(ti.Texture.Width / ti.NumTiles.X, ti.Texture.Height / ti.NumTiles.Y); return s; }
//use new TRS { T=a_T, R=a_S, S=a_S } instead? // public TRS( Vector2 a_T , // Vector2 a_R , // Vector2 a_S ) // { // T = a_T; // R = a_R; // S = a_S; // } /// <summary> /// Get a subregion from source_area, given a number of tiles and a tile index, /// assuming evenly spaced subdivision. Typically source_area will be Quad0_1 /// (the unit quad, means the whole texture) and we return the uv info for a /// given tile in the tiled texture. /// </summary> public static TRS Tile( Vector2i num_tiles, Vector2i tile_index, TRS source_area ) { Vector2 num_tiles_f = num_tiles.Vector2(); Vector2 tile_index_f = tile_index.Vector2(); Vector2 tile_size = source_area.S / num_tiles_f; Vector2 X = source_area.X; Vector2 Y = source_area.Y; TRS ret = new TRS(); ret.T = source_area.T + tile_index_f * tile_size; ret.R = source_area.R; ret.S = tile_size; return ret; }
/// <summary> /// TextureInfo constructor. /// Note: TextureInfo takes ownership of the Texture2D passed to this constructor, and disposes of it in Dispose. /// </summary> /// <param name="texture">The source texture.</param> /// <param name="num_tiles">The number of tile subdivisions on x and y.</param> /// <param name="source_area">The source rectangle, in UV domain, on which we are going to build the tiles (bottom left is 0,0).</param> public TextureInfo( Texture2D texture, Vector2i num_tiles, TRS source_area ) { Initialize( texture, num_tiles, source_area ); }
/// <summary> /// The actual init function called by TextureInfo constructors. /// </summary> /// <param name="texture">The source texture.</param> /// <param name="num_tiles">The number of tiles/cells, horitonally and vertically.</param> /// <param name="source_area">The source rectangle, in UV domain, on which we are going to build the tiles (bottom left is 0,0).</param> public void Initialize( Texture2D texture, Vector2i num_tiles, TRS source_area ) { Texture = texture; TileSizeInUV = source_area.S / num_tiles.Vector2(); NumTiles = num_tiles; m_tiles_uvs = new CachedTileData[ num_tiles.Product() ]; for ( int y=0; y < NumTiles.Y; ++y ) { for ( int x=0; x < NumTiles.X; ++x ) { Vector2i tile_index = new Vector2i( x, y ); TRS tile = TRS.Tile( NumTiles, tile_index, source_area ); // lots of calculation duplicated, but this is an init function int index = tile_index.X + tile_index.Y * NumTiles.X; m_tiles_uvs[ index ] = new CachedTileData() { UV_00 = tile.Point00 , UV_10 = tile.Point10 , UV_01 = tile.Point01 , UV_11 = tile.Point11 }; } } }
/// <summary>The draw function.</summary> public override void Draw() { base.Draw(); float alpha = Tween( FadeCompletion ); TRS pos = new TRS( Director.Instance.CurrentScene.Camera.CalcBounds() ); TRS uv = TRS.Quad0_1; m_shader.SetUVTransform( ref GameEngine2D.Base.Math.UV_TransformIdentity ); Director.Instance.GL.Context.SetTexture( 1, m_next_scene_render.Texture ); { Director.Instance.GL.SetBlendMode( BlendMode.None); Vector2 plane_normal = -Direction.Normalize(); Vector2 plane_start = new Vector2( 0.0f, 0.0f ); Vector2 plane_end = new Vector2( 1.0f, 1.0f ); if ( plane_normal.X > 0.0f ) { plane_start.X = 1.0f; plane_end.X = 0.0f; } if ( plane_normal.Y > 0.0f ) { plane_start.Y = 1.0f; plane_end.Y = 0.0f; } plane_end -= plane_normal * Width; Vector4 plane = new Vector4( GameEngine2D.Base.Math.Lerp( plane_start, plane_end, alpha ), plane_normal ); m_shader.SetPlane( ref plane ); m_shader.SetOffsetRcp( 1.0f / Width ); Director.Instance.SpriteRenderer.BeginSprites( m_previous_scene_render, (ISpriteShader)m_shader, 1 ); Director.Instance.SpriteRenderer.AddSprite( ref pos, ref uv ); Director.Instance.SpriteRenderer.EndSprites(); } }
private void InitializeSprites() { OffScreenTileHidingPlace = GetTilePositionAtLowerLeft(-2, -2); TRS initialPlacement = new TRS(new Bounds2(new Vector2(32f, 32f), new Vector2(1f, 1f))); for (Int32 c = 0; c < SpriteColumns; c++) { for (Int32 r = 0; r < SpriteRows; r++) { RawSpriteTile rst = Mode.TextureManager.CreateRawSpriteTile(Asset, 0, 0, initialPlacement); AddToSpriteList(rst); } } }
/// <summary> /// Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites. /// </summary> /// <param name="quad">The sprite geometry.</param> /// <param name="uv">Sprite UVs are specified directly using a TRS object.</param> /// <param name="mat">A per sprite transform matrix.</param> public void AddSprite( ref TRS quad, ref TRS uv, ref Matrix3 mat ) { Vector2 quadX = quad.X; Vector2 quadY = quad.Y; Vector2 uvX = uv.X; Vector2 uvY = uv.Y; m_v0 = new Vector4( transform_point( ref mat, quad.T ), uv.T ); m_v1 = new Vector4( transform_point( ref mat, quad.T + quadX ), uv.T + uvX ); m_v2 = new Vector4( transform_point( ref mat, quad.T + quadY ), uv.T + uvY ); m_v3 = new Vector4( transform_point( ref mat, quad.T + quadX + quadY ), uv.T + uvX + uvY ); add_quad(); }
/// <summary> /// Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites. /// </summary> /// <param name="quad">The sprite geometry.</param> /// <param name="uv">Sprite UVs are specified directly using a TRS object.</param> public void AddSprite( ref TRS quad, ref TRS uv ) { Vector2 posX = quad.X; Vector2 posY = quad.Y; Vector2 uvX = uv.X; Vector2 uvY = uv.Y; m_v0 = new Vector4( quad.T , uv.T ); m_v1 = new Vector4( quad.T + posX , uv.T + uvX ); m_v2 = new Vector4( quad.T + posY , uv.T + uvY ); m_v3 = new Vector4( quad.T + posX + posY , uv.T + uvX + uvY ); add_quad(); }
/// <summary> /// Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites. /// </summary> /// <param name="quad">The sprite geometry.</param> /// <param name="tile_index">Sprite UVs are specified by a tile index.</param> /// <param name="mat">A per sprite transform matrix.</param> public void AddSprite( ref TRS quad, Vector2i tile_index, ref Matrix3 mat ) { Vector2 posX = quad.X; Vector2 posY = quad.Y; TextureInfo.CachedTileData uvs = m_current_texture_info.GetCachedTiledData( ref tile_index ); m_v0 = new Vector4( transform_point( ref mat, quad.T ), uvs.UV_00 ); m_v1 = new Vector4( transform_point( ref mat, quad.T + posX ), uvs.UV_10 ); m_v2 = new Vector4( transform_point( ref mat, quad.T + posY ), uvs.UV_01 ); m_v3 = new Vector4( transform_point( ref mat, quad.T + posX + posY ), uvs.UV_11 ); add_quad(); }
/// <summary> /// Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites. /// </summary> /// <param name="quad">The sprite geometry.</param> /// <param name="tile_index">Sprite UVs are specified by a tile index.</param> public void AddSprite( ref TRS quad, Vector2i tile_index ) { Vector2 posX = quad.X; Vector2 posY = quad.Y; TextureInfo.CachedTileData uvs = m_current_texture_info.GetCachedTiledData( ref tile_index ); m_v0 = new Vector4( quad.T , uvs.UV_00 ); m_v1 = new Vector4( quad.T + posX , uvs.UV_10 ); m_v2 = new Vector4( quad.T + posY , uvs.UV_01 ); m_v3 = new Vector4( quad.T + posX + posY , uvs.UV_11 ); add_quad(); }
/// <summary> /// Stretch sprite Quad so that it covers the entire screen. The scene /// needs to have been set/started, since it uses CurrentScene.Camera. /// </summary> public void MakeFullScreen() { Quad = new TRS( Director.Instance.CurrentScene.Camera.CalcBounds() ); }
private static Sce.PlayStation.HighLevel.GameEngine2D.Base.TextureInfo MakeTextureInfoFromAtlas(string atlas, string filename, int columns=1, int rows=1) { string assetName = atlas + "_" + filename; UnifiedTextureInfo uInfo = GetAtlas(atlas)[filename]; // System.Console.WriteLine(assetName + ": " + uInfo.u0.ToString() + " " + uInfo.v0.ToString() + " " + uInfo.w.ToString() + " " + uInfo.h.ToString()); TRS trs = new TRS(new Bounds2(new Vector2(uInfo.u0, uInfo.v0), new Vector2(uInfo.u1, uInfo.v1))); var info = new TextureInfo(TextureCache[atlas], new Vector2i(columns,rows), trs); TextureInfoCache[assetName] = info; return info; }