(VI)グラフィックスの基本的なアプリケーション

1.はじめに

本論文では、テクスチャを描き、Graphicsクラスのためにメッシュ。

2.Drawテクスチャ

それらは平面上に直接描画するために属しているため、Graphicsクラスは、直接テクスチャを描画するとき、それは画素空間平面に変換する必要がある、LoadPixelMatrix法を用いる必要があります。空間変換のために参照することができ、このセクション

2.1 ToScreen

サンプルコード:

    public void Dmainxture()
    {
        GL.PushMatrix(); //GL.LoadPixelMatrix(); GL.LoadPixelMatrix(0,Screen.width,Screen.height,0); Graphics.DrawTexture(new Rect(0, 0, 200, 100), mainTexture); GL.PopMatrix(); } 

使用Graphics.DrawTextureコードは(0、0、200、100)の範囲内で画面に描画すなわち新規のRect mainTexture最も基本的な方法です。この方法は、多くのオーバーロードがあり、あなたは自分のニーズに応じて様々な方法を選択することができます。
GL.LoadPixelMatrix座標変換)((コメントコード部分)を用いて、mainTextureは、画面領域の左下隅に描画されますが、上下の画素が反転されます。これは、異なるグラフィカル・インターフェースに起因するテクスチャ座標原点に対応します。左下隅にOpenGlの、D3D左上隅。もしGL.LoadPixelMatrix使用する場合(0、Screen.width、Screen.height、 0) ピクセルのが反転するが、上から下へとなる座標変換行列ためされていないので、画面の左上隅を描きます。

2.1.1コールの場所

それは、画面上に描画されているので、我々は唯一のメソッドを呼び出すことができ、更新がカメラにレンダリングされるときOnGuiでOnPostRenderはクリアされます。テクスチャがRenderTextureに描画する場合は、更新にすることができます。

2.2 ToTarget

サンプルコード:

    public void DrawTextureToTarget()
    {
        Graphics.SetRenderTarget(target); clearBuffer.Clear(); clearBuffer.ClearRenderTarget(true, true, clearColor); Graphics.ExecuteCommandBuffer(clearBuffer); GL.PushMatrix(); GL.LoadPixelMatrix(0, target.width, target.height, 0); //GL.LoadPixelMatrix(0, target.width, 0, target.height); Graphics.DrawTexture(new Rect(0, 0, target.width, target.height), mainTexture); GL.PopMatrix(); } 

、更新を呼び出すことができ、この場合、Graphics.SetRenderTarget(ターゲット)は、画面変換がGL.LoadPixelMatrix(0、target.width、target.height、0)を必要とするようにプロットされた結果は、型RenderTexture対象の変数にプロットされています。

3.Drawメッシュ

3.1アップデートコール

サンプルコード:

    public void DrawMesh()
    {
        Graphics.DrawMesh(Graphics00Mesh.Instance.GetMesh(10, 5), Matrix4x4.identity, material, 0); //Graphics.DrawMesh(Graphics00Mesh.Instance.GetMesh(10, 5), center,Quaternion.identity, material, 0); } 

同様に、多くのオーバーロードGraphics.DrawMesh満たす多くのニーズがあり、紙は座標変換行列によって提供される唯一の2つの例を与える、他の(コメントの方法)は、メッシュと回転が行われる位置によって提供されますポジショニング。モデルが描かれているので、それが唯一の更新で呼び出すことができます。

3.2 OnPostRenderコール

呼ばれるレンダリングステージは唯一、直ちに命令を有効にするGraphics.DrawMeshNowの方法を使用することができます。

4.完全なコード

using System.Collections;
using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; public enum DrawLocation { ONGUI, POSTRENDER, UPDATE } public class Graphics06Graphics : MonoBehaviour { public DrawLocation location = DrawLocation.ONGUI; public bool toTarget = false; public Texture mainTexture; public RenderTexture target; public Color clearColor = Color.red; CommandBuffer clearBuffer; void Draw() { if (toTarget) { DrawTextureToTarget(); } else { DrawTexture(); } } public void DrawTexture() { GL.PushMatrix(); //GL.LoadPixelMatrix(); GL.LoadPixelMatrix(0,Screen.width,Screen.height,0); Graphics.DrawTexture(new Rect(0, 0, 200, 100), mainTexture); GL.PopMatrix(); } public void DrawTextureToTarget() { Graphics.SetRenderTarget(target); clearBuffer.Clear(); clearBuffer.ClearRenderTarget(true, true, clearColor); Graphics.ExecuteCommandBuffer(clearBuffer); GL.PushMatrix(); GL.LoadPixelMatrix(0, target.width, target.height, 0); //GL.LoadPixelMatrix(0, target.width, 0, target.height); Graphics.DrawTexture(new Rect(0, 0, target.width, target.height), mainTexture); GL.PopMatrix(); } private void Start() { clearBuffer = new CommandBuffer() { name = "Clear Buffer" }; } private void OnGUI() { if (location != DrawLocation.ONGUI) return; if (Event.current.type.Equals(EventType.Repaint)) { Draw(); } } private void Update() { if (location != DrawLocation.UPDATE) return; //如果此时绘制到屏幕上,则不会看到绘制的结果 Draw(); } private void OnPostRender() { if (location != DrawLocation.POSTRENDER) return; Draw(); } } 

5.まとめ

RenderTexture少しトラブルを描画するメッシュ、だけでなく、食感などの問題にあるので、それは次のセクションで説明されて別々に解析。

おすすめ

転載: www.cnblogs.com/llstart-new0201/p/12315716.html
おすすめ