simplify point shader in preparation for #196
This commit is contained in:
@@ -13,8 +13,8 @@ public:
|
||||
|
||||
void setImage(int32_t image);
|
||||
void setColor(const std::array<float, 4>& color);
|
||||
void setPointTopLeft(const std::array<float, 2>& point_tl);
|
||||
void setPointBottomRight(const std::array<float, 2>& point_br);
|
||||
void setPosition(const std::array<float, 2>& pos);
|
||||
void setDimension(const std::array<float, 2>& dimension);
|
||||
void setSize(float size);
|
||||
|
||||
private:
|
||||
@@ -26,11 +26,11 @@ private:
|
||||
std::array<float, 4> color = {{}};
|
||||
int32_t u_color = -1;
|
||||
|
||||
std::array<float, 2> point_tl = {{}};
|
||||
int32_t u_point_tl = -1;
|
||||
std::array<float, 2> pos = {{}};
|
||||
int32_t u_pos = -1;
|
||||
|
||||
std::array<float, 2> point_br = {{}};
|
||||
int32_t u_point_br = -1;
|
||||
std::array<float, 2> dimension = {{}};
|
||||
int32_t u_dimension = -1;
|
||||
|
||||
float size = 0;
|
||||
int32_t u_size = -1;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <llmr/renderer/point_bucket.hpp>
|
||||
#include <llmr/map/map.hpp>
|
||||
#include <llmr/style/sprite.hpp>
|
||||
#include <llmr/util/math.hpp>
|
||||
|
||||
using namespace llmr;
|
||||
|
||||
@@ -43,9 +44,8 @@ void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, co
|
||||
dotShader->setColor(color);
|
||||
|
||||
const float pointSize = (properties.radius ? properties.radius * 2 : 8) * map.getState().getPixelRatio();
|
||||
#if defined(GL_ES_VERSION_2_0)
|
||||
dotShader->setSize(pointSize);
|
||||
#else
|
||||
dotShader->setSize(pointSize);
|
||||
#ifndef GL_ES_VERSION_2_0
|
||||
glPointSize(pointSize);
|
||||
glEnable(GL_POINT_SPRITE);
|
||||
#endif
|
||||
@@ -57,19 +57,24 @@ void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, co
|
||||
useProgram(pointShader->program);
|
||||
pointShader->setMatrix(vtxMatrix);
|
||||
pointShader->setColor(color);
|
||||
|
||||
pointShader->setImage(0);
|
||||
pointShader->setPointTopLeft({{ imagePos.tl.x, imagePos.tl.y }});
|
||||
pointShader->setPointBottomRight({{ imagePos.br.x, imagePos.br.y }});
|
||||
pointShader->setPosition({{
|
||||
0.5f * (imagePos.tl.x + imagePos.br.x),
|
||||
0.5f * (imagePos.tl.y + imagePos.br.y),
|
||||
}});
|
||||
|
||||
pointShader->setDimension({{
|
||||
static_cast<float>(sprite->raster.width),
|
||||
static_cast<float>(sprite->raster.height)
|
||||
}});
|
||||
|
||||
sprite->raster.bind(map.getState().isChanging());
|
||||
|
||||
const float pointSize = (properties.size ? properties.size : (imagePos.size.x / map.getState().getPixelRatio())) * 1.4142135623730951 * map.getState().getPixelRatio();
|
||||
#if defined(GL_ES_VERSION_2_0)
|
||||
pointShader->setSize(pointSize);
|
||||
#else
|
||||
glPointSize(pointSize);
|
||||
glEnable(GL_POINT_SPRITE);
|
||||
const float pointSize = util::max(imagePos.size.x, imagePos.size.y) + 2;
|
||||
pointShader->setSize(pointSize);
|
||||
#ifndef GL_ES_VERSION_2_0
|
||||
glPointSize(pointSize);
|
||||
glEnable(GL_POINT_SPRITE);
|
||||
#endif
|
||||
|
||||
glDepthRange(strata, 1.0f);
|
||||
|
||||
@@ -1,21 +1,10 @@
|
||||
#define root2 1.4142135623730951
|
||||
|
||||
uniform sampler2D u_image;
|
||||
uniform vec2 u_tl;
|
||||
uniform vec2 u_br;
|
||||
uniform vec2 u_pos;
|
||||
uniform vec2 u_dimension;
|
||||
uniform vec4 u_color;
|
||||
|
||||
uniform vec2 pos;
|
||||
uniform float inbounds;
|
||||
uniform vec4 color;
|
||||
uniform float u_size;
|
||||
|
||||
void main() {
|
||||
vec2 pos = (gl_PointCoord * 2.0 - 1.0) * root2 / 2.0 + 0.5;
|
||||
|
||||
float inbounds = step(0.0, pos.x) * step(0.0, pos.y) *
|
||||
(1.0 - step(1.0, pos.x)) * (1.0 - step(1.0, pos.y));
|
||||
|
||||
vec4 color = texture2D(u_image, mix(u_tl, u_br, pos)) * inbounds;
|
||||
|
||||
gl_FragColor = color * u_color;
|
||||
vec2 pos = u_pos + (gl_PointCoord - 0.5) * u_size / u_dimension;
|
||||
gl_FragColor = texture2D(u_image, pos) * u_color;
|
||||
}
|
||||
|
||||
@@ -21,15 +21,15 @@ PointShader::PointShader()
|
||||
u_matrix = glGetUniformLocation(program, "u_matrix");
|
||||
u_color = glGetUniformLocation(program, "u_color");
|
||||
u_size = glGetUniformLocation(program, "u_size");
|
||||
u_point_tl = glGetUniformLocation(program, "u_tl");
|
||||
u_point_br = glGetUniformLocation(program, "u_br");
|
||||
u_pos = glGetUniformLocation(program, "u_pos");
|
||||
u_dimension = glGetUniformLocation(program, "u_dimension");
|
||||
|
||||
// fprintf(stderr, "PointShader:\n");
|
||||
// fprintf(stderr, " - u_matrix: %d\n", u_matrix);
|
||||
// fprintf(stderr, " - u_color: %d\n", u_color);
|
||||
// fprintf(stderr, " - u_size: %d\n", u_size);
|
||||
// fprintf(stderr, " - u_point_tl: %d\n", u_point_tl);
|
||||
// fprintf(stderr, " - u_point_br: %d\n", u_point_br);
|
||||
// fprintf(stderr, " - u_pos: %d\n", u_pos);
|
||||
// fprintf(stderr, " - u_dimension: %d\n", u_dimension);
|
||||
// fprintf(stderr, " - u_image: %d\n", u_image);
|
||||
}
|
||||
|
||||
@@ -59,16 +59,16 @@ void PointShader::setSize(float new_size) {
|
||||
}
|
||||
}
|
||||
|
||||
void PointShader::setPointTopLeft(const std::array<float, 2>& new_point_tl) {
|
||||
if (point_tl != new_point_tl) {
|
||||
glUniform2fv(u_point_tl, 1, new_point_tl.data());
|
||||
point_tl = new_point_tl;
|
||||
void PointShader::setPosition(const std::array<float, 2>& new_pos) {
|
||||
if (pos != new_pos) {
|
||||
glUniform2fv(u_pos, 1, new_pos.data());
|
||||
pos = new_pos;
|
||||
}
|
||||
}
|
||||
|
||||
void PointShader::setPointBottomRight(const std::array<float, 2>& new_point_br) {
|
||||
if (point_br != new_point_br) {
|
||||
glUniform2fv(u_point_br, 1, new_point_br.data());
|
||||
point_br = new_point_br;
|
||||
void PointShader::setDimension(const std::array<float, 2>& new_dimension) {
|
||||
if (dimension != new_dimension) {
|
||||
glUniform2fv(u_dimension, 1, new_dimension.data());
|
||||
dimension = new_dimension;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ const shader_source llmr::shaders[SHADER_COUNT] = {
|
||||
},
|
||||
{
|
||||
"#version 120\nattribute vec2 a_pos;\nuniform mat4 u_matrix;\nuniform float u_size;\nvoid main ()\n{\n vec4 tmpvar_1;\n tmpvar_1.zw = vec2(0.0, 1.0);\n tmpvar_1.xy = a_pos;\n gl_Position = (u_matrix * tmpvar_1);\n gl_PointSize = u_size;\n}\n\n",
|
||||
"#version 120\nuniform sampler2D u_image;\nuniform vec2 u_tl;\nuniform vec2 u_br;\nuniform vec4 u_color;\nvoid main ()\n{\n vec2 tmpvar_1;\n tmpvar_1 = (((\n ((gl_PointCoord * 2.0) - 1.0)\n * 1.41421) / 2.0) + 0.5);\n gl_FragColor = ((texture2D (u_image, mix (u_tl, u_br, tmpvar_1)) * (\n ((float((tmpvar_1.x >= 0.0)) * float((tmpvar_1.y >= 0.0))) * (1.0 - float((tmpvar_1.x >= 1.0))))\n * \n (1.0 - float((tmpvar_1.y >= 1.0)))\n )) * u_color);\n}\n\n",
|
||||
"#version 120\nuniform sampler2D u_image;\nuniform vec2 u_pos;\nuniform vec2 u_dimension;\nuniform vec4 u_color;\nuniform float u_size;\nvoid main ()\n{\n gl_FragColor = (texture2D (u_image, (u_pos + (\n ((gl_PointCoord - 0.5) * u_size)\n / u_dimension))) * u_color);\n}\n\n",
|
||||
},
|
||||
{
|
||||
"#version 120\nuniform mat4 u_matrix;\nattribute vec2 a_pos;\nvarying vec2 v_pos;\nvoid main ()\n{\n vec4 tmpvar_1;\n tmpvar_1.zw = vec2(0.0, 1.0);\n tmpvar_1.xy = a_pos;\n gl_Position = (u_matrix * tmpvar_1);\n v_pos = (a_pos / 4096.0);\n}\n\n",
|
||||
|
||||
@@ -32,7 +32,7 @@ const shader_source llmr::shaders[SHADER_COUNT] = {
|
||||
},
|
||||
{
|
||||
"precision highp float;\nattribute vec2 a_pos;\nuniform mat4 u_matrix;\nuniform float u_size;\nvoid main ()\n{\n vec4 tmpvar_1;\n tmpvar_1.zw = vec2(0.0, 1.0);\n tmpvar_1.xy = a_pos;\n gl_Position = (u_matrix * tmpvar_1);\n gl_PointSize = u_size;\n}\n\n",
|
||||
"precision highp float;\nuniform sampler2D u_image;\nuniform vec2 u_tl;\nuniform vec2 u_br;\nuniform vec4 u_color;\nvoid main ()\n{\n mediump vec2 tmpvar_1;\n tmpvar_1 = (((\n ((gl_PointCoord * 2.0) - 1.0)\n * 1.41421) / 2.0) + 0.5);\n mediump vec2 tmpvar_2;\n tmpvar_2 = mix (u_tl, u_br, tmpvar_1);\n lowp vec4 tmpvar_3;\n tmpvar_3 = texture2D (u_image, tmpvar_2);\n gl_FragColor = ((tmpvar_3 * (\n ((float((tmpvar_1.x >= 0.0)) * float((tmpvar_1.y >= 0.0))) * (1.0 - float((tmpvar_1.x >= 1.0))))\n * \n (1.0 - float((tmpvar_1.y >= 1.0)))\n )) * u_color);\n}\n\n",
|
||||
"precision highp float;\nuniform sampler2D u_image;\nuniform vec2 u_pos;\nuniform vec2 u_dimension;\nuniform vec4 u_color;\nuniform float u_size;\nvoid main ()\n{\n mediump vec2 tmpvar_1;\n tmpvar_1 = (u_pos + ((\n (gl_PointCoord - 0.5)\n * u_size) / u_dimension));\n lowp vec4 tmpvar_2;\n tmpvar_2 = (texture2D (u_image, tmpvar_1) * u_color);\n gl_FragColor = tmpvar_2;\n}\n\n",
|
||||
},
|
||||
{
|
||||
"precision highp float;\nuniform mat4 u_matrix;\nattribute vec2 a_pos;\nvarying vec2 v_pos;\nvoid main ()\n{\n vec4 tmpvar_1;\n tmpvar_1.zw = vec2(0.0, 1.0);\n tmpvar_1.xy = a_pos;\n gl_Position = (u_matrix * tmpvar_1);\n v_pos = (a_pos / 4096.0);\n}\n\n",
|
||||
|
||||
Reference in New Issue
Block a user