gpu_tonemapper: Adjust sample points to maintain linearity
Adjust texture sample points to maintain linearity throughout the sample range CRs-Fixed: 1110654 Change-Id: I2c198c9f330a0b6001d2eda28c0355f2c9ecbde4
This commit is contained in:
committed by
Sushil Chauhan
parent
f0b7c337ec
commit
1d1e57dc0e
@@ -33,6 +33,12 @@ Tonemapper::Tonemapper()
|
|||||||
lutXformTexture = 0;
|
lutXformTexture = 0;
|
||||||
programID = 0;
|
programID = 0;
|
||||||
eglImageWrapper = new EGLImageWrapper();
|
eglImageWrapper = new EGLImageWrapper();
|
||||||
|
|
||||||
|
lutXformScaleOffset[0] = 1.0f;
|
||||||
|
lutXformScaleOffset[1] = 0.0f;
|
||||||
|
|
||||||
|
tonemapScaleOffset[0] = 1.0f;
|
||||||
|
tonemapScaleOffset[1] = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -72,9 +78,17 @@ Tonemapper *Tonemapper::build(int type, void *colorMap, int colorMapSize, void *
|
|||||||
|
|
||||||
// load the 3d lut
|
// load the 3d lut
|
||||||
tonemapper->tonemapTexture = engine_load3DTexture(colorMap, colorMapSize, 0);
|
tonemapper->tonemapTexture = engine_load3DTexture(colorMap, colorMapSize, 0);
|
||||||
|
tonemapper->tonemapScaleOffset[0] = ((float)(colorMapSize-1))/((float)(colorMapSize));
|
||||||
|
tonemapper->tonemapScaleOffset[1] = 1.0f/(2.0f*colorMapSize);
|
||||||
|
|
||||||
// load the non-uniform xform
|
// load the non-uniform xform
|
||||||
tonemapper->lutXformTexture = engine_load1DTexture(lutXform, lutXformSize, 0);
|
tonemapper->lutXformTexture = engine_load1DTexture(lutXform, lutXformSize, 0);
|
||||||
bool bUseXform = (tonemapper->lutXformTexture != 0) && (lutXformSize != 0);
|
bool bUseXform = (tonemapper->lutXformTexture != 0) && (lutXformSize != 0);
|
||||||
|
if( bUseXform )
|
||||||
|
{
|
||||||
|
tonemapper->lutXformScaleOffset[0] = ((float)(lutXformSize-1))/((float)(lutXformSize));
|
||||||
|
tonemapper->lutXformScaleOffset[1] = 1.0f/(2.0f*lutXformSize);
|
||||||
|
}
|
||||||
|
|
||||||
// create the program
|
// create the program
|
||||||
const char *fragmentShaders[3];
|
const char *fragmentShaders[3];
|
||||||
@@ -115,6 +129,13 @@ int Tonemapper::blit(const void *dst, const void *src, int srcFenceFd)
|
|||||||
// bind the program
|
// bind the program
|
||||||
engine_setProgram(programID);
|
engine_setProgram(programID);
|
||||||
|
|
||||||
|
engine_setData2f(3, tonemapScaleOffset);
|
||||||
|
bool bUseXform = (lutXformTexture != 0);
|
||||||
|
if( bUseXform )
|
||||||
|
{
|
||||||
|
engine_setData2f(4, lutXformScaleOffset);
|
||||||
|
}
|
||||||
|
|
||||||
// set destination
|
// set destination
|
||||||
engine_setDestination(dst_buffer->getFramebuffer(), 0, 0, dst_buffer->getWidth(),
|
engine_setDestination(dst_buffer->getFramebuffer(), 0, 0, dst_buffer->getWidth(),
|
||||||
dst_buffer->getHeight());
|
dst_buffer->getHeight());
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ class Tonemapper {
|
|||||||
unsigned int tonemapTexture;
|
unsigned int tonemapTexture;
|
||||||
unsigned int lutXformTexture;
|
unsigned int lutXformTexture;
|
||||||
unsigned int programID;
|
unsigned int programID;
|
||||||
|
float lutXformScaleOffset[2];
|
||||||
|
float tonemapScaleOffset[2];
|
||||||
EGLImageWrapper* eglImageWrapper;
|
EGLImageWrapper* eglImageWrapper;
|
||||||
Tonemapper();
|
Tonemapper();
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ void engine_set2DInputBuffer(int binding, unsigned int textureID);
|
|||||||
void engine_set3DInputBuffer(int binding, unsigned int textureID);
|
void engine_set3DInputBuffer(int binding, unsigned int textureID);
|
||||||
void engine_setExternalInputBuffer(int binding, unsigned int textureID);
|
void engine_setExternalInputBuffer(int binding, unsigned int textureID);
|
||||||
void engine_setDestination(int id, int x, int y, int w, int h);
|
void engine_setDestination(int id, int x, int y, int w, int h);
|
||||||
|
void engine_setData2f(int loc, float* data);
|
||||||
|
|
||||||
int engine_blit(int);
|
int engine_blit(int);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
|
||||||
* Not a Contribution.
|
* Not a Contribution.
|
||||||
*
|
*
|
||||||
* Copyright 2015 The Android Open Source Project
|
* Copyright 2015 The Android Open Source Project
|
||||||
@@ -24,22 +24,32 @@ const char* forward_tonemap_shader = ""
|
|||||||
"layout(binding = 0) uniform samplerExternalOES externalTexture; \n"
|
"layout(binding = 0) uniform samplerExternalOES externalTexture; \n"
|
||||||
"layout(binding = 1) uniform sampler3D tonemapper; \n"
|
"layout(binding = 1) uniform sampler3D tonemapper; \n"
|
||||||
"layout(binding = 2) uniform sampler2D xform; \n"
|
"layout(binding = 2) uniform sampler2D xform; \n"
|
||||||
|
"layout(location = 3) uniform vec2 tSO; \n"
|
||||||
|
"#ifdef USE_NONUNIFORM_SAMPLING \n"
|
||||||
|
"layout(location = 4) uniform vec2 xSO; \n"
|
||||||
|
"#endif \n"
|
||||||
"in vec2 uv; \n"
|
"in vec2 uv; \n"
|
||||||
"out vec4 fs_color; \n"
|
"out vec4 fs_color; \n"
|
||||||
|
" \n"
|
||||||
|
"vec3 ScaleOffset(in vec3 samplePt, in vec2 so) \n"
|
||||||
|
"{ \n"
|
||||||
|
" vec3 adjPt = so.x * samplePt + so.y; \n"
|
||||||
|
" return adjPt; \n"
|
||||||
|
"} \n"
|
||||||
|
" \n"
|
||||||
"void main() \n"
|
"void main() \n"
|
||||||
"{ \n"
|
"{ \n"
|
||||||
"vec2 flipped = uv; \n"
|
"vec2 flipped = vec2(uv.x, 1.0f - uv.y); \n"
|
||||||
"flipped.y = 1.0 - flipped.y; \n"
|
|
||||||
"flipped.x = flipped.x; \n"
|
|
||||||
"vec4 rgb = texture(externalTexture, flipped); \n"
|
"vec4 rgb = texture(externalTexture, flipped); \n"
|
||||||
"#ifdef USE_NONUNIFORM_SAMPLING \n"
|
"#ifdef USE_NONUNIFORM_SAMPLING \n"
|
||||||
"float r = texture(xform, vec2(r, 0.0f)).r; \n"
|
"vec3 adj = ScaleOffset(rgb.xyz, xSO); \n"
|
||||||
"float g = texture(xform, vec2(g, 0.0f)).g; \n"
|
"float r = texture(xform, vec2(adj.r, 0.5f)).r; \n"
|
||||||
"float b = texture(xform, vec2(b, 0.0f)).b; \n"
|
"float g = texture(xform, vec2(adj.g, 0.5f)).g; \n"
|
||||||
|
"float b = texture(xform, vec2(adj.b, 0.5f)).b; \n"
|
||||||
"#else \n"
|
"#else \n"
|
||||||
"float r = rgb.r; \n"
|
"float r = rgb.r; \n"
|
||||||
"float g = rgb.g; \n"
|
"float g = rgb.g; \n"
|
||||||
"float b = rgb.b; \n"
|
"float b = rgb.b; \n"
|
||||||
"#endif \n"
|
"#endif \n"
|
||||||
"fs_color.rgb = texture(tonemapper, vec3(r, g, b)).rgb; \n"
|
"fs_color.rgb = texture(tonemapper, ScaleOffset(vec3(r, g, b), tSO)).rgb; \n"
|
||||||
"} \n";
|
"} \n";
|
||||||
|
|||||||
@@ -120,6 +120,13 @@ void engine_deleteProgram(unsigned int id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void engine_setData2f(int location, float* data)
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
{
|
||||||
|
GL(glUniform2f(location, data[0], data[1]));
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
unsigned int engine_load3DTexture(void *colorMapData, int sz, int format)
|
unsigned int engine_load3DTexture(void *colorMapData, int sz, int format)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
|
||||||
* Not a Contribution.
|
* Not a Contribution.
|
||||||
*
|
*
|
||||||
* Copyright 2015 The Android Open Source Project
|
* Copyright 2015 The Android Open Source Project
|
||||||
@@ -24,27 +24,37 @@ const char* rgba_inverse_tonemap_shader = ""
|
|||||||
"layout(binding = 0) uniform samplerExternalOES externalTexture; \n"
|
"layout(binding = 0) uniform samplerExternalOES externalTexture; \n"
|
||||||
"layout(binding = 1) uniform sampler3D tonemapper; \n"
|
"layout(binding = 1) uniform sampler3D tonemapper; \n"
|
||||||
"layout(binding = 2) uniform sampler2D xform; \n"
|
"layout(binding = 2) uniform sampler2D xform; \n"
|
||||||
|
"layout(location = 3) uniform vec2 tSO; \n"
|
||||||
|
"#if defined(USE_NONUNIFORM_SAMPLING) \n"
|
||||||
|
"layout(location = 4) uniform vec2 xSO; \n"
|
||||||
|
"#endif \n"
|
||||||
"in vec2 uv; \n"
|
"in vec2 uv; \n"
|
||||||
"out vec4 fs_color; \n"
|
"out vec4 fs_color; \n"
|
||||||
|
" \n"
|
||||||
|
"vec3 ScaleOffset(in vec3 samplePt, in vec2 so) \n"
|
||||||
|
"{ \n"
|
||||||
|
" vec3 adjPt = so.x * samplePt + so.y; \n"
|
||||||
|
" return adjPt; \n"
|
||||||
|
"} \n"
|
||||||
|
" \n"
|
||||||
"void main() \n"
|
"void main() \n"
|
||||||
"{ \n"
|
"{ \n"
|
||||||
"vec2 flipped = uv; \n"
|
"vec2 flipped = vec2(uv.x, 1.0f - uv.y); \n"
|
||||||
"flipped.y = 1.0 - flipped.y; \n"
|
|
||||||
"flipped.x = flipped.x; \n"
|
|
||||||
"vec4 rgb_premulalpha = texture(externalTexture, flipped); \n"
|
"vec4 rgb_premulalpha = texture(externalTexture, flipped); \n"
|
||||||
"fs_color = rgb_premulalpha; \n"
|
"fs_color = rgb_premulalpha; \n"
|
||||||
"if( rgb_premulalpha.a > 0.0 ) { \n"
|
"if( rgb_premulalpha.a > 0.0 ) { \n"
|
||||||
"vec3 rgb = rgb_premulalpha.rgb/rgb_premulalpha.a; \n"
|
"vec3 rgb = rgb_premulalpha.rgb/rgb_premulalpha.a; \n"
|
||||||
"#if defined(USE_NONUNIFORM_SAMPLING) \n"
|
"#if defined(USE_NONUNIFORM_SAMPLING) \n"
|
||||||
"float r = texture(xform, vec2(rgb.r, 0.0f)).r; \n"
|
"vec3 adj = ScaleOffset(rgb.xyz, xSO); \n"
|
||||||
"float g = texture(xform, vec2(rgb.g, 0.0f)).g; \n"
|
"float r = texture(xform, vec2(adj.r, 0.5f)).r; \n"
|
||||||
"float b = texture(xform, vec2(rgb.b, 0.0f)).b; \n"
|
"float g = texture(xform, vec2(adj.g, 0.5f)).g; \n"
|
||||||
|
"float b = texture(xform, vec2(adj.b, 0.5f)).b; \n"
|
||||||
"#else \n"
|
"#else \n"
|
||||||
"float r = rgb.r; \n"
|
"float r = rgb.r; \n"
|
||||||
"float g = rgb.g; \n"
|
"float g = rgb.g; \n"
|
||||||
"float b = rgb.b; \n"
|
"float b = rgb.b; \n"
|
||||||
"#endif \n"
|
"#endif \n"
|
||||||
"fs_color.rgb = texture(tonemapper, vec3(r, g, b)).rgb * rgb_premulalpha.a; \n"
|
"fs_color.rgb = texture(tonemapper, ScaleOffset(vec3(r, g, b), tSO)).rgb * rgb_premulalpha.a; \n"
|
||||||
"fs_color.a = rgb_premulalpha.a; \n"
|
"fs_color.a = rgb_premulalpha.a; \n"
|
||||||
"} \n"
|
"} \n"
|
||||||
"} \n";
|
"} \n";
|
||||||
|
|||||||
Reference in New Issue
Block a user