Search Unity

DrawPreviewTexture -- any way to clip it?

Discussion in 'Immediate Mode GUI (IMGUI)' started by ArenMook, Dec 5, 2011.

  1. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    The topic pretty much sums it up. I had this:

    GUI.BeginGroup(rect);
    GUI.DrawTexture(drawRect, tex);
    GUI.EndGroup();

    Everything was fine, but in order to support materials I switched to EditorGUI.DrawPreviewTexture instead of GUI.DrawTexture. Unfortunately now the drawing is no longer clipped by the BeginGroup. Intentional? Bug? Any work-arounds?

    P.S. Using DrawPreviewTexture(drawRect, tex) works fine -- it gets clipped. It's only no longer clipped when I add the Material property -- DrawPreviewTexture(drawRect, tex, mat);
     
    Last edited: Dec 5, 2011
    chadfranklin47 and einWikinger like this.
  2. einWikinger

    einWikinger

    Joined:
    Jul 30, 2013
    Posts:
    97
    Just stumbled upon the same problem. I have a custom shader for previewing a texture and needed to use DrawPreviewTexture to have it draw with my custom shader in a custom material.

    The solution is to look at the shader "Internal-GUITextureClip.shader" from the builtin shaders package (download link can be found on the unity download page). It has some additional properties that need to be utilized to properly clip the output:

    sampler2D _GUIClipTexture;
    uniform float4x4 unity_GUIClipTextureMatrix;


    Take a look at the internal shader, which is really simple, to integrate it into your own shader (or directly utilize the internal shader in your material for DrawPreviewTexture).
     
    chadfranklin47, dandrea and kdkd like this.