示例#1
0
 /// <summary>
 /// Called once per frame, the call is the entry point for animating the scene.
 /// </summary>
 protected override void FrameMove()
 {
     // When the window has focus, let the mouse adjust the scene
     if (System.Windows.Forms.Form.ActiveForm == this)
     {
         Quaternion quat = GraphicsUtility.GetRotationFromCursor(this);
         device.Transform.World = Matrix.RotationQuaternion(quat);
         RenderSceneIntoCubeMap();
     }
 }
示例#2
0
        private void CreateMaterial()
        {
            if (source.PrimaryModel != null)
            {
                //Create a material
                unSelectedMaterial = GraphicsUtility.InitMaterial(Color.FromArgb(60, source.PrimaryModel.ModelColor));

                selectedMaterial = GraphicsUtility.InitMaterial(source.PrimaryModel.ModelColor);
            }
        }
示例#3
0
        private static ulong GetAlignmentForBufferUsage(PlatformRenderContext ctx, SharpVulkan.BufferUsageFlags usage)
        {
            ulong alignment = 1;

            if ((usage & SharpVulkan.BufferUsageFlags.UniformBuffer) != 0)
            {
                alignment = GraphicsUtility.CombineAlignment(alignment, ctx.PhysicalDeviceLimits.MinUniformBufferOffsetAlignment);
            }
            return(alignment);
        }
示例#4
0
 public void Execute()
 {
     randNumber         = (float4)(rand->NextDouble4());
     nonJitterVP        = mul(GraphicsUtility.GetGPUProjectionMatrix(nonJitterP, false, isD3D), worldToView);
     nonJitterInverseVP = inverse(nonJitterVP);
     nonJitterTextureVP = mul(GraphicsUtility.GetGPUProjectionMatrix(nonJitterP, true, isD3D), worldToView);
     lastInverseVP      = inverse(lastVP);
     *VP        = mul(GraphicsUtility.GetGPUProjectionMatrix(p, false, isD3D), worldToView);
     *inverseVP = inverse(*VP);
 }
示例#5
0
        protected override void OnResize(EventArgs e)
        {
            var cornerRadius = Renderer.FloatCornerRadius;

            if (cornerRadius != 0)
            {
                Region = GraphicsUtility.GetRoundedRegion(ClientRectangle, cornerRadius);
            }
            base.OnResize(e);
        }
示例#6
0
        /// <summary>
        /// The device exists, but may have just been Reset().  Resources in
        /// Pool.Default and any other device state that persists during
        /// rendering should be set here.  Render states, matrices, textures,
        /// etc., that don't change during rendering can be set once here to
        /// avoid redundant state setting during Render() or FrameMove().
        /// </summary>
        protected override void RestoreDeviceObjects(System.Object sender, System.EventArgs e)
        {
            // Build the device objects for the file-based objecs
            helicopterMesh.RestoreDeviceObjects(device, null);
            terrainMesh.RestoreDeviceObjects(device, null);

            // Set up textures
            device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
            device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
            device.TextureState[0].ColorOperation = TextureOperation.Modulate;
            device.SamplerState[0].MinFilter      = TextureFilter.Linear;
            device.SamplerState[0].MagFilter      = TextureFilter.Linear;

            // Set up misc render states
            device.RenderState.ZBufferEnable  = true;
            device.RenderState.DitherEnable   = true;
            device.RenderState.SpecularEnable = false;
            device.RenderState.Ambient        = System.Drawing.Color.FromArgb(0x00555555);

            // Set the transform matrices
            Vector3 vEyePt = new Vector3(0.0f, 5.5f, -15.0f);
            Vector3 vLookatPt = new Vector3(0.0f, 1.5f, 0.0f);
            Vector3 vUpVec = new Vector3(0.0f, 1.0f, 0.0f);
            Matrix  matWorld, matView, matProj;

            matWorld = Matrix.Identity;
            matView  = Matrix.LookAtLH(vEyePt, vLookatPt, vUpVec);
            float fAspect = device.PresentationParameters.BackBufferWidth / (float)device.PresentationParameters.BackBufferHeight;

            matProj = Matrix.PerspectiveFovLH((float)Math.PI / 4, fAspect, 1.0f, 1000.0f);

            device.Transform.World      = matWorld;
            device.Transform.View       = matView;
            device.Transform.Projection = matProj;

            // Set up a material
            mirrorMaterial = GraphicsUtility.InitMaterial(System.Drawing.Color.LightBlue);

            // Set up the light
            GraphicsUtility.InitLight(device.Lights[0], LightType.Directional, 0.0f, -1.0f, 1.0f);
            device.Lights[0].Commit();
            device.Lights[0].Enabled = true;

            // Turn on fog
            float fFogStart = 80.0f;
            float fFogEnd   = 100.0f;

            device.RenderState.FogEnable      = true;
            device.RenderState.FogColor       = FogColor;
            device.RenderState.FogTableMode   = FogMode.None;
            device.RenderState.FogVertexMode  = FogMode.Linear;
            device.RenderState.RangeFogEnable = false;
            device.RenderState.FogStart       = fFogStart;
            device.RenderState.FogEnd         = fFogEnd;
        }
示例#7
0
        /// <summary>
        /// The device exists, but may have just been Reset().  Resources in
        /// Pool.Default and any other device state that persists during
        /// rendering should be set here.  Render states, matrices, textures,
        /// etc., that don't change during rendering can be set once here to
        /// avoid redundant state setting during Render() or FrameMove().
        /// </summary>
        protected override void RestoreDeviceObjects(System.Object sender, System.EventArgs e)
        {
            // Set the transform matrices
            Vector3 vEyePt    = new Vector3(0.0f, 0.0f, -5.0f);
            Vector3 vLookatPt = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 vUpVec    = new Vector3(0.0f, 1.0f, 0.0f);
            float   fAspect   = ((float)device.PresentationParameters.BackBufferWidth) / device.PresentationParameters.BackBufferHeight;

            worldMatrix      = Matrix.Identity;
            viewMatrix       = Matrix.LookAtLH(vEyePt, vLookatPt, vUpVec);
            projectionMatrix = Matrix.PerspectiveFovLH((float)Math.PI / 3, fAspect, 1.0f, 10000.0f);

            // Set default render states
            device.SamplerState[0].MinFilter = TextureFilter.Linear;
            device.SamplerState[0].MagFilter = TextureFilter.Linear;
            device.RenderState.ZBufferEnable = true;
            device.RenderState.FogEnable     = true;
            device.RenderState.FogColor      = WaterColor;

            // Create vertex shader for the dolphin
            VertexElement[] dolphinVertexDecl = new VertexElement[]
            {
                // First stream is first mesh
                new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                new VertexElement(0, 12, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
                new VertexElement(0, 24, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
                // Second stream is second mesh
                new VertexElement(1, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 1),
                new VertexElement(1, 12, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 1),
                new VertexElement(1, 24, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 1),
                // Third stream is third mesh
                new VertexElement(2, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 2),
                new VertexElement(2, 12, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 2),
                new VertexElement(2, 24, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 2),
                VertexElement.VertexDeclarationEnd
            };

            dolphinVertexDeclaration = new VertexDeclaration(device, dolphinVertexDecl);
            dolphinVertexShader      = GraphicsUtility.CreateVertexShader(device, "DolphinTween.vsh");
            dolphinVertexShader2     = GraphicsUtility.CreateVertexShader(device, "DolphinTween2.vsh");


            // Create vertex shader for the seafloor
            VertexElement[] seaFloorVertexDecl = new VertexElement[]
            {
                new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                new VertexElement(0, 12, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
                new VertexElement(0, 24, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
                VertexElement.VertexDeclarationEnd
            };

            seaFloorVertexDeclaration = new VertexDeclaration(device, seaFloorVertexDecl);
            seaFloorVertexShader      = GraphicsUtility.CreateVertexShader(device, "SeaFloor.vsh");
            seaFloorVertexShader2     = GraphicsUtility.CreateVertexShader(device, "SeaFloor2.vsh");
        }
示例#8
0
        /// <summary>
        /// The device exists, but may have just been Reset().  Resources in
        /// Pool.Default and any other device state that persists during
        /// rendering should be set here.  Render states, matrices, textures,
        /// etc., that don't change during rendering can be set once here to
        /// avoid redundant state setting during Render() or FrameMove().
        /// </summary>
        protected override void RestoreDeviceObjects(System.Object sender, System.EventArgs e)
        {
            // Restore mesh's local memory objects
            blendObject.RestoreDeviceObjects(device, null);

            // Get access to the mesh vertex and index buffers
            vertexBuffer = blendObject.LocalMesh.VertexBuffer;
            indexBuffer  = blendObject.LocalMesh.IndexBuffer;
            numVertices  = blendObject.LocalMesh.NumberVertices;
            numFaces     = blendObject.LocalMesh.NumberFaces;

            if (BehaviorFlags.SoftwareVertexProcessing ||
                Caps.VertexShaderVersion.Major >= 1)
            {
                // Setup the vertex declaration
                VertexElement[] decl = VertexInformation.DeclaratorFromFormat(BlendVertex.Format);
                declaration = new VertexDeclaration(device, decl);

                // Create vertex shader from a file
                try
                {
                    shader = GraphicsUtility.CreateVertexShader(device, "blend.vsh");
                }
                catch
                {
                    SampleException d3de = new MediaNotFoundException();
                    HandleSampleException(d3de, ApplicationMessage.ApplicationMustExit);
                    throw d3de;
                }
            }
            // Set miscellaneous render states
            renderState.ZBufferEnable = true;
            renderState.Ambient       = System.Drawing.Color.FromArgb(0x00404040);

            // Set the projection matrix
            float fAspect = device.PresentationParameters.BackBufferWidth / (float)device.PresentationParameters.BackBufferHeight;

            device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, fAspect, 1.0f, 10000.0f);

            // Set the app view matrix for normal viewing
            Vector3 vEyePt    = new Vector3(0.0f, -5.0f, -10.0f);
            Vector3 vLookatPt = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 vUpVec    = new Vector3(0.0f, 1.0f, 0.0f);

            device.Transform.View = Matrix.LookAtLH(vEyePt, vLookatPt, vUpVec);

            // Create a directional light. (Use yellow light to distinguish from
            // vertex shader case.)
            GraphicsUtility.InitLight(device.Lights[0], LightType.Directional, -0.5f, -1.0f, 1.0f);
            device.Lights[0].Diffuse = System.Drawing.Color.Yellow;
            device.Lights[0].Commit();
            device.Lights[0].Enabled = true;
            renderState.Lighting     = true;
        }
示例#9
0
        /// <summary>
        /// Create forward region path
        /// </summary>
        /// <param name="previewSize">preview size</param>
        /// <returns>back region path</returns>
        private static GraphicsPath CreateNextRegionPath(Size previewSize)
        {
            GraphicsPath regionPath = GraphicsUtility.CreateRoundRectPath(0, 0, previewSize.Width, previewSize.Height, 5);

            Matrix transformMatrix = new Matrix();

            transformMatrix.Shear(0.0F, 0.50F);
            regionPath.Transform(transformMatrix);

            return(regionPath);
        }
示例#10
0
        public BillBoard(string sName, string sTextureName, float fWidth, float fHeight) : base(sName)
        {
            m_sName    = sName;
            m_sTexture = sTextureName;

            m_fRadius = fWidth / 2.0f;

            // create the vertices for the box
            m_Corners = new CustomVertex.PositionNormalTextured[4];

            m_Corners[0].X  = m_fRadius;        // upper left
            m_Corners[0].Y  = fHeight;          // upper left
            m_Corners[0].Z  = 0.0f;             // upper left
            m_Corners[0].Tu = 1.0f;
            m_Corners[0].Tv = 0.0f;
            m_Corners[0].Nx = 0.0f;
            m_Corners[0].Ny = 0.0f;
            m_Corners[0].Nz = -1.0f;
            m_Corners[1].X  = -m_fRadius;       // upper right
            m_Corners[1].Y  = fHeight;          // upper right
            m_Corners[1].Z  = 0.0f;             // upper right
            m_Corners[1].Tu = 0.0f;
            m_Corners[1].Tv = 0.0f;
            m_Corners[1].Nx = 0.0f;
            m_Corners[1].Ny = 0.0f;
            m_Corners[1].Nz = -1.0f;
            m_Corners[2].X  = m_fRadius;        // lower left
            m_Corners[2].Y  = 0.0f;             // lower left
            m_Corners[2].Z  = 0.0f;             // lower left
            m_Corners[2].Tu = 1.0f;
            m_Corners[2].Tv = 1.0f;
            m_Corners[2].Nx = 0.0f;
            m_Corners[2].Ny = 0.0f;
            m_Corners[2].Nz = -1.0f;
            m_Corners[3].X  = -m_fRadius;       // lower right
            m_Corners[3].Y  = 0.0f;             // lower right
            m_Corners[3].Z  = 0.0f;             // lower right
            m_Corners[3].Tu = 0.0f;
            m_Corners[3].Tv = 1.0f;
            m_Corners[3].Nx = 0.0f;
            m_Corners[3].Ny = 0.0f;
            m_Corners[3].Nz = -1.0f;

            // load the texture for the face
            try
            {
                m_Texture = GraphicsUtility.CreateTexture(CGameEngine.Device3D, sTextureName);
                m_bValid  = true;
            }
            catch
            {
                Console.AddLine("Unable to create billboard texture for " + sName);
            }
        }
示例#11
0
        /// <summary>
        /// Event handler for windows events
        /// </summary>
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Quaternion qCursor   = GraphicsUtility.GetRotationFromCursor(this);
                Matrix     matCursor = Matrix.RotationQuaternion(qCursor);
                matTrackBall = Matrix.Multiply(matTrackBall, matCursor);

                this.Capture = false;
            }
            base.OnMouseUp(e);
        }
示例#12
0
        private void UpdateFontSize()
        {
            if (m_txtSize1 != null)
            {
                m_txtSize1.fontSize = GraphicsUtility.GetScreenScale(m_txtSize1.transform.position, Window.Camera) * 1.7f;
            }

            if (m_txtSize2 != null)
            {
                m_txtSize2.fontSize = GraphicsUtility.GetScreenScale(m_txtSize2.transform.position, Window.Camera) * 1.7f;
            }
        }
示例#13
0
        /// <summary>
        /// Create back region path
        /// </summary>
        /// <param name="previewSize">preview size</param>
        /// <returns>back region path</returns>
        private static GraphicsPath CreateBackRegionPath(Size previewSize)
        {
            int          dh         = ComputePreviewHeightOffset(previewSize);
            GraphicsPath regionPath = GraphicsUtility.CreateRoundRectPath(0, dh, previewSize.Width, previewSize.Height, 5);

            Matrix transformMatrix = new Matrix();

            transformMatrix.Shear(0.0F, -0.50F);
            regionPath.Transform(transformMatrix);

            return(regionPath);
        }
示例#14
0
        /// <summary>
        /// Occurs when visibility of this control changes
        /// </summary>
        /// <param name="e">event argument</param>
        protected override void OnSizeChanged(EventArgs e)
        {
            using (GraphicsPath path = GraphicsUtility.CreateRoundRectPath(0, 0, Width, Height, 5))
            {
                Region = new Region(ClientRectangle);
                Region = new Region(path);
            }

            base.OnSizeChanged(e);

            Invalidate();
        }
示例#15
0
        private static IEnumerable <SensorsTableRowViewModel> FlattenGroups(IEnumerable <SensorGroupViewModel> groups)
        {
            List <SensorsTableRowViewModel> output = new List <SensorsTableRowViewModel>();

            ExceptionUtility.Try(() =>
            {
                foreach (var group in groups)
                {
                    if (group.SensorValues != null && group.SensorValues.Count() > 0)
                    {
                        var groupHeader = (new SensorsTableRowViewModel()
                        {
                            IsGroupName = true,
                            LeftValue = group.Name + (String.IsNullOrEmpty(group.Name) ? String.Empty : ":"),
                            LeftColor = Colors.StandardTextColor,
                            RightColor = Colors.StandardTextColor
                        });

                        if (!String.IsNullOrEmpty(groupHeader.LeftValue))
                        {
                            var childValues = new List <SensorsTableRowViewModel>();

                            foreach (var value in group.SensorValues)
                            {
                                if (value.HasValue)                                 // && !String.IsNullOrEmpty(value.Name))
                                {
                                    childValues.Add(new SensorsTableRowViewModel()
                                    {
                                        IsGroupName = false,
                                        LeftValue   = value.Name,
                                        RightValue  = value.Value,
                                        RightColor  = GraphicsUtility.TextColorForSeverity(value.Severity),
                                        LeftColor   = Colors.StandardTextColor
                                    });
                                }
                            }

                            if (childValues.Count > 0)
                            {
                                output.Add(groupHeader);
                                foreach (var i in childValues)
                                {
                                    output.Add(i);
                                }
                            }
                        }
                    }
                }
            });

            return(output);
        }
示例#16
0
        //protected override Icon GetIcon()
        //{
        //    if(Data.Status == FileStatus.Removed)
        //    {
        //        return Utility.ExtractAssociatedFileIcon16ByExt(Data.FullPath);
        //    }
        //    else
        //    {
        //        return Utility.ExtractAssociatedFileIcon16(Data.FullPath);
        //    }
        //}

        protected override Bitmap GetBitmapIcon()
        {
            var path = DataContext.RelativePath;

            if (path.EndsWith('/'))
            {
                return(CachedResources.Bitmaps["ImgSubmodule"]);
            }
            else
            {
                return(GraphicsUtility.QueryIcon(DataContext.FullPath));
            }
        }
示例#17
0
文件: CubeMap.cs 项目: sjk7/DX90SDK
        /// <summary>
        /// Message proc function to handle mouse input
        /// </summary>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Quaternion qCursor   = GraphicsUtility.GetRotationFromCursor(this);
                Matrix     matCursor = Matrix.RotationQuaternion(qCursor);
                matCursor.Transpose(matCursor);
                trackBallMatrix = Matrix.Multiply(trackBallMatrix, matCursor);

                this.Capture = true;
            }
            base.OnMouseDown(e);
        }
示例#18
0
    /// <summary>
    /// Called when a device needs to be restored.
    /// </summary>
    protected override void RestoreDeviceObjects(System.Object sender, System.EventArgs e)
    {
        Material mtrl = GraphicsUtility.InitMaterial(Color.White);

        device.Material = mtrl;

        device.Lights[0].Type      = LightType.Directional;
        device.Lights[0].Direction = new Vector3(0.3f, -0.5f, 0.2f);
        device.Lights[0].Diffuse   = Color.White;

        device.RenderState.Lighting = true;
//		device.RenderState.FillMode = FillMode.WireFrame;
    }
示例#19
0
        public override void LayoutSubviews()
        {
            ExceptionUtility.Try(() =>
            {
                base.LayoutSubviews();

                if (!_setStyleFlag)
                {
                    _setStyleFlag = true;

                    if (this.AquamonixStyle == AquamonixButtonStyle.RoundedSolidColor)
                    {
                        if (this._disabledImage == null)
                        {
                            this._disabledImage = GraphicsUtility.CreateColoredRect(UIColor.Gray, this.Frame.Size);

                            if (this._disabledImage != null)
                            {
                                this.SetBackgroundImage(this._disabledImage, UIControlState.Disabled);
                            }
                        }

                        if (this._normalImage == null)
                        {
                            this._normalImage = GraphicsUtility.CreateColoredRect(this.BackgroundColor, this.Frame.Size);

                            if (this._normalImage != null)
                            {
                                this.SetBackgroundImage(this._normalImage, UIControlState.Normal);
                            }
                        }

                        this.MakeRoundedCorners(UIRectCorner.AllCorners, 20);
                        this.SetTitleColor(UIColor.White, UIControlState.Normal);
                        this.SetTitleColor(UIColor.White, UIControlState.Disabled);
                    }
                    else if (this.AquamonixStyle == AquamonixButtonStyle.Prev)
                    {
                        this.SetBackgroundImage(_prevButtonImage, UIControlState.Normal);
                        this.SizeToFit();
                        this.SetTitleColor(UIColor.White, UIControlState.Normal);
                    }
                    else if (this.AquamonixStyle == AquamonixButtonStyle.Next)
                    {
                        this.SetBackgroundImage(_nextButtonImage, UIControlState.Normal);
                        this.SizeToFit();
                        this.SetTitleColor(UIColor.White, UIControlState.Normal);
                    }
                }
            });
        }
示例#20
0
文件: Billboard.cs 项目: sjk7/DX90SDK
        /// <summary>
        /// The device has been created.  Resources that are not lost on
        /// Reset() can be created here -- resources in Pool.Managed,
        /// Pool.Scratch, or Pool.SystemMemory.  Image surfaces created via
        /// CreateImageSurface are never lost and can be created here.  Vertex
        /// shaders and pixel shaders can also be created here as they are not
        /// lost on Reset().
        /// </summary>
        protected override void InitializeDeviceObjects()
        {
            // Initialize the font's internal textures
            drawingFont.InitializeDeviceObjects(device);

            try
            {
                // Create the tree textures
                for (int i = 0; i < treeTextureFileNames.Length; i++)
                {
                    treeTextures[i] = GraphicsUtility.CreateTexture(device, treeTextureFileNames[i]);
                }
            }
            catch
            {
                SampleException e = new MediaNotFoundException();
                HandleSampleException(e, ApplicationMessage.ApplicationMustExit);
                throw e;
            }


            try
            {
                // Load the skybox
                skyBoxMesh.Create(device, "SkyBox2.x");

                // Load the terrain
                terrainMesh.Create(device, "SeaFloor.x");
            }
            catch
            {
                SampleException e = new MediaNotFoundException();
                HandleSampleException(e, ApplicationMessage.ApplicationMustExit);
                throw e;
            }

            // Add some "hilliness" to the terrain
            VertexBuffer tempVertexBuffer;

            tempVertexBuffer = terrainMesh.SystemMesh.VertexBuffer;
            CustomVertex.PositionTextured[] pVertices;
            int numberVertices = terrainMesh.SystemMesh.NumberVertices;

            pVertices = (CustomVertex.PositionTextured[])tempVertexBuffer.Lock(0, typeof(CustomVertex.PositionTextured), 0, numberVertices);
            for (int i = 0; i < numberVertices; i++)
            {
                pVertices[i].Y = HeightField(pVertices[i].X, pVertices[i].Z);
            }
            tempVertexBuffer.Unlock();
        }
示例#21
0
        public static void DrawDirectionalLight(CommandBuffer commandBuffer, Camera camera, Vector3 position, Quaternion rotation, Vector3 scale, MaterialPropertyBlock properties)
        {
            float sScale = GraphicsUtility.GetScreenScale(position, camera);

            float radius = 0.25f;
            float length = 1.25f;

            Matrix4x4 circleTransform   = Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one * radius);
            Matrix4x4 cylinderTransform = Matrix4x4.TRS(Vector3.zero, rotation, new Vector3(radius, radius, length));
            Matrix4x4 objToWorld        = Matrix4x4.TRS(position, Quaternion.identity, scale * sScale);

            GraphicsUtility.DrawMesh(commandBuffer, WireCircle, objToWorld * circleTransform, LinesMaterial, properties);
            GraphicsUtility.DrawMesh(commandBuffer, WireCylinder, objToWorld * cylinderTransform, LinesMaterial, properties);
        }
示例#22
0
        public void UpdateRender(CommandBuffer buffer)
        {
            buffer.SetRenderTarget(colorBuffers, albedoRT.depthBuffer);
            buffer.ClearRenderTarget(true, true, new Color(0, 0, 0, 0));
            foreach (var i in data.allSettings)
            {
                buffer.SetGlobalTexture("_BlendAlbedo", i.startAlbedo ? i.startAlbedo : whiteTex);
                buffer.SetGlobalTexture("_BlendNormal", i.startNormal ? i.startNormal : normalTex);
                buffer.SetGlobalTexture("_BlendSMO", i.startSMO ? i.startNormal : normalTex);
                buffer.SetGlobalTexture("_BlendMask", i.maskTex ? i.maskTex : whiteTex);
                buffer.SetGlobalVector("_BlendScaleOffset", i.scaleOffset);
                buffer.SetGlobalVector("_MaskScaleOffset", new Vector4(i.maskScale, i.maskOffset));
                buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, blendTexMat, 0, 0);
            }
            OrthoCam orthoCam = new OrthoCam
            {
                up            = Vector3.forward,
                right         = Vector3.right,
                forward       = Vector3.down,
                position      = transform.position,
                farClipPlane  = 50,
                nearClipPlane = -50,
                size          = transform.localScale.x * 0.5f
            };

            orthoCam.UpdateProjectionMatrix();
            orthoCam.UpdateTRSMatrix();
            float4x4 vp = mul(GraphicsUtility.GetGPUProjectionMatrix(orthoCam.projectionMatrix, true), orthoCam.worldToCameraMatrix);

            buffer.SetGlobalMatrix(ShaderIDs._VP, vp);
            for (int i = 0; i < transform.childCount; ++i)
            {
                VTDecal vtDecal = transform.GetChild(i).GetComponent <VTDecal>();
                if (!vtDecal)
                {
                    continue;
                }
                buffer.SetGlobalVector("_DecalScaleOffset", vtDecal.scaleOffset);
                buffer.SetGlobalTexture("_DecalAlbedo", vtDecal.albedoTex ? vtDecal.albedoTex : whiteTex);
                buffer.SetGlobalTexture("_DecalNormal", vtDecal.normalTex ? vtDecal.normalTex : normalTex);
                buffer.SetGlobalTexture("_DecalSMO", vtDecal.smoTex ? vtDecal.smoTex : whiteTex);
                buffer.SetGlobalTexture("_DecalMask", vtDecal.opaqueMask ? vtDecal.opaqueMask : whiteTex);
                buffer.SetGlobalVector("_DecalSMOWeight", new Vector4(vtDecal.smoothness, vtDecal.metallic, vtDecal.occlusion, vtDecal.opaque));
                buffer.DrawMesh(vtDecal.sharedMesh, vtDecal.transform.localToWorldMatrix, blendTexMat, 0, 1);
            }
            testMat.SetTexture("_MainTex", albedoRT);
            testMat.SetTexture("_BumpMap", normalRT);
            testMat.SetTexture("_SpecularMap", smoRT);
        }
    /// <summary>
    /// Enumerates available D3D adapters, devices, modes, etc.
    /// </summary>
    public void Enumerate()
    {
        foreach (AdapterInformation ai in Manager.Adapters)
        {
            ArrayList           adapterFormatList = new ArrayList();
            GraphicsAdapterInfo adapterInfo       = new GraphicsAdapterInfo();
            adapterInfo.AdapterOrdinal = ai.Adapter;
            adapterInfo.AdapterDetails = ai.Information;

            // Get list of all display modes on this adapter.
            // Also build a temporary list of all display adapter formats.
            foreach (DisplayMode displayMode in ai.SupportedDisplayModes)
            {
                if (displayMode.Width < AppMinFullscreenWidth)
                {
                    continue;
                }
                if (displayMode.Height < AppMinFullscreenHeight)
                {
                    continue;
                }
                if (GraphicsUtility.GetColorChannelBits(displayMode.Format) < AppMinColorChannelBits)
                {
                    continue;
                }
                adapterInfo.DisplayModeList.Add(displayMode);
                if (!adapterFormatList.Contains(displayMode.Format))
                {
                    adapterFormatList.Add(displayMode.Format);
                }
            }

            // Sort displaymode list
            DisplayModeComparer dmc = new DisplayModeComparer();
            adapterInfo.DisplayModeList.Sort(dmc);

            // Get info for each device on this adapter
            EnumerateDevices(adapterInfo, adapterFormatList);

            // If at least one device on this adapter is available and compatible
            // with the app, add the adapterInfo to the list
            if (adapterInfo.DeviceInfoList.Count == 0)
            {
                continue;
            }
            AdapterInfoList.Add(adapterInfo);
        }
    }
示例#24
0
        public static void DrawWireCapsule(CommandBuffer commandBuffer, int axis, float height, float radius, Vector3 position, Quaternion rotation, Vector3 scale, MaterialPropertyBlock properties)
        {
            Matrix4x4 topCircleTransform;
            Matrix4x4 bottomCircleTransform;
            Matrix4x4 capsule2DTransform;
            Matrix4x4 capsule2DTransform2;

            radius = Mathf.Abs(radius);

            if (Mathf.Abs(height) < 2 * radius)
            {
                height = 0;
            }
            else
            {
                height = Mathf.Abs(height) - 2 * radius;
            }

            if (axis == 1)
            {
                topCircleTransform    = Matrix4x4.TRS(Vector3.up * height / 2, Quaternion.AngleAxis(-90, Vector3.right), Vector3.one * radius);
                bottomCircleTransform = Matrix4x4.TRS(Vector3.down * height / 2, Quaternion.AngleAxis(-90, Vector3.right), Vector3.one * radius);
                capsule2DTransform    = Matrix4x4.identity;
                capsule2DTransform2   = Matrix4x4.TRS(Vector3.zero, Quaternion.AngleAxis(-90, Vector3.up), Vector3.one);
            }
            else if (axis == 0)
            {
                topCircleTransform    = Matrix4x4.TRS(Vector3.right * height / 2, Quaternion.AngleAxis(-90, Vector3.up), Vector3.one * radius);
                bottomCircleTransform = Matrix4x4.TRS(Vector3.left * height / 2, Quaternion.AngleAxis(-90, Vector3.up), Vector3.one * radius);
                capsule2DTransform    = Matrix4x4.TRS(Vector3.zero, Quaternion.AngleAxis(-90, Vector3.forward), Vector3.one);
                capsule2DTransform2   = Matrix4x4.TRS(Vector3.zero, Quaternion.AngleAxis(-90, Vector3.forward) * Quaternion.AngleAxis(-90, Vector3.up), Vector3.one);
            }
            else
            {
                topCircleTransform    = Matrix4x4.TRS(Vector3.forward * height / 2, Quaternion.identity, Vector3.one * radius);
                bottomCircleTransform = Matrix4x4.TRS(Vector3.back * height / 2, Quaternion.identity, Vector3.one * radius);
                capsule2DTransform    = Matrix4x4.TRS(Vector3.zero, Quaternion.AngleAxis(-90, Vector3.right), Vector3.one);
                capsule2DTransform2   = Matrix4x4.TRS(Vector3.zero, Quaternion.AngleAxis(-90, Vector3.right) * Quaternion.AngleAxis(-90, Vector3.up), Vector3.one);
            }

            Matrix4x4 objToWorld = Matrix4x4.TRS(position, rotation, scale);

            GraphicsUtility.DrawMesh(commandBuffer, WireCircle, objToWorld * topCircleTransform, LinesMaterial, properties);
            GraphicsUtility.DrawMesh(commandBuffer, WireCircle, objToWorld * bottomCircleTransform, LinesMaterial, properties);

            DrawCapsule2DGL(commandBuffer, objToWorld * capsule2DTransform, radius, height, properties);
            DrawCapsule2DGL(commandBuffer, objToWorld * capsule2DTransform2, radius, height, properties);
        }
示例#25
0
            public FileItem(DiffFile file)
            {
                Verify.Argument.IsNotNull(file, nameof(file));

                _file = file;

                if (file.Status == FileStatus.Removed)
                {
                    _text = file.SourceFile;
                }
                else
                {
                    _text = file.TargetFile;
                }
                _icon = GraphicsUtility.QueryIcon(_text);
                switch (file.Status)
                {
                case FileStatus.Removed:
                    _overlay = CachedResources.Bitmaps["ImgOverlayDel"];
                    break;

                case FileStatus.Added:
                    _overlay = CachedResources.Bitmaps["ImgOverlayAdd"];
                    break;

                case FileStatus.Modified:
                    _overlay = CachedResources.Bitmaps["ImgOverlayEdit"];
                    break;

                case FileStatus.Unmerged:
                    _overlay = CachedResources.Bitmaps["ImgOverlayConflict"];
                    break;

                case FileStatus.Copied:
                    _overlay = CachedResources.Bitmaps["ImgOverlayCopy"];
                    _text    = GetRenamedOrCopiedText(file.SourceFile, file.TargetFile);
                    break;

                case FileStatus.Renamed:
                    _overlay = CachedResources.Bitmaps["ImgOverlayRename"];
                    _text    = GetRenamedOrCopiedText(file.SourceFile, file.TargetFile);
                    break;

                case FileStatus.ModeChanged:
                    _overlay = CachedResources.Bitmaps["ImgOverlayChmod"];
                    break;
                }
            }
示例#26
0
        public AxisRender(Direct3d d3d, Camera camera)
            : base(d3d)
        {
            lineRender = new Line(d3d.Dx);

            this.camera                    = camera;
            this.camera.ViewChanged       += new Camera.ViewChangedEventHandler(camera_ViewChanged);
            this.camera.ProjectionChanged += new Camera.ProjectionChangedEventHandler(camera_ProjectionChanged);

            System.Drawing.Font localFont = new System.Drawing.Font("Verdana", 10.0f, FontStyle.Bold);
            font = new Microsoft.DirectX.Direct3D.Font(d3d.Dx, localFont);

            xAxisConeMatrial = GraphicsUtility.InitMaterial(Direct3dRender.DefaultXAxisColor);
            yAxisConeMatrial = GraphicsUtility.InitMaterial(Direct3dRender.DefaultYAxisColor);
            zAxisConeMatrial = GraphicsUtility.InitMaterial(Direct3dRender.DefaultZAxisColor);
        }
示例#27
0
        /// <summary>
        /// Called once per frame, the call is the entry point for animating the scene.
        /// </summary>
        protected override void FrameMove()
        {
            // Set the teapot's local matrix (rotating about the y-axis)
            teapotMatrix.RotateY(appTime);

            // When the window has focus, let the mouse adjust the camera view
            if (this == System.Windows.Forms.Form.ActiveForm)
            {
                Quaternion quat = GraphicsUtility.GetRotationFromCursor(this);
                eyePart.X = 5 * quat.Y;
                eyePart.Y = 5 * quat.X;
                eyePart.Z = -(float)Math.Sqrt(50.0f - 25 * quat.X * quat.X - 25 * quat.Y * quat.Y);

                device.Transform.View = Matrix.LookAtLH(eyePart, lookAtPart, upVector);
            }
        }
示例#28
0
        /// <summary>
        /// The device exists, but may have just been Reset().  Resources in
        /// Pool.Default and any other device state that persists during
        /// rendering should be set here.  Render states, matrices, textures,
        /// etc., that don't change during rendering can be set once here to
        /// avoid redundant state setting during Render() or FrameMove().
        /// </summary>
        protected override void RestoreDeviceObjects(System.Object sender, System.EventArgs e)
        {
            // Build the device objects for the file-based objecs
            for (int i = 0; i < 2; i++)
            {
                fileObject[i].RestoreDeviceObjects(device, null);
            }

            // Setup textures (the .X file may have textures)
            device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
            device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
            device.TextureState[0].ColorOperation = TextureOperation.Modulate;
            device.SamplerState[0].MinFilter      = TextureFilter.Linear;
            device.SamplerState[0].MagFilter      = TextureFilter.Linear;

            // Set up misc render states
            device.RenderState.ZBufferEnable  = true;
            device.RenderState.DitherEnable   = true;
            device.RenderState.SpecularEnable = false;
            device.RenderState.ColorVertex    = true;
            device.RenderState.Ambient        = System.Drawing.Color.Black;

            // Set the transform matrices
            Vector3 vEyePt = new Vector3(0.0f, 0.0f, -15.0f);
            Vector3 vLookatPt = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 vUpVec = new Vector3(0.0f, 1.0f, 0.0f);
            Matrix  matWorld, matView, matProj;

            matWorld = Matrix.Identity;
            matView  = Matrix.LookAtLH(vEyePt, vLookatPt, vUpVec);
            float fAspect = device.PresentationParameters.BackBufferWidth / (float)device.PresentationParameters.BackBufferHeight;

            matProj = Matrix.PerspectiveFovLH((float)Math.PI / 4, fAspect, 1.0f, 1000.0f);

            device.Transform.World      = matWorld;
            device.Transform.View       = matView;
            device.Transform.Projection = matProj;

            // Set up a material
            device.Material = GraphicsUtility.InitMaterial(System.Drawing.Color.White);

            // Set up the light
            GraphicsUtility.InitLight(device.Lights[0], LightType.Directional, 0.0f, -1.0f, 0.0f);
            device.Lights[0].Commit();
            device.Lights[0].Enabled    = true;
            device.RenderState.Lighting = true;
        }
示例#29
0
            public void Execute()
            {
                randNumber = (float4)(rand->NextDouble4());
                float4x4 nonJitterPNoTex = GraphicsUtility.GetGPUProjectionMatrix(nonJitterP, false, isD3D);

                nonJitterVP                    = mul(nonJitterPNoTex, worldToView);
                nonJitterInverseVP             = inverse(nonJitterVP);
                nonJitterTextureVP             = mul(GraphicsUtility.GetGPUProjectionMatrix(nonJitterP, true, isD3D), worldToView);
                lastCameraLocalToWorld.c3.xyz += sceneOffset;
                float4x4 lastV = GetWorldToCamera(ref lastCameraLocalToWorld);

                lastVP        = mul(lastP, lastV);
                lastP         = nonJitterPNoTex;
                lastInverseVP = inverse(lastVP);
                *VP        = mul(GraphicsUtility.GetGPUProjectionMatrix(p, false, isD3D), worldToView);
                *inverseVP = inverse(*VP);
            }
示例#30
0
        /// <summary>
        /// The device exists, but may have just been Reset().  Resources in
        /// Pool.Default and any other device state that persists during
        /// rendering should be set here.  Render states, matrices, textures,
        /// etc., that don't change during rendering can be set once here to
        /// avoid redundant state setting during Render() or FrameMove().
        /// </summary>
        protected override void RestoreDeviceObjects(System.Object sender, System.EventArgs e)
        {
            // Set up the geometry objects
            teapotMesh.RestoreDeviceObjects(device, null);

            if ((mirrorVertexBuffer == null) || (mirrorVertexBuffer.Disposed))
            {
                // Create a square for rendering the mirror
                mirrorVertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionNormalColored), 4, device,
                                                      Usage.WriteOnly, CustomVertex.PositionNormalColored.Format, Pool.Default);

                // Hook the created event so we can repopulate our data
                mirrorVertexBuffer.Created += new System.EventHandler(this.VertexBufferCreated);
                // Call our created handler for the first time
                this.VertexBufferCreated(mirrorVertexBuffer, null);
            }

            // Set up the textures
            device.TextureState[0].ColorOperation = TextureOperation.Modulate;
            device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
            device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
            device.SamplerState[0].MinFilter      = TextureFilter.Linear;
            device.SamplerState[0].MagFilter      = TextureFilter.Linear;

            // Set miscellaneous render states
            device.RenderState.DitherEnable   = true;
            device.RenderState.SpecularEnable = true;
            device.RenderState.ZBufferEnable  = true;

            // Set up the matrices
            device.Transform.World = Matrix.Identity;
            device.Transform.View  = Matrix.LookAtLH(eyePart, lookAtPart, upVector);
            float fAspect = device.PresentationParameters.BackBufferWidth / (float)device.PresentationParameters.BackBufferHeight;

            device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, fAspect, 1.0f, 100.0f);

            // Set up a light
            if ((Caps.VertexProcessingCaps.SupportsDirectionalLights) ||
                !(BehaviorFlags.HardwareVertexProcessing))
            {
                GraphicsUtility.InitLight(device.Lights[0], LightType.Directional, 0.2f, -1.0f, -0.2f);
                device.Lights[0].Commit();
                device.Lights[0].Enabled = true;
            }
            device.RenderState.Ambient = System.Drawing.Color.Black;
        }