コード例 #1
0
        protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
        {
            PaintStandardBackground(pevent);
            SmoothingMode smoothingMode = pevent.Graphics.SmoothingMode;

            pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            using (Brush brush = new SolidBrush(BackgroundColor))
            {
                if (ShapeType == ShapeType.Star || ShapeType == ShapeType.Octagon)
                {
                    PointF[] pts = GetPolygonPoints(7, DisplayRectangle);

                    pevent.Graphics.FillPolygon(brush, pts);
                }
                else if (ShapeType == ShapeType.Circle)
                {
                    pevent.Graphics.FillEllipse(brush, DisplayRectangle);
                }
                else if (ShapeType == ShapeType.RoundedRectangle)
                {
                    FillRoundedRectangle(pevent.Graphics, DisplayRectangle, 30, brush);
                }
            }

            pevent.Graphics.SmoothingMode = smoothingMode;

            if (Focused || Pressed)
            {
                GraphicsUtilities.DrawOutline(this, pevent.Graphics);
            }
        }
コード例 #2
0
        //TODO: Fix the dependency on the specific ordering of vertex vectors then face vectors.
        // Constructs Vector3 for at each Vertex and at the center of each Face. Returns an array which contains
        // the Vertex vectors followed by the Face vectors.
        private static Vector3[] CreateVertexArray(IPolyhedron surface)
        {
            var vertexVectors = surface.Vertices.Select(vertex => GraphicsUtilities.Vector3(vertex.Position));
            var faceVectors   = surface.Faces.Select(face => GraphicsUtilities.Vector3(face.SphericalCenter()));

            return(vertexVectors.Concat(faceVectors).ToArray());
        }
コード例 #3
0
        public void Capture(ScriptableRenderContext context, Action <int, NativeArray <T>, RenderTexture> imageReadCallback)
        {
            if (!GraphicsUtilities.SupportsAsyncReadback())
            {
                RenderTexture.active = m_Source;

                if (m_CpuTexture == null)
                {
                    m_CpuTexture = new Texture2D(m_Source.width, m_Source.height, m_Source.graphicsFormat, TextureCreationFlags.None);
                }

                m_CpuTexture.ReadPixels(new Rect(
                                            Vector2.zero,
                                            new Vector2(m_Source.width, m_Source.height)),
                                        0, 0);
                RenderTexture.active = null;
                var data = m_CpuTexture.GetRawTextureData <T>();
                imageReadCallback(Time.frameCount, data, m_Source);
            }
            else
            {
                var commandBuffer = CommandBufferPool.Get("RenderTextureReader");
                var frameCount    = Time.frameCount;
                commandBuffer.RequestAsyncReadback(m_Source, r => OnGpuReadback(r, frameCount, imageReadCallback));
                context.ExecuteCommandBuffer(commandBuffer);
                context.Submit();
                CommandBufferPool.Release(commandBuffer);
            }
        }
コード例 #4
0
 public IEnumerator CaptureTestsRedux_Async_Motion_Orientation()
 {
     if (!GraphicsUtilities.SupportsAsyncReadback())
     {
         Assert.Ignore();
     }
     return(CaptureTestsRedux_Parametric(true, false, false, Channel.Motion));
 }
コード例 #5
0
 //TODO: Seeing as this information isn't needed update-to-update, should it really be stored?
 // Updates the _vertexVelocities array using the new velocity field.
 private void UpdateVertexVelocities(VectorField <Vertex> velocityField)
 {
     for (int i = 0; i < _vertexVelocities.Length; i++)
     {
         // Convert from a MathNet.Iridium vector to a Unity vector.
         _vertexVelocities[i] = GraphicsUtilities.Vector3(velocityField[i]);
     }
 }
コード例 #6
0
 public IEnumerator CaptureTestsRedux_AsyncBatched_Depth_Orientation_short16()
 {
     if (!GraphicsUtilities.SupportsAsyncReadback())
     {
         Assert.Ignore();
     }
     return(CaptureTestsRedux_Parametric(true, true, false, Channel.Depth, 16));
 }
コード例 #7
0
 public IEnumerator CaptureTestsRedux_AsyncBatchedRT_Color_Orientation()
 {
     if (!GraphicsUtilities.SupportsAsyncReadback())
     {
         Assert.Ignore();
     }
     return(CaptureTestsRedux_Parametric(true, true, true, Channel.Color));
 }
コード例 #8
0
        public DisplayFact(Individual ind, string surname, string forenames, Fact fact)
        {
            Ind        = ind;
            Surname    = surname;
            Forenames  = forenames;
            Fact       = fact;
            IgnoreFact = false;
#if __PC__
            Icon = GraphicsUtilities.ResizeImageToCurrentScale(FactImage.ErrorIcon(fact.FactErrorLevel).Icon);
#endif
        }
コード例 #9
0
        private void RenderDepthScatter(Texture source, RenderTexture target)
        {
            Water water = (!this._HasWaterOverride) ? this._LocalWaterCamera.ContainingWater : this._WaterOverride;

            this._ImeMaterial.CopyPropertiesFromMaterial(water.Materials.SurfaceMaterial);
            this._ImeMaterial.SetTexture("_UnderwaterAbsorptionGradient", water.Materials.UnderwaterAbsorptionColorByDepth);
            this._ImeMaterial.SetFloat("_UnderwaterLightFadeScale", water.Materials.UnderwaterLightFadeScale);
            this._ImeMaterial.SetMatrix("UNITY_MATRIX_VP_INVERSE", Matrix4x4.Inverse(this._LocalCamera.projectionMatrix * this._LocalCamera.worldToCameraMatrix));
            MaterialPropertyBlock propertyBlock = water.Renderer.PropertyBlock;

            GraphicsUtilities.Blit(source, target, this._ImeMaterial, 1, propertyBlock);
        }
コード例 #10
0
        /// <summary>
        /// Creates a new <see cref="RenderTextureReader{T}"/> for the given <see cref="RenderTexture"/>, <see cref="Camera"/>, and image readback callback
        /// </summary>
        /// <param name="source">The <see cref="RenderTexture"/> to read from.</param>
        /// <param name="cameraRenderingToSource">The <see cref="Camera"/> which renders to the given renderTexture. This is used to determine when to read from the texture.</param>
        /// <param name="imageReadCallback">The callback to call after reading the texture</param>
        public RenderTextureReader(RenderTexture source, Camera cameraRenderingToSource, Action <int, NativeArray <T>, RenderTexture> imageReadCallback)
        {
            this.m_Source                  = source;
            this.m_ImageReadCallback       = imageReadCallback;
            this.m_CameraRenderingToSource = cameraRenderingToSource;
            m_NextFrameToCapture           = Time.frameCount;

            if (!GraphicsUtilities.SupportsAsyncReadback())
            {
                m_CpuTexture = new Texture2D(m_Source.width, m_Source.height, m_Source.graphicsFormat, TextureCreationFlags.None);
            }

            RenderPipelineManager.endFrameRendering += OnEndFrameRendering;
        }
コード例 #11
0
        void OnEndFrameRendering(ScriptableRenderContext context, Camera[] cameras)
        {
#if UNITY_EDITOR
            if (UnityEditor.EditorApplication.isPaused)
            {
                return;
            }
#endif
            if (!cameras.Contains(m_CameraRenderingToSource))
            {
                return;
            }

            if (m_NextFrameToCapture > Time.frameCount)
            {
                return;
            }

            m_NextFrameToCapture = Time.frameCount + 1;

            if (!GraphicsUtilities.SupportsAsyncReadback())
            {
                RenderTexture.active = m_Source;

                if (m_CpuTexture == null)
                {
                    m_CpuTexture = new Texture2D(m_Source.width, m_Source.height, m_Source.graphicsFormat, TextureCreationFlags.None);
                }

                m_CpuTexture.ReadPixels(new Rect(
                                            Vector2.zero,
                                            new Vector2(m_Source.width, m_Source.height)),
                                        0, 0);
                RenderTexture.active = null;
                var data = m_CpuTexture.GetRawTextureData <T>();
                m_ImageReadCallback(Time.frameCount, data, m_Source);
                return;
            }
            else
            {
                var commandBuffer = CommandBufferPool.Get("RenderTextureReader");
                var frameCount    = Time.frameCount;
                commandBuffer.RequestAsyncReadback(m_Source, r => OnGpuReadback(r, frameCount));
                context.ExecuteCommandBuffer(commandBuffer);
                context.Submit();
                CommandBufferPool.Release(commandBuffer);
            }
        }
コード例 #12
0
        private void SpawnWindWavesParticlesTiled(Transform origin)
        {
            Vector3 position = origin.position;
            float   num      = 400f / (float)this._BlankOutput.width;

            this._SprayTiledGeneratorMaterial.CopyPropertiesFromMaterial(this._Water.Materials.SurfaceMaterial);
            this._SprayTiledGeneratorMaterial.SetVector("_SurfaceOffset", new Vector3(this._Water.SurfaceOffset.x, this._Water.transform.position.y, this._Water.SurfaceOffset.y));
            this._SprayTiledGeneratorMaterial.SetVector("_Params", new Vector4(this._SpawnThreshold * 0.25835f, this._SkipRatioPrecomp, 0f, this._Scale * 0.455f));
            this._SprayTiledGeneratorMaterial.SetVector("_Coordinates", new Vector4(position.x - 200f + UnityEngine.Random.value * num, position.z - 200f + UnityEngine.Random.value * num, 400f, 400f));
            if (this._Overlays == null)
            {
                this._SprayTiledGeneratorMaterial.SetTexture("_LocalNormalMap", this.GetBlankWhiteTex());
            }
            Graphics.SetRandomWriteTarget(1, this._ParticlesA);
            GraphicsUtilities.Blit(null, this._BlankOutput, this._SprayTiledGeneratorMaterial, 0, this._Water.Renderer.PropertyBlock);
            Graphics.ClearRandomWriteTargets();
        }
コード例 #13
0
        private static GameObject DrawLongitude(float radius, float azimuth)
        {
            var azimuths = AnglesInRange(0, Mathf.PI, NumberOfPointsPerLongitude);

            var vertices =
                azimuths.Select(
                    colatitude => radius * GraphicsUtilities.Vector3(colatitude, azimuth, 1))
                .ToArray();

            var longitudeObject =
                CreateLineObject(
                    "Longitude " + Mathf.Rad2Deg * azimuth,
                    vertices,
                    "Materials/LatLongGrid/Boundaries");

            return(longitudeObject);
        }
コード例 #14
0
    public IEnumerator CaptureTest_CaptureColorUsingNonAsyncMethod()
    {
        const int kDimension = 64;
        const int kLength    = kDimension * kDimension;

        var color = kTestColor;

        var data = new Color32[kLength];

        for (var i = 0; i < data.Length; ++i)
        {
            data[i] = color;
        }

        var texture = new Texture2D(kDimension, kDimension, GraphicsFormat.R8G8B8A8_UNorm, TextureCreationFlags.None);

        texture.SetPixels32(data);
        texture.Apply();

        var rt = new RenderTexture(kDimension, kDimension, 0, GraphicsFormat.R8G8B8A8_UNorm);

        rt.useMipMap        = false;
        rt.autoGenerateMips = false;

        Graphics.Blit(texture, rt);

        var request = Manager.Instance.CreateRequest <AsyncRequest <object> >();

        Func <AsyncRequest <object>, AsyncRequest <object> .Result> functor = (AsyncRequest <object> r) =>
        {
            var colorBuffer = GraphicsUtilities.GetPixelsSlow(rt as RenderTexture);
            Debug.Assert(EnsureColorsCloseTo(kTestColor, colorBuffer, 0) == 0, "colorBuffer differs from expected output");
            return(AsyncRequest <object> .Result.Completed);
        };

        request.Enqueue(functor);
        request.Execute(AsyncRequest.ExecutionContext.EndOfFrame);

        while (!request.completed)
        {
            yield return(null);
        }

        Debug.Assert(request.error == false, "Request had an error");
    }
コード例 #15
0
    public IEnumerator CaptureTest_CaptureColorAndDepthParametric(int depthBpp, GraphicsFormat renderTextureFormat, Action <AsyncRequest <CaptureCamera.CaptureState> > validator)
    {
        Debug.Assert(GraphicsUtilities.SupportsRenderTextureFormat(renderTextureFormat), "GraphicsFormat not supported");

        var camera = SetupCameraTestWithMaterial(depthBpp, renderTextureFormat, new Vector3(0, 0, 1.0f));

        var request = CaptureCamera.Capture(camera, colorFunctor: AsyncRequest <CaptureCamera.CaptureState> .DontCare, depthFunctor: AsyncRequest <CaptureCamera.CaptureState> .DontCare, depthFormat: GraphicsUtilities.DepthFormatForDepth(depthBpp));

        camera.Render();

        while (!request.completed)
        {
            yield return(null);
        }

        Debug.Assert(request.error == false, "Capture request had an error");

        validator.Invoke(request);
    }
コード例 #16
0
        /// <summary>
        /// Updates the camera's radial and orbital position in response to user input.
        /// </summary>
        public void Update()
        {
            // If the rotate key is depressed, update the _azimuth and _colatitude fields.
            if (Input.GetKey(_options.RotateKey))
            {
                UpdateAzimuthAndColatitude();
            }
            // If the zoom key is depressed, update the _radius field.
            if (Input.GetKey(_options.ZoomKey))
            {
                UpdateRadius();
            }

            // Update the camera's transform to match the _azimuth, _colatitude & _radius fields
            var position   = GraphicsUtilities.Vector3(_colatitude, _azimuth, _radius);
            var localEast  = Vector3.Cross(position, new Vector3(0, 0, 1));
            var localNorth = Vector3.Cross(localEast, position);

            _cameraTransform.rotation = Quaternion.LookRotation(-position, localNorth);
            _cameraTransform.position = position;
        }
コード例 #17
0
        private void RenderDistortions(Texture source, RenderTexture target)
        {
            Water water = (!this._HasWaterOverride) ? this._LocalWaterCamera.ContainingWater : this._WaterOverride;
            float underwaterDistortionsIntensity = water.Materials.UnderwaterDistortionsIntensity;

            if (underwaterDistortionsIntensity > 0f)
            {
                int width  = Camera.current.pixelWidth >> 2;
                int height = Camera.current.pixelHeight >> 2;
                TemporaryRenderTexture temporary = RenderTexturesCache.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, true, false, false);
                this.RenderDistortionMap(temporary);
                temporary.Texture.filterMode = FilterMode.Bilinear;
                this._ImeMaterial.SetTexture("_DistortionTex", temporary);
                this._ImeMaterial.SetFloat("_DistortionIntensity", underwaterDistortionsIntensity);
                GraphicsUtilities.Blit(source, target, this._ImeMaterial, 2, water.Renderer.PropertyBlock);
                temporary.Dispose();
            }
            else
            {
                Graphics.Blit(source, target);
            }
        }
コード例 #18
0
        // Draw a label at the specified position
        private static GameObject DrawLabel(float scaleFactor, float colatitude, float azimuth)
        {
            var text = String.Format("{0,3:N0}  {1,3:N0}", Mathf.Rad2Deg * colatitude, Mathf.Rad2Deg * azimuth);

            var labelObject = new GameObject("Label " + text);

            var normal     = GraphicsUtilities.Vector3(colatitude, azimuth, 1);
            var localEast  = Vector3.Cross(normal, new Vector3(0, 0, 1));
            var localNorth = Vector3.Cross(localEast, normal);

            labelObject.transform.position = scaleFactor * normal;
            labelObject.transform.rotation = Quaternion.LookRotation(-normal, localNorth);

            var textMesh = labelObject.AddComponent <TextMesh>();

            textMesh.text = text;
            textMesh.font = Resources.Load("Materials/LatLongGrid/ARIAL", typeof(Font)) as Font;
            textMesh.renderer.material = Resources.Load("Materials/LatLongGrid/OneSidedMaterial", typeof(Material)) as Material;
            textMesh.characterSize     = scaleFactor * 0.005f;
            textMesh.anchor            = TextAnchor.UpperCenter;

            return(labelObject);
        }
コード例 #19
0
 // Returns the positions of each vertex in the given geometry.
 private static Vector3[] GetVertexPositions(IPolyhedron surface)
 {
     return(surface.Vertices.Select(vertex => GraphicsUtilities.Vector3(vertex.Position)).ToArray());
 }
コード例 #20
0
        // Select the Vertex of a Face that's closest to the given vector.
        private Vertex FindClosestVertex(Face face, Vector3 target)
        {
            var sortedVertices = face.Vertices.OrderBy(vertex => (GraphicsUtilities.Vector3(vertex.Position) - target).magnitude);

            return(sortedVertices.First());
        }