Revision 47511918
Added by Leszek Koltunski over 7 years ago
| src/main/java/org/distorted/library/main/Distorted.java | ||
|---|---|---|
| 119 | 119 | 
    final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();  | 
| 120 | 120 | 
        android.util.Log.e("DISTORTED", "Using OpenGL ES "+configurationInfo.getGlEsVersion());
   | 
| 121 | 121 | 
     | 
| 122 | 
        GLSL = ( (configurationInfo.reqGlEsVersion>>16)>=3 ? 300 : 100 );
   | 
|
| 123 | 
        GLSL_VERSION= (GLSL==100 ? "#version 100\n" : "#version 300 es\n");
   | 
|
| 122 | 
        GLSL = ( (configurationInfo.reqGlEsVersion>>16)>=3 ? 310 : 100 );
   | 
|
| 123 | 
        GLSL_VERSION= (GLSL==100 ? "#version 100\n" : "#version 310 es\n");
   | 
|
| 124 | 124 | 
     | 
| 125 | 125 | 
    EffectMessageSender.startSending();  | 
| 126 | 126 | 
     | 
| src/main/java/org/distorted/library/program/DistortedProgram.java | ||
|---|---|---|
| 292 | 292 | 
    final int[] compileStatus = new int[1];  | 
| 293 | 293 | 
    GLES31.glGetShaderiv(shaderHandle, GLES31.GL_COMPILE_STATUS, compileStatus, 0);  | 
| 294 | 294 | 
     | 
| 295 | 
          if (compileStatus[0] != GLES31.GL_TRUE )
   | 
|
| 295 | 
    if (compileStatus[0] != GLES31.GL_TRUE)  | 
|
| 296 | 296 | 
            {
   | 
| 297 | 
    GLES31.glDeleteShader(shaderHandle);  | 
|
| 298 | 
    shaderHandle = 0;  | 
|
| 299 | 
    }  | 
|
| 300 | 
    }  | 
|
| 297 | 
    String error = GLES31.glGetShaderInfoLog(shaderHandle);  | 
|
| 301 | 298 | 
     | 
| 302 | 
    if (shaderHandle == 0)  | 
|
| 303 | 
          {
   | 
|
| 304 | 
    String error = GLES31.glGetShaderInfoLog(shaderHandle);  | 
|
| 299 | 
            //android.util.Log.e("Program", "error compiling :" + error);
   | 
|
| 305 | 300 | 
     | 
| 306 | 
          //android.util.Log.e("Program", "error compiling :"+error);
   | 
|
| 301 | 
            GLES31.glDeleteShader(shaderHandle);
   | 
|
| 307 | 302 | 
     | 
| 308 | 
    switch(shaderType)  | 
|
| 309 | 
            {
   | 
|
| 310 | 
    case GLES31.GL_VERTEX_SHADER : throw new VertexCompilationException(error);  | 
|
| 311 | 
    case GLES31.GL_FRAGMENT_SHADER: throw new FragmentCompilationException(error);  | 
|
| 312 | 
    default : throw new RuntimeException(error);  | 
|
| 303 | 
    switch (shaderType)  | 
|
| 304 | 
              {
   | 
|
| 305 | 
    case GLES31.GL_VERTEX_SHADER: throw new VertexCompilationException(error);  | 
|
| 306 | 
    case GLES31.GL_FRAGMENT_SHADER: throw new FragmentCompilationException(error);  | 
|
| 307 | 
    default: throw new RuntimeException(error);  | 
|
| 308 | 
    }  | 
|
| 313 | 309 | 
    }  | 
| 314 | 310 | 
    }  | 
| 315 | 311 | 
     | 
| ... | ... | |
| 447 | 443 | 
    * Create a new Shader Program from two source strings.  | 
| 448 | 444 | 
    * <p>  | 
| 449 | 445 | 
    * Needs to be called from a thread holding the OpenGL context.  | 
| 450 | 
    * Assumed to hold GLSL 'version 300 es' source.  | 
|
| 451 | 446 | 
    *  | 
| 452 | 447 | 
    * @param vertex Vertex shader code.  | 
| 453 | 448 | 
    * @param fragment Fragment shader code.  | 
| src/main/res/raw/blit_depth_fragment_shader.glsl | ||
|---|---|---|
| 18 | 18 | 
    //////////////////////////////////////////////////////////////////////////////////////////////  | 
| 19 | 19 | 
     | 
| 20 | 20 | 
    precision highp float;  | 
| 21 | 
    precision highp uint;
   | 
|
| 21 | 
    precision highp int;  | 
|
| 22 | 22 | 
     | 
| 23 | 23 | 
    #if __VERSION__ != 100  | 
| 24 | 24 | 
    out vec4 fragColor; // The output color  | 
| ... | ... | |
| 56 | 56 | 
    // This arranges fragments by decreasing 'depth', so one would think - from back to front, but  | 
| 57 | 57 | 
    // in main() below the depth is mapped with S*(1-depth)/2, so it is really front to back.  | 
| 58 | 58 | 
     | 
| 59 | 
    void insert( vec2 ij, uint depth, uint rgba )  | 
|
| 59 | 
    void insert2( vec2 ij, uint depth, uint rgba )
   | 
|
| 60 | 60 | 
      {
   | 
| 61 | 
    uint ptr = atomicCounterIncrement(u_Counter)-1u;  | 
|
| 61 | 
    /*  | 
|
| 62 | 
    uint index = uint(ij.x + ij.y * float(u_Size.x));  | 
|
| 63 | 
    u_Records[index] = (255u<<24u)+ uint( (int(255*int(ij.y)/u_Size.y))<<16u ) + (255u);  | 
|
| 64 | 
    discard;  | 
|
| 65 | 
    */  | 
|
| 66 | 
     | 
|
| 67 | 
    uint ptr = atomicCounterIncrement(u_Counter);  | 
|
| 62 | 68 | 
     | 
| 63 | 69 | 
    if( ptr<u_numRecords )  | 
| 64 | 
        {/*
   | 
|
| 65 | 
    uint color;  | 
|
| 66 | 
    vec2 c = vec2(0.0,1.0);  | 
|
| 70 | 
        {
   | 
|
| 71 | 
    ptr = ptr /*uint(ij.x + ij.y * float(u_Size.x))*/ + uint(u_Size.x*u_Size.y);  | 
|
| 67 | 72 | 
     | 
| 68 | 
    uint rgb = ((uint(255.0*c.x))<<16u) + uint(255.0*c.y);  | 
|
| 73 | 
    u_Records[ptr ] = (255u<<( (4*int(ij.x) > u_Size.x) ? 24u:16u)) + (255u);  | 
|
| 74 | 
    //u_Records[ptr+1u] = depth;  | 
|
| 75 | 
    //u_Records[ptr+2u] = rgba;  | 
|
| 69 | 76 | 
     | 
| 70 | 
    if( rgb == 0u ) color = (255u<<24u) + (255u<<16u) + 255u;  | 
|
| 71 | 
    else if( (rgb&255u) == 0u ) color = (255u<<24u) + 255u;  | 
|
| 72 | 
    else if( (rgb&255u) <= 50u ) color = (255u<<16u) + 255u;  | 
|
| 73 | 
    else if( (rgb&255u) == 255u) color = (255u<<16u) + (255u<< 8u) + 255u;  | 
|
| 74 | 
    else color = (255u<< 8u) + 255u;  | 
|
| 75 | 
    */  | 
|
| 76 | 
    vec4 c= vec4(1.0,1.0,0.0,1.0);  | 
|
| 77 | 
    uint color = ((uint(255.0*c.r))<<24u) + ((uint(255.0*c.g))<<16u) + ((uint(255.0*c.b))<<8u) + uint(255.0*c.a);  | 
|
| 77 | 
    uint index = uint(ij.x + ij.y * float(u_Size.x));  | 
|
| 78 | 
    u_Records[index] = ptr;  | 
|
| 79 | 
    discard;  | 
|
| 80 | 
    }  | 
|
| 81 | 
    }  | 
|
| 82 | 
     | 
|
| 83 | 
    void insert( vec2 ij, uint depth, uint rgba )  | 
|
| 84 | 
      {
   | 
|
| 85 | 
    uint ptr = atomicCounterIncrement(u_Counter);  | 
|
| 78 | 86 | 
     | 
| 87 | 
    if( ptr<u_numRecords )  | 
|
| 88 | 
        {
   | 
|
| 79 | 89 | 
    ptr = 3u*ptr + uint(u_Size.x*u_Size.y);  | 
| 80 | 90 | 
     | 
| 81 | 91 | 
    u_Records[ptr ] = 0u;  | 
| ... | ... | |
| 138 | 148 | 
      {
   | 
| 139 | 149 | 
    vec4 frag = TEXTURE(u_Texture , v_TexCoordinate);  | 
| 140 | 150 | 
    float depth= TEXTURE(u_DepthTexture, v_TexCoordinate).r;  | 
| 141 | 
     | 
|
| 151 | 
    /*  | 
|
| 142 | 152 | 
    if( frag.a > 0.95 )  | 
| 143 | 153 | 
        {
   | 
| 144 | 154 | 
    gl_FragDepth = depth;  | 
| 145 | 155 | 
    FRAG_COLOR = frag;  | 
| 146 | 156 | 
    }  | 
| 147 | 157 | 
    else if( frag.a > 0.0 )  | 
| 148 | 
        {
   | 
|
| 158 | 
        {*/
   | 
|
| 149 | 159 | 
    const float S= 2147483647.0; // max signed int. Could probably be max unsigned int but this is enough.  | 
| 150 | 
    insert(v_Pixel, uint(S*(1.0-depth)/2.0), convert(frag) );  | 
|
| 151 | 
    discard;  | 
|
| 152 | 
    }  | 
|
| 160 | 
    insert2(v_Pixel, uint(S*(1.0-depth)/2.0), convert(frag) );  | 
|
| 161 | 
    //}  | 
|
| 153 | 162 | 
    }  | 
| src/main/res/raw/blit_depth_render_fragment_shader.glsl | ||
|---|---|---|
| 18 | 18 | 
    //////////////////////////////////////////////////////////////////////////////////////////////  | 
| 19 | 19 | 
     | 
| 20 | 20 | 
    precision highp float;  | 
| 21 | 
    precision highp uint;
   | 
|
| 21 | 
    precision highp int;  | 
|
| 22 | 22 | 
     | 
| 23 | 23 | 
    #if __VERSION__ != 100  | 
| 24 | 24 | 
    out vec4 fragColor; // The output color  | 
| ... | ... | |
| 66 | 66 | 
    void main()  | 
| 67 | 67 | 
      {
   | 
| 68 | 68 | 
    uint index = uint(v_Pixel.x + v_Pixel.y * float(u_Size.x));  | 
| 69 | 
    uint ptr = u_Records[index];  | 
|
| 69 | 70 | 
     | 
| 70 | 
      if( u_Records[index] == 0u ) discard;
   | 
|
| 71 | 
      if( ptr == 0u ) discard;
   | 
|
| 71 | 72 | 
    else  | 
| 72 | 73 | 
        {
   | 
| 73 | 
    index = u_Records[index];  | 
|
| 74 | 
    FRAG_COLOR = convert(u_Records[index+2u]);  | 
|
| 74 | 
    u_Records[index] = 0u;  | 
|
| 75 | 
    vec4 color = convert(u_Records[ptr]);  | 
|
| 76 | 
     | 
|
| 77 | 
    if( (4*int(v_Pixel.x) > u_Size.x) && color.r==1.0 ) FRAG_COLOR = color;  | 
|
| 78 | 
    else if( (4*int(v_Pixel.x) <=u_Size.x) && color.g==1.0 ) FRAG_COLOR = color;  | 
|
| 79 | 
    else FRAG_COLOR = vec4(0.0,0.0,1.0,1.0);  | 
|
| 80 | 
    //FRAG_COLOR = convert(u_Records[index]);  | 
|
| 81 | 
    //u_Records[index] = 0u;  | 
|
| 75 | 82 | 
    }  | 
| 76 | 83 | 
     | 
| 77 | 
    u_Records[index] = 0u;  | 
|
| 78 | 
     | 
|
| 79 | 84 | 
    /*  | 
| 80 | 85 | 
    uint index = uint(v_Pixel.x + v_Pixel.y * float(u_Size.x));  | 
| 81 | 86 | 
    uint curr = u_Records[index];  | 
| src/main/res/raw/blit_depth_vertex_shader.glsl | ||
|---|---|---|
| 17 | 17 | 
    // along with Distorted. If not, see <http://www.gnu.org/licenses/>. //  | 
| 18 | 18 | 
    //////////////////////////////////////////////////////////////////////////////////////////////  | 
| 19 | 19 | 
     | 
| 20 | 
    precision lowp float;
   | 
|
| 21 | 
    precision highp uint;
   | 
|
| 20 | 
    precision highp float;
   | 
|
| 21 | 
    precision highp int;  | 
|
| 22 | 22 | 
     | 
| 23 | 23 | 
    #if __VERSION__ != 100  | 
| 24 | 24 | 
    in vec2 a_Position; // Per-vertex position.  | 
Also available in: Unified diff
Order Independent Transparency: some progress