protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var materialBuilder = builder as MyObjectBuilder_TransparentMaterialDefinition;
            MyDebug.AssertDebug(materialBuilder != null, "Initializing transparent material definition using wrong object builder.");

            Texture = materialBuilder.Texture;
            TextureType = materialBuilder.TextureType;
            CanBeAffectedByLights = materialBuilder.CanBeAffectedByOtherLights;
            AlphaMistingEnable = materialBuilder.AlphaMistingEnable;
            IgnoreDepth = materialBuilder.IgnoreDepth;
            NeedSort = materialBuilder.NeedSort;
            UseAtlas = materialBuilder.UseAtlas;
            AlphaMistingStart = materialBuilder.AlphaMistingStart;
            AlphaMistingEnd = materialBuilder.AlphaMistingEnd;
            SoftParticleDistanceScale = materialBuilder.SoftParticleDistanceScale;
            Emissivity = materialBuilder.Emissivity;
            AlphaSaturation = materialBuilder.AlphaSaturation;
            Reflection = materialBuilder.Reflection;
            Reflectivity = materialBuilder.Reflectivity;
            Color = materialBuilder.Color;
            AlphaCutout = materialBuilder.AlphaCutout;
            TargetSize = materialBuilder.TargetSize;
        }   
Ejemplo n.º 2
0
        internal void Clear()
        {
            m_deviceContext.ClearState();

            m_inputLayout = null;
            m_primitiveTopology = PrimitiveTopology.Undefined;
            m_indexBufferRef = null;
            m_indexBufferFormat = 0;
            m_indexBufferOffset = 0;
            for (int i = 0; i < m_vertexBuffers.Length; i++)
                m_vertexBuffers[i] = null;
            for (int i = 0; i < m_vertexBuffersStrides.Length; i++)
                m_vertexBuffersStrides[i] = 0;

            m_blendState = null;
            m_stencilRef = 0;
            m_depthStencilState = null;
            m_rtvsCount = 0;
            for (int i = 0; i < m_rtvs.Length; i++)
                m_rtvs[i] = null;
            m_dsv = null;

            m_rasterizerState = null;
            m_scissorLeftTop = new Vector2I(-1, -1);
            m_scissorRightBottom = new Vector2I(-1, -1);
            m_viewport = default(RawViewportF);

            m_targetBuffer = null;
            m_targetOffsets = 0;

            m_statistics.ClearStates++;
        }
 /// <summary>
 /// Serialize a chunk.
 /// </summary>
 /// <param name="chunk">The chunk to serialize.</param>
 /// <param name="chunkIndex">The chunk index.</param>
 public void SerializeChunk(Chunk chunk, Vector2I chunkIndex)
 {
     // NOTE: This should occur in a seperate thread, since terrain serialization isn't high priority.
     // However, care should be taken to consider the situation when a terrain is being serialized in another thread
     // and then a new deserialization request comes in for that chunk. In this case the deserialization thread
     // should block
 }
Ejemplo n.º 4
0
        public TexturedExtensibleRectangle(IContext context, Vector2I size, Texture texture, int fixedBorderRadius)
        {
            DeviceContext = context.DirectX.DeviceContext;
            _shader = context.Shaders.Get<TextureShader>();
            _texture = texture;
            _fixedBorderRadius = fixedBorderRadius;

            const int vertexCount = 16;
            _vertices = new VertexDefinition.PositionTexture[vertexCount];
            VertexBuffer = Buffer.Create(context.DirectX.Device, _vertices,
                new BufferDescription
                {
                    Usage = ResourceUsage.Dynamic,
                    SizeInBytes = Utilities.SizeOf<VertexDefinition.PositionTexture>() * vertexCount,
                    BindFlags = BindFlags.VertexBuffer,
                    CpuAccessFlags = CpuAccessFlags.Write,
                    OptionFlags = ResourceOptionFlags.None,
                    StructureByteStride = 0
                });

            IndexCount = 54;
            uint[] indices = new uint[IndexCount];
            for(uint i=0; i< 3; i++)
                for (uint j = 0; j < 3; j++)
                {
                    indices[(i * 3 + j) * 6] = (i + 1) * 4 + j + 1;
                    indices[(i * 3 + j) * 6 + 1] = i * 4 + j + 1;
                    indices[(i * 3 + j) * 6 + 2] = i * 4 + j;
                    indices[(i * 3 + j) * 6 + 3] = (i + 1) * 4 + j;
                    indices[(i * 3 + j) * 6 + 4] = (i + 1) * 4 + j + 1;
                    indices[(i * 3 + j) * 6 + 5] = i * 4 + j;
                }
            IndexBuffer = Buffer.Create(context.DirectX.Device, BindFlags.IndexBuffer, indices);
            Size = size;
        }
Ejemplo n.º 5
0
        public Bitmap(Device device, ShaderResourceView texture, Vector2I screenSize, Vector2I size, float depth = 0.0f)
        {
            Texture = texture;
            ScreenSize = screenSize;
            Size = size;
            _changed = true;
            Depth = depth;

            VertexCount = 4;
            IndexCount = 6;

            _vertices = new TranslateShader.Vertex[VertexCount];
            UInt32[] indices =  {0, 1, 2, 0, 3, 1};

            VertexBuffer = Buffer.Create(device, _vertices,
                new BufferDescription
                {
                    Usage = ResourceUsage.Dynamic,
                    SizeInBytes = Utilities.SizeOf<TranslateShader.Vertex>() * VertexCount,
                    BindFlags = BindFlags.VertexBuffer,
                    CpuAccessFlags = CpuAccessFlags.Write,
                    OptionFlags = ResourceOptionFlags.None,
                    StructureByteStride = 0
                });

            IndexBuffer = Buffer.Create(device, BindFlags.IndexBuffer, indices);
        }
Ejemplo n.º 6
0
 public bool Contains(Vector2I point)
 {
     bool b1 = Sign(point, Points[0], Points[1]) < 0.0f;
     bool b2 = Sign(point, Points[1], Points[2]) < 0.0f;
     bool b3 = Sign(point, Points[2], Points[0]) < 0.0f;
     return ((b1 == b2) && (b2 == b3));
 }
Ejemplo n.º 7
0
 public TilesetImage(string imagePath, Vector2I tileSize, Vector2I tileMargin, Vector2I tileBorder)
 {
     ImagePath = imagePath;
     TileSize = tileSize;
     TileMargin = tileMargin;
     TileBorder = tileBorder;
 }
Ejemplo n.º 8
0
 public void Init(
     string name,
     int width,
     int height,
     Format resourceFormat,
     Format srvFormat,
     BindFlags bindFlags,
     int samplesCount,
     int samplesQuality,
     ResourceOptionFlags roFlags,
     ResourceUsage ru,
     int mipmapLevels,
     CpuAccessFlags cpuAccessFlags)
 {
     m_name = name;
     m_size = new Vector2I(width, height);
     m_resourceFormat = resourceFormat;
     m_srvFormat = srvFormat;
     m_bindFlags = bindFlags;
     m_samplesCount = samplesCount;
     m_samplesQuality = samplesQuality;
     m_roFlags = roFlags;
     m_resourceUsage = ru;
     m_mipmapLevels = mipmapLevels;
     m_cpuAccessFlags = cpuAccessFlags;
 }
Ejemplo n.º 9
0
        public Rectangle(Renderer renderer, Vector2I screenSize, Vector2I position, Vector2I size, Vector4 color, float depth = 0.0f)
        {
            _shader = renderer.ColorShader;
            Position = position;
            ScreenSize = screenSize;
            Size = size;
            _color = color;
            _changed = true;
            Depth = depth;

            int vertexCount = 4;
            _indexCount = 6;

            _vertices = new VertexDefinition.PositionColor[vertexCount];
            UInt32[] indices = { 0, 1, 2, 0, 3, 1 };

            _vertexBuffer = Buffer.Create(renderer.DirectX.Device, _vertices,
                new BufferDescription
                {
                    Usage = ResourceUsage.Dynamic,
                    SizeInBytes = Utilities.SizeOf<VertexDefinition.PositionColor>() * vertexCount,
                    BindFlags = BindFlags.VertexBuffer,
                    CpuAccessFlags = CpuAccessFlags.Write,
                    OptionFlags = ResourceOptionFlags.None,
                    StructureByteStride = 0
                });

            _indexBuffer = Buffer.Create(renderer.DirectX.Device, BindFlags.IndexBuffer, indices);
        }
Ejemplo n.º 10
0
 internal void Init(string name, Texture2DDescription desc, Vector2I size, int bytes)
 {
     m_name = name;
     m_size = size;
     m_desc = desc;
     m_bytes = bytes;
 }
Ejemplo n.º 11
0
 public static IEnumerable<Vector2I> ChebyshevNeighborhood(Vector2I position, int range = 1)
 {
     for (int i = -range; i <= range; ++i)
         for (int j = -range; j <= range; ++j)
             if (!(i == 0 && j == 0))    // omit center position
                 yield return new Vector2I(position.X + i, position.Y + j);
 }
Ejemplo n.º 12
0
 public Triangle(Vector2I a, Vector2I b, Vector2I c)
 {
     Points[0] = a;
     Points[1] = b;
     Points[2] = c;
     Id = AutoIncrement++;
 }
Ejemplo n.º 13
0
        public DuplicatedCubeGrid(Vector2I dimensions)
        {
            Dimensions = dimensions;

            this[VboPosition.Vertices] = StaticVboFactory.GetDuplicatedCubeGridVertices(dimensions);
            EnableAttrib(VboPosition.Vertices);
        }
Ejemplo n.º 14
0
        public RenderTexture(Device device, Vector2I screenSize)
        {
            var textureDesc = new Texture2DDescription()
            {
                Width = screenSize.X,
                Height = screenSize.Y,
                MipLevels = 1,
                ArraySize = 1,
                Format = Format.R32G32B32A32_Float,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default,
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None
            };

            _renderTargetTexture = new Texture2D(device, textureDesc);

            _renderTargetView = new RenderTargetView(device, _renderTargetTexture,
                new RenderTargetViewDescription
                {
                    Format = textureDesc.Format,
                    Dimension = RenderTargetViewDimension.Texture2D,
                    Texture2D = {MipSlice = 0},
                });

            // Create the render target view.
            ShaderResourceView = new ShaderResourceView(device, _renderTargetTexture,
                new ShaderResourceViewDescription
                {
                    Format = textureDesc.Format,
                    Dimension = ShaderResourceViewDimension.Texture2D,
                    Texture2D = { MipLevels = 1, MostDetailedMip = 0 },
                });
        }
    /// <summary>
    /// Generate a chunk and return it. The terrain object remains unmodified.
    /// </summary>
    /// <param name="terrain">The terrain.</param>
    /// <param name="chunkIndex">The chunk index.</param>
    /// <returns>The chunk.</returns>
    public Chunk GenerateChunk(Terrain terrain, Vector2I chunkIndex)
    {
        Chunk chunk = new Chunk();

        // Calculate the position of the chunk in world coordinates
        var chunkPos = new Vector2I(chunkIndex.X * Chunk.SizeX, chunkIndex.Y * Chunk.SizeY);

        // Get the surface heights for this chunk
        int[] surfaceHeights = this.GenerateSurfaceHeights(chunkPos);

        // For now, fill the terrain with mud under the surface
        for (int x = 0; x < Chunk.SizeX; x++)
        {
            int surfaceHeight = surfaceHeights[x];
            if (surfaceHeight > 0)
            {
                for (int y = 0; y < surfaceHeight; y++)
                {
                    chunk[x, y] = new Block(BlockType.Dirt);
                }
            }
        }

        return chunk;
    }
Ejemplo n.º 16
0
        public BasicFbo(RenderTargetManager textureManager, Vector2I size)
        {
            AttachTexture(FramebufferAttachment.DepthAttachment, textureManager.Get<RenderTargetDepthTexture>(size)); // Must be first due to error checking
            AttachTexture(FramebufferAttachment.ColorAttachment0, textureManager.Get<RenderTargetColorTexture>(size));

            FramebufferErrorCode err = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
            Debug.Assert(err == FramebufferErrorCode.FramebufferComplete, "Framebuffer error: " + err);
        }
Ejemplo n.º 17
0
 public bool InBounds(Vector2I position)
 {
     return IsVisible()
            && position.X >= Position.X
            && position.X < Position.X + Size.X
            && position.Y >= Position.Y
            && position.Y < Position.Y + Size.Y;
 }
Ejemplo n.º 18
0
 public override bool InBoundsAndActive(Vector2I position)
 {
     if (Overlay || !IsVisible()) return false;
     return    position.X >= Position.X
            && position.X < Position.X + Size.X
            && position.Y >= Position.Y
            && position.Y < Position.Y + Size.Y;
 }
        public override void Close()
        {
            Id = 0;
            ScreenData = null;
            Resolution = new Vector2I();

            base.Close();
        }
		public TileSetTileContentSource(BitmapTileSet tileSet, int tileIndex, Color tint, float rotate, Vector2I translate)
		{
			_tileSet = tileSet;
			_tileIndex = tileIndex;
			_tint = tint;
			_translate = translate;
			_rotate = rotate;
		}
Ejemplo n.º 21
0
 public Text Create(string fontName, int fontSize, string content, Vector2I size, Color color, 
     HorizontalAlignment horizontalAligment, VerticalAlignment verticalAlignment, Padding padding)
 {
     string fontKey = fontName + "-" + size;
     if (!_fontDictionary.ContainsKey(fontKey))
         _fontDictionary.Add(fontKey, new Font(_context, fontName, fontSize));
     return new Text(_context, content, _fontDictionary[fontKey], size, color, horizontalAligment, verticalAlignment, padding);
 }
 Vector2I GetThreadsPerThreadGroup(Vector2I textureSizeInPixels)
 {
     int pixelsPerThreadGroupX = textureSizeInPixels.X / m_threadGroupCountX;
     int pixelsPerThreadGroupY = textureSizeInPixels.Y/ m_threadGroupCountY;
     return new Vector2I(
     (pixelsPerThreadGroupX + m_pixelsPerThreadX - 1) / m_pixelsPerThreadX,
     (pixelsPerThreadGroupY + m_pixelsPerThreadY - 1) / m_pixelsPerThreadY);
 }
        public override void Close()
        {
            Id = 0;
            PreallocatedBuffer = null;
            Resolution = new Vector2I();

            base.Close();
        }
Ejemplo n.º 24
0
 protected RenderTargetTexture(Vector2I size)
     : base(size.X, size.Y) // Use default pixel format)
 {
     Init2D();
     SetParameters(
            TextureMinFilter.Nearest,
            TextureMagFilter.Nearest,
            TextureWrapMode.ClampToEdge);
 }
Ejemplo n.º 25
0
Archivo: Edge.cs Proyecto: ndech/Alpha
 public Edge(Triangle onlyOne, Vector2I a, Vector2I b)
 {
     if(!(onlyOne.Points.Contains(a) && onlyOne.Points.Contains(b)))
         throw new InvalidOperationException("Points do not belong to the triangle.");
     Points[0] = a;
     Points[1] = b;
     Triangles[0] = null;
     Triangles[1] = onlyOne;
 }
Ejemplo n.º 26
0
 protected RenderTargetTexture(Vector2I size, PixelFormat pixelFormat, PixelInternalFormat internalFormat)
     : base(size.X, size.Y)
 {
     Init2D(pixelFormat, internalFormat);
     SetParameters(
            TextureMinFilter.Nearest,
            TextureMagFilter.Nearest,
            TextureWrapMode.ClampToEdge);
 }
Ejemplo n.º 27
0
 public void SetSetting(string mapName, string warpPointName, Vector2I tileDimension = null)
 {
     SetSetting(
         mapName,
         warpPointName,
         tileDimension == null ? null : (new IntRect(
             0, 0, tileDimension.X * GameData.TILE_SIZE,
             tileDimension.Y * GameData.TILE_SIZE)));
 }
Ejemplo n.º 28
0
        public void TestRectangleICenter()
        {
            // ARRANGE.
            var rectangle = new RectangleI(new Vector2I(2, 3), new Vector2I(6, 8));
            var center = new Vector2I(5, 7);

            // ASSERT.
            Assert.AreEqual(center, rectangle.Center);
        }
Ejemplo n.º 29
0
    private bool ContainsBlock(Vector2I blockPos)
    {
        foreach (LevelBlock levelBlock in levelBlockList)
        {
            if(levelBlock.xPos == blockPos.x && levelBlock.yPos == blockPos.y)
                return true;
        }

        return false;
    }
Ejemplo n.º 30
0
        public CombatCell(Vector2I position)
        {
            Position = position;

            ColorEffects = new Dictionary<CellSelectionType, CellShape>();
            foreach (CellSelectionType type in System.Enum.GetValues(typeof(CellSelectionType)))
                ColorEffects.Add(type, null);

            Combatants = new List<BaseCombatant>();
        }
Ejemplo n.º 31
0
 /// <summary>Attempts to find a curve under the provided coordinates.</summary>
 /// <param name="pixelCoords">Coordinates relative to this GUI element in pixels.</param>
 /// <returns>Index of the curve, or -1 if none found.</returns>
 public int FindCurve(Vector2I pixelCoords)
 {
     return(Internal_findCurve(mCachedPtr, ref pixelCoords));
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Uses the assigned FPS, range and physical size to calculate the frame that is under the provided coordinates.
 /// </summary>
 /// <param name="pixelCoords">Coordinates relative to this GUI element.</param>
 /// <returns>Frame that was clicked on, or -1 if the coordinates are outside of valid bounds.</returns>
 public uint GetFrame(Vector2I pixelCoords)
 {
     return(Internal_getFrame(mCachedPtr, ref pixelCoords));
 }
Ejemplo n.º 33
0
 void SetInfluence(Vector2I pos, float value)
 {
     _influenceMap.SetInfluence(pos, value);
 }
Ejemplo n.º 34
0
        internal static void PreparePointLights()
        {
            var activePointlights = 0;

            MyLights.Update();
            BoundingFrustumD viewFrustumClippedD = MyRender11.Environment.ViewFrustumClippedD;

            if (MyStereoRender.Enable)
            {
                if (MyStereoRender.RenderRegion == MyStereoRegion.LEFT)
                {
                    viewFrustumClippedD = MyStereoRender.EnvMatricesLeftEye.ViewFrustumClippedD;
                }
                else if (MyStereoRender.RenderRegion == MyStereoRegion.RIGHT)
                {
                    viewFrustumClippedD = MyStereoRender.EnvMatricesRightEye.ViewFrustumClippedD;
                }
            }
            MyLights.PointlightsBvh.OverlapAllFrustum(ref viewFrustumClippedD, VisiblePointlights);

            bool visiblePointlights = VisiblePointlights.Count != 0;

            if (!visiblePointlights && !m_lastFrameVisiblePointlights)
            {
                return;
            }

            m_lastFrameVisiblePointlights = visiblePointlights;

            if (VisiblePointlights.Count > MyRender11Constants.MAX_POINT_LIGHTS)
            {
                VisiblePointlights.Sort((x, y) => x.ViewerDistanceSquared.CompareTo(y.ViewerDistanceSquared));

                while (VisiblePointlights.Count > MyRender11Constants.MAX_POINT_LIGHTS)
                {
                    VisiblePointlights.RemoveAtFast(VisiblePointlights.Count - 1);
                }
            }

            foreach (var light in VisiblePointlights)
            {
                MyLights.WritePointlightConstants(light, ref m_pointlightsCullBuffer[activePointlights]);

                activePointlights++;
                Debug.Assert(activePointlights <= MyRender11Constants.MAX_POINT_LIGHTS);
            }
            for (int lightIndex = activePointlights; lightIndex < MyRender11Constants.MAX_POINT_LIGHTS; ++lightIndex)
            {
                MyLights.WritePointlightConstants(LightId.NULL, ref m_pointlightsCullBuffer[lightIndex]);
            }

            var mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(16));

            mapping.WriteAndPosition(ref activePointlights);
            mapping.Unmap();

            mapping = MyMapping.MapDiscard(m_pointlightCullHwBuffer.Buffer);
            mapping.WriteAndPosition(m_pointlightsCullBuffer, 0, MyRender11Constants.MAX_POINT_LIGHTS);
            mapping.Unmap();

            if (!MyStereoRender.Enable)
            {
                RC.CSSetCB(0, MyCommon.FrameConstants);
            }
            else
            {
                MyStereoRender.CSBindRawCB_FrameConstants(RC);
            }
            RC.CSSetCB(1, MyCommon.GetObjectCB(16));

            //RC.BindUAV(0, MyScreenDependants.m_test);
            RC.BindUAV(0, MyScreenDependants.m_tileIndices);
            RC.BindGBufferForRead(0, MyGBuffer.Main);
            RC.CSBindRawSRV(MyCommon.POINTLIGHT_SLOT, m_pointlightCullHwBuffer);
            RC.SetCS(m_preparePointLights);
            Vector2I tiles = new Vector2I(MyScreenDependants.TilesX, MyScreenDependants.TilesY);

            if (MyStereoRender.Enable && MyStereoRender.RenderRegion != MyStereoRegion.FULLSCREEN)
            {
                tiles.X /= 2;
            }

            RC.DeviceContext.Dispatch(tiles.X, tiles.Y, 1);
            RC.SetCS(null);
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Renders all tilable objects in view.
        /// </summary>
        internal void Render()
        {
            Vector2I min, max;
            var      cc = CameraController.Instance;

            if (cc != null && !GameUtil.IsCapturingTimeLapse())
            {
                // Use camera area
                var visibleArea = cc.VisibleArea.CurrentArea;
                min    = visibleArea.Min;
                max    = visibleArea.Max;
                min.x /= CHUNK_SIZE;
                min.y /= CHUNK_SIZE;
                // Round UP!
                max.x = (max.x + CHUNK_SIZE - 1) / CHUNK_SIZE;
                max.y = (max.y + CHUNK_SIZE - 1) / CHUNK_SIZE;
            }
            else
            {
                min = Vector2I.zero;
                max = new Vector2I(Grid.WidthInCells / CHUNK_SIZE, Grid.HeightInCells /
                                   CHUNK_SIZE);
            }
            int minX = min.x, maxX = max.x, minY = min.y, maxY = max.y;
            int lMinX = lastVisible.x, lMaxX = lastVisible.width, lMinY = lastVisible.y,
                lMaxY = lastVisible.height;

            // Turn off hidden chunks
            for (int x = lMinX; x < lMaxX; x++)
            {
                for (int y = lMinY; y < lMaxY; y++)
                {
                    if (y < minY || y >= maxY || x < minX || x >= maxX)
                    {
                        deactivated.Add(new Vector2I(x, y));
                    }
                }
            }
            // Store the last visible volume
            lastVisible.x      = minX;
            lastVisible.y      = minY;
            lastVisible.width  = maxX;
            lastVisible.height = maxY;
            int n = deactivated.Count;

            foreach (var pair in renderInfo)
            {
                var info = pair.Value;
                for (int i = 0; i < n; i++)
                {
                    var coords = deactivated[i];
                    info.Deactivate(coords.x, coords.y);
                }
                for (int x = minX; x < maxX; x++)
                {
                    for (int y = minY; y < maxY; y++)
                    {
                        info.Rebuild(this, x, y);
                    }
                }
            }
            deactivated.Clear();
            forceRebuild = false;
        }
Ejemplo n.º 36
0
 public FireplaceBurning(Vector2I position, string textureName) : base(position, textureName)
 {
     Init();
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Inserts a string starting on a given line at a given position.
 /// </summary>
 public override void Insert(RichStringMembers text, Vector2I start) =>
 Insert(new RichStringMembers[] { text }, start);
Ejemplo n.º 38
0
 private static extern bool Internal_findTangent(IntPtr thisPtr, ref Vector2I pixelCoords, out TangentRef tangent);
Ejemplo n.º 39
0
 /// <summary>Converts pixel coordinates into coordinates in curve space.</summary>
 /// <param name="pixelCoords">Coordinates relative to this GUI element, in pixels.</param>
 /// <param name="curveCoords">
 /// Curve coordinates within the range as specified by setRange(). Only valid when function returns true.
 /// </param>
 /// <param name="padding">Determines should coordinates over the area reserved for padding be registered.</param>
 /// <returns>True if the coordinates are within the curve area, false otherwise.</returns>
 public bool PixelToCurveSpace(Vector2I pixelCoords, out Vector2 curveCoords, bool padding = false)
 {
     return(Internal_pixelToCurveSpace(mCachedPtr, ref pixelCoords, out curveCoords, padding));
 }
Ejemplo n.º 40
0
 public KeyToDoor(ITilesetTable tilesetTable, Vector2I position)
     : base(tilesetTable, position)
 {
 }
Ejemplo n.º 41
0
 public KeyToDoor(int tileType, Vector2I position)
     : base(tileType, position)
 {
 }
Ejemplo n.º 42
0
 private static extern uint Internal_getFrame(IntPtr thisPtr, ref Vector2I pixelCoords);
Ejemplo n.º 43
0
        public static Component_Material CreateMaterial(Component materialsGroup, MaterialData data)
        {
            //create material
            var material = materialsGroup.CreateComponent <Component_Material>(enabled: false);

            material.Name         = data.Name;
            material.ShadingModel = data.ShadingModel;
            material.TwoSided     = data.TwoSided;
            if (!string.IsNullOrEmpty(data.OpacityTexture))
            {
                material.BlendMode = Component_Material.BlendModeEnum.Masked;
            }

            //create shader graph
            Component_FlowGraph graph;
            {
                graph                = material.CreateComponent <Component_FlowGraph>();
                graph.Name           = material.Name + " shader graph";
                graph.Specialization = ReferenceUtility.MakeReference <Component_FlowGraphSpecialization>(null,
                                                                                                          MetadataManager.GetTypeOfNetType(typeof(Component_FlowGraphSpecialization_Shader)).Name + "|Instance");

                var node = graph.CreateComponent <Component_FlowGraphNode>();
                node.Name             = "Node " + material.Name;
                node.Position         = new Vector2I(10, -7);
                node.ControlledObject = ReferenceUtility.MakeThisReference(node, material);
            }

            const int step     = 9;
            Vector2I  position = new Vector2I(-20, -data.GetTextureCount() * step / 2);

            //BaseColor
            if (!string.IsNullOrEmpty(data.BaseColorTexture))
            {
                var node = graph.CreateComponent <Component_FlowGraphNode>();
                node.Name     = "Node Texture Sample " + "BaseColor";
                node.Position = position;
                position.Y   += step;

                var sample = node.CreateComponent <Component_ShaderTextureSample>();
                sample.Name    = ComponentUtility.GetNewObjectUniqueName(sample);
                sample.Texture = new Reference <Component_Image>(null, data.BaseColorTexture);

                node.ControlledObject = ReferenceUtility.MakeThisReference(node, sample);

                material.BaseColor = ReferenceUtility.MakeThisReference(material, sample, "RGBA");
            }
            else if (data.BaseColor.HasValue)
            {
                material.BaseColor = data.BaseColor.Value;
            }

            //Metallic
            if (!string.IsNullOrEmpty(data.MetallicTexture))
            {
                var node = graph.CreateComponent <Component_FlowGraphNode>();
                node.Name     = "Node Texture Sample " + "Metallic";
                node.Position = position;
                position.Y   += step;

                var sample = node.CreateComponent <Component_ShaderTextureSample>();
                sample.Name    = ComponentUtility.GetNewObjectUniqueName(sample);
                sample.Texture = new Reference <Component_Image>(null, data.MetallicTexture);

                node.ControlledObject = ReferenceUtility.MakeThisReference(node, sample);

                material.Metallic = ReferenceUtility.MakeThisReference(material, sample, "R");
            }

            //Roughness
            if (!string.IsNullOrEmpty(data.RoughnessTexture))
            {
                var node = graph.CreateComponent <Component_FlowGraphNode>();
                node.Name     = "Node Texture Sample " + "Roughness";
                node.Position = position;
                position.Y   += step;

                var sample = node.CreateComponent <Component_ShaderTextureSample>();
                sample.Name    = ComponentUtility.GetNewObjectUniqueName(sample);
                sample.Texture = new Reference <Component_Image>(null, data.RoughnessTexture);

                node.ControlledObject = ReferenceUtility.MakeThisReference(node, sample);

                material.Roughness = ReferenceUtility.MakeThisReference(material, sample, "R");
            }

            //Normal
            if (!string.IsNullOrEmpty(data.NormalTexture))
            {
                var node = graph.CreateComponent <Component_FlowGraphNode>();
                node.Name     = "Node Texture Sample " + "Normal";
                node.Position = position;
                position.Y   += step;

                var sample = node.CreateComponent <Component_ShaderTextureSample>();
                sample.Name    = ComponentUtility.GetNewObjectUniqueName(sample);
                sample.Texture = new Reference <Component_Image>(null, data.NormalTexture);

                node.ControlledObject = ReferenceUtility.MakeThisReference(node, sample);

                material.Normal = ReferenceUtility.MakeThisReference(material, sample, "RGBA");
            }

            //Displacement
            if (!string.IsNullOrEmpty(data.DisplacementTexture))
            {
                var node = graph.CreateComponent <Component_FlowGraphNode>();
                node.Name     = "Node Texture Sample " + "Displacement";
                node.Position = position;
                position.Y   += step;

                var sample = node.CreateComponent <Component_ShaderTextureSample>();
                sample.Name    = ComponentUtility.GetNewObjectUniqueName(sample);
                sample.Texture = new Reference <Component_Image>(null, data.DisplacementTexture);

                node.ControlledObject = ReferenceUtility.MakeThisReference(node, sample);

                material.Displacement = ReferenceUtility.MakeThisReference(material, sample, "R");
            }

            //AmbientOcclusion
            if (!string.IsNullOrEmpty(data.AmbientOcclusionTexture))
            {
                var node = graph.CreateComponent <Component_FlowGraphNode>();
                node.Name     = "Node Texture Sample " + "AmbientOcclusion";
                node.Position = position;
                position.Y   += step;

                var sample = node.CreateComponent <Component_ShaderTextureSample>();
                sample.Name    = ComponentUtility.GetNewObjectUniqueName(sample);
                sample.Texture = new Reference <Component_Image>(null, data.AmbientOcclusionTexture);

                node.ControlledObject = ReferenceUtility.MakeThisReference(node, sample);

                material.AmbientOcclusion = ReferenceUtility.MakeThisReference(material, sample, "R");
            }

            //Emissive
            if (!string.IsNullOrEmpty(data.EmissiveTexture))
            {
                var node = graph.CreateComponent <Component_FlowGraphNode>();
                node.Name     = "Node Texture Sample " + "Emissive";
                node.Position = position;
                position.Y   += step;

                var sample = node.CreateComponent <Component_ShaderTextureSample>();
                sample.Name    = ComponentUtility.GetNewObjectUniqueName(sample);
                sample.Texture = new Reference <Component_Image>(null, data.EmissiveTexture);

                node.ControlledObject = ReferenceUtility.MakeThisReference(node, sample);

                material.Emissive = ReferenceUtility.MakeThisReference(material, sample, "RGBA");
            }

            //Opacity
            if (!string.IsNullOrEmpty(data.OpacityTexture))
            {
                var node = graph.CreateComponent <Component_FlowGraphNode>();
                node.Name     = "Node Texture Sample " + "Opacity";
                node.Position = position;
                position.Y   += step;

                var sample = node.CreateComponent <Component_ShaderTextureSample>();
                sample.Name    = ComponentUtility.GetNewObjectUniqueName(sample);
                sample.Texture = new Reference <Component_Image>(null, data.OpacityTexture);

                node.ControlledObject = ReferenceUtility.MakeThisReference(node, sample);

                material.Opacity = ReferenceUtility.MakeThisReference(material, sample, "R");
            }

            material.Enabled = true;

            return(material);
        }
Ejemplo n.º 44
0
 private static extern bool Internal_findKeyFrame(IntPtr thisPtr, ref Vector2I pixelCoords, out KeyframeRef keyframe);
Ejemplo n.º 45
0
 /// <summary>
 /// Applies glyph formatting to a range of characters.
 /// </summary>
 /// <param name="start">Position of the first character being formatted.</param>
 /// <param name="end">Position of the last character being formatted.</param>
 public override void SetFormatting(Vector2I start, Vector2I end, GlyphFormat formatting, bool onlyChangeColor)
 {
     base.SetFormatting(start, end, formatting, onlyChangeColor);
     RewrapRange(start.X, end.X);
 }
Ejemplo n.º 46
0
 private static extern int Internal_findCurve(IntPtr thisPtr, ref Vector2I pixelCoords);
Ejemplo n.º 47
0
 public CachingValueProvider2D(Vector2I offset, Vector2I size, ValueProvider2D <T> source)
 {
     this.source = source;
     this.offset = offset;
     this.size   = size;
 }
Ejemplo n.º 48
0
 private static extern void Internal_curveToPixelSpace(IntPtr thisPtr, ref Vector2 curveCoords, out Vector2I __output);
Ejemplo n.º 49
0
 public FireplaceBurning(Vector2I position) : base(position)
 {
     Init();
 }
 public BoardPieceMove(int fromX, int fromY, int toX, int toY)
 {
     From = new Vector2I(fromX, fromY);
     To   = new Vector2I(toX, toY);
 }
        internal MyDepthStencil(int width, int height,
                                int sampleCount, int sampleQuality)
        {
            m_resolution = new Vector2I(width, height);
            m_samples    = new Vector2I(sampleCount, sampleQuality);

            m_depthSubresource   = new MyDepthView(this);
            m_stencilSubresource = new MyStencilView(this);

            Texture2DDescription desc = new Texture2DDescription();

            desc.Width                     = width;
            desc.Height                    = height;
            desc.Format                    = Depth32F ? Format.R32G8X24_Typeless : Format.R24G8_Typeless;
            desc.ArraySize                 = 1;
            desc.MipLevels                 = 1;
            desc.BindFlags                 = BindFlags.DepthStencil | BindFlags.ShaderResource;
            desc.Usage                     = ResourceUsage.Default;
            desc.CpuAccessFlags            = 0;
            desc.SampleDescription.Count   = sampleCount;
            desc.SampleDescription.Quality = sampleQuality;
            desc.OptionFlags               = 0;
            m_resource                     = new Texture2D(MyRender11.Device, desc);

            DepthStencilViewDescription dsvDesc = new DepthStencilViewDescription();

            dsvDesc.Format = Depth32F ? Format.D32_Float_S8X24_UInt : Format.D24_UNorm_S8_UInt;
            if (sampleCount == 1)
            {
                dsvDesc.Dimension          = DepthStencilViewDimension.Texture2D;
                dsvDesc.Flags              = DepthStencilViewFlags.None;
                dsvDesc.Texture2D.MipSlice = 0;
            }
            else
            {
                dsvDesc.Dimension = DepthStencilViewDimension.Texture2DMultisampled;
                dsvDesc.Flags     = DepthStencilViewFlags.None;
            }
            m_DSV = new DepthStencilView(MyRender11.Device, m_resource, dsvDesc);
            if (sampleCount == 1)
            {
                dsvDesc.Dimension          = DepthStencilViewDimension.Texture2D;
                dsvDesc.Flags              = DepthStencilViewFlags.ReadOnlyDepth;
                dsvDesc.Texture2D.MipSlice = 0;
            }
            else
            {
                dsvDesc.Dimension = DepthStencilViewDimension.Texture2DMultisampled;
                dsvDesc.Flags     = DepthStencilViewFlags.ReadOnlyDepth;
            }
            m_DSV_roDepth = new DepthStencilView(MyRender11.Device, m_resource, dsvDesc);
            if (sampleCount == 1)
            {
                dsvDesc.Dimension          = DepthStencilViewDimension.Texture2D;
                dsvDesc.Flags              = DepthStencilViewFlags.ReadOnlyStencil;
                dsvDesc.Texture2D.MipSlice = 0;
            }
            else
            {
                dsvDesc.Dimension = DepthStencilViewDimension.Texture2DMultisampled;
                dsvDesc.Flags     = DepthStencilViewFlags.ReadOnlyStencil;
            }
            m_DSV_roStencil = new DepthStencilView(MyRender11.Device, m_resource, dsvDesc);
            dsvDesc.Flags   = DepthStencilViewFlags.ReadOnlyStencil | DepthStencilViewFlags.ReadOnlyDepth;
            if (sampleCount == 1)
            {
                dsvDesc.Dimension          = DepthStencilViewDimension.Texture2D;
                dsvDesc.Texture2D.MipSlice = 0;
            }
            else
            {
                dsvDesc.Dimension = DepthStencilViewDimension.Texture2DMultisampled;
            }
            m_DSV_ro = new DepthStencilView(MyRender11.Device, m_resource, dsvDesc);

            ShaderResourceViewDescription srvDesc = new ShaderResourceViewDescription();

            srvDesc.Format = Depth32F ? Format.R32_Float_X8X24_Typeless : Format.R24_UNorm_X8_Typeless;
            if (sampleCount == 1)
            {
                srvDesc.Dimension                 = ShaderResourceViewDimension.Texture2D;
                srvDesc.Texture2D.MipLevels       = -1;
                srvDesc.Texture2D.MostDetailedMip = 0;
            }
            else
            {
                srvDesc.Dimension = ShaderResourceViewDimension.Texture2DMultisampled;
            }
            m_SRV_depth = new ShaderResourceView(MyRender11.Device, m_resource, srvDesc);

            srvDesc.Format = Depth32F ? Format.X32_Typeless_G8X24_UInt : Format.X24_Typeless_G8_UInt;
            if (sampleCount == 1)
            {
                srvDesc.Dimension                 = ShaderResourceViewDimension.Texture2D;
                srvDesc.Texture2D.MipLevels       = -1;
                srvDesc.Texture2D.MostDetailedMip = 0;
            }
            else
            {
                srvDesc.Dimension = ShaderResourceViewDimension.Texture2DMultisampled;
            }
            m_SRV_stencil = new ShaderResourceView(MyRender11.Device, m_resource, srvDesc);
        }
Ejemplo n.º 52
0
 public LocalArrayValueProvider2D(Vector2I size, T defaultValue)
 {
     this.defaultValue = defaultValue;
     this.size         = size;
 }
Ejemplo n.º 53
0
        //////////////////////////////////////////////////////////////////////////
        // Vector2I
        //////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Convert value to a safely formated string.
        /// </summary>
        /// <param name="v">Value to convert.</param>
        /// <returns>A string without culture variation.</returns>
        public static string ToString(Vector2I v)
        {
            return
                (v.X.ToString(CultureInfo.InvariantCulture) + listSeparatorAndSpace +
                 v.Y.ToString(CultureInfo.InvariantCulture));
        }
Ejemplo n.º 54
0
 public Trap(int tileType, Vector2I position) : base(tileType, position)
 {
 }
Ejemplo n.º 55
0
 private static extern bool Internal_pixelToCurveSpace(IntPtr thisPtr, ref Vector2I pixelCoords, out Vector2 curveCoords, bool padding);
        private void InitShaders()
        {
            if (m_markVS == VertexShaderId.NULL)
            {
                m_markVS = MyShaders.CreateVs("shape.hlsl");
            }

            if (m_markPS == PixelShaderId.NULL)
            {
                m_markPS = MyShaders.CreatePs("shape.hlsl");
            }

            if (m_inputLayout == InputLayoutId.NULL)
            {
                m_inputLayout = MyShaders.CreateIL(m_markVS.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3));
            }

            if (m_combinePS == PixelShaderId.NULL)
            {
                m_combinePS = MyShaders.CreatePs("CombineShadows.hlsl");
            }

            m_threadGroupCountX = 32;
            m_threadGroupCountY = 32;
            Vector2I pixelCount            = MyRender11.ViewportResolution;
            Vector2I threadsPerThreadGroup = GetThreadsPerThreadGroup(pixelCount);

            int tryIndex = 0;

            while (threadsPerThreadGroup.X * threadsPerThreadGroup.Y > 1024)   // Make sure we do are not over the limit of threads per thread group
            {
                if (tryIndex++ % 2 == 0)
                {
                    ++m_threadGroupCountX;
                }
                else
                {
                    ++m_threadGroupCountY;
                }

                threadsPerThreadGroup = GetThreadsPerThreadGroup(pixelCount);
            }

            int pixelsCoveredX = threadsPerThreadGroup.X * m_pixelsPerThreadX * m_threadGroupCountX;

            if (pixelsCoveredX < pixelCount.X)
            {
                ++m_threadGroupCountX;
            }
            int pixelsCoveredY = threadsPerThreadGroup.Y * m_pixelsPerThreadY * m_threadGroupCountY;

            if (pixelsCoveredY < pixelCount.Y)
            {
                ++m_threadGroupCountY;
            }

            m_gatherCS = MyShaders.CreateCs("shadows.hlsl", new [] {
                new ShaderMacro("NUMTHREADS_X", threadsPerThreadGroup.X),
                new ShaderMacro("NUMTHREADS_Y", threadsPerThreadGroup.Y),
                new ShaderMacro("THREAD_GROUPS_X", m_threadGroupCountX),
                new ShaderMacro("THREAD_GROUPS_Y", m_threadGroupCountY),
                new ShaderMacro("PIXELS_PER_THREAD_X", m_pixelsPerThreadX),
                new ShaderMacro("PIXELS_PER_THREAD_Y", m_pixelsPerThreadY)
            });
        }
Ejemplo n.º 57
0
 /// <summary>Attempts to find a a tangent handle under the provided coordinates.</summary>
 /// <param name="pixelCoords">Coordinates relative to this GUI element in pixels.</param>
 /// <param name="tangent">
 /// Output object containing keyframe information and tangent type. Only valid if method returns true.
 /// </param>
 /// <returns>True if there is a tangent handle under the coordinates, false otherwise.</returns>
 public bool FindTangent(Vector2I pixelCoords, out TangentRef tangent)
 {
     return(Internal_findTangent(mCachedPtr, ref pixelCoords, out tangent));
 }
Ejemplo n.º 58
0
 /// <summary>Attempts to find a keyframe under the provided coordinates.</summary>
 /// <param name="pixelCoords">Coordinates relative to this GUI element in pixels.</param>
 /// <param name="keyframe">
 /// Output object containing keyframe index and index of the curve it belongs to. Only  valid if method returns true.
 /// </param>
 /// <returns>True if there is a keyframe under the coordinates, false otherwise.</returns>
 public bool FindKeyFrame(Vector2I pixelCoords, out KeyframeRef keyframe)
 {
     return(Internal_findKeyFrame(mCachedPtr, ref pixelCoords, out keyframe));
 }
Ejemplo n.º 59
0
        private void OnEditorUpdate()
        {
            if (currentType == InspectorType.SceneObject)
            {
                Component[] allComponents   = activeSO.GetComponents();
                bool        requiresRebuild = allComponents.Length != inspectorComponents.Count;

                if (!requiresRebuild)
                {
                    for (int i = 0; i < inspectorComponents.Count; i++)
                    {
                        if (inspectorComponents[i].instanceId != allComponents[i].InstanceId)
                        {
                            requiresRebuild = true;
                            break;
                        }
                    }
                }

                if (requiresRebuild)
                {
                    SceneObject so = activeSO;
                    Clear();
                    SetObjectToInspect(so);
                }
                else
                {
                    RefreshSceneObjectFields(false);

                    InspectableState componentModifyState = InspectableState.NotModified;
                    for (int i = 0; i < inspectorComponents.Count; i++)
                    {
                        componentModifyState |= inspectorComponents[i].inspector.Refresh();
                    }

                    if (componentModifyState.HasFlag(InspectableState.ModifyInProgress))
                    {
                        EditorApplication.SetSceneDirty();
                    }

                    modifyState |= componentModifyState;
                }
            }
            else if (currentType == InspectorType.Resource)
            {
                inspectorResource.inspector.Refresh();
            }

            // Detect drag and drop
            bool isValidDrag = false;

            if (activeSO != null)
            {
                if ((DragDrop.DragInProgress || DragDrop.DropInProgress) && DragDrop.Type == DragDropType.Resource)
                {
                    Vector2I windowPos     = ScreenToWindowPos(Input.PointerPosition);
                    Vector2I scrollPos     = windowPos;
                    Rect2I   contentBounds = inspectorLayout.Bounds;
                    scrollPos.x -= contentBounds.x;
                    scrollPos.y -= contentBounds.y;

                    bool   isInBounds = false;
                    Rect2I dropArea   = new Rect2I();
                    foreach (var bounds in dropAreas)
                    {
                        if (bounds.Contains(scrollPos))
                        {
                            isInBounds = true;
                            dropArea   = bounds;
                            break;
                        }
                    }

                    Type draggedComponentType = null;
                    if (isInBounds)
                    {
                        ResourceDragDropData dragData = DragDrop.Data as ResourceDragDropData;
                        if (dragData != null)
                        {
                            foreach (var resPath in dragData.Paths)
                            {
                                ResourceMeta meta = ProjectLibrary.GetMeta(resPath);
                                if (meta != null)
                                {
                                    if (meta.ResType == ResourceType.ScriptCode)
                                    {
                                        ScriptCode scriptFile = ProjectLibrary.Load <ScriptCode>(resPath);

                                        if (scriptFile != null)
                                        {
                                            Type[] scriptTypes = scriptFile.Types;
                                            foreach (var type in scriptTypes)
                                            {
                                                if (type.IsSubclassOf(typeof(Component)))
                                                {
                                                    draggedComponentType = type;
                                                    isValidDrag          = true;
                                                    break;
                                                }
                                            }

                                            if (draggedComponentType != null)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (isValidDrag)
                    {
                        scrollAreaHighlight.Bounds = dropArea;

                        if (DragDrop.DropInProgress)
                        {
                            activeSO.AddComponent(draggedComponentType);

                            modifyState = InspectableState.Modified;
                            EditorApplication.SetSceneDirty();
                        }
                    }
                }
            }

            if (scrollAreaHighlight != null)
            {
                scrollAreaHighlight.Active = isValidDrag;
            }
        }
Ejemplo n.º 60
0
 public Trap(ITilesetTable tilesetTable, Vector2I position) : base(tilesetTable, position)
 {
 }