SetPass() private method

private SetPass ( int pass ) : bool
pass int
return bool
コード例 #1
0
ファイル: Graph.cs プロジェクト: STOpandthink/Credence
    public static void DrawAnswers(List<Bar> bars, Material material)
    {
        if(bars.Count == 0) return;

        // Draw bar chart.
        GL.PushMatrix();
        material.SetPass(0);
        GL.LoadOrtho();

        // Draw arrows.
        GL.Begin(GL.LINES);
        foreach(Bar bar in bars){
            double barY = System.Math.Min(100.0, bar.y + 0.5);
            Vector3 origin = ConvertToPixel(bar.x, barY);
            Vector3 end = ConvertToPixel(System.Math.Max(barY, m_minX), barY);
            if(System.Math.Abs(bar.x - barY) <= Answer.CLOSE_ENOUGH) continue;
            int arrowSign = System.Math.Sign(end.x - origin.x);
            GL.Color(arrowSign > 0 ? Color.cyan : Color.magenta);
            GLVertex(origin);
            GL.Color(Color.yellow);
            GLVertex(end);
            GLVertex(end + new Vector3(-arrowSign * 10f / Screen.width, 10f / (float)Screen.height, 0f));
            GLVertex(end);
            GLVertex(end + new Vector3(-arrowSign * 10f / Screen.width, -10f / (float)Screen.height, 0f));
            GLVertex(end);
        }
        GL.End();

        DrawAxis(bars);
        GL.PopMatrix();
    }
コード例 #2
0
ファイル: MRT.cs プロジェクト: mattatz/unity-mrt-example
    public void Render(Material mat, int pass = 0)
    {
        Graphics.SetRenderTarget(ColorBuffers, DepthBuffer);

        GL.PushMatrix();

        mat.SetPass(pass);

        GL.LoadOrtho();

        GL.Begin(GL.QUADS);

        GL.TexCoord(new Vector3(0, 0, 0));
        GL.Vertex3(0, 0, 0);

        GL.TexCoord(new Vector3(1, 0, 0));
        GL.Vertex3(1, 0, 0);

        GL.TexCoord(new Vector3(1, 1, 0));
        GL.Vertex3(1, 1, 0);

        GL.TexCoord(new Vector3(0, 1, 0));
        GL.Vertex3(0, 1, 0);

        GL.End();

        GL.PopMatrix();
    }
コード例 #3
0
    public static void DrawLine(Vector3 pointA, Vector3 pointB, float width, Material material)
    {
        material.SetPass(0);
        GL.Begin(GL.QUADS);

        float halfLineWidth = width * 0.5f;

        Vector3 normal = -Camera.main.transform.forward;
        Vector3 side = Vector3.Cross(normal, pointB-pointA);
        side.Normalize();

        Vector3 a = pointA + side * halfLineWidth;
        Vector3 b = pointA - side * halfLineWidth;
        Vector3 c = pointB + side * halfLineWidth;
        Vector3 d = pointB - side * halfLineWidth;

        GL.TexCoord2(0.0f, 0.0f);
        GL.Vertex(a);
        GL.TexCoord2(0.0f, 1.0f);
        GL.Vertex(b);
        GL.TexCoord2(1.0f, 1.0f);
        GL.Vertex(d);
        GL.TexCoord2(1.0f, 0.0f);
        GL.Vertex(c);

        GL.End();
    }
コード例 #4
0
ファイル: RTUtility.cs プロジェクト: DerBasti/Rift-Wingsuit
    /// <summary>
    /// Renders into a array of render textures using multi-target blit.
    /// Up to 4 render targets are supported in Unity but some GPU's can
    /// support up to 8 so this may change in the future. You MUST set up 
    /// the materials shader correctly for multitarget blit for this to work.
    /// </summary>
    /// <param name="des">The destination render textures.</param>
    /// <param name="mat">The amterial to use</param>
    /// <param name="pass">Which pass of the materials shader to use.</param>
    public static void MultiTargetBlit(RenderTexture[] des, Material mat, int pass = 0)
    {
        RenderBuffer[] rb = new RenderBuffer[des.Length];

        // Set targets needs the color buffers so make a array from
        // each textures buffer.
        for(int i = 0; i < des.Length; i++)
            rb[i] = des[i].colorBuffer;

        //Set the targets to render into.
        //Will use the depth buffer of the
        //first render texture provided.
        Graphics.SetRenderTarget(rb, des[0].depthBuffer);

        GL.Clear(true, true, Color.clear);

        GL.PushMatrix();
        GL.LoadOrtho();

        mat.SetPass(pass);

        GL.Begin(GL.QUADS);
        GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(0.0f, 0.0f, 0.1f);
        GL.TexCoord2(1.0f, 0.0f); GL.Vertex3(1.0f, 0.0f, 0.1f);
        GL.TexCoord2(1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 0.1f);
        GL.TexCoord2(0.0f, 1.0f); GL.Vertex3(0.0f, 1.0f, 0.1f);
        GL.End();

        GL.PopMatrix();
    }
コード例 #5
0
 void RectLighting(MeshFilter obj,Material exMat)
 {
     Mesh ms = obj.sharedMesh;
     Transform tr = obj.transform;
     exMat.SetPass(0);
     Graphics.DrawMeshNow(ms, tr.localToWorldMatrix);
 }
コード例 #6
0
        void CustomGraphicsBlit(RenderTexture source, RenderTexture dest, Material mat, int pass)
        {
            RenderTexture.active = dest;

            mat.SetTexture("_MainTex", source);

            GL.PushMatrix();
            GL.LoadOrtho();

            mat.SetPass (pass);

            GL.Begin (GL.QUADS);

            //This custom blit is needed as information about what corner verts relate to what frustum corners is needed
            //A index to the frustum corner is store in the z pos of vert

            GL.MultiTexCoord2(0, 0.0f, 0.0f);
            GL.Vertex3(0.0f, 0.0f, 3.0f); // BL

            GL.MultiTexCoord2(0, 1.0f, 0.0f);
            GL.Vertex3(1.0f, 0.0f, 2.0f); // BR

            GL.MultiTexCoord2(0, 1.0f, 1.0f);
            GL.Vertex3(1.0f, 1.0f, 1.0f); // TR

            GL.MultiTexCoord2(0, 0.0f, 1.0f);
            GL.Vertex3(0.0f, 1.0f, 0.0f); // TL

            GL.End();
            GL.PopMatrix();
        }
コード例 #7
0
        public static void DrawLine(Vector2 pointA, Vector2 pointB, Color color)
        {
            if (clippingEnabled)
            {
                if (!SegmentRectIntersection(clippingBounds, ref pointA, ref pointB))
                {
                    return;
                }
            }

            if (!lineMaterial)
            {
                /* Credit:  */
                lineMaterial = new UnityEngine.Material("Shader \"Lines/Colored Blended\" {" +
                                                        "SubShader { Pass {" +
                                                        "   BindChannels { Bind \"Color\",color }" +
                                                        "   Blend SrcAlpha OneMinusSrcAlpha" +
                                                        "   ZWrite Off Cull Off Fog { Mode Off }" +
                                                        "} } }");
                lineMaterial.hideFlags        = HideFlags.HideAndDontSave;
                lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
            }

            lineMaterial.SetPass(0);
            GL.Begin(GL.LINES);
            GL.Color(color);
            GL.Vertex3(pointA.x, pointA.y, 0);
            GL.Vertex3(pointB.x, pointB.y, 0);
            GL.End();
        }
コード例 #8
0
ファイル: GLLines.cs プロジェクト: Rubensaccnt/Sputnik
    /// <summary>
    /// Draws a circle thingy.
    /// </summary>
    /// <param name="lineMaterial">The line material.</param>
    /// <param name="color">The color.</param>
    /// <param name="iteration">The iteration.</param>
    /// <param name="radius">The radius.</param>
    /// <param name="s">The s.</param>
    /// <param name="q">The q.</param>
    public static void CircleDrawing(Material lineMaterial, Color color, int iteration, float radius, Vector3 source, Quaternion rotatiom)
    {
        lineMaterial.SetColor("_TintColor", color);
        lineMaterial.SetPass(0);

        GL.Begin(GL.LINES);
        for (int i = 1; i <= iteration + 1; i++)
        {
            float dg = i;
            float n = iteration;

            Vector3 v = Vector3.zero;

            v.x = radius * Mathf.Cos((dg / n) * Mathf.PI * 2);
            v.z = radius * Mathf.Sin((dg / n) * Mathf.PI * 2);
            v = rotatiom * v;

            Vector3 v1 = new Vector3(v.x + source.x, v.y + source.y, v.z + source.z);

            GL.Vertex3(v1.x, v1.y, v1.z);

            if (i != 1 && i != iteration + 1)
            {
                GL.Vertex3(v.x + source.x, v.y + source.y, v.z + source.z);
            }
        }

        GL.End();
    }
コード例 #9
0
ファイル: RTUtility.cs プロジェクト: kharbechteinn/Scatterer
//	static public void MultiTargetBlit(RenderTexture[] des, Material mat, int pass = 0)
	static public void MultiTargetBlit(RenderTexture[] des, Material mat, int pass)
    {
       	//RenderTexture oldRT = RenderTexture.active;
		
		RenderBuffer[] rb = new RenderBuffer[des.Length];
		
		for(int i = 0; i < des.Length; i++)
			rb[i] = des[i].colorBuffer;

        Graphics.SetRenderTarget(rb, des[0].depthBuffer);

        GL.Clear(true, true, Color.clear);

        GL.PushMatrix();
        GL.LoadOrtho();
		
		mat.SetPass(pass);

        GL.Begin(GL.QUADS);
        GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(0.0f, 0.0f, 0.1f);
        GL.TexCoord2(1.0f, 0.0f); GL.Vertex3(1.0f, 0.0f, 0.1f);
        GL.TexCoord2(1.0f, 1.0f); GL.Vertex3(1.0f, 1.0f, 0.1f);
        GL.TexCoord2(0.0f, 1.0f); GL.Vertex3(0.0f, 1.0f, 0.1f);
        GL.End();

        GL.PopMatrix();

        //RenderTexture.active = oldRT;
    }
コード例 #10
0
ファイル: RTUtility.cs プロジェクト: kharbechteinn/Scatterer
//	static public void Blit(RenderTexture src, RenderTexture des, Material mat, Rect rect, int pass = 0, bool clear = true)
	static public void Blit(RenderTexture src, RenderTexture des, Material mat, Rect rect, int pass, bool clear)
    {
		//rect must have normalized coords, ie 0 - 1
		
		mat.SetTexture("_MainTex", src);
		
        RenderTexture oldRT = RenderTexture.active;
		
        Graphics.SetRenderTarget(des);

        if(clear) GL.Clear(true, true, Color.clear);

        GL.PushMatrix();
        GL.LoadOrtho();
		
		mat.SetPass(pass);

        GL.Begin(GL.QUADS);
        GL.TexCoord2(rect.x, rect.y); GL.Vertex3(rect.x, rect.y, 0.1f);
        GL.TexCoord2(rect.x+rect.width, rect.y); GL.Vertex3(rect.x+rect.width, rect.y, 0.1f);
        GL.TexCoord2(rect.x+rect.width, rect.y+rect.height); GL.Vertex3(rect.x+rect.width, rect.y+rect.height, 0.1f);
        GL.TexCoord2(rect.x, rect.y+rect.height); GL.Vertex3(rect.x, rect.y+rect.height, 0.1f);
        GL.End();

        GL.PopMatrix();

        RenderTexture.active = oldRT;
    }
コード例 #11
0
    public static void DrawProteinSphereBatches(Material renderProteinsMaterial, Camera camera, RenderBuffer colorBuffer, RenderBuffer depthBuffer, int pass, bool animated = false)
    {
        // Protein params
        renderProteinsMaterial.SetInt("_EnableLod", Convert.ToInt32(PersistantSettings.Instance.EnableLod));
        renderProteinsMaterial.SetFloat("_Scale", PersistantSettings.Instance.Scale);
        renderProteinsMaterial.SetFloat("_FirstLevelBeingRange", PersistantSettings.Instance.FirstLevelOffset);
        renderProteinsMaterial.SetVector("_CameraForward", camera.transform.forward);

        renderProteinsMaterial.SetBuffer("_LodLevelsInfos", GPUBuffers.Instance.LodInfo);
        renderProteinsMaterial.SetBuffer("_ProteinInstanceInfo", GPUBuffers.Instance.ProteinInstanceInfo);

        if(animated) renderProteinsMaterial.SetBuffer("_ProteinInstancePositions", GPUBuffers.Instance.ProteinAnimationPositions);
        else renderProteinsMaterial.SetBuffer("_ProteinInstancePositions", GPUBuffers.Instance.ProteinInstancePositions);

        if (animated) renderProteinsMaterial.SetBuffer("_ProteinInstanceRotations", GPUBuffers.Instance.ProteinAnimationRotations);
        else renderProteinsMaterial.SetBuffer("_ProteinInstanceRotations", GPUBuffers.Instance.ProteinInstanceRotations);

        renderProteinsMaterial.SetBuffer("_ProteinAtomCount", GPUBuffers.Instance.ProteinAtomCount);
        renderProteinsMaterial.SetBuffer("_ProteinColors", GPUBuffers.Instance.ProteinColors);
        renderProteinsMaterial.SetBuffer("_ProteinAtomPositions", GPUBuffers.Instance.ProteinAtoms);
        renderProteinsMaterial.SetBuffer("_ProteinClusterPositions", GPUBuffers.Instance.ProteinAtomClusters);
        renderProteinsMaterial.SetBuffer("_ProteinSphereBatchInfos", GPUBuffers.Instance.SphereBatches);

        Graphics.SetRenderTarget(colorBuffer, depthBuffer);
        renderProteinsMaterial.SetPass(pass);
        Graphics.DrawProceduralIndirect(MeshTopology.Points, GPUBuffers.Instance.ArgBuffer);
    }
コード例 #12
0
ファイル: RTUtility.cs プロジェクト: kharbechteinn/Scatterer
//	static public void Blit(RenderTexture src, RenderTexture des, Material mat, int pass = 0, bool clear = true)
	static public void Blit(RenderTexture src, RenderTexture des, Material mat, int pass, bool clear)
    {
		mat.SetTexture("_MainTex", src);
		
        RenderTexture oldRT = RenderTexture.active;
		
        Graphics.SetRenderTarget(des);

        if(clear) GL.Clear(true, true, Color.clear);

        GL.PushMatrix();
        GL.LoadOrtho();
		
		mat.SetPass(pass);

        GL.Begin(GL.QUADS);
		GL.TexCoord3(0.0f, 0.0f, 0.0f); GL.Vertex3(0.0f, 0.0f, 0.1f);
		GL.TexCoord3(1.0f, 0.0f, 0.0f); GL.Vertex3(1.0f, 0.0f, 0.1f);
		GL.TexCoord3(1.0f, 1.0f, 0.0f); GL.Vertex3(1.0f, 1.0f, 0.1f);
		GL.TexCoord3(0.0f, 1.0f, 0.0f); GL.Vertex3(0.0f, 1.0f, 0.1f);
        GL.End();

        GL.PopMatrix();

        RenderTexture.active = oldRT;
    }
コード例 #13
0
ファイル: ScionGraphics.cs プロジェクト: B-LiTE/MemeTeam
        public static void Blit(RenderTexture dest, Material fxMaterial, int passNr)
        {
            Graphics.SetRenderTarget(dest);

            GL.PushMatrix ();
            GL.LoadOrtho ();

            fxMaterial.SetPass(passNr);

            GL.Begin (GL.QUADS);

            GL.MultiTexCoord2 (0, 0.0f, 0.0f);
            GL.Vertex3 (0.0f, 0.0f, 0.0f); // BL

            GL.MultiTexCoord2 (0, 1.0f, 0.0f);
            GL.Vertex3 (1.0f, 0.0f, 0.0f); // BR

            GL.MultiTexCoord2 (0, 1.0f, 1.0f);
            GL.Vertex3 (1.0f, 1.0f, 0.0f); // TR

            GL.MultiTexCoord2 (0, 0.0f, 1.0f);
            GL.Vertex3 (0.0f, 1.0f, 0.0f); // TL

            GL.End ();
            GL.PopMatrix ();
        }
コード例 #14
0
        static void CustomGraphicsBlit(RenderTexture source, RenderTexture dest, Material fxMaterial, int passNr)
        {
            RenderTexture.active = dest;

            fxMaterial.SetTexture ("_MainTex", source);

            GL.PushMatrix ();
            GL.LoadOrtho ();

            fxMaterial.SetPass (passNr);

            GL.Begin (GL.QUADS);

            GL.MultiTexCoord2 (0, 0.0f, 0.0f);
            GL.Vertex3 (0.0f, 0.0f, 3.0f); // BL

            GL.MultiTexCoord2 (0, 1.0f, 0.0f);
            GL.Vertex3 (1.0f, 0.0f, 2.0f); // BR

            GL.MultiTexCoord2 (0, 1.0f, 1.0f);
            GL.Vertex3 (1.0f, 1.0f, 1.0f); // TR

            GL.MultiTexCoord2 (0, 0.0f, 1.0f);
            GL.Vertex3 (0.0f, 1.0f, 0.0f); // TL

            GL.End ();
            GL.PopMatrix ();
        }
コード例 #15
0
    /// <summary>
    /// Draws a full-screen rectangle with the given material.
    /// </summary>
    /// <param name="material">The material to render to the quad.</param>
    /// <param name="rect">An optional rectangle region of the screen to render to.</param>
    public static void DrawFullScreenQuad(Material material, Rect? rect = null)
    {
        if (rect == null)
            rect = new Rect (0, 0, 1, 1);
        Rect r = rect.Value;

        GL.PushMatrix();
        GL.LoadOrtho();

        for (int i = 0; i < material.passCount; ++i)
        {
            material.SetPass(i);
            GL.Begin(GL.QUADS);
            GL.Color(Color.white);
            GL.TexCoord2(0, 0);
            GL.Vertex3(r.xMin, r.yMin, 0.1f);

            GL.TexCoord2(1, 0);
            GL.Vertex3(r.xMax, r.yMin, 0.1f);

            GL.TexCoord2(1, 1);
            GL.Vertex3(r.xMax, r.yMax, 0.1f);

            GL.TexCoord2(0, 1);
            GL.Vertex3(r.xMin, r.yMax, 0.1f);
            GL.End();
        }

        GL.PopMatrix();
    }
コード例 #16
0
    static void CustomGraphicsBlit(RenderTexture src, RenderTexture dst, Material mat, int pass)
    {
        RenderTexture.active = dst;

        mat.SetTexture("_MainTex", src);

        GL.PushMatrix();
        GL.LoadOrtho();

        mat.SetPass(pass);

        GL.Begin(GL.QUADS);

        GL.MultiTexCoord2(0, 0.0f, 0.0f);
        GL.Vertex3(0.0f, 0.0f, 3.0f); // BL

        GL.MultiTexCoord2(0, 1.0f, 0.0f);
        GL.Vertex3(1.0f, 0.0f, 2.0f); // BR

        GL.MultiTexCoord2(0, 1.0f, 1.0f);
        GL.Vertex3(1.0f, 1.0f, 1.0f); // TR

        GL.MultiTexCoord2(0, 0.0f, 1.0f);
        GL.Vertex3(0.0f, 1.0f, 0.0f); // TL

        GL.End();
        GL.PopMatrix();
    }
コード例 #17
0
ファイル: Paint.cs プロジェクト: DeanLu/SnowBall
    void PaintTexture(RenderTexture _canvas, Material _brush, float _size, float _posX, float _posY)
    {
        Debug.Log (string.Format("_size = {0}, _posX = {1}, _posY = {2}",_size,_posX,_posY));

        float halfSize = _size / 2F;

        _canvas.MarkRestoreExpected ();
        Graphics.SetRenderTarget(_canvas);

        GL.PushMatrix();

        _brush.SetPass (0);

        GL.LoadOrtho();

        GL.Begin(GL.QUADS);

        GL.TexCoord(new Vector3(0, 0, 0));
        GL.Vertex3(_posX - halfSize, _posY - halfSize, 0);

        GL.TexCoord(new Vector3(0, 1, 0));
        GL.Vertex3(_posX - halfSize, _posY + halfSize, 0);

        GL.TexCoord(new Vector3(1, 1, 0));
        GL.Vertex3(_posX + halfSize, _posY + halfSize, 0);

        GL.TexCoord(new Vector3(1, 0, 0));
        GL.Vertex3(_posX + halfSize, _posY - halfSize, 0);

        GL.End();

        GL.PopMatrix();

        Graphics.SetRenderTarget(null);
    }
コード例 #18
0
ファイル: GLLines.cs プロジェクト: Rubensaccnt/Sputnik
    /// <summary>
    /// 
    /// </summary>
    /// <param name="lineMaterial"></param>
    /// <param name="color"></param>
    /// <param name="source"></param>
    /// <param name="destination"></param>
    public static void BoxDrawing(Material lineMaterial, Color color, float width, float height, Vector3 position)
    {
        lineMaterial.SetColor("_TintColor", color);
        lineMaterial.SetPass(0);

        GL.Begin(GL.LINES);

        // upper width line
        GL.Vertex3(position.x - width / 2, position.y, position.z + height / 2);
        GL.Vertex3(position.x + width / 2, position.y, position.z + height / 2);

        // right height line
        GL.Vertex3(position.x + width / 2, position.y, position.z + height / 2);
        GL.Vertex3(position.x + width / 2, position.y, position.z - height / 2);

        // lower width line
        GL.Vertex3(position.x + width / 2, position.y, position.z - height / 2);
        GL.Vertex3(position.x - width / 2, position.y, position.z - height / 2);

        //height lines
        GL.Vertex3(position.x - width / 2, position.y, position.z - height / 2);
        GL.Vertex3(position.x - width / 2, position.y, position.z + height / 2);

        GL.End();
    }
コード例 #19
0
ファイル: RenderUtils.cs プロジェクト: matmuze/cellVIEW_color
    public static void DrawProteinsAtoms(Material renderProteinsMaterial, Camera camera, RenderBuffer instanceId, RenderBuffer atomId, RenderBuffer depthBuffer, int pass)
    {
        // Protein params
        renderProteinsMaterial.SetInt("_EnableLod", Convert.ToInt32(GlobalProperties.Get.EnableLod));
        renderProteinsMaterial.SetFloat("_Scale", GlobalProperties.Get.Scale);
        renderProteinsMaterial.SetFloat("_FirstLevelBeingRange", GlobalProperties.Get.FirstLevelOffset);
        renderProteinsMaterial.SetVector("_CameraForward", camera.transform.forward);

        renderProteinsMaterial.SetBuffer("_LodLevelsInfos", GPUBuffers.Get.LodInfo);
        renderProteinsMaterial.SetBuffer("_ProteinInstanceInfo", GPUBuffers.Get.ProteinInstancesInfo);
        renderProteinsMaterial.SetBuffer("_ProteinInstancePositions", GPUBuffers.Get.ProteinInstancePositions);
        renderProteinsMaterial.SetBuffer("_ProteinInstanceRotations", GPUBuffers.Get.ProteinInstanceRotations);

        renderProteinsMaterial.SetBuffer("_ProteinColors", GPUBuffers.Get.IngredientsColors);
        renderProteinsMaterial.SetBuffer("_ProteinAtomInfo", GPUBuffers.Get.ProteinAtomInfo);
        renderProteinsMaterial.SetBuffer("_ProteinAtomPositions", GPUBuffers.Get.ProteinAtoms);
        renderProteinsMaterial.SetBuffer("_ProteinClusterPositions", GPUBuffers.Get.ProteinAtomClusters);
        renderProteinsMaterial.SetBuffer("_ProteinSphereBatchInfos", GPUBuffers.Get.SphereBatches);

        /****/
        renderProteinsMaterial.SetInt("_NumCutObjects", SceneManager.Get.NumCutObjects);
        renderProteinsMaterial.SetInt("_NumIngredientTypes", SceneManager.Get.NumAllIngredients);
        

        renderProteinsMaterial.SetBuffer("_CutInfos", GPUBuffers.Get.CutInfo);
        renderProteinsMaterial.SetBuffer("_CutScales", GPUBuffers.Get.CutScales);
        renderProteinsMaterial.SetBuffer("_CutPositions", GPUBuffers.Get.CutPositions);
        renderProteinsMaterial.SetBuffer("_CutRotations", GPUBuffers.Get.CutRotations);
        /****/

        Graphics.SetRenderTarget(new[] { instanceId, atomId }, depthBuffer);
        renderProteinsMaterial.SetPass(1);
        Graphics.DrawProceduralIndirect(MeshTopology.Points, GPUBuffers.Get.ArgBuffer);
    }
コード例 #20
0
        static void DrawNoiseQuadGrid(RenderTexture source, RenderTexture dest, Material fxMaterial, Texture2D noise, int passNr)
        {
            RenderTexture.active = dest;

            float noiseSize = (noise.width * 1.0f);
            float subDs = (1.0f * source.width) / TILE_AMOUNT;

            fxMaterial.SetTexture ("_MainTex", source);

            GL.PushMatrix ();
            GL.LoadOrtho ();

            float aspectCorrection = (1.0f * source.width) / (1.0f * source.height);
            float stepSizeX = 1.0f / subDs;
            float stepSizeY = stepSizeX * aspectCorrection;
            float texTile = noiseSize / (noise.width * 1.0f);

            fxMaterial.SetPass (passNr);

            GL.Begin (GL.QUADS);

            for (float x1 = 0.0f; x1 < 1.0f; x1 += stepSizeX)
            {
                for (float y1 = 0.0f; y1 < 1.0f; y1 += stepSizeY)
                {
                    float tcXStart = Random.Range (0.0f, 1.0f);
                    float tcYStart = Random.Range (0.0f, 1.0f);

                    //Vector3 v3 = Random.insideUnitSphere;
                    //Color c = new Color(v3.x, v3.y, v3.z);

                    tcXStart = Mathf.Floor(tcXStart*noiseSize) / noiseSize;
                    tcYStart = Mathf.Floor(tcYStart*noiseSize) / noiseSize;

                    float texTileMod = 1.0f / noiseSize;

                    GL.MultiTexCoord2 (0, tcXStart, tcYStart);
                    GL.MultiTexCoord2 (1, 0.0f, 0.0f);
                    //GL.Color( c );
                    GL.Vertex3 (x1, y1, 0.1f);
                    GL.MultiTexCoord2 (0, tcXStart + texTile * texTileMod, tcYStart);
                    GL.MultiTexCoord2 (1, 1.0f, 0.0f);
                    //GL.Color( c );
                    GL.Vertex3 (x1 + stepSizeX, y1, 0.1f);
                    GL.MultiTexCoord2 (0, tcXStart + texTile * texTileMod, tcYStart + texTile * texTileMod);
                    GL.MultiTexCoord2 (1, 1.0f, 1.0f);
                    //GL.Color( c );
                    GL.Vertex3 (x1 + stepSizeX, y1 + stepSizeY, 0.1f);
                    GL.MultiTexCoord2 (0, tcXStart, tcYStart + texTile * texTileMod);
                    GL.MultiTexCoord2 (1, 0.0f, 1.0f);
                    //GL.Color( c );
                    GL.Vertex3 (x1, y1 + stepSizeY, 0.1f);
                }
            }

            GL.End ();
            GL.PopMatrix ();
        }
コード例 #21
0
        static void DrawLowLevelPlaneAlignedWithCamera (
            float dist ,
            RenderTexture source, RenderTexture dest ,
            Material material ,
            Camera cameraForProjectionMatrix )
        {
            // Make the destination texture the target for all rendering
            RenderTexture.active = dest;
            // Assign the source texture to a property from a shader
            material.SetTexture("_MainTex", source);
            bool  invertY = true; // source.texelSize.y < 0.0f;
            // Set up the simple Matrix
            GL.PushMatrix();
            GL.LoadIdentity();
            GL.LoadProjectionMatrix(cameraForProjectionMatrix.projectionMatrix);

            float fovYHalfRad = cameraForProjectionMatrix.fieldOfView * 0.5f * Mathf.Deg2Rad;
            float cotangent = Mathf.Cos(fovYHalfRad) / Mathf.Sin(fovYHalfRad);
            float asp = cameraForProjectionMatrix.aspect;

            float x1 = asp/-cotangent;
            float x2 = asp/cotangent;
            float y1 = 1.0f/-cotangent;
            float y2 = 1.0f/cotangent;

            float sc = 1.0f; // magic constant (for now)

            x1 *= dist * sc;
            x2 *= dist * sc;
            y1 *= dist * sc;
            y2 *= dist * sc;

            float z1 = -dist;

            for (int i = 0; i < material.passCount; i++)
            {
                material.SetPass(i);

                GL.Begin(GL.QUADS);
                float y1_; float y2_;
                if (invertY)
                {
                    y1_ = 1.0f; y2_ = 0.0f;
                }
                else
                {
                    y1_ = 0.0f; y2_ = 1.0f;
                }
                GL.TexCoord2(0.0f, y1_); GL.Vertex3(x1, y1, z1);
                GL.TexCoord2(1.0f, y1_); GL.Vertex3(x2, y1, z1);
                GL.TexCoord2(1.0f, y2_); GL.Vertex3(x2, y2, z1);
                GL.TexCoord2(0.0f, y2_); GL.Vertex3(x1, y2, z1);
                GL.End();
            }

            GL.PopMatrix();
        }
コード例 #22
0
ファイル: VolShaft_1.cs プロジェクト: trojanfoe/UnityShader
    void DrawShaft(MeshFilter obj, Vector4 lightPos,Material exMat)
    {
        exMat.SetVector("litPos", lightPos);

        Mesh ms = obj.sharedMesh;
        Transform tr = obj.transform;
        exMat.SetPass(0);
        Graphics.DrawMeshNow(ms, tr.localToWorldMatrix);
    }
コード例 #23
0
    public static void DrawLine(Vector3 pointA, Vector3 pointB, Material material)
    {
        material.SetPass(0);
        GL.Begin(GL.LINES);

        GL.Vertex3(pointA.x, pointA.y, pointA.z);
        GL.Vertex3(pointB.x, pointB.y, pointB.z);

        GL.End();
    }
コード例 #24
0
		/// <summary>
		/// 	Begins GL drawing with the current handles settings.
		/// 	(this is taken from the Handles.DrawLine method)
		/// </summary>
		/// <param name="mode">Mode.</param>
		/// <param name="material">Material.</param>
		public static void BeginGL(int mode, Material material)
		{
			material.SetPass(0);

			GL.PushMatrix();
			GL.MultMatrix(Handles.matrix);

			GL.Begin(mode);

			Color color = Handles.color * new Color(1.0f, 1.0f, 1.0f, 0.75f);
			GL.Color(color);
		}
コード例 #25
0
ファイル: DebugShapes.cs プロジェクト: Deus0/Zeltex
	public static void DrawCube(Vector3 Position, Vector3 Size, Color MyColor, bool IsDepth) {
		List<Vector3> CubeLines = new List<Vector3> ();
		CubeLines.Add (new Vector3(-Size.x, -Size.y, -Size.z));
		CubeLines.Add (new Vector3(Size.x, -Size.y, -Size.z));

		CubeLines.Add (new Vector3(Size.x, -Size.y, -Size.z));
		CubeLines.Add (new Vector3(Size.x, -Size.y, Size.z));
		
		CubeLines.Add (new Vector3(Size.x, -Size.y, Size.z));
		CubeLines.Add (new Vector3(-Size.x, -Size.y, Size.z));
		
		CubeLines.Add (new Vector3(-Size.x, -Size.y, Size.z));
		CubeLines.Add (new Vector3(-Size.x, -Size.y, -Size.z));

		CubeLines.Add (new Vector3(-Size.x, Size.y, -Size.z));
		CubeLines.Add (new Vector3(Size.x,  Size.y, -Size.z));
		CubeLines.Add (new Vector3(Size.x,  Size.y, -Size.z));
		CubeLines.Add (new Vector3(Size.x,  Size.y, Size.z));
		CubeLines.Add (new Vector3(Size.x,  Size.y, Size.z));
		CubeLines.Add (new Vector3(-Size.x,  Size.y, Size.z));
		CubeLines.Add (new Vector3(-Size.x,  Size.y, Size.z));
		CubeLines.Add (new Vector3(-Size.x,  Size.y, -Size.z));

		CubeLines.Add (new Vector3(-Size.x, -Size.y, -Size.z));
		CubeLines.Add (new Vector3(-Size.x,  Size.y, -Size.z));
		CubeLines.Add ( new Vector3(Size.x, -Size.y, -Size.z));
		CubeLines.Add ( new Vector3(Size.x,  Size.y, -Size.z));
		CubeLines.Add ( new Vector3(Size.x, -Size.y, Size.z));
		CubeLines.Add ( new Vector3(Size.x,  Size.y, Size.z));
		CubeLines.Add ( new Vector3(-Size.x, -Size.y, Size.z));
		CubeLines.Add ( new Vector3(-Size.x,  Size.y, Size.z));


		GL.PushMatrix ();
		Material MyMaterial = new Material (Shader.Find("Transparent/Diffuse"));
		// reset matrix
		//GL.LoadIdentity ();
		Matrix4x4 MyMatrix = Matrix4x4.TRS (Position, Quaternion.identity, new Vector3(1,1,1));
		GL.MultMatrix (MyMatrix);
		//GL.MultMatrix (Position.localToWorldMatrix);
		//GL.matr
		MyMaterial.SetPass (0);
		// Draw lines
		GL.Begin (GL.LINES);
		for (int i = 0; i < CubeLines.Count; i += 2)
		{
			GL.Color (MyColor);
			GL.Vertex3 (CubeLines[i].x, CubeLines[i].y, CubeLines[i].z);
			GL.Vertex3 (CubeLines[i+1].x, CubeLines[i+1].y, CubeLines[i+1].z);
		}
		GL.End ();
		GL.PopMatrix ();
	}
コード例 #26
0
ファイル: ImageEffects.cs プロジェクト: ChrAfonso/imagination
    public static void BlitWithMaterial(Material material, RenderTexture source, RenderTexture destination)
    {
        RenderTexture.active = destination;
        material.SetTexture("_MainTex", source);

        GL.PushMatrix ();
        GL.LoadOrtho ();

        for (int i = 0; i < material.passCount; i++) {
            material.SetPass (i);
            ImageEffects.DrawQuad();
        }
        GL.PopMatrix ();
    }
コード例 #27
0
 static public int SetPass(IntPtr l)
 {
     try {
         UnityEngine.Material self = (UnityEngine.Material)checkSelf(l);
         System.Int32         a1;
         checkType(l, 2, out a1);
         var ret = self.SetPass(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #28
0
ファイル: VertexLine.cs プロジェクト: cupsster/drawLine
    //GL 함수를 사용한 low-level drawLine
    void DrawGLLine(Vector3 p0, Vector3 p1, Color color, Material mat)
    {
        mat.SetPass(0);
        GL.PushMatrix();

        GL.MultMatrix(transform.localToWorldMatrix);
        GL.Begin(GL.LINES);

        GL.Color(color);
        GL.Vertex(p0);
        GL.Vertex(p1);

        GL.End();
        GL.PopMatrix();
    }
コード例 #29
0
 static public int SetPass(IntPtr l)
 {
     try {
         UnityEngine.Material self = (UnityEngine.Material)checkSelf(l);
         System.Int32         a1;
         checkType(l, 2, out a1);
         var ret = self.SetPass(a1);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
コード例 #30
0
 static int SetPass(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.Material obj = (UnityEngine.Material)ToLua.CheckObject(L, 1, typeof(UnityEngine.Material));
         int  arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         bool o    = obj.SetPass(arg0);
         LuaDLL.lua_pushboolean(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #31
0
 //Draw dem triangles
 void DrawTriangle(Vector3 v1, Vector3 v2, Vector3 v3, Material mat, float depth)
 {
     v1.z = depth;
     v2.z = depth;
     v3.z = depth;
     GL.PushMatrix();
     mat.SetPass(0);
     GL.LoadOrtho();
     GL.Color(mat.color);
     GL.Begin(GL.TRIANGLES);
     GL.Vertex(v1);
     GL.Vertex(v2);
     GL.Vertex(v3);
     GL.End();
     GL.PopMatrix();
 }
コード例 #32
0
    // Helper to draw a screenspace grid of quads with random texture coordinates
    static void DrawNoiseQuadGrid( RenderTexture source ,   RenderTexture dest ,   Material fxMaterial ,   Texture2D noise ,   int passNr  )
    {
        RenderTexture.active = dest;

        #if UNITY_XBOX360
            float tileSize = 128.0ff;
        #else
            float tileSize = 64.0f;
        #endif

        float subDs = (1.0f * source.width) / tileSize;

        fxMaterial.SetTexture ("_MainTex", source);

        GL.PushMatrix ();
        GL.LoadOrtho ();

        float aspectCorrection = (1.0f * source.width) / (1.0f * source.height);
        float stepSizeX = 1.0f / subDs;
        float stepSizeY = stepSizeX * aspectCorrection;
           	    float texTile = tileSize / (noise.width * 1.0f);

        fxMaterial.SetPass (passNr);

        GL.Begin (GL.QUADS);

           	    for (float x1 = 0.0f; x1 < 1.0f; x1 += stepSizeX) {
           		    for (float y1 = 0.0f; y1 < 1.0f; y1 += stepSizeY) {

           			    float tcXStart = Random.Range (-1.0f, 1.0f);
           			    float tcYStart = Random.Range (-1.0f, 1.0f);
           			    float texTileMod = Mathf.Sign (Random.Range (-1.0f, 1.0f));

                GL.MultiTexCoord2 (0, tcXStart, tcYStart);
                GL.Vertex3 (x1, y1, 0.1f);
                GL.MultiTexCoord2 (0, tcXStart + texTile * texTileMod, tcYStart);
                GL.Vertex3 (x1 + stepSizeX, y1, 0.1f);
                GL.MultiTexCoord2 (0, tcXStart + texTile * texTileMod, tcYStart + texTile * texTileMod);
                GL.Vertex3 (x1 + stepSizeX, y1 + stepSizeY, 0.1f);
                GL.MultiTexCoord2 (0, tcXStart, tcYStart + texTile * texTileMod);
                GL.Vertex3 (x1, y1 + stepSizeY, 0.1f);
           		    }
           	    }

        GL.End ();
        GL.PopMatrix ();
    }
コード例 #33
0
    void DrawQuad(Material mat, int pass = 0)
    {
        GL.PushMatrix();
        mat.SetPass(pass);
        GL.Begin(GL.QUADS);
        GL.Vertex3(-1.0f, -1.0f, 1.0f);
        GL.Vertex3(1.0f, -1.0f, 1.0f);
        GL.Vertex3(1.0f, 1.0f, 1.0f);
        GL.Vertex3(-1.0f, 1.0f, 1.0f);

        GL.Vertex3(-1.0f, 1.0f, 1.0f);
        GL.Vertex3(1.0f, 1.0f, 1.0f);
        GL.Vertex3(1.0f, -1.0f, 1.0f);
        GL.Vertex3(-1.0f, -1.0f, 1.0f);
        GL.End();
        GL.PopMatrix();
    }
コード例 #34
0
ファイル: MeshBlit.cs プロジェクト: MaTriXy/cardboard-unity
 public static void Render(Mesh mesh, Matrix4x4 meshTRS, Camera camera, RenderTexture targetBuffer,
                           Color clearColor, Material material, int pass = 0) {
   RenderTexture activeRT = RenderTexture.active;
   Graphics.SetRenderTarget(targetBuffer);
   GL.PushMatrix();
   GL.LoadProjectionMatrix(GL.GetGPUProjectionMatrix(camera.projectionMatrix, true));
   if (material.SetPass(pass)) {
     GL.Clear(true, true, clearColor, 1f);
     Profiler.BeginSample("MeshBlit.Render.Draw Mesh Objects");
     for (int i = 0; i < mesh.subMeshCount; i++) {
       Graphics.DrawMeshNow(mesh, meshTRS, i);
     }
     Profiler.EndSample();
   }
   GL.PopMatrix();
   RenderTexture.active = activeRT;
 }
コード例 #35
0
        void DrawMesh(UnityEngine.Mesh mesh, float4x4 localToWorld)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            var wireFrame = GL.wireframe;

            GL.wireframe = true;
            var lighting = Handles.lighting;

            Handles.lighting = false;
            Shader.SetGlobalColor("_HandleColor", Handles.color);
            Shader.SetGlobalFloat("_HandleSize", 1f);
            Shader.SetGlobalMatrix("_ObjectToWorld", localToWorld);
            m_PreviewMeshMaterial.SetInt("_HandleZTest", (int)Handles.zTest);
            m_PreviewMeshMaterial.SetPass(0);
            Graphics.DrawMeshNow(mesh, localToWorld);
            Handles.lighting = lighting;
            GL.wireframe     = wireFrame;
        }
コード例 #36
0
        //https://forum.unity.com/threads/specular-convolution-when-calculating-mip-maps-for-cubemap-render-texture.617680/
        private Texture2D[] GetCubeMapFaces(Cubemap srcCubemap, string[] origAssetPathes)
        {
            var result = new Texture2D[6];

            for (int i = 0; i < 6; i += 1)
            {
                result[i] = new Texture2D(srcCubemap.width, srcCubemap.height, TextureFormat.RGBAHalf, false);
            }

            var origAssetPath = AssetDatabase.GetAssetPath(srcCubemap);
            var ext           = Path.GetExtension(origAssetPath);

            origAssetPath = origAssetPath.Replace(ext, "");
            var convolutionMaterial = new UnityEngine.Material(Shader.Find("Hidden/CubeCopy"));

            GL.PushMatrix();
            GL.LoadOrtho();
            var dstCubemap = new RenderTexture(srcCubemap.width, srcCubemap.height, 0, RenderTextureFormat.ARGBHalf);

            dstCubemap.dimension    = UnityEngine.Rendering.TextureDimension.Cube;
            dstCubemap.volumeDepth  = 6;
            dstCubemap.wrapMode     = TextureWrapMode.Clamp;
            dstCubemap.filterMode   = FilterMode.Trilinear;
            dstCubemap.isPowerOfTwo = true;
            dstCubemap.Create();
            // not support texture lod now
            var mip    = -1;
            var dstMip = 0;
            var mipRes = srcCubemap.width;

            convolutionMaterial.SetTexture("_MainTex", srcCubemap);
            convolutionMaterial.SetFloat("_Level", mip);

            convolutionMaterial.SetPass(0);

            // Positive X
            Graphics.SetRenderTarget(dstCubemap, dstMip, CubemapFace.PositiveX);
            GL.Begin(GL.QUADS);
            GL.TexCoord3(1, 1, 1);
            GL.Vertex3(1, 0, 1);
            GL.TexCoord3(1, -1, 1);
            GL.Vertex3(1, 1, 1);
            GL.TexCoord3(1, -1, -1);
            GL.Vertex3(0, 1, 1);
            GL.TexCoord3(1, 1, -1);
            GL.Vertex3(0, 0, 1);
            GL.End();
            result[0].ReadPixels(new Rect(0, 0, srcCubemap.width, srcCubemap.height), 0, 0);
            origAssetPathes[0] = origAssetPath + "-0";

            // Negative X
            Graphics.SetRenderTarget(dstCubemap, dstMip, CubemapFace.NegativeX);
            GL.Begin(GL.QUADS);
            GL.TexCoord3(-1, 1, -1);
            GL.Vertex3(1, 0, 1);
            GL.TexCoord3(-1, -1, -1);
            GL.Vertex3(1, 1, 1);
            GL.TexCoord3(-1, -1, 1);
            GL.Vertex3(0, 1, 1);
            GL.TexCoord3(-1, 1, 1);
            GL.Vertex3(0, 0, 1);
            GL.End();
            result[1].ReadPixels(new Rect(0, 0, srcCubemap.width, srcCubemap.height), 0, 0);
            origAssetPathes[1] = origAssetPath + "-1";

            // Positive Y
            Graphics.SetRenderTarget(dstCubemap, dstMip, CubemapFace.PositiveY);
            GL.Begin(GL.QUADS);
            GL.TexCoord3(-1, 1, -1);
            GL.Vertex3(0, 1, 1);
            GL.TexCoord3(-1, 1, 1);
            GL.Vertex3(0, 0, 1);
            GL.TexCoord3(1, 1, 1);
            GL.Vertex3(1, 0, 1);
            GL.TexCoord3(1, 1, -1);
            GL.Vertex3(1, 1, 1);
            GL.End();
            result[2].ReadPixels(new Rect(0, 0, srcCubemap.width, srcCubemap.height), 0, 0);
            origAssetPathes[2] = origAssetPath + "-2";

            // Negative Y
            Graphics.SetRenderTarget(dstCubemap, dstMip, CubemapFace.NegativeY);
            GL.Begin(GL.QUADS);
            GL.TexCoord3(-1, -1, 1);
            GL.Vertex3(0, 1, 1);
            GL.TexCoord3(-1, -1, -1);
            GL.Vertex3(0, 0, 1);
            GL.TexCoord3(1, -1, -1);
            GL.Vertex3(1, 0, 1);
            GL.TexCoord3(1, -1, 1);
            GL.Vertex3(1, 1, 1);
            GL.End();
            result[3].ReadPixels(new Rect(0, 0, srcCubemap.width, srcCubemap.height), 0, 0);
            origAssetPathes[3] = origAssetPath + "-3";

            // Positive Z
            Graphics.SetRenderTarget(dstCubemap, dstMip, CubemapFace.PositiveZ);
            GL.Begin(GL.QUADS);
            GL.TexCoord3(1, 1, -1);
            GL.Vertex3(1, 0, 1);
            GL.TexCoord3(1, -1, -1);
            GL.Vertex3(1, 1, 1);
            GL.TexCoord3(-1, -1, -1);
            GL.Vertex3(0, 1, 1);
            GL.TexCoord3(-1, 1, -1);
            GL.Vertex3(0, 0, 1);
            GL.End();
            result[4].ReadPixels(new Rect(0, 0, srcCubemap.width, srcCubemap.height), 0, 0);
            origAssetPathes[4] = origAssetPath + "-4";

            // Negative Z
            Graphics.SetRenderTarget(dstCubemap, dstMip, CubemapFace.NegativeZ);
            GL.Begin(GL.QUADS);
            GL.TexCoord3(-1, 1, 1);
            GL.Vertex3(1, 0, 1);
            GL.TexCoord3(-1, -1, 1);
            GL.Vertex3(1, 1, 1);
            GL.TexCoord3(1, -1, 1);
            GL.Vertex3(0, 1, 1);
            GL.TexCoord3(1, 1, 1);
            GL.Vertex3(0, 0, 1);
            GL.End();
            result[5].ReadPixels(new Rect(0, 0, srcCubemap.width, srcCubemap.height), 0, 0);
            origAssetPathes[5] = origAssetPath + "-5";

            GL.PopMatrix();

            for (int i = 0; i < 6; i += 1)
            {
                result[i].Apply();
            }

            Graphics.SetRenderTarget(null);
            UnityEngine.Object.DestroyImmediate(dstCubemap);

            return(result);
        }
コード例 #37
0
        // https://forum.unity.com/threads/specular-convolution-when-calculating-mip-maps-for-cubemap-render-texture.617680/
        private Cubemap GetSpecularCubeMap(Cubemap srcCubemap)
        {
            var convolutionMaterial = new UnityEngine.Material(Shader.Find("Hidden/CubeBlur"));

            GL.PushMatrix();
            GL.LoadOrtho();
            RenderTexture dstCubemap = new RenderTexture(srcCubemap.width, srcCubemap.height, 0, RenderTextureFormat.ARGBHalf);

            dstCubemap.dimension    = UnityEngine.Rendering.TextureDimension.Cube;
            dstCubemap.volumeDepth  = 6;
            dstCubemap.wrapMode     = TextureWrapMode.Clamp;
            dstCubemap.filterMode   = FilterMode.Trilinear;
            dstCubemap.isPowerOfTwo = true;
            dstCubemap.Create();
            var mip    = .2f;
            var dstMip = 0;
            var mipRes = srcCubemap.width;

            convolutionMaterial.SetTexture("_MainTex", srcCubemap);
            convolutionMaterial.SetFloat("_Texel", 1f / mipRes);
            convolutionMaterial.SetFloat("_Level", mip);

            convolutionMaterial.SetPass(0);

            Texture2D tex2d = new Texture2D(srcCubemap.width * 6, srcCubemap.height, TextureFormat.RGBAHalf, false);

            // Positive X
            Graphics.SetRenderTarget(dstCubemap, dstMip, CubemapFace.PositiveX);
            GL.Begin(GL.QUADS);
            GL.TexCoord3(1, 1, 1);
            GL.Vertex3(0, 0, 1);
            GL.TexCoord3(1, -1, 1);
            GL.Vertex3(0, 1, 1);
            GL.TexCoord3(1, -1, -1);
            GL.Vertex3(1, 1, 1);
            GL.TexCoord3(1, 1, -1);
            GL.Vertex3(1, 0, 1);
            GL.End();
            tex2d.ReadPixels(new Rect(0, 0, srcCubemap.width, srcCubemap.height), srcCubemap.width * 0, 0);

            // Negative X
            Graphics.SetRenderTarget(dstCubemap, dstMip, CubemapFace.NegativeX);
            GL.Begin(GL.QUADS);
            GL.TexCoord3(-1, 1, -1);
            GL.Vertex3(0, 0, 1);
            GL.TexCoord3(-1, -1, -1);
            GL.Vertex3(0, 1, 1);
            GL.TexCoord3(-1, -1, 1);
            GL.Vertex3(1, 1, 1);
            GL.TexCoord3(-1, 1, 1);
            GL.Vertex3(1, 0, 1);
            GL.End();
            tex2d.ReadPixels(new Rect(0, 0, srcCubemap.width, srcCubemap.height), srcCubemap.width * 1, 0);

            // Positive Y
            Graphics.SetRenderTarget(dstCubemap, dstMip, CubemapFace.PositiveY);
            GL.Begin(GL.QUADS);
            GL.TexCoord3(-1, 1, -1);
            GL.Vertex3(0, 0, 1);
            GL.TexCoord3(-1, 1, 1);
            GL.Vertex3(0, 1, 1);
            GL.TexCoord3(1, 1, 1);
            GL.Vertex3(1, 1, 1);
            GL.TexCoord3(1, 1, -1);
            GL.Vertex3(1, 0, 1);
            GL.End();
            tex2d.ReadPixels(new Rect(0, 0, srcCubemap.width, srcCubemap.height), srcCubemap.width * 2, 0);

            // Negative Y
            Graphics.SetRenderTarget(dstCubemap, dstMip, CubemapFace.NegativeY);
            GL.Begin(GL.QUADS);
            GL.TexCoord3(-1, -1, 1);
            GL.Vertex3(0, 0, 1);
            GL.TexCoord3(-1, -1, -1);
            GL.Vertex3(0, 1, 1);
            GL.TexCoord3(1, -1, -1);
            GL.Vertex3(1, 1, 1);
            GL.TexCoord3(1, -1, 1);
            GL.Vertex3(1, 0, 1);
            GL.End();
            tex2d.ReadPixels(new Rect(0, 0, srcCubemap.width, srcCubemap.height), srcCubemap.width * 3, 0);

            // Positive Z
            Graphics.SetRenderTarget(dstCubemap, dstMip, CubemapFace.PositiveZ);
            GL.Begin(GL.QUADS);
            GL.TexCoord3(-1, 1, 1);
            GL.Vertex3(0, 0, 1);
            GL.TexCoord3(-1, -1, 1);
            GL.Vertex3(0, 1, 1);
            GL.TexCoord3(1, -1, 1);
            GL.Vertex3(1, 1, 1);
            GL.TexCoord3(1, 1, 1);
            GL.Vertex3(1, 0, 1);
            GL.End();
            tex2d.ReadPixels(new Rect(0, 0, srcCubemap.width, srcCubemap.height), srcCubemap.width * 4, 0);

            // Negative Z
            Graphics.SetRenderTarget(dstCubemap, dstMip, CubemapFace.NegativeZ);
            GL.Begin(GL.QUADS);
            GL.TexCoord3(1, 1, -1);
            GL.Vertex3(0, 0, 1);
            GL.TexCoord3(1, -1, -1);
            GL.Vertex3(0, 1, 1);
            GL.TexCoord3(-1, -1, -1);
            GL.Vertex3(1, 1, 1);
            GL.TexCoord3(-1, 1, -1);
            GL.Vertex3(1, 0, 1);
            GL.End();
            tex2d.ReadPixels(new Rect(0, 0, srcCubemap.width, srcCubemap.height), srcCubemap.width * 5, 0);

            GL.PopMatrix();

            tex2d.Apply();

            for (int x = 0; x < tex2d.width; x++)
            {
                for (int y1 = 0, y2 = tex2d.height - 1; y1 < y2; y1++, y2--)
                {
                    var t1 = tex2d.GetPixel(x, y1);
                    tex2d.SetPixel(x, y1, tex2d.GetPixel(x, y2));
                    tex2d.SetPixel(x, y2, t1);
                }
            }

            UnityEngine.Object.DestroyImmediate(dstCubemap);

            var path = "Assets/temp" + DateTime.Now.ToBinary() + ".exr";

            File.WriteAllBytes(path, tex2d.EncodeToEXR());
            AssetDatabase.Refresh();
            TextureImporter im = AssetImporter.GetAtPath(path) as TextureImporter;

            im.isReadable   = true;
            im.textureShape = TextureImporterShape.TextureCube;
            im.SaveAndReimport();

            return(AssetDatabase.LoadAssetAtPath <Cubemap>(path));
        }