Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Drawing fullscreen GL.QUAD on Mac; surprise Lightmap.

Discussion in 'Editor & General Support' started by TheShane, Oct 21, 2013.

  1. TheShane

    TheShane

    Joined:
    May 26, 2013
    Posts:
    136
    I am attempting to draw a screen quad for a simple full screen texture overlay effect.

    I am using GL in the OnRenderObject() function of a script attached to my main camera:

    Code (csharp):
    1.    
    2. void OnRenderObject()  
    3. {
    4.         GL.PushMatrix();
    5.  
    6.         material.SetPass(0);
    7.        
    8.         GL.LoadOrtho();
    9.        
    10.         GL.Begin(GL.QUADS);
    11.         GL.TexCoord2(0, 0);
    12.         GL.Vertex3(0, 0, 0);
    13.         GL.TexCoord2(0, 1);
    14.         GL.Vertex3(0, 1, 0);
    15.         GL.TexCoord2(1, 1);
    16.         GL.Vertex3(1, 1, 0);
    17.         GL.TexCoord2(1, 0);
    18.         GL.Vertex3(1, 0, 0);
    19.         GL.End();
    20.        
    21.         GL.PopMatrix();    
    22. }
    My shader looks like this. Right now it is a solid color shader (I commented out the texture for now):

    Code (csharp):
    1.     SubShader {
    2.         Tags { "RenderType"="Opaque" }
    3.         LOD 200
    4.        
    5.         CGPROGRAM
    6.         #pragma surface surf NoLighting
    7.        
    8.         fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten)
    9.         {
    10.             fixed4 c;
    11.             c.rgb = s.Albedo;
    12.             c.a = s.Alpha;
    13.             return c;
    14.         }      
    15.  
    16.         //sampler2D _MainTex;
    17.  
    18.         struct Input {
    19.             float2 uv_MainTex;
    20.         };
    21.  
    22.         void surf (Input IN, inout SurfaceOutput o) {
    23.             //half4 c = tex2D (_MainTex, IN.uv_MainTex);
    24.             o.Albedo= float3(1,1,0);//c.rgb;
    25.             o.Alpha = 1;//c.a; 
    26.         }
    27.         ENDCG
    28.     }
    When I draw it, I should see a yellow screen, but instead I see one of my two lightmaps rendered over the yellow. Depending on where I look it seems to flicker between them or none at all. If I leave the texcoords out of the quads, it flickers yellow (i.e. apparently the same behaviour except only sampling the texture at 0,0). If I use a texture, that texture gets a lightmap overlay.

    I only have on active camera in the scene that clears to skybox. The behaviour is the same if I put the GL code into OnPostRender(). I just upgraded to the newest Unity 4.2.2f1 (did not try it in any earlier versions).

    There should be nothing else drawing to the scene, but it seems like somehow my quad is getting left over and something is rendering the lightmap to it? I don't have any other scripts on the camera (I disabled the GUILayer and Flare Layer) except for MouseLook.

    Alternatively, I tried using Graphics.DrawTexture (in OnRenderObject or OnPostRender). Despite its description, it has the less-then-helpful behaviour of rendering the quad in world space not screen space. So I get a textured 1024 by 768 meter wall appearing in my scene instead of overlaying the camera.

    So I am looking for suggestions as to why this is happening, or else a working solution to draw a textured full-screen quad. This should be a relatively straight-forward task. There is Graphics.Blit, but that is listed as "Pro Only" and my trial is going to expire sometime in the next week (the overlay image effect without Blit is actually what I am trying to accomplish).

    Thanks for any thoughts!
     
  2. TheShane

    TheShane

    Joined:
    May 26, 2013
    Posts:
    136
    Solved my own problem.

    Apparently, the info I Googled on making an unlit surface shader was incorrect. I switched it to an unlit vertex/frag shader and now everything is working. Obviously, I needed to turn off some type of lightmapping options in the surface shader that was being added automatically. Easier in this case to simply not use a surface shader.