Home | History | Annotate | Download | only in gpu_tonemapper
      1 /*
      2  * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
      3  * Not a Contribution.
      4  *
      5  * Copyright 2015 The Android Open Source Project
      6  *
      7  * Licensed under the Apache License, Version 2.0 (the "License");
      8  * you may not use this file except in compliance with the License.
      9  * You may obtain a copy of the License at
     10  *
     11  *      http://www.apache.org/licenses/LICENSE-2.0
     12  *
     13  * Unless required by applicable law or agreed to in writing, software
     14  * distributed under the License is distributed on an "AS IS" BASIS,
     15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16  * See the License for the specific language governing permissions and
     17  * limitations under the License.
     18  */
     19 
     20 const char* rgba_inverse_tonemap_shader = ""
     21     "#extension GL_OES_EGL_image_external_essl3 : require                                               \n"
     22     "precision highp float;                                                                             \n"
     23     "precision highp sampler2D;                                                                         \n"
     24     "layout(binding = 0) uniform samplerExternalOES externalTexture;                                    \n"
     25     "layout(binding = 1) uniform sampler3D tonemapper;                                                  \n"
     26     "layout(binding = 2) uniform sampler2D xform;                                                       \n"
     27     "layout(location = 3) uniform vec2 tSO;                                                             \n"
     28     "#if defined(USE_NONUNIFORM_SAMPLING)                                                               \n"
     29     "layout(location = 4) uniform vec2 xSO;                                                             \n"
     30     "#endif                                                                                             \n"
     31     "in vec2 uv;                                                                                        \n"
     32     "out vec4 fs_color;                                                                                 \n"
     33     "                                                                                                   \n"
     34     "vec3 ScaleOffset(in vec3 samplePt, in vec2 so)                                                     \n"
     35     "{                                                                                                  \n"
     36     "   vec3 adjPt = so.x * samplePt + so.y;                                                            \n"
     37     "   return adjPt;                                                                                   \n"
     38     "}                                                                                                  \n"
     39     "                                                                                                   \n"
     40     "void main()                                                                                        \n"
     41     "{                                                                                                  \n"
     42     "vec2 flipped = vec2(uv.x, 1.0f - uv.y);                                                            \n"
     43     "vec4 rgb_premulalpha = texture(externalTexture, flipped);                                          \n"
     44     "fs_color = rgb_premulalpha;                                                                        \n"
     45     "if( rgb_premulalpha.a > 0.0 ) {                                                                    \n"
     46     "vec3 rgb = rgb_premulalpha.rgb/rgb_premulalpha.a;                                                  \n"
     47     "#if defined(USE_NONUNIFORM_SAMPLING)                                                               \n"
     48     "vec3 adj = ScaleOffset(rgb.xyz, xSO);                                                              \n"
     49     "float r = texture(xform, vec2(adj.r, 0.5f)).r;                                                     \n"
     50     "float g = texture(xform, vec2(adj.g, 0.5f)).g;                                                     \n"
     51     "float b = texture(xform, vec2(adj.b, 0.5f)).b;                                                     \n"
     52     "#else                                                                                              \n"
     53     "float r = rgb.r;                                                                                   \n"
     54     "float g = rgb.g;                                                                                   \n"
     55     "float b = rgb.b;                                                                                   \n"
     56     "#endif                                                                                             \n"
     57     "fs_color.rgb = texture(tonemapper, ScaleOffset(vec3(r, g, b), tSO)).rgb * rgb_premulalpha.a;       \n"
     58     "fs_color.a = rgb_premulalpha.a;                                                                    \n"
     59     "}                                                                                                  \n"
     60     "}                                                                                                  \n";
     61