Search Unity

GLSLPROGRAM shader using specific OpenGL ES extensions

Discussion in 'Shaders' started by TheShane, Nov 26, 2013.

  1. TheShane

    TheShane

    Joined:
    May 26, 2013
    Posts:
    136
    I'm writing an iOS specific GLSL shader that uses the "GL_EXT_shader_framebuffer_fetch" extension for custom blending.

    This is my simple shader:
    Code (csharp):
    1.  
    2. Shader "Hidden/TestEffect" {
    3.  
    4. Properties {
    5. }
    6.  
    7. SubShader {
    8.  
    9.     Tags { "Queue" = "Overlay" }
    10.  
    11.     ZWrite Off
    12.  
    13.     Pass {
    14.          
    15.         GLSLPROGRAM
    16.         #extension GL_EXT_shader_framebuffer_fetch : require
    17.  
    18.         #ifdef VERTEX
    19.  
    20.         void main() {
    21.             gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    22.         }
    23.  
    24.         #endif
    25.  
    26.         #ifdef FRAGMENT
    27.  
    28.         void main() {      
    29.             gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);
    30.         }
    31.  
    32.         #endif      
    33.  
    34.         ENDGLSL
    35.  
    36.     }
    37. }
    38.  
    39. Fallback Off
    40.  
    41. }
    But I get this error:
    Code (csharp):
    1. Shader error in 'Hidden/TestEffect': GLSL Error in Vertex Shader: ERROR: 0:20: '' :  extension 'GL_EXT_shader_framebuffer_fetch' is not supported
    2.  at line 0
    This is expected since I am running the Unity editor on a Mac. How do I get rid of this error? The #pragma only_renderers option seems to only be available within a CGPROGRAM block, and there is not a lot of documentation on using GLSLPROGRAM (I found a total of one page with a couple paragraphs in the Unity docs). How do I get it to ignore platforms where it is not supported? At runtime I can easily check Shader.isSupported() to find which shaders are supported.

    I was also having trouble getting material keywords working properly with the GLSLPROGRAM, and including .glslinc files.

    Any examples out there of the correct way to set up shaders that use specific GLES extensions with Unity? I've been doing some searches but haven't come up with much yet.

    The error itself isn't a big problem assuming it works on iOS devices, but I might have many shaders and other extensions that are all throwing these useless errors which will make it harder to find real errors.