separate shaders, RGBA16F doesn’t work with picking in iOS

This commit is contained in:
2018-08-08 11:09:35 +02:00
parent f941fc4254
commit 9cccecd381
7 changed files with 45 additions and 17 deletions

View File

@@ -35,6 +35,20 @@ void App::initShaders()
"}";
// TEXTURE ALPHA
static const char* shader_alpha_f =
SHADER_VERSION
"uniform sampler2D tex;\n"
"uniform mediump float alpha;\n"
"uniform bool highlight;\n"
"in mediump vec3 uv;\n"
"out mediump vec4 frag;\n"
"void main(){\n"
" mediump vec4 c = texture(tex, uv.xy);\n"
" frag = highlight ? \n"
" vec4(clamp(vec3(.3)+c.rgb, vec3(0), vec3(1)), c.a) : \n"
" texture(tex, uv.xy) * vec4(1,1,1,alpha);\n"
"}\n";
// TEXTURE ALPHA SEPARATED
static const char* shader_alpha_sep_f =
SHADER_VERSION
"uniform sampler2D tex;\n"
"uniform sampler2D tex_alpha;\n"
@@ -479,6 +493,8 @@ void App::initShaders()
LOG("Failed to create shader Texture");
if (!ShaderManager::create(kShader::TextureAlpha, shader_v, shader_alpha_f))
LOG("Failed to create shader TextureAlpha");
if (!ShaderManager::create(kShader::TextureAlphaSep, shader_v, shader_alpha_sep_f))
LOG("Failed to create shader TextureAlphaSep");
if (!ShaderManager::create(kShader::StrokePreview, shader_v, shader_stroke_preview_f))
LOG("Failed to create shader StrokePreview");
if (!ShaderManager::create(kShader::CompErase, shader_v, shader_comp_erase_f))

View File

@@ -246,7 +246,7 @@ void ui::Canvas::stroke_draw_mix(const glm::vec2& bb_min, const glm::vec2& bb_sz
m_plane_transform[plane_index] *
glm::translate(glm::vec3(0, 0, -1));
ui::ShaderManager::use(kShader::TextureAlpha);
ui::ShaderManager::use(kShader::TextureAlphaSep);
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
ui::ShaderManager::u_int(kShaderUniform::TexA, 1);
ui::ShaderManager::u_float(kShaderUniform::Alpha, m_layers[layer_index].m_opacity);
@@ -899,8 +899,8 @@ void ui::Canvas::resize(int width, int height)
for (int i = 0; i < 6; i++)
{
#if __IOS__
m_tmp[i].create(width, height, -1, GL_RGBA16F);
m_tex[i].create(width, height, GL_RGBA16F);
m_tmp[i].create(width, height, -1, GL_RGBA8);
m_tex[i].create(width, height, GL_RGBA8);
#else
m_tmp[i].create(width, height, -1, GL_RGBA32F);
m_tex[i].create(width, height, GL_RGBA32F);
@@ -919,8 +919,8 @@ bool ui::Canvas::create(int width, int height)
for (int i = 0; i < 6; i++)
{
#if __IOS__
m_tmp[i].create(width, height, -1, GL_RGBA16F);
m_tex[i].create(width, height, GL_RGBA16F);
m_tmp[i].create(width, height, -1, GL_RGBA8);
m_tex[i].create(width, height, GL_RGBA8);
#else
m_tmp[i].create(width, height, -1, GL_RGBA32F);
m_tex[i].create(width, height, GL_RGBA32F);

View File

@@ -55,14 +55,13 @@ ui::Image ui::Image::resize(int w, int h)
auto pixels = (glm::u8vec4*)data();
float x_ratio = ((float)(width - 1)) / w;
float y_ratio = ((float)(height - 1)) / h;
float x_diff, y_diff, ya, yb;
int offset = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
int x = (int)(x_ratio * j);
int y = (int)(y_ratio * i);
x_diff = (x_ratio * j) - x;
y_diff = (y_ratio * i) - y;
float x_diff = (x_ratio * j) - x;
float y_diff = (y_ratio * i) - y;
int index = y * width + x;
// range is 0 to 255 thus bitwise AND with 0xff

View File

@@ -201,7 +201,7 @@ void NodeCanvas::draw()
{
m_sampler.bind(0);
m_sampler_linear.bind(1);
ui::ShaderManager::use(kShader::TextureAlpha);
ui::ShaderManager::use(kShader::TextureAlphaSep);
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
ui::ShaderManager::u_int(kShaderUniform::TexA, 1);
ui::ShaderManager::u_float(kShaderUniform::Alpha, m_canvas->m_layers[layer_index].m_opacity);

View File

@@ -50,14 +50,16 @@ void NodePanelGrid::init_controls()
m_hm_load->on_click = [this](Node*) {
App::I.pick_image([this](std::string path) {
ui::Image img;
img.load(path);
m_hm_image = img.resize(128, 128);
m_hm_preview->tex.create(m_hm_image);
m_hm_preview->tex.create_mipmaps();
auto sz = m_hm_preview->tex.size();
m_hm_preview->SetAspectRatio(sz.x / sz.y);
m_hm_plane.create(1, 1, m_hm_image, -m_hm_height->get_value());
m_hm_preview->SetHeight(100);
if (img.load_file(path))
{
m_hm_image = img.resize(128, 128);
m_hm_preview->tex.create(m_hm_image);
m_hm_preview->tex.create_mipmaps();
auto sz = m_hm_preview->tex.size();
m_hm_preview->SetAspectRatio(sz.x / sz.y);
m_hm_plane.create(1, 1, m_hm_image, -m_hm_height->get_value());
m_hm_preview->SetHeight(100);
}
});
};
}

View File

@@ -40,6 +40,7 @@ enum class kShader : uint16_t
ColorHue = const_hash("color-hue"),
Texture = const_hash("texture"),
TextureAlpha= const_hash("texture-alpha"),
TextureAlphaSep= const_hash("texture-alpha-sep"),
CompErase = const_hash("comp-erase"),
CompDraw = const_hash("comp-draw"),
UVs = const_hash("uvs"),