Rewrite shaders to use OpenGL ES3 syntax

Signed-off-by: renderexpert <expert@renderconsulting.co.uk>
This commit is contained in:
renderexpert
2025-02-06 10:49:02 +00:00
committed by Konstantin Pastbin
parent 9b3507211f
commit 6d0daf6fe7
97 changed files with 1520 additions and 1015 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@@ -811,7 +811,7 @@ int8_t GLFunctions::glGetUniformLocation(uint32_t programID, std::string const &
ASSERT(glGetUniformLocationFn != nullptr, ()); ASSERT(glGetUniformLocationFn != nullptr, ());
int result = glGetUniformLocationFn(programID, name.c_str()); int result = glGetUniformLocationFn(programID, name.c_str());
GLCHECKCALL(); GLCHECKCALL();
ASSERT(result != -1, ()); ASSERT(result != -1, (name));
return static_cast<int8_t>(result); return static_cast<int8_t>(result);
} }

View File

@@ -95,7 +95,7 @@ void GLGpuProgram::LoadUniformLocations()
std::string name; std::string name;
GLFunctions::glGetActiveUniform(m_programID, static_cast<uint32_t>(i), &size, &info.m_type, name); GLFunctions::glGetActiveUniform(m_programID, static_cast<uint32_t>(i), &size, &info.m_type, name);
CHECK(kSupportedTypes.find(info.m_type) != kSupportedTypes.cend(), CHECK(kSupportedTypes.find(info.m_type) != kSupportedTypes.cend(),
("Used uniform has unsupported type. Program =", m_programName, "Type =", info.m_type)); ("Used uniform has unsupported type. Program =", m_programName, "; Type =", info.m_type, "; Name =", name));
info.m_location = GLFunctions::glGetUniformLocation(m_programID, name); info.m_location = GLFunctions::glGetUniformLocation(m_programID, name);
m_uniforms[name] = std::move(info); m_uniforms[name] = std::move(info);

View File

@@ -1,15 +1,26 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec2 a_colorTexCoords; layout (location = 1) in vec2 a_colorTexCoords;
uniform mat4 u_modelView;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
uniform sampler2D u_colorTex; layout (location = 0) out LOW_P vec4 v_color;
out LOW_P vec4 v_color;
#else #else
out vec2 v_colorTexCoords; layout (location = 1) out vec2 v_colorTexCoords;
#endif
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
#ifdef ENABLE_VTF
layout (binding = 1) uniform sampler2D u_colorTex;
#endif #endif
void main() void main()

View File

@@ -1,34 +1,36 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec3 a_normal; layout (location = 1) in vec3 a_normal;
in vec2 a_colorTexCoords; layout (location = 2) in vec2 a_colorTexCoords;
layout (location = 0) out vec2 v_colorTexCoords;
layout (location = 1) out float v_intensity;
uniform mat4 u_modelView; layout (binding = 0) uniform UBO
uniform mat4 u_projection; {
uniform mat4 u_pivotTransform; mat4 u_modelView;
uniform float u_zScale; mat4 u_projection;
mat4 u_pivotTransform;
out vec2 v_colorTexCoords; vec2 u_contrastGamma;
out float v_intensity; float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
const vec4 kNormalizedLightDir = vec4(0.3162, 0.0, 0.9486, 0.0); const vec4 kNormalizedLightDir = vec4(0.3162, 0.0, 0.9486, 0.0);
void main() void main()
{ {
vec4 pos = vec4(a_position, 1.0) * u_modelView; vec4 pos = vec4(a_position, 1.0) * u_modelView;
vec4 normal = vec4(a_position + a_normal, 1.0) * u_modelView; vec4 normal = vec4(a_position + a_normal, 1.0) * u_modelView;
normal.xyw = (normal * u_projection).xyw; normal.xyw = (normal * u_projection).xyw;
normal.z = normal.z * u_zScale; normal.z = normal.z * u_zScale;
pos.xyw = (pos * u_projection).xyw; pos.xyw = (pos * u_projection).xyw;
pos.z = a_position.z * u_zScale; pos.z = a_position.z * u_zScale;
vec4 normDir = normal - pos; vec4 normDir = normal - pos;
if (dot(normDir, normDir) != 0.0) if (dot(normDir, normDir) != 0.0)
v_intensity = max(0.0, -dot(kNormalizedLightDir, normalize(normDir))); v_intensity = max(0.0, -dot(kNormalizedLightDir, normalize(normDir)));
else else
v_intensity = 0.0; v_intensity = 0.0;
gl_Position = u_pivotTransform * pos; gl_Position = u_pivotTransform * pos;
#ifdef VULKAN #ifdef VULKAN
gl_Position.y = -gl_Position.y; gl_Position.y = -gl_Position.y;

View File

@@ -1,16 +1,26 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec2 a_colorTexCoords; layout (location = 1) in vec2 a_colorTexCoords;
uniform mat4 u_modelView;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
uniform float u_zScale;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
uniform sampler2D u_colorTex; layout (location = 0) out LOW_P vec4 v_color;
out LOW_P vec4 v_color;
#else #else
out vec2 v_colorTexCoords; layout (location = 1) out vec2 v_colorTexCoords;
#endif
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
#ifdef ENABLE_VTF
layout (binding = 1) uniform sampler2D u_colorTex;
#endif #endif
void main() void main()
@@ -23,7 +33,6 @@ void main()
gl_Position.y = -gl_Position.y; gl_Position.y = -gl_Position.y;
gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5; gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5;
#endif #endif
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
v_color = texture(u_colorTex, a_colorTexCoords); v_color = texture(u_colorTex, a_colorTexCoords);
#else #else

View File

@@ -1,11 +1,17 @@
in vec3 v_normal; layout (location = 0) in vec3 v_normal;
layout (location = 0) out vec4 v_FragColor;
layout (binding = 0) uniform UBO
{
mat4 u_transform;
mat4 u_normalTransform;
vec4 u_color;
vec2 u_texCoordFlipping;
};
const vec3 lightDir = vec3(0.316, 0.0, 0.948); const vec3 lightDir = vec3(0.316, 0.0, 0.948);
uniform vec4 u_color;
out vec4 v_FragColor;
void main() void main()
{ {
float phongDiffuse = max(0.0, -dot(lightDir, v_normal)); float phongDiffuse = max(0.0, -dot(lightDir, v_normal));

View File

@@ -1,10 +1,15 @@
in vec3 a_pos; layout (location = 0) in vec3 a_pos;
in vec3 a_normal; layout (location = 1) in vec3 a_normal;
uniform mat4 u_transform; layout (location = 0) out vec3 v_normal;
uniform mat4 u_normalTransform;
out vec3 v_normal; layout (binding = 0) uniform UBO
{
mat4 u_transform;
mat4 u_normalTransform;
vec4 u_color;
vec2 u_texCoordFlipping;
};
void main() void main()
{ {

View File

@@ -1,8 +1,14 @@
in float v_intensity; layout (location = 0) in float v_intensity;
uniform vec4 u_color; layout (location = 0) out vec4 v_FragColor;
out vec4 v_FragColor; layout (binding = 0) uniform UBO
{
mat4 u_transform;
mat4 u_normalTransform;
vec4 u_color;
vec2 u_texCoordFlipping;
};
void main() void main()
{ {

View File

@@ -1,8 +1,14 @@
in float v_intensity; layout (location = 0) in float v_intensity;
uniform vec4 u_color; layout (location = 0) out vec4 v_FragColor;
out vec4 v_FragColor; layout (binding = 0) uniform UBO
{
mat4 u_transform;
mat4 u_normalTransform;
vec4 u_color;
vec2 u_texCoordFlipping;
};
void main() void main()
{ {

View File

@@ -1,9 +1,15 @@
in vec3 a_pos; layout (location = 0) in vec3 a_pos;
in vec2 a_texCoords; layout (location = 1) in vec2 a_texCoords;
uniform mat4 u_transform; layout (location = 0) out float v_intensity;
out float v_intensity; layout (binding = 0) uniform UBO
{
mat4 u_transform;
mat4 u_normalTransform;
vec4 u_color;
vec2 u_texCoordFlipping;
};
void main() void main()
{ {

View File

@@ -1,14 +1,20 @@
in vec3 v_normal; layout (location = 0) in vec3 v_normal;
in vec2 v_texCoords; layout (location = 1) in vec2 v_texCoords;
uniform sampler2D u_colorTex; layout (location = 0) out vec4 v_FragColor;
layout (binding = 0) uniform UBO
{
mat4 u_transform;
mat4 u_normalTransform;
vec4 u_color;
vec2 u_texCoordFlipping;
};
layout (binding = 1) uniform sampler2D u_colorTex;
const vec3 lightDir = vec3(0.316, 0.0, 0.948); const vec3 lightDir = vec3(0.316, 0.0, 0.948);
uniform vec4 u_color;
out vec4 v_FragColor;
void main() void main()
{ {
float phongDiffuse = max(0.0, -dot(lightDir, v_normal)); float phongDiffuse = max(0.0, -dot(lightDir, v_normal));

View File

@@ -1,13 +1,17 @@
in vec3 a_pos; layout (location = 0) in vec3 a_pos;
in vec3 a_normal; layout (location = 1) in vec3 a_normal;
in vec2 a_texCoords; layout (location = 2) in vec2 a_texCoords;
uniform mat4 u_transform; layout (location = 0) out vec3 v_normal;
uniform mat4 u_normalTransform; layout (location = 1) out vec2 v_texCoords;
uniform vec2 u_texCoordFlipping;
out vec3 v_normal; layout (binding = 0) uniform UBO
out vec2 v_texCoords; {
mat4 u_transform;
mat4 u_normalTransform;
vec4 u_color;
vec2 u_texCoordFlipping;
};
void main() void main()
{ {

View File

@@ -1,17 +1,27 @@
uniform float u_opacity;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
in LOW_P vec4 v_color; layout (location = 0) in LOW_P vec4 v_color;
#else #else
uniform sampler2D u_colorTex; layout (location = 1) in vec2 v_colorTexCoords;
in vec2 v_colorTexCoords; layout (binding = 1) uniform sampler2D u_colorTex;
#endif #endif
layout (location = 2) in vec3 v_radius;
in vec3 v_radius; layout (location = 0) out vec4 v_FragColor;
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
const float aaPixelsCount = 2.5; const float aaPixelsCount = 2.5;
out vec4 v_FragColor;
void main() void main()
{ {
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
@@ -19,7 +29,6 @@ void main()
#else #else
LOW_P vec4 finalColor = texture(u_colorTex, v_colorTexCoords); LOW_P vec4 finalColor = texture(u_colorTex, v_colorTexCoords);
#endif #endif
float smallRadius = v_radius.z - aaPixelsCount; float smallRadius = v_radius.z - aaPixelsCount;
float stepValue = smoothstep(smallRadius * smallRadius, v_radius.z * v_radius.z, float stepValue = smoothstep(smallRadius * smallRadius, v_radius.z * v_radius.z,
v_radius.x * v_radius.x + v_radius.y * v_radius.y); v_radius.x * v_radius.x + v_radius.y * v_radius.y);

View File

@@ -1,19 +1,29 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec3 a_normal; layout (location = 1) in vec3 a_normal;
in vec2 a_colorTexCoords; layout (location = 2) in vec2 a_colorTexCoords;
uniform mat4 u_modelView;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
uniform sampler2D u_colorTex; layout (location = 0) out LOW_P vec4 v_color;
out LOW_P vec4 v_color;
#else #else
out vec2 v_colorTexCoords; layout (location = 1) out vec2 v_colorTexCoords;
#endif #endif
layout (location = 2) out vec3 v_radius;
out vec3 v_radius; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
#ifdef ENABLE_VTF
layout (binding = 1) uniform sampler2D u_colorTex;
#endif
void main() void main()
{ {

View File

@@ -1,20 +1,28 @@
uniform float u_opacity; layout (location = 0) in vec3 v_radius;
layout (location = 1) in vec4 v_color;
in vec3 v_radius; layout (location = 0) out vec4 v_FragColor;
in vec4 v_color;
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
const float kAntialiasingScalar = 0.9; const float kAntialiasingScalar = 0.9;
out vec4 v_FragColor;
void main() void main()
{ {
float d = dot(v_radius.xy, v_radius.xy); float d = dot(v_radius.xy, v_radius.xy);
vec4 finalColor = v_color; vec4 finalColor = v_color;
float aaRadius = v_radius.z * kAntialiasingScalar; float aaRadius = v_radius.z * kAntialiasingScalar;
float stepValue = smoothstep(aaRadius * aaRadius, v_radius.z * v_radius.z, d); float stepValue = smoothstep(aaRadius * aaRadius, v_radius.z * v_radius.z, d);
finalColor.a = finalColor.a * u_opacity * (1.0 - stepValue); finalColor.a = finalColor.a * u_opacity * (1.0 - stepValue);
v_FragColor = finalColor; v_FragColor = finalColor;
} }

View File

@@ -1,13 +1,21 @@
in vec3 a_normal; layout (location = 0) in vec3 a_normal;
in vec3 a_position; layout (location = 1) in vec3 a_position;
in vec4 a_color; layout (location = 2) in vec4 a_color;
uniform mat4 u_modelView; layout (location = 0) out vec3 v_radius;
uniform mat4 u_projection; layout (location = 1) out vec4 v_color;
uniform mat4 u_pivotTransform;
out vec3 v_radius; layout (binding = 0) uniform UBO
out vec4 v_color; {
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
void main() void main()
{ {
@@ -15,7 +23,6 @@ void main()
vec4 pos = vec4(a_position.xy, 0, 1) * u_modelView; vec4 pos = vec4(a_position.xy, 0, 1) * u_modelView;
vec4 shiftedPos = vec4(radius.xy, 0, 0) + pos; vec4 shiftedPos = vec4(radius.xy, 0, 0) + pos;
gl_Position = applyPivotTransform(shiftedPos * u_projection, u_pivotTransform, 0.0); gl_Position = applyPivotTransform(shiftedPos * u_projection, u_pivotTransform, 0.0);
v_radius = radius; v_radius = radius;
v_color = a_color; v_color = a_color;
} }

View File

@@ -1,16 +1,26 @@
uniform float u_opacity; layout (location = 0) in vec4 v_normal;
in vec4 v_normal;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
in LOW_P vec4 v_color; layout (location = 1) in LOW_P vec4 v_color;
#else #else
uniform sampler2D u_colorTex; layout (location = 2) in vec2 v_colorTexCoords;
in vec2 v_colorTexCoords; layout (binding = 1) uniform sampler2D u_colorTex;
#endif #endif
const float aaPixelsCount = 2.5; layout (location = 0) out vec4 v_FragColor;
out vec4 v_FragColor; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
const float aaPixelsCount = 2.5;
void main() void main()
{ {
@@ -19,16 +29,13 @@ void main()
#else #else
LOW_P vec4 color = texture(u_colorTex, v_colorTexCoords); LOW_P vec4 color = texture(u_colorTex, v_colorTexCoords);
#endif #endif
float r1 = (v_normal.z - aaPixelsCount) * (v_normal.z - aaPixelsCount); float r1 = (v_normal.z - aaPixelsCount) * (v_normal.z - aaPixelsCount);
float r2 = v_normal.x * v_normal.x + v_normal.y * v_normal.y; float r2 = v_normal.x * v_normal.x + v_normal.y * v_normal.y;
float r3 = v_normal.z * v_normal.z; float r3 = v_normal.z * v_normal.z;
float alpha = mix(step(r3, r2), smoothstep(r1, r3, r2), v_normal.w); float alpha = mix(step(r3, r2), smoothstep(r1, r3, r2), v_normal.w);
LOW_P vec4 finalColor = color; LOW_P vec4 finalColor = color;
finalColor.a = finalColor.a * u_opacity * (1.0 - alpha); finalColor.a = finalColor.a * u_opacity * (1.0 - alpha);
if (finalColor.a == 0.0) if (finalColor.a == 0.0)
discard; discard;
v_FragColor = finalColor; v_FragColor = finalColor;
} }

View File

@@ -1,17 +1,28 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec4 a_normal; layout (location = 1) in vec4 a_normal;
in vec4 a_colorTexCoords; layout (location = 2) in vec4 a_colorTexCoords;
uniform mat4 u_modelView; layout (location = 0) out vec4 v_normal;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
out vec4 v_normal;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
uniform sampler2D u_colorTex; layout (location = 1) out LOW_P vec4 v_color;
out LOW_P vec4 v_color;
#else #else
out vec2 v_colorTexCoords; layout (location = 2) out vec2 v_colorTexCoords;
#endif
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
#ifdef ENABLE_VTF
layout (binding = 1) uniform sampler2D u_colorTex;
#endif #endif
void main() void main()
@@ -19,7 +30,6 @@ void main()
vec4 p = vec4(a_position, 1) * u_modelView; vec4 p = vec4(a_position, 1) * u_modelView;
vec4 pos = vec4(a_normal.xy + a_colorTexCoords.zw, 0, 0) + p; vec4 pos = vec4(a_normal.xy + a_colorTexCoords.zw, 0, 0) + p;
gl_Position = applyPivotTransform(pos * u_projection, u_pivotTransform, 0.0); gl_Position = applyPivotTransform(pos * u_projection, u_pivotTransform, 0.0);
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
v_color = texture(u_colorTex, a_colorTexCoords.xy); v_color = texture(u_colorTex, a_colorTexCoords.xy);
#else #else

View File

@@ -1,17 +1,28 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec4 a_normal; layout (location = 1) in vec4 a_normal;
in vec4 a_colorTexCoords; layout (location = 2) in vec4 a_colorTexCoords;
uniform mat4 u_modelView; layout (location = 0) out vec4 v_normal;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
out vec4 v_normal;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
uniform sampler2D u_colorTex; layout (location = 1) out LOW_P vec4 v_color;
out LOW_P vec4 v_color;
#else #else
out vec2 v_colorTexCoords; layout (location = 2) out vec2 v_colorTexCoords;
#endif
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
#ifdef ENABLE_VTF
layout (binding = 1) uniform sampler2D u_colorTex;
#endif #endif
void main() void main()
@@ -19,7 +30,6 @@ void main()
vec4 pivot = vec4(a_position.xyz, 1.0) * u_modelView; vec4 pivot = vec4(a_position.xyz, 1.0) * u_modelView;
vec4 offset = vec4(a_normal.xy + a_colorTexCoords.zw, 0.0, 0.0) * u_projection; vec4 offset = vec4(a_normal.xy + a_colorTexCoords.zw, 0.0, 0.0) * u_projection;
gl_Position = applyBillboardPivotTransform(pivot * u_projection, u_pivotTransform, 0.0, offset.xy); gl_Position = applyBillboardPivotTransform(pivot * u_projection, u_pivotTransform, 0.0, offset.xy);
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
v_color = texture(u_colorTex, a_colorTexCoords.xy); v_color = texture(u_colorTex, a_colorTexCoords.xy);
#else #else

View File

@@ -1,26 +1,35 @@
in vec2 v_colorTexCoord; layout (location = 0) in vec2 v_colorTexCoord;
in vec2 v_maskTexCoord; layout (location = 1) in vec2 v_maskTexCoord;
//in vec2 v_halfLength; //layout (location = 2) in vec2 v_halfLength;
uniform sampler2D u_colorTex; layout (location = 0) out vec4 v_FragColor;
uniform sampler2D u_maskTex;
uniform float u_opacity; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
layout (binding = 1) uniform sampler2D u_colorTex;
layout (binding = 2) uniform sampler2D u_maskTex;
//const float aaPixelsCount = 2.5; //const float aaPixelsCount = 2.5;
out vec4 v_FragColor;
void main() void main()
{ {
vec4 color = texture(u_colorTex, v_colorTexCoord); vec4 color = texture(u_colorTex, v_colorTexCoord);
float mask = texture(u_maskTex, v_maskTexCoord).r; float mask = texture(u_maskTex, v_maskTexCoord).r;
color.a = color.a * mask * u_opacity; color.a = color.a * mask * u_opacity;
// Disabled too agressive AA-like blurring of edges, // Disabled too agressive AA-like blurring of edges,
// see https://github.com/organicmaps/organicmaps/issues/6583. // see https://github.com/organicmaps/organicmaps/issues/6583.
//float currentW = abs(v_halfLength.x); //float currentW = abs(v_halfLength.x);
//float diff = v_halfLength.y - currentW; //float diff = v_halfLength.y - currentW;
//color.a *= mix(0.3, 1.0, clamp(diff / aaPixelsCount, 0.0, 1.0)); //color.a *= mix(0.3, 1.0, clamp(diff / aaPixelsCount, 0.0, 1.0));
v_FragColor = color; v_FragColor = color;
} }

View File

@@ -1,15 +1,23 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec3 a_normal; layout (location = 1) in vec3 a_normal;
in vec2 a_colorTexCoord; layout (location = 2) in vec2 a_colorTexCoord;
in vec4 a_maskTexCoord; layout (location = 3) in vec4 a_maskTexCoord;
uniform mat4 u_modelView; layout (location = 0) out vec2 v_colorTexCoord;
uniform mat4 u_projection; layout (location = 1) out vec2 v_maskTexCoord;
uniform mat4 u_pivotTransform; //layout (location = 2) out vec2 v_halfLength;
out vec2 v_colorTexCoord; layout (binding = 0) uniform UBO
out vec2 v_maskTexCoord; {
//out vec2 v_halfLength; mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
void main() void main()
{ {
@@ -21,12 +29,10 @@ void main()
transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + normal, transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + normal,
u_modelView, halfWidth); u_modelView, halfWidth);
} }
float uOffset = min(length(vec4(kShapeCoordScalar, 0, 0, 0) * u_modelView) * a_maskTexCoord.x, 1.0); float uOffset = min(length(vec4(kShapeCoordScalar, 0, 0, 0) * u_modelView) * a_maskTexCoord.x, 1.0);
v_colorTexCoord = a_colorTexCoord; v_colorTexCoord = a_colorTexCoord;
v_maskTexCoord = vec2(a_maskTexCoord.y + uOffset * a_maskTexCoord.z, a_maskTexCoord.w); v_maskTexCoord = vec2(a_maskTexCoord.y + uOffset * a_maskTexCoord.z, a_maskTexCoord.w);
//v_halfLength = vec2(sign(a_normal.z) * halfWidth, abs(a_normal.z)); //v_halfLength = vec2(sign(a_normal.z) * halfWidth, abs(a_normal.z));
vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * u_projection; vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * u_projection;
gl_Position = applyPivotTransform(pos, u_pivotTransform, 0.0); gl_Position = applyPivotTransform(pos, u_pivotTransform, 0.0);
} }

View File

@@ -1,6 +1,9 @@
uniform vec4 u_color; layout (location = 0) out vec4 v_FragColor;
out vec4 v_FragColor; layout (binding = 0) uniform UBO
{
vec4 u_color;
};
void main() void main()
{ {

View File

@@ -1,4 +1,4 @@
in vec2 a_position; layout (location = 0) in vec2 a_position;
void main() void main()
{ {

View File

@@ -1,16 +1,26 @@
uniform float u_opacity;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
in LOW_P vec4 v_color; layout (location = 0) in LOW_P vec4 v_color;
#else #else
uniform sampler2D u_colorTex; layout (location = 1) in vec2 v_colorTexCoords;
in vec2 v_colorTexCoords; layout (binding = 1) uniform sampler2D u_colorTex;
#endif #endif
layout (location = 2) in vec2 v_maskTexCoords;
uniform sampler2D u_maskTex; layout (location = 0) out vec4 v_FragColor;
in vec2 v_maskTexCoords;
out vec4 v_FragColor; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
layout (binding = 2) uniform sampler2D u_maskTex;
void main() void main()
{ {
@@ -23,4 +33,3 @@ void main()
color.a *= u_opacity; color.a *= u_opacity;
v_FragColor = color; v_FragColor = color;
} }

View File

@@ -1,18 +1,29 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec2 a_colorTexCoords; layout (location = 1) in vec2 a_colorTexCoords;
in vec2 a_maskTexCoords; layout (location = 2) in vec2 a_maskTexCoords;
uniform mat4 u_modelView;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
uniform sampler2D u_colorTex; layout (location = 0) out LOW_P vec4 v_color;
out LOW_P vec4 v_color;
#else #else
out vec2 v_colorTexCoords; layout (location = 1) out vec2 v_colorTexCoords;
#endif
layout (location = 2) out vec2 v_maskTexCoords;
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
#ifdef ENABLE_VTF
layout (binding = 1) uniform sampler2D u_colorTex;
#endif #endif
out vec2 v_maskTexCoords;
void main() void main()
{ {

View File

@@ -1,9 +1,9 @@
in vec2 v_texCoords; layout (location = 0) in vec2 v_texCoords;
in vec4 v_color; layout (location = 1) in vec4 v_color;
uniform sampler2D u_colorTex; layout (location = 0) out vec4 v_FragColor;
out vec4 v_FragColor; layout (binding = 1) uniform sampler2D u_colorTex;
void main() void main()
{ {

View File

@@ -1,11 +1,14 @@
in vec2 a_position; layout (location = 0) in vec2 a_position;
in vec2 a_texCoords; layout (location = 1) in vec2 a_texCoords;
in vec4 a_color; layout (location = 2) in vec4 a_color;
out vec2 v_texCoords; layout (location = 0) out vec2 v_texCoords;
out vec4 v_color; layout (location = 1) out vec4 v_color;
uniform mat4 u_projection; layout (binding = 0) uniform UBO
{
mat4 u_projection;
};
void main() void main()
{ {

View File

@@ -1,17 +1,27 @@
uniform float u_opacity;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
in LOW_P vec4 v_color; layout (location = 0) in LOW_P vec4 v_color;
#else #else
uniform sampler2D u_colorTex; layout (location = 1) in vec2 v_colorTexCoord;
in vec2 v_colorTexCoord; layout (binding = 1) uniform sampler2D u_colorTex;
#endif #endif
//layout (location = 2) in vec2 v_halfLength;
//in vec2 v_halfLength; layout (location = 0) out vec4 v_FragColor;
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
//const float aaPixelsCount = 2.5; //const float aaPixelsCount = 2.5;
out vec4 v_FragColor;
void main() void main()
{ {
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
@@ -20,12 +30,10 @@ void main()
LOW_P vec4 color = texture(u_colorTex, v_colorTexCoord); LOW_P vec4 color = texture(u_colorTex, v_colorTexCoord);
#endif #endif
color.a *= u_opacity; color.a *= u_opacity;
// Disabled too agressive AA-like blurring of edges, // Disabled too agressive AA-like blurring of edges,
// see https://github.com/organicmaps/organicmaps/issues/6583. // see https://github.com/organicmaps/organicmaps/issues/6583.
//float currentW = abs(v_halfLength.x); //float currentW = abs(v_halfLength.x);
//float diff = v_halfLength.y - currentW; //float diff = v_halfLength.y - currentW;
//color.a *= mix(0.3, 1.0, clamp(diff / aaPixelsCount, 0.0, 1.0)); //color.a *= mix(0.3, 1.0, clamp(diff / aaPixelsCount, 0.0, 1.0));
v_FragColor = color; v_FragColor = color;
} }

View File

@@ -1,19 +1,30 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec3 a_normal; layout (location = 1) in vec3 a_normal;
in vec2 a_colorTexCoord; layout (location = 2) in vec2 a_colorTexCoord;
uniform mat4 u_modelView;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
uniform sampler2D u_colorTex; layout (location = 0) out LOW_P vec4 v_color;
out LOW_P vec4 v_color;
#else #else
out vec2 v_colorTexCoord; layout (location = 1) out vec2 v_colorTexCoord;
#endif #endif
//out vec2 v_halfLength; //layout (location = 2) out vec2 v_halfLength;
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
#ifdef ENABLE_VTF
layout (binding = 1) uniform sampler2D u_colorTex;
#endif
void main() void main()
{ {
@@ -25,7 +36,6 @@ void main()
transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + normal, transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + normal,
u_modelView, halfWidth); u_modelView, halfWidth);
} }
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
v_color = texture(u_colorTex, a_colorTexCoord); v_color = texture(u_colorTex, a_colorTexCoord);
#else #else

View File

@@ -1,11 +1,22 @@
uniform sampler2D u_colorTex; layout (location = 0) in vec2 v_colorTexCoords;
uniform sampler2D u_maskTex; layout (location = 1) in vec2 v_maskTexCoords;
uniform float u_opacity;
in vec2 v_colorTexCoords; layout (location = 0) out vec4 v_FragColor;
in vec2 v_maskTexCoords;
out vec4 v_FragColor; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
layout (binding = 1) uniform sampler2D u_colorTex;
layout (binding = 2) uniform sampler2D u_maskTex;
void main() void main()
{ {

View File

@@ -1,14 +1,22 @@
in vec4 a_position; layout (location = 0) in vec4 a_position;
in vec2 a_normal; layout (location = 1) in vec2 a_normal;
in vec2 a_colorTexCoords; layout (location = 2) in vec2 a_colorTexCoords;
in vec2 a_maskTexCoords; layout (location = 3) in vec2 a_maskTexCoords;
uniform mat4 u_modelView; layout (location = 0) out vec2 v_colorTexCoords;
uniform mat4 u_projection; layout (location = 1) out vec2 v_maskTexCoords;
uniform mat4 u_pivotTransform;
out vec2 v_colorTexCoords; layout (binding = 0) uniform UBO
out vec2 v_maskTexCoords; {
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
void main() void main()
{ {

View File

@@ -1,15 +1,22 @@
in vec4 a_position; layout (location = 0) in vec4 a_position;
in vec2 a_normal; layout (location = 1) in vec2 a_normal;
in vec2 a_colorTexCoords; layout (location = 2) in vec2 a_colorTexCoords;
in vec2 a_maskTexCoords; layout (location = 3) in vec2 a_maskTexCoords;
uniform mat4 u_modelView; layout (location = 0) out vec2 v_colorTexCoords;
uniform mat4 u_projection; layout (location = 1) out vec2 v_maskTexCoords;
uniform mat4 u_pivotTransform;
uniform float u_zScale;
out vec2 v_colorTexCoords; layout (binding = 0) uniform UBO
out vec2 v_maskTexCoords; {
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
void main() void main()
{ {

View File

@@ -1,30 +1,33 @@
in vec2 a_normal; layout (location = 0) in vec2 a_normal;
in vec2 a_colorTexCoords; layout (location = 1) in vec2 a_colorTexCoords;
uniform vec3 u_position; layout (location = 0) out vec2 v_colorTexCoords;
uniform float u_azimut;
uniform mat4 u_modelView; layout (binding = 0) uniform UBO
uniform mat4 u_projection; {
uniform mat4 u_pivotTransform; mat4 u_modelView;
mat4 u_projection;
out vec2 v_colorTexCoords; mat4 u_pivotTransform;
vec4 u_position;
vec2 u_lineParams;
float u_accuracy;
float u_zScale;
float u_opacity;
float u_azimut;
};
void main() void main()
{ {
float sinV = sin(u_azimut); float sinV = sin(u_azimut);
float cosV = cos(u_azimut); float cosV = cos(u_azimut);
mat4 rotation; mat4 rotation;
rotation[0] = vec4(cosV, sinV, 0.0, 0.0); rotation[0] = vec4(cosV, sinV, 0.0, 0.0);
rotation[1] = vec4(-sinV, cosV, 0.0, 0.0); rotation[1] = vec4(-sinV, cosV, 0.0, 0.0);
rotation[2] = vec4(0.0, 0.0, 1.0, 0.0); rotation[2] = vec4(0.0, 0.0, 1.0, 0.0);
rotation[3] = vec4(0.0, 0.0, 0.0, 1.0); rotation[3] = vec4(0.0, 0.0, 0.0, 1.0);
vec4 pos = vec4(u_position.xyz, 1.0) * u_modelView;
vec4 pos = vec4(u_position, 1.0) * u_modelView;
vec4 normal = vec4(a_normal, 0, 0); vec4 normal = vec4(a_normal, 0, 0);
vec4 shiftedPos = normal * rotation + pos; vec4 shiftedPos = normal * rotation + pos;
gl_Position = applyPivotTransform(shiftedPos * u_projection, u_pivotTransform, 0.0); gl_Position = applyPivotTransform(shiftedPos * u_projection, u_pivotTransform, 0.0);
v_colorTexCoords = a_colorTexCoords; v_colorTexCoords = a_colorTexCoords;
} }

View File

@@ -1,23 +1,29 @@
in vec4 a_position; layout (location = 0) in vec4 a_position;
in vec2 a_normal; layout (location = 1) in vec2 a_normal;
in vec2 a_colorTexCoords; layout (location = 2) in vec2 a_colorTexCoords;
uniform mat4 u_modelView; layout (location = 0) out vec2 v_colorTexCoords;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
out vec2 v_colorTexCoords; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
void main() void main()
{ {
vec4 pos = vec4(a_position.xyz, 1) * u_modelView; vec4 pos = vec4(a_position.xyz, 1) * u_modelView;
float normalLen = length(a_normal); float normalLen = length(a_normal);
vec4 n = vec4(a_position.xy + a_normal * kShapeCoordScalar, 0.0, 0.0) * u_modelView; vec4 n = vec4(a_position.xy + a_normal * kShapeCoordScalar, 0.0, 0.0) * u_modelView;
vec4 norm = vec4(0.0, 0.0, 0.0, 0.0); vec4 norm = vec4(0.0, 0.0, 0.0, 0.0);
if (dot(n, n) != 0.0) if (dot(n, n) != 0.0)
norm = normalize(n) * normalLen; norm = normalize(n) * normalLen;
vec4 shiftedPos = norm + pos; vec4 shiftedPos = norm + pos;
gl_Position = applyPivotTransform(shiftedPos * u_projection, u_pivotTransform, 0.0); gl_Position = applyPivotTransform(shiftedPos * u_projection, u_pivotTransform, 0.0);
v_colorTexCoords = a_colorTexCoords; v_colorTexCoords = a_colorTexCoords;

View File

@@ -1,15 +1,20 @@
in vec2 a_normal; layout (location = 0) in vec2 a_normal;
in vec2 a_colorTexCoords; layout (location = 1) in vec2 a_colorTexCoords;
uniform vec3 u_position; layout (location = 0) out vec2 v_colorTexCoords;
uniform float u_accuracy;
uniform mat4 u_modelView; layout (binding = 0) uniform UBO
uniform mat4 u_projection; {
uniform mat4 u_pivotTransform; mat4 u_modelView;
uniform float u_zScale; mat4 u_projection;
mat4 u_pivotTransform;
out vec2 v_colorTexCoords; vec4 u_position;
vec2 u_lineParams;
float u_accuracy;
float u_zScale;
float u_opacity;
float u_azimut;
};
void main() void main()
{ {
@@ -17,6 +22,5 @@ void main()
vec4 normal = vec4(a_normal * u_accuracy, 0.0, 0.0); vec4 normal = vec4(a_normal * u_accuracy, 0.0, 0.0);
position = (position + normal) * u_projection; position = (position + normal) * u_projection;
gl_Position = applyPivotTransform(position, u_pivotTransform, u_position.z * u_zScale); gl_Position = applyPivotTransform(position, u_pivotTransform, u_position.z * u_zScale);
v_colorTexCoords = a_colorTexCoords; v_colorTexCoords = a_colorTexCoords;
} }

View File

@@ -1,38 +1,43 @@
// Warning! Beware to use this shader. "discard" command may significally reduce performance. // Warning! Beware to use this shader. "discard" command may significally reduce performance.
// Unfortunately some CG algorithms cannot be implemented on OpenGL ES 2.0 without discarding // Unfortunately some CG algorithms cannot be implemented without discarding fragments from depth buffer.
// fragments from depth buffer.
in vec3 v_length; layout (location = 0) in vec3 v_length;
in vec4 v_color; layout (location = 1) in vec4 v_color;
uniform vec4 u_color; layout (location = 0) out vec4 v_FragColor;
uniform vec4 u_outlineColor;
uniform vec4 u_routeParams;
uniform vec4 u_maskColor;
uniform vec2 u_fakeBorders; layout (binding = 0) uniform UBO
uniform vec4 u_fakeColor; {
uniform vec4 u_fakeOutlineColor; mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec4 u_routeParams;
vec4 u_color;
vec4 u_maskColor;
vec4 u_outlineColor;
vec4 u_fakeColor;
vec4 u_fakeOutlineColor;
vec2 u_fakeBorders;
vec2 u_pattern;
vec2 u_angleCosSin;
float u_arrowHalfWidth;
float u_opacity;
};
const float kAntialiasingThreshold = 0.92; const float kAntialiasingThreshold = 0.92;
const float kOutlineThreshold1 = 0.81; const float kOutlineThreshold1 = 0.81;
const float kOutlineThreshold2 = 0.71; const float kOutlineThreshold2 = 0.71;
out vec4 v_FragColor;
void main() void main()
{ {
if (v_length.x < v_length.z) if (v_length.x < v_length.z)
discard; discard;
vec2 coefs = step(v_length.xx, u_fakeBorders); vec2 coefs = step(v_length.xx, u_fakeBorders);
coefs.y = 1.0 - coefs.y; coefs.y = 1.0 - coefs.y;
vec4 mainColor = mix(u_color, u_fakeColor, coefs.x); vec4 mainColor = mix(u_color, u_fakeColor, coefs.x);
mainColor = mix(mainColor, u_fakeColor, coefs.y); mainColor = mix(mainColor, u_fakeColor, coefs.y);
vec4 mainOutlineColor = mix(u_outlineColor, u_fakeOutlineColor, coefs.x); vec4 mainOutlineColor = mix(u_outlineColor, u_fakeOutlineColor, coefs.x);
mainOutlineColor = mix(mainOutlineColor, u_fakeOutlineColor, coefs.y); mainOutlineColor = mix(mainOutlineColor, u_fakeOutlineColor, coefs.y);
vec4 color = mix(mix(mainColor, vec4(v_color.rgb, 1.0), v_color.a), mainColor, step(u_routeParams.w, 0.0)); vec4 color = mix(mix(mainColor, vec4(v_color.rgb, 1.0), v_color.a), mainColor, step(u_routeParams.w, 0.0));
color = mix(color, mainOutlineColor, step(kOutlineThreshold1, abs(v_length.y))); color = mix(color, mainOutlineColor, step(kOutlineThreshold1, abs(v_length.y)));
color = mix(color, mainOutlineColor, smoothstep(kOutlineThreshold2, kOutlineThreshold1, abs(v_length.y))); color = mix(color, mainOutlineColor, smoothstep(kOutlineThreshold2, kOutlineThreshold1, abs(v_length.y)));

View File

@@ -1,16 +1,28 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec2 a_normal; layout (location = 1) in vec2 a_normal;
in vec3 a_length; layout (location = 2) in vec3 a_length;
in vec4 a_color; layout (location = 3) in vec4 a_color;
uniform mat4 u_modelView; layout (location = 0) out vec3 v_length;
uniform mat4 u_projection; layout (location = 1) out vec4 v_color;
uniform mat4 u_pivotTransform;
uniform vec4 u_routeParams; layout (binding = 0) uniform UBO
{
out vec3 v_length; mat4 u_modelView;
out vec4 v_color; mat4 u_projection;
mat4 u_pivotTransform;
vec4 u_routeParams;
vec4 u_color;
vec4 u_maskColor;
vec4 u_outlineColor;
vec4 u_fakeColor;
vec4 u_fakeOutlineColor;
vec2 u_fakeBorders;
vec2 u_pattern;
vec2 u_angleCosSin;
float u_arrowHalfWidth;
float u_opacity;
};
void main() void main()
{ {
@@ -24,7 +36,6 @@ void main()
if (u_routeParams.y != 0.0) if (u_routeParams.y != 0.0)
len = vec2(a_length.x + a_length.y * u_routeParams.y, a_length.z); len = vec2(a_length.x + a_length.y * u_routeParams.y, a_length.z);
} }
v_length = vec3(len, u_routeParams.z); v_length = vec3(len, u_routeParams.z);
v_color = a_color; v_color = a_color;
vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * u_projection; vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * u_projection;

View File

@@ -1,14 +1,29 @@
// Warning! Beware to use this shader. "discard" command may significally reduce performance. // Warning! Beware to use this shader. "discard" command may significally reduce performance.
// Unfortunately some CG algorithms cannot be implemented on OpenGL ES 2.0 without discarding // Unfortunately some CG algorithms cannot be implemented without discarding fragments from depth buffer.
// fragments from depth buffer.
uniform sampler2D u_colorTex; layout (location = 0) in vec2 v_colorTexCoords;
uniform float u_opacity;
uniform vec4 u_maskColor;
in vec2 v_colorTexCoords; layout (location = 0) out vec4 v_FragColor;
out vec4 v_FragColor; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec4 u_routeParams;
vec4 u_color;
vec4 u_maskColor;
vec4 u_outlineColor;
vec4 u_fakeColor;
vec4 u_fakeOutlineColor;
vec2 u_fakeBorders;
vec2 u_pattern;
vec2 u_angleCosSin;
float u_arrowHalfWidth;
float u_opacity;
};
layout (binding = 1) uniform sampler2D u_colorTex;
void main() void main()
{ {

View File

@@ -1,14 +1,26 @@
in vec4 a_position; layout (location = 0) in vec4 a_position;
in vec2 a_normal; layout (location = 1) in vec2 a_normal;
in vec2 a_colorTexCoords; layout (location = 2) in vec2 a_colorTexCoords;
uniform mat4 u_modelView; layout (location = 0) out vec2 v_colorTexCoords;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
uniform float u_arrowHalfWidth; layout (binding = 0) uniform UBO
{
out vec2 v_colorTexCoords; mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec4 u_routeParams;
vec4 u_color;
vec4 u_maskColor;
vec4 u_outlineColor;
vec4 u_fakeColor;
vec4 u_fakeOutlineColor;
vec2 u_fakeBorders;
vec2 u_pattern;
vec2 u_angleCosSin;
float u_arrowHalfWidth;
float u_opacity;
};
void main() void main()
{ {
@@ -19,9 +31,7 @@ void main()
transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + norm, transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + norm,
u_modelView, length(norm)); u_modelView, length(norm));
} }
v_colorTexCoords = a_colorTexCoords; v_colorTexCoords = a_colorTexCoords;
vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * u_projection; vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * u_projection;
gl_Position = applyPivotTransform(pos, u_pivotTransform, 0.0); gl_Position = applyPivotTransform(pos, u_pivotTransform, 0.0);
} }

View File

@@ -1,16 +1,28 @@
// Warning! Beware to use this shader. "discard" command may significally reduce performance. // Warning! Beware to use this shader. "discard" command may significally reduce performance.
// Unfortunately some CG algorithms cannot be implemented on OpenGL ES 2.0 without discarding // Unfortunately some CG algorithms cannot be implemented without discarding fragments from depth buffer.
// fragments from depth buffer.
in vec3 v_length; layout (location = 0) in vec3 v_length;
in vec4 v_color; layout (location = 1) in vec4 v_color;
uniform vec4 u_color; layout (location = 0) out vec4 v_FragColor;
uniform vec2 u_pattern;
uniform vec4 u_maskColor;
uniform vec2 u_fakeBorders; layout (binding = 0) uniform UBO
uniform vec4 u_fakeColor; {
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec4 u_routeParams;
vec4 u_color;
vec4 u_maskColor;
vec4 u_outlineColor;
vec4 u_fakeColor;
vec4 u_fakeOutlineColor;
vec2 u_fakeBorders;
vec2 u_pattern;
vec2 u_angleCosSin;
float u_arrowHalfWidth;
float u_opacity;
};
const float kAntialiasingThreshold = 0.92; const float kAntialiasingThreshold = 0.92;
@@ -21,18 +33,14 @@ float alphaFromPattern(float curLen, float dashLen, float gapLen)
return step(offset, dashLen); return step(offset, dashLen);
} }
out vec4 v_FragColor;
void main() void main()
{ {
if (v_length.x < v_length.z) if (v_length.x < v_length.z)
discard; discard;
vec2 coefs = step(v_length.xx, u_fakeBorders); vec2 coefs = step(v_length.xx, u_fakeBorders);
coefs.y = 1.0 - coefs.y; coefs.y = 1.0 - coefs.y;
vec4 mainColor = mix(u_color, u_fakeColor, coefs.x); vec4 mainColor = mix(u_color, u_fakeColor, coefs.x);
mainColor = mix(mainColor, u_fakeColor, coefs.y); mainColor = mix(mainColor, u_fakeColor, coefs.y);
vec4 color = mainColor + v_color; vec4 color = mainColor + v_color;
color.a *= (1.0 - smoothstep(kAntialiasingThreshold, 1.0, abs(v_length.y))) * color.a *= (1.0 - smoothstep(kAntialiasingThreshold, 1.0, abs(v_length.y))) *
alphaFromPattern(v_length.x, u_pattern.x, u_pattern.y); alphaFromPattern(v_length.x, u_pattern.x, u_pattern.y);

View File

@@ -1,29 +1,40 @@
// Warning! Beware to use this shader. "discard" command may significally reduce performance. // Warning! Beware to use this shader. "discard" command may significally reduce performance.
// Unfortunately some CG algorithms cannot be implemented on OpenGL ES 2.0 without discarding // Unfortunately some CG algorithms cannot be implemented without discarding fragments from depth buffer.
// fragments from depth buffer.
uniform vec4 u_routeParams; layout (location = 0) in vec4 v_radius;
uniform vec4 u_maskColor; layout (location = 1) in vec4 v_color;
uniform float u_opacity;
in vec4 v_radius; layout (location = 0) out vec4 v_FragColor;
in vec4 v_color;
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec4 u_routeParams;
vec4 u_color;
vec4 u_maskColor;
vec4 u_outlineColor;
vec4 u_fakeColor;
vec4 u_fakeOutlineColor;
vec2 u_fakeBorders;
vec2 u_pattern;
vec2 u_angleCosSin;
float u_arrowHalfWidth;
float u_opacity;
};
const float kAntialiasingPixelsCount = 2.5; const float kAntialiasingPixelsCount = 2.5;
out vec4 v_FragColor;
void main() void main()
{ {
vec4 finalColor = v_color; vec4 finalColor = v_color;
float aaRadius = max(v_radius.z - kAntialiasingPixelsCount, 0.0); float aaRadius = max(v_radius.z - kAntialiasingPixelsCount, 0.0);
float stepValue = smoothstep(aaRadius * aaRadius, v_radius.z * v_radius.z, float stepValue = smoothstep(aaRadius * aaRadius, v_radius.z * v_radius.z,
dot(v_radius.xy, v_radius.xy)); dot(v_radius.xy, v_radius.xy));
finalColor.a = finalColor.a * u_opacity * (1.0 - stepValue); finalColor.a = finalColor.a * u_opacity * (1.0 - stepValue);
if (finalColor.a < 0.01 || u_routeParams.y > v_radius.w) if (finalColor.a < 0.01 || u_routeParams.y > v_radius.w)
discard; discard;
finalColor = vec4(mix(finalColor.rgb, u_maskColor.rgb, u_maskColor.a), finalColor.a); finalColor = vec4(mix(finalColor.rgb, u_maskColor.rgb, u_maskColor.a), finalColor.a);
v_FragColor = finalColor; v_FragColor = finalColor;
} }

View File

@@ -1,16 +1,27 @@
in vec4 a_position; layout (location = 0) in vec4 a_position;
in vec3 a_normal; layout (location = 1) in vec3 a_normal;
in vec4 a_color; layout (location = 2) in vec4 a_color;
uniform mat4 u_modelView; layout (location = 0) out vec4 v_radius;
uniform mat4 u_projection; layout (location = 1) out vec4 v_color;
uniform mat4 u_pivotTransform;
uniform vec2 u_angleCosSin; layout (binding = 0) uniform UBO
uniform vec4 u_routeParams; {
mat4 u_modelView;
out vec4 v_radius; mat4 u_projection;
out vec4 v_color; mat4 u_pivotTransform;
vec4 u_routeParams;
vec4 u_color;
vec4 u_maskColor;
vec4 u_outlineColor;
vec4 u_fakeColor;
vec4 u_fakeOutlineColor;
vec2 u_fakeBorders;
vec2 u_pattern;
vec2 u_angleCosSin;
float u_arrowHalfWidth;
float u_opacity;
};
void main() void main()
{ {

View File

@@ -0,0 +1,23 @@
layout (location = 0) in vec2 v_colorTexCoords;
layout (location = 0) out vec4 v_FragColor;
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
vec2 u_contrastGamma;
vec2 u_position;
float u_isOutlinePass;
float u_opacity;
float u_length;
};
layout (binding = 1) uniform sampler2D u_colorTex;
void main()
{
vec4 finalColor = texture(u_colorTex, v_colorTexCoords);
finalColor.a *= u_opacity;
v_FragColor = finalColor;
}

View File

@@ -1,12 +1,19 @@
in vec2 a_position; layout (location = 0) in vec2 a_position;
in vec2 a_normal; layout (location = 1) in vec2 a_normal;
in vec2 a_colorTexCoords; layout (location = 2) in vec2 a_colorTexCoords;
uniform vec2 u_position; layout (location = 0) out vec2 v_colorTexCoords;
uniform float u_length;
uniform mat4 u_projection;
out vec2 v_colorTexCoords; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
vec2 u_contrastGamma;
vec2 u_position;
float u_isOutlinePass;
float u_opacity;
float u_length;
};
void main() void main()
{ {

View File

@@ -0,0 +1,17 @@
layout (location = 0) in vec2 v_colorTexCoords;
layout (location = 0) out vec4 v_FragColor;
layout (binding = 0) uniform UBO
{
float u_opacity;
};
layout (binding = 1) uniform sampler2D u_colorTex;
void main()
{
vec4 finalColor = texture(u_colorTex, v_colorTexCoords);
finalColor.a *= u_opacity;
v_FragColor = finalColor;
}

View File

@@ -1,11 +1,10 @@
in vec2 a_pos; layout (location = 0) in vec2 a_pos;
in vec2 a_tcoord; layout (location = 1) in vec2 a_tcoord;
out vec2 v_colorTexCoords; layout (location = 0) out vec2 v_colorTexCoords;
void main() void main()
{ {
v_colorTexCoords = a_tcoord; v_colorTexCoords = a_tcoord;
gl_Position = vec4(a_pos, 0.0, 1.0); gl_Position = vec4(a_pos, 0.0, 1.0);
} }

View File

@@ -1,17 +1,28 @@
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
in LOW_P vec4 v_color; layout (location = 0) in LOW_P vec4 v_color;
#else #else
uniform sampler2D u_colorTex; layout (location = 1) in vec2 v_colorTexCoord;
in vec2 v_colorTexCoord; layout (binding = 1) uniform sampler2D u_colorTex;
#endif #endif
uniform float u_opacity; layout (location = 2) in float v_lengthY;
in float v_lengthY; layout (location = 0) out vec4 v_FragColor;
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec4 u_position;
vec2 u_lineParams;
float u_accuracy;
float u_zScale;
float u_opacity;
float u_azimut;
};
const float kAntialiasingThreshold = 0.92; const float kAntialiasingThreshold = 0.92;
out vec4 v_FragColor;
void main() void main()
{ {
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
@@ -21,6 +32,5 @@ void main()
#endif #endif
color.a *= u_opacity; color.a *= u_opacity;
color.a *= (1.0 - smoothstep(kAntialiasingThreshold, 1.0, abs(v_lengthY))); color.a *= (1.0 - smoothstep(kAntialiasingThreshold, 1.0, abs(v_lengthY)));
v_FragColor = color; v_FragColor = color;
} }

View File

@@ -1,22 +1,33 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec2 a_normal; layout (location = 1) in vec2 a_normal;
in vec2 a_colorTexCoords; layout (location = 2) in vec2 a_colorTexCoords;
in vec3 a_length; layout (location = 3) in vec3 a_length;
uniform mat4 u_modelView;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
uniform vec2 u_lineParams;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
uniform sampler2D u_colorTex; layout (location = 0) out LOW_P vec4 v_color;
out LOW_P vec4 v_color;
#else #else
out vec2 v_colorTexCoord; layout (location = 1) out vec2 v_colorTexCoord;
#endif
layout (location = 2) out float v_lengthY;
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec4 u_position;
vec2 u_lineParams;
float u_accuracy;
float u_zScale;
float u_opacity;
float u_azimut;
};
#ifdef ENABLE_VTF
layout (binding = 1) uniform sampler2D u_colorTex;
#endif #endif
out float v_lengthY; const float kAntialiasingThreshold = 0.92;
void main() void main()
{ {
@@ -30,7 +41,6 @@ void main()
if (u_lineParams.y != 0.0) if (u_lineParams.y != 0.0)
len = vec2(a_length.x + a_length.y * u_lineParams.y, a_length.z); len = vec2(a_length.x + a_length.y * u_lineParams.y, a_length.z);
} }
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
v_color = texture(u_colorTex, a_colorTexCoords); v_color = texture(u_colorTex, a_colorTexCoords);
#else #else

View File

@@ -5,8 +5,8 @@ Bookmark user_mark.vsh.glsl user_mark.fsh.glsl
BookmarkAnim user_mark.vsh.glsl user_mark.fsh.glsl BookmarkAnim user_mark.vsh.glsl user_mark.fsh.glsl
TextOutlined text_outlined.vsh.glsl text.fsh.glsl TextOutlined text_outlined.vsh.glsl text.fsh.glsl
Text text.vsh.glsl text.fsh.glsl Text text.vsh.glsl text.fsh.glsl
TextStaticOutlinedGui text_outlined_gui.vsh.glsl text.fsh.glsl TextStaticOutlinedGui text_outlined_gui.vsh.glsl text_outlined_gui.fsh.glsl
TextOutlinedGui text_outlined_gui.vsh.glsl text.fsh.glsl TextOutlinedGui text_outlined_gui.vsh.glsl text_outlined_gui.fsh.glsl
Area area.vsh.glsl solid_color.fsh.glsl Area area.vsh.glsl solid_color.fsh.glsl
AreaOutline area.vsh.glsl solid_color.fsh.glsl AreaOutline area.vsh.glsl solid_color.fsh.glsl
Area3d area3d.vsh.glsl texturing3d.fsh.glsl Area3d area3d.vsh.glsl texturing3d.fsh.glsl
@@ -18,10 +18,10 @@ PathSymbol path_symbol.vsh.glsl texturing.fsh.glsl
TransparentArea area.vsh.glsl solid_color.fsh.glsl TransparentArea area.vsh.glsl solid_color.fsh.glsl
CapJoin circle.vsh.glsl circle.fsh.glsl CapJoin circle.vsh.glsl circle.fsh.glsl
HatchingArea hatching_area.vsh.glsl hatching_area.fsh.glsl HatchingArea hatching_area.vsh.glsl hatching_area.fsh.glsl
TexturingGui texturing_gui.vsh.glsl texturing.fsh.glsl TexturingGui texturing_gui.vsh.glsl texturing_gui.fsh.glsl
Ruler ruler.vsh.glsl texturing.fsh.glsl Ruler ruler.vsh.glsl ruler.fsh.glsl
Accuracy position_accuracy3d.vsh.glsl texturing.fsh.glsl Accuracy position_accuracy3d.vsh.glsl texturing_position.fsh.glsl
MyPosition my_position.vsh.glsl texturing.fsh.glsl MyPosition my_position.vsh.glsl texturing_position.fsh.glsl
SelectionLine selection_line.vsh.glsl selection_line.fsh.glsl SelectionLine selection_line.vsh.glsl selection_line.fsh.glsl
Transit transit.vsh.glsl transit.fsh.glsl Transit transit.vsh.glsl transit.fsh.glsl
TransitMarker transit_marker.vsh.glsl transit_marker.fsh.glsl TransitMarker transit_marker.vsh.glsl transit_marker.fsh.glsl
@@ -33,7 +33,7 @@ CirclePoint circle_point.vsh.glsl circle_point.fsh.glsl
BookmarkAboveText user_mark.vsh.glsl user_mark.fsh.glsl BookmarkAboveText user_mark.vsh.glsl user_mark.fsh.glsl
BookmarkAnimAboveText user_mark.vsh.glsl user_mark.fsh.glsl BookmarkAnimAboveText user_mark.vsh.glsl user_mark.fsh.glsl
DebugRect debug_rect.vsh.glsl debug_rect.fsh.glsl DebugRect debug_rect.vsh.glsl debug_rect.fsh.glsl
ScreenQuad screen_quad.vsh.glsl texturing.fsh.glsl ScreenQuad screen_quad.vsh.glsl screen_quad.fsh.glsl
Arrow3d arrow3d.vsh.glsl arrow3d.fsh.glsl Arrow3d arrow3d.vsh.glsl arrow3d.fsh.glsl
Arrow3dTextured arrow3d_textured.vsh.glsl arrow3d_textured.fsh.glsl Arrow3dTextured arrow3d_textured.vsh.glsl arrow3d_textured.fsh.glsl
Arrow3dShadow arrow3d_shadow.vsh.glsl arrow3d_shadow.fsh.glsl Arrow3dShadow arrow3d_shadow.vsh.glsl arrow3d_shadow.fsh.glsl

View File

@@ -1,21 +1,24 @@
// Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa // Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa
layout (location = 0) in vec4 v_coords;
layout (location = 1) in vec4 v_offset0;
layout (location = 2) in vec4 v_offset1;
layout (location = 3) in vec4 v_offset2;
uniform sampler2D u_colorTex; layout (location = 0) out vec4 v_FragColor;
uniform sampler2D u_smaaArea;
uniform sampler2D u_smaaSearch;
uniform vec4 u_framebufferMetrics; layout (binding = 0) uniform UBO
{
vec4 u_framebufferMetrics;
};
in vec4 v_coords; layout (binding = 1) uniform sampler2D u_colorTex;
in vec4 v_offset0; layout (binding = 2) uniform sampler2D u_smaaArea;
in vec4 v_offset1; layout (binding = 3) uniform sampler2D u_smaaSearch;
in vec4 v_offset2;
#define SMAA_SEARCHTEX_SIZE vec2(66.0, 33.0) #define SMAA_SEARCHTEX_SIZE vec2(66.0, 33.0)
#define SMAA_SEARCHTEX_PACKED_SIZE vec2(64.0, 16.0) #define SMAA_SEARCHTEX_PACKED_SIZE vec2(64.0, 16.0)
#define SMAA_AREATEX_MAX_DISTANCE 16.0 #define SMAA_AREATEX_MAX_DISTANCE 16.0
#define SMAA_AREATEX_PIXEL_SIZE (vec2(1.0 / 256.0, 1.0 / 1024.0)) #define SMAA_AREATEX_PIXEL_SIZE (vec2(1.0 / 256.0, 1.0 / 1024.0))
#define SMAALoopBegin(condition) while (condition) { #define SMAALoopBegin(condition) while (condition) {
#define SMAALoopEnd } #define SMAALoopEnd }
#define SMAASampleLevelZero(tex, coord) textureLod(tex, coord, 0.0) #define SMAASampleLevelZero(tex, coord) textureLod(tex, coord, 0.0)
@@ -32,16 +35,13 @@ float SMAASearchLength(vec2 e, float offset)
// of the space horizontally. // of the space horizontally.
vec2 scale = SMAA_SEARCHTEX_SIZE * vec2(0.5, -1.0); vec2 scale = SMAA_SEARCHTEX_SIZE * vec2(0.5, -1.0);
vec2 bias = SMAA_SEARCHTEX_SIZE * vec2(offset, 1.0); vec2 bias = SMAA_SEARCHTEX_SIZE * vec2(offset, 1.0);
// Scale and bias to access texel centers. // Scale and bias to access texel centers.
scale += vec2(-1.0, 1.0); scale += vec2(-1.0, 1.0);
bias += vec2( 0.5, -0.5); bias += vec2( 0.5, -0.5);
// Convert from pixel coordinates to texcoords. // Convert from pixel coordinates to texcoords.
// (We use SMAA_SEARCHTEX_PACKED_SIZE because the texture is cropped). // (We use SMAA_SEARCHTEX_PACKED_SIZE because the texture is cropped).
scale *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE; scale *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE;
bias *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE; bias *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE;
// Lookup the search texture. // Lookup the search texture.
return SMAASampleLevelZero(u_smaaSearch, scale * e + bias).r; return SMAASampleLevelZero(u_smaaSearch, scale * e + bias).r;
} }
@@ -101,79 +101,60 @@ vec2 SMAAArea(vec2 dist, float e1, float e2)
return SMAASampleLevelZero(u_smaaArea, texcoord).rg; return SMAASampleLevelZero(u_smaaArea, texcoord).rg;
} }
out vec4 v_FragColor;
void main() void main()
{ {
vec4 weights = vec4(0.0, 0.0, 0.0, 0.0); vec4 weights = vec4(0.0, 0.0, 0.0, 0.0);
vec2 e = texture(u_colorTex, v_coords.xy).rg; vec2 e = texture(u_colorTex, v_coords.xy).rg;
if (e.g > 0.0) // Edge at north if (e.g > 0.0) // Edge at north
{ {
vec2 d; vec2 d;
// Find the distance to the left. // Find the distance to the left.
vec3 coords; vec3 coords;
coords.x = SMAASearchXLeft(v_offset0.xy, v_offset2.x); coords.x = SMAASearchXLeft(v_offset0.xy, v_offset2.x);
coords.y = v_offset1.y; coords.y = v_offset1.y;
d.x = coords.x; d.x = coords.x;
// Now fetch the left crossing edges, two at a time using bilinear // Now fetch the left crossing edges, two at a time using bilinear
// filtering. Sampling at -0.25 enables to discern what value each edge has. // filtering. Sampling at -0.25 enables to discern what value each edge has.
float e1 = SMAASampleLevelZero(u_colorTex, coords.xy).r; float e1 = SMAASampleLevelZero(u_colorTex, coords.xy).r;
// Find the distance to the right. // Find the distance to the right.
coords.z = SMAASearchXRight(v_offset0.zw, v_offset2.y); coords.z = SMAASearchXRight(v_offset0.zw, v_offset2.y);
d.y = coords.z; d.y = coords.z;
// We want the distances to be in pixel units (doing this here allow to // We want the distances to be in pixel units (doing this here allow to
// better interleave arithmetic and memory accesses). // better interleave arithmetic and memory accesses).
vec2 zz = u_framebufferMetrics.zz; vec2 zz = u_framebufferMetrics.zz;
d = abs(SMAARound(zz * d - v_coords.zz)); d = abs(SMAARound(zz * d - v_coords.zz));
// SMAAArea below needs a sqrt, as the areas texture is compressed // SMAAArea below needs a sqrt, as the areas texture is compressed
// quadratically. // quadratically.
vec2 sqrt_d = sqrt(d); vec2 sqrt_d = sqrt(d);
// Fetch the right crossing edges. // Fetch the right crossing edges.
float e2 = SMAASampleLevelZeroOffset(u_colorTex, coords.zy, SMAAOffset(1, 0)).r; float e2 = SMAASampleLevelZeroOffset(u_colorTex, coords.zy, SMAAOffset(1, 0)).r;
// Here we know how this pattern looks like, now it is time for getting // Here we know how this pattern looks like, now it is time for getting
// the actual area. // the actual area.
weights.rg = SMAAArea(sqrt_d, e1, e2); weights.rg = SMAAArea(sqrt_d, e1, e2);
} }
if (e.r > 0.0) // Edge at west if (e.r > 0.0) // Edge at west
{ {
vec2 d; vec2 d;
// Find the distance to the top. // Find the distance to the top.
vec3 coords; vec3 coords;
coords.y = SMAASearchYUp(v_offset1.xy, v_offset2.z); coords.y = SMAASearchYUp(v_offset1.xy, v_offset2.z);
coords.x = v_offset0.x; coords.x = v_offset0.x;
d.x = coords.y; d.x = coords.y;
// Fetch the top crossing edges. // Fetch the top crossing edges.
float e1 = SMAASampleLevelZero(u_colorTex, coords.xy).g; float e1 = SMAASampleLevelZero(u_colorTex, coords.xy).g;
// Find the distance to the bottom. // Find the distance to the bottom.
coords.z = SMAASearchYDown(v_offset1.zw, v_offset2.w); coords.z = SMAASearchYDown(v_offset1.zw, v_offset2.w);
d.y = coords.z; d.y = coords.z;
// We want the distances to be in pixel units. // We want the distances to be in pixel units.
vec2 ww = u_framebufferMetrics.ww; vec2 ww = u_framebufferMetrics.ww;
d = abs(SMAARound(ww * d - v_coords.ww)); d = abs(SMAARound(ww * d - v_coords.ww));
// SMAAArea below needs a sqrt, as the areas texture is compressed // SMAAArea below needs a sqrt, as the areas texture is compressed
// quadratically. // quadratically.
vec2 sqrt_d = sqrt(d); vec2 sqrt_d = sqrt(d);
// Fetch the bottom crossing edges. // Fetch the bottom crossing edges.
float e2 = SMAASampleLevelZeroOffset(u_colorTex, coords.xz, SMAAOffset(0, 1)).g; float e2 = SMAASampleLevelZeroOffset(u_colorTex, coords.xz, SMAAOffset(0, 1)).g;
// Get the area for this direction. // Get the area for this direction.
weights.ba = SMAAArea(sqrt_d, e1, e2); weights.ba = SMAAArea(sqrt_d, e1, e2);
} }
v_FragColor = weights; v_FragColor = weights;
} }

View File

@@ -1,14 +1,16 @@
// Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa // Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa
layout (location = 0) in vec2 a_pos;
layout (location = 1) in vec2 a_tcoord;
in vec2 a_pos; layout (location = 0) out vec4 v_coords;
in vec2 a_tcoord; layout (location = 1) out vec4 v_offset0;
layout (location = 2) out vec4 v_offset1;
layout (location = 3) out vec4 v_offset2;
uniform vec4 u_framebufferMetrics; layout (binding = 0) uniform UBO
{
out vec4 v_coords; vec4 u_framebufferMetrics;
out vec4 v_offset0; };
out vec4 v_offset1;
out vec4 v_offset2;
// SMAA_MAX_SEARCH_STEPS specifies the maximum steps performed in the // SMAA_MAX_SEARCH_STEPS specifies the maximum steps performed in the
// horizontal/vertical pattern searches, at each side of the pixel. // horizontal/vertical pattern searches, at each side of the pixel.

View File

@@ -1,11 +1,12 @@
// Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa // Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa
layout (location = 0) in vec2 v_colorTexCoords;
layout (location = 1) in vec4 v_offset0;
layout (location = 2) in vec4 v_offset1;
layout (location = 3) in vec4 v_offset2;
uniform sampler2D u_colorTex; layout (location = 0) out vec4 v_FragColor;
in vec2 v_colorTexCoords; layout (binding = 1) uniform sampler2D u_colorTex;
in vec4 v_offset0;
in vec4 v_offset1;
in vec4 v_offset2;
// SMAA_THRESHOLD specifies the threshold or sensitivity to edges. // SMAA_THRESHOLD specifies the threshold or sensitivity to edges.
// Lowering this value you will be able to detect more edges at the expense of // Lowering this value you will be able to detect more edges at the expense of
@@ -22,46 +23,36 @@ const vec2 kThreshold = vec2(SMAA_THRESHOLD, SMAA_THRESHOLD);
// that, if there is too much contrast in a direction, that will hide // that, if there is too much contrast in a direction, that will hide
// perceptually contrast in the other neighbors. // perceptually contrast in the other neighbors.
#define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 2.0 #define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 2.0
// Standard relative luminance weights. // Standard relative luminance weights.
// https://en.wikipedia.org/wiki/Relative_luminance // https://en.wikipedia.org/wiki/Relative_luminance
const vec3 kWeights = vec3(0.2126, 0.7152, 0.0722); const vec3 kWeights = vec3(0.2126, 0.7152, 0.0722);
out vec4 v_FragColor;
void main() void main()
{ {
// Calculate lumas. // Calculate lumas.
float L = dot(texture(u_colorTex, v_colorTexCoords).rgb, kWeights); float L = dot(texture(u_colorTex, v_colorTexCoords).rgb, kWeights);
float Lleft = dot(texture(u_colorTex, v_offset0.xy).rgb, kWeights); float Lleft = dot(texture(u_colorTex, v_offset0.xy).rgb, kWeights);
float Ltop = dot(texture(u_colorTex, v_offset0.zw).rgb, kWeights); float Ltop = dot(texture(u_colorTex, v_offset0.zw).rgb, kWeights);
// We do the usual threshold. // We do the usual threshold.
vec4 delta; vec4 delta;
delta.xy = abs(L - vec2(Lleft, Ltop)); delta.xy = abs(L - vec2(Lleft, Ltop));
vec2 edges = step(kThreshold, delta.xy); vec2 edges = step(kThreshold, delta.xy);
if (dot(edges, vec2(1.0, 1.0)) == 0.0) if (dot(edges, vec2(1.0, 1.0)) == 0.0)
discard; discard;
// Calculate right and bottom deltas. // Calculate right and bottom deltas.
float Lright = dot(texture(u_colorTex, v_offset1.xy).rgb, kWeights); float Lright = dot(texture(u_colorTex, v_offset1.xy).rgb, kWeights);
float Lbottom = dot(texture(u_colorTex, v_offset1.zw).rgb, kWeights); float Lbottom = dot(texture(u_colorTex, v_offset1.zw).rgb, kWeights);
delta.zw = abs(L - vec2(Lright, Lbottom)); delta.zw = abs(L - vec2(Lright, Lbottom));
// Calculate the maximum delta in the direct neighborhood. // Calculate the maximum delta in the direct neighborhood.
vec2 maxDelta = max(delta.xy, delta.zw); vec2 maxDelta = max(delta.xy, delta.zw);
// Calculate left-left and top-top deltas. // Calculate left-left and top-top deltas.
float Lleftleft = dot(texture(u_colorTex, v_offset2.xy).rgb, kWeights); float Lleftleft = dot(texture(u_colorTex, v_offset2.xy).rgb, kWeights);
float Ltoptop = dot(texture(u_colorTex, v_offset2.zw).rgb, kWeights); float Ltoptop = dot(texture(u_colorTex, v_offset2.zw).rgb, kWeights);
delta.zw = abs(vec2(Lleft, Ltop) - vec2(Lleftleft, Ltoptop)); delta.zw = abs(vec2(Lleft, Ltop) - vec2(Lleftleft, Ltoptop));
// Calculate the final maximum delta. // Calculate the final maximum delta.
maxDelta = max(maxDelta.xy, delta.zw); maxDelta = max(maxDelta.xy, delta.zw);
float finalDelta = max(maxDelta.x, maxDelta.y); float finalDelta = max(maxDelta.x, maxDelta.y);
// Local contrast adaptation // Local contrast adaptation
edges *= step(finalDelta, SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR * delta.xy); edges *= step(finalDelta, SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR * delta.xy);
v_FragColor = vec4(edges, 0.0, 1.0); v_FragColor = vec4(edges, 0.0, 1.0);
} }

View File

@@ -1,14 +1,16 @@
// Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa // Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa
layout (location = 0) in vec2 a_pos;
layout (location = 1) in vec2 a_tcoord;
in vec2 a_pos; layout (location = 0) out vec2 v_colorTexCoords;
in vec2 a_tcoord; layout (location = 1) out vec4 v_offset0;
layout (location = 2) out vec4 v_offset1;
layout (location = 3) out vec4 v_offset2;
uniform vec4 u_framebufferMetrics; layout (binding = 0) uniform UBO
{
out vec2 v_colorTexCoords; vec4 u_framebufferMetrics;
out vec4 v_offset0; };
out vec4 v_offset1;
out vec4 v_offset2;
void main() void main()
{ {
@@ -18,4 +20,3 @@ void main()
v_offset2 = u_framebufferMetrics.xyxy * vec4(-2.0, 0.0, 0.0, -2.0) + a_tcoord.xyxy; v_offset2 = u_framebufferMetrics.xyxy * vec4(-2.0, 0.0, 0.0, -2.0) + a_tcoord.xyxy;
gl_Position = vec4(a_pos, 0.0, 1.0); gl_Position = vec4(a_pos, 0.0, 1.0);
} }

View File

@@ -1,17 +1,20 @@
// Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa // Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa
layout (location = 0) in vec2 v_colorTexCoords;
layout (location = 1) in vec4 v_offset;
uniform sampler2D u_colorTex; layout (location = 0) out vec4 v_FragColor;
uniform sampler2D u_blendingWeightTex;
uniform vec4 u_framebufferMetrics; layout (binding = 0) uniform UBO
{
vec4 u_framebufferMetrics;
};
in vec2 v_colorTexCoords; layout (binding = 1) uniform sampler2D u_colorTex;
in vec4 v_offset;
layout (binding = 2) uniform sampler2D u_blendingWeightTex;
#define SMAASampleLevelZero(tex, coord) textureLod(tex, coord, 0.0) #define SMAASampleLevelZero(tex, coord) textureLod(tex, coord, 0.0)
out vec4 v_FragColor;
void main() void main()
{ {
// Fetch the blending weights for current pixel. // Fetch the blending weights for current pixel.
@@ -19,7 +22,6 @@ void main()
a.x = texture(u_blendingWeightTex, v_offset.xy).a; // Right a.x = texture(u_blendingWeightTex, v_offset.xy).a; // Right
a.y = texture(u_blendingWeightTex, v_offset.zw).g; // Top a.y = texture(u_blendingWeightTex, v_offset.zw).g; // Top
a.wz = texture(u_blendingWeightTex, v_colorTexCoords).xz; // Bottom / Left a.wz = texture(u_blendingWeightTex, v_colorTexCoords).xz; // Bottom / Left
// Is there any blending weight with a value greater than 0.0? // Is there any blending weight with a value greater than 0.0?
if (dot(a, vec4(1.0, 1.0, 1.0, 1.0)) < 1e-5) if (dot(a, vec4(1.0, 1.0, 1.0, 1.0)) < 1e-5)
{ {
@@ -36,11 +38,9 @@ void main()
blendingWeight = a.xz; blendingWeight = a.xz;
} }
blendingWeight /= dot(blendingWeight, vec2(1.0, 1.0)); blendingWeight /= dot(blendingWeight, vec2(1.0, 1.0));
// Calculate the texture coordinates. // Calculate the texture coordinates.
vec4 bc = blendingOffset * vec4(u_framebufferMetrics.xy, -u_framebufferMetrics.xy); vec4 bc = blendingOffset * vec4(u_framebufferMetrics.xy, -u_framebufferMetrics.xy);
bc += v_colorTexCoords.xyxy; bc += v_colorTexCoords.xyxy;
// We exploit bilinear filtering to mix current pixel with the chosen neighbor. // We exploit bilinear filtering to mix current pixel with the chosen neighbor.
vec4 color = blendingWeight.x * SMAASampleLevelZero(u_colorTex, bc.xy); vec4 color = blendingWeight.x * SMAASampleLevelZero(u_colorTex, bc.xy);
color += blendingWeight.y * SMAASampleLevelZero(u_colorTex, bc.zw); color += blendingWeight.y * SMAASampleLevelZero(u_colorTex, bc.zw);

View File

@@ -1,12 +1,14 @@
// Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa // Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa
layout (location = 0) in vec2 a_pos;
layout (location = 1) in vec2 a_tcoord;
in vec2 a_pos; layout (location = 0) out vec2 v_colorTexCoords;
in vec2 a_tcoord; layout (location = 1) out vec4 v_offset;
uniform vec4 u_framebufferMetrics; layout (binding = 0) uniform UBO
{
out vec2 v_colorTexCoords; vec4 u_framebufferMetrics;
out vec4 v_offset; };
void main() void main()
{ {

View File

@@ -1,13 +1,23 @@
uniform float u_opacity;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
in LOW_P vec4 v_color; layout (location = 0) in LOW_P vec4 v_color;
#else #else
uniform sampler2D u_colorTex; layout (location = 1) in vec2 v_colorTexCoords;
in vec2 v_colorTexCoords; layout (binding = 1) uniform sampler2D u_colorTex;
#endif #endif
out vec4 v_FragColor; layout (location = 0) out vec4 v_FragColor;
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
void main() void main()
{ {
@@ -19,4 +29,3 @@ void main()
finalColor.a *= u_opacity; finalColor.a *= u_opacity;
v_FragColor = finalColor; v_FragColor = finalColor;
} }

View File

@@ -1,17 +1,26 @@
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
in LOW_P vec4 v_color; layout (location = 0) in LOW_P vec4 v_color;
#else #else
in vec2 v_colorTexCoord; layout (location = 1) in vec2 v_colorTexCoord;
uniform sampler2D u_colorTex; layout (binding = 1) uniform sampler2D u_colorTex;
#endif #endif
layout (location = 2) in vec2 v_maskTexCoord;
in vec2 v_maskTexCoord; layout (location = 0) out vec4 v_FragColor;
uniform sampler2D u_maskTex; layout (binding = 0) uniform UBO
uniform float u_opacity; {
uniform vec2 u_contrastGamma; mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
out vec4 v_FragColor; layout (binding = 2) uniform sampler2D u_maskTex;
void main() void main()
{ {

View File

@@ -1,27 +1,36 @@
in vec2 a_colorTexCoord; layout (location = 0) in vec2 a_colorTexCoord;
in vec2 a_maskTexCoord; layout (location = 1) in vec2 a_maskTexCoord;
in vec4 a_position; layout (location = 2) in vec4 a_position;
in vec2 a_normal; layout (location = 3) in vec2 a_normal;
uniform mat4 u_modelView;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
uniform sampler2D u_colorTex; layout (location = 0) out LOW_P vec4 v_color;
out LOW_P vec4 v_color;
#else #else
out vec2 v_colorTexCoord; layout (location = 1) out vec2 v_colorTexCoord;
#endif #endif
layout (location = 2) out vec2 v_maskTexCoord;
out vec2 v_maskTexCoord; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
#ifdef ENABLE_VTF
layout (binding = 1) uniform sampler2D u_colorTex;
#endif
void main() void main()
{ {
vec4 pos = vec4(a_position.xyz, 1) * u_modelView; vec4 pos = vec4(a_position.xyz, 1) * u_modelView;
vec4 shiftedPos = vec4(a_normal, 0.0, 0.0) + pos; vec4 shiftedPos = vec4(a_normal, 0.0, 0.0) + pos;
gl_Position = applyPivotTransform(shiftedPos * u_projection, u_pivotTransform, 0.0); gl_Position = applyPivotTransform(shiftedPos * u_projection, u_pivotTransform, 0.0);
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
v_color = texture(u_colorTex, a_colorTexCoord); v_color = texture(u_colorTex, a_colorTexCoord);
#else #else

View File

@@ -1,22 +1,28 @@
in vec2 a_colorTexCoord; layout (location = 0) in vec2 a_colorTexCoord;
in vec2 a_maskTexCoord; layout (location = 1) in vec2 a_maskTexCoord;
in vec4 a_position; layout (location = 2) in vec4 a_position;
in vec2 a_normal; layout (location = 3) in vec2 a_normal;
uniform mat4 u_modelView;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
uniform float u_isOutlinePass;
uniform float u_zScale;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
uniform sampler2D u_colorTex; layout (location = 0) out LOW_P vec4 v_color;
out LOW_P vec4 v_color;
#else #else
out vec2 v_colorTexCoord; layout (location = 1) out vec2 v_colorTexCoord;
#endif #endif
layout (location = 2) out vec2 v_maskTexCoord;
out vec2 v_maskTexCoord; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
layout (binding = 1) uniform sampler2D u_colorTex;
void main() void main()
{ {

View File

@@ -1,22 +1,31 @@
in vec2 a_colorTexCoord; layout (location = 0) in vec2 a_colorTexCoord;
in vec2 a_outlineColorTexCoord; layout (location = 1) in vec2 a_outlineColorTexCoord;
in vec2 a_maskTexCoord; layout (location = 2) in vec2 a_maskTexCoord;
in vec4 a_position; layout (location = 3) in vec4 a_position;
in vec2 a_normal; layout (location = 4) in vec2 a_normal;
uniform mat4 u_modelView;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
uniform float u_isOutlinePass;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
uniform sampler2D u_colorTex; layout (location = 0) out LOW_P vec4 v_color;
out LOW_P vec4 v_color;
#else #else
out vec2 v_colorTexCoord; layout (location = 1) out vec2 v_colorTexCoord;
#endif #endif
layout (location = 2) out vec2 v_maskTexCoord;
out vec2 v_maskTexCoord; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
#ifdef ENABLE_VTF
layout (binding = 1) uniform sampler2D u_colorTex;
#endif
const float BaseDepthShift = -10.0; const float BaseDepthShift = -10.0;
@@ -25,7 +34,6 @@ void main()
float isOutline = step(0.5, u_isOutlinePass); float isOutline = step(0.5, u_isOutlinePass);
float notOutline = 1.0 - isOutline; float notOutline = 1.0 - isOutline;
float depthShift = BaseDepthShift * isOutline; float depthShift = BaseDepthShift * isOutline;
vec4 pos = (vec4(a_position.xyz, 1) + vec4(0.0, 0.0, depthShift, 0.0)) * u_modelView; vec4 pos = (vec4(a_position.xyz, 1) + vec4(0.0, 0.0, depthShift, 0.0)) * u_modelView;
vec4 shiftedPos = vec4(a_normal, 0.0, 0.0) + pos; vec4 shiftedPos = vec4(a_normal, 0.0, 0.0) + pos;
gl_Position = applyPivotTransform(shiftedPos * u_projection, u_pivotTransform, 0.0); gl_Position = applyPivotTransform(shiftedPos * u_projection, u_pivotTransform, 0.0);

View File

@@ -1,23 +1,29 @@
in vec2 a_colorTexCoord; layout (location = 0) in vec2 a_colorTexCoord;
in vec2 a_outlineColorTexCoord; layout (location = 1) in vec2 a_outlineColorTexCoord;
in vec2 a_maskTexCoord; layout (location = 2) in vec2 a_maskTexCoord;
in vec4 a_position; layout (location = 3) in vec4 a_position;
in vec2 a_normal; layout (location = 4) in vec2 a_normal;
uniform mat4 u_modelView;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
uniform float u_isOutlinePass;
uniform float u_zScale;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
uniform sampler2D u_colorTex; layout (location = 0) out LOW_P vec4 v_color;
out LOW_P vec4 v_color;
#else #else
out vec2 v_colorTexCoord; layout (location = 1) out vec2 v_colorTexCoord;
#endif #endif
layout (location = 2) out vec2 v_maskTexCoord;
out vec2 v_maskTexCoord; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
layout (binding = 1) uniform sampler2D u_colorTex;
const float kBaseDepthShift = -10.0; const float kBaseDepthShift = -10.0;
@@ -25,12 +31,10 @@ void main()
{ {
float isOutline = step(0.5, u_isOutlinePass); float isOutline = step(0.5, u_isOutlinePass);
float depthShift = kBaseDepthShift * isOutline; float depthShift = kBaseDepthShift * isOutline;
vec4 pivot = (vec4(a_position.xyz, 1.0) + vec4(0.0, 0.0, depthShift, 0.0)) * u_modelView; vec4 pivot = (vec4(a_position.xyz, 1.0) + vec4(0.0, 0.0, depthShift, 0.0)) * u_modelView;
vec4 offset = vec4(a_normal, 0.0, 0.0) * u_projection; vec4 offset = vec4(a_normal, 0.0, 0.0) * u_projection;
gl_Position = applyBillboardPivotTransform(pivot * u_projection, u_pivotTransform, gl_Position = applyBillboardPivotTransform(pivot * u_projection, u_pivotTransform,
a_position.w * u_zScale, offset.xy); a_position.w * u_zScale, offset.xy);
vec2 colorTexCoord = mix(a_colorTexCoord, a_outlineColorTexCoord, isOutline); vec2 colorTexCoord = mix(a_colorTexCoord, a_outlineColorTexCoord, isOutline);
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
v_color = texture(u_colorTex, colorTexCoord); v_color = texture(u_colorTex, colorTexCoord);

View File

@@ -0,0 +1,35 @@
#ifdef ENABLE_VTF
layout (location = 0) in LOW_P vec4 v_color;
#else
layout (location = 1) in vec2 v_colorTexCoord;
layout (binding = 1) uniform sampler2D u_colorTex;
#endif
layout (location = 2) in vec2 v_maskTexCoord;
layout (location = 0) out vec4 v_FragColor;
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
vec2 u_contrastGamma;
vec2 u_position;
float u_isOutlinePass;
float u_opacity;
float u_length;
};
layout (binding = 2) uniform sampler2D u_maskTex;
void main()
{
#ifdef ENABLE_VTF
LOW_P vec4 glyphColor = v_color;
#else
LOW_P vec4 glyphColor = texture(u_colorTex, v_colorTexCoord);
#endif
float dist = texture(u_maskTex, v_maskTexCoord).r;
float alpha = smoothstep(u_contrastGamma.x - u_contrastGamma.y, u_contrastGamma.x + u_contrastGamma.y, dist) * u_opacity;
glyphColor.a *= alpha;
v_FragColor = glyphColor;
}

View File

@@ -1,21 +1,30 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec2 a_colorTexCoord; layout (location = 1) in vec2 a_colorTexCoord;
in vec2 a_outlineColorTexCoord; layout (location = 2) in vec2 a_outlineColorTexCoord;
in vec2 a_normal; layout (location = 3) in vec2 a_normal;
in vec2 a_maskTexCoord; layout (location = 4) in vec2 a_maskTexCoord;
uniform mat4 u_modelView;
uniform mat4 u_projection;
uniform float u_isOutlinePass;
#ifdef ENABLE_VTF #ifdef ENABLE_VTF
uniform sampler2D u_colorTex; layout (location = 0) out LOW_P vec4 v_color;
out LOW_P vec4 v_color;
#else #else
out vec2 v_colorTexCoord; layout (location = 1) out vec2 v_colorTexCoord;
#endif #endif
layout (location = 2) out vec2 v_maskTexCoord;
out vec2 v_maskTexCoord; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
vec2 u_contrastGamma;
vec2 u_position;
float u_isOutlinePass;
float u_opacity;
float u_length;
};
#ifdef ENABLE_VTF
layout (binding = 1) uniform sampler2D u_colorTex;
#endif
const float kBaseDepthShift = -10.0; const float kBaseDepthShift = -10.0;
@@ -23,7 +32,6 @@ void main()
{ {
float isOutline = step(0.5, u_isOutlinePass); float isOutline = step(0.5, u_isOutlinePass);
float depthShift = kBaseDepthShift * isOutline; float depthShift = kBaseDepthShift * isOutline;
vec4 pos = (vec4(a_position, 1.0) + vec4(0.0, 0.0, depthShift, 0.0)) * u_modelView; vec4 pos = (vec4(a_position, 1.0) + vec4(0.0, 0.0, depthShift, 0.0)) * u_modelView;
vec4 shiftedPos = vec4(a_normal, 0.0, 0.0) + pos; vec4 shiftedPos = vec4(a_normal, 0.0, 0.0) + pos;
gl_Position = shiftedPos * u_projection; gl_Position = shiftedPos * u_projection;

View File

@@ -1,9 +1,20 @@
uniform sampler2D u_colorTex; layout (location = 0) in vec2 v_colorTexCoords;
uniform float u_opacity;
in vec2 v_colorTexCoords; layout (location = 0) out vec4 v_FragColor;
out vec4 v_FragColor; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
layout (binding = 1) uniform sampler2D u_colorTex;
void main() void main()
{ {

View File

@@ -1,12 +1,20 @@
in vec4 a_position; layout (location = 0) in vec4 a_position;
in vec2 a_normal; layout (location = 1) in vec2 a_normal;
in vec2 a_colorTexCoords; layout (location = 2) in vec2 a_colorTexCoords;
uniform mat4 u_modelView; layout (location = 0) out vec2 v_colorTexCoords;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
out vec2 v_colorTexCoords; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
void main() void main()
{ {

View File

@@ -1,10 +1,21 @@
uniform sampler2D u_colorTex; layout (location = 0) in vec2 v_colorTexCoords;
uniform float u_opacity; layout (location = 1) in float v_intensity;
in vec2 v_colorTexCoords; layout (location = 0) out vec4 v_FragColor;
in float v_intensity;
out vec4 v_FragColor; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
layout (binding = 1) uniform sampler2D u_colorTex;
void main() void main()
{ {

View File

@@ -1,13 +1,20 @@
in vec4 a_position; layout (location = 0) in vec4 a_position;
in vec2 a_normal; layout (location = 1) in vec2 a_normal;
in vec2 a_colorTexCoords; layout (location = 2) in vec2 a_colorTexCoords;
uniform mat4 u_modelView; layout (location = 0) out vec2 v_colorTexCoords;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
uniform float u_zScale;
out vec2 v_colorTexCoords; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
void main() void main()
{ {

View File

@@ -0,0 +1,23 @@
layout (location = 0) in vec2 v_colorTexCoords;
layout (location = 0) out vec4 v_FragColor;
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
vec2 u_contrastGamma;
vec2 u_position;
float u_isOutlinePass;
float u_opacity;
float u_length;
};
layout (binding = 1) uniform sampler2D u_colorTex;
void main()
{
vec4 finalColor = texture(u_colorTex, v_colorTexCoords);
finalColor.a *= u_opacity;
v_FragColor = finalColor;
}

View File

@@ -1,10 +1,18 @@
in vec2 a_position; layout (location = 0) in vec2 a_position;
in vec2 a_colorTexCoords; layout (location = 1) in vec2 a_colorTexCoords;
uniform mat4 u_modelView; layout (location = 0) out vec2 v_colorTexCoords;
uniform mat4 u_projection;
out vec2 v_colorTexCoords; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
vec2 u_contrastGamma;
vec2 u_position;
float u_isOutlinePass;
float u_opacity;
float u_length;
};
void main() void main()
{ {

View File

@@ -0,0 +1,25 @@
layout (location = 0) in vec2 v_colorTexCoords;
layout (location = 0) out vec4 v_FragColor;
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec4 u_position;
vec2 u_lineParams;
float u_accuracy;
float u_zScale;
float u_opacity;
float u_azimut;
};
layout (binding = 1) uniform sampler2D u_colorTex;
void main()
{
vec4 finalColor = texture(u_colorTex, v_colorTexCoords);
finalColor.a *= u_opacity;
v_FragColor = finalColor;
}

View File

@@ -1,36 +1,41 @@
in vec2 v_colorTexCoord; layout (location = 0) in vec2 v_colorTexCoord;
in vec2 v_maskTexCoord; layout (location = 1) in vec2 v_maskTexCoord;
in float v_halfLength; layout (location = 2) in float v_halfLength;
uniform sampler2D u_colorTex; layout (location = 0) out vec4 v_FragColor;
uniform sampler2D u_maskTex;
uniform float u_opacity;
uniform float u_outline;
uniform vec3 u_lightArrowColor; layout (binding = 0) uniform UBO
uniform vec3 u_darkArrowColor; {
uniform vec3 u_outlineColor; mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec4 u_trafficParams;
vec4 u_outlineColor;
vec4 u_lightArrowColor;
vec4 u_darkArrowColor;
float u_outline;
float u_opacity;
};
layout (binding = 1) uniform sampler2D u_colorTex;
layout (binding = 2) uniform sampler2D u_maskTex;
const float kAntialiasingThreshold = 0.92; const float kAntialiasingThreshold = 0.92;
const float kOutlineThreshold1 = 0.8; const float kOutlineThreshold1 = 0.8;
const float kOutlineThreshold2 = 0.5; const float kOutlineThreshold2 = 0.5;
const float kMaskOpacity = 0.7; const float kMaskOpacity = 0.7;
out vec4 v_FragColor;
void main() void main()
{ {
vec4 color = texture(u_colorTex, v_colorTexCoord); vec4 color = texture(u_colorTex, v_colorTexCoord);
float alphaCode = color.a; float alphaCode = color.a;
vec4 mask = texture(u_maskTex, v_maskTexCoord); vec4 mask = texture(u_maskTex, v_maskTexCoord);
color.a = u_opacity * (1.0 - smoothstep(kAntialiasingThreshold, 1.0, abs(v_halfLength))); color.a = u_opacity * (1.0 - smoothstep(kAntialiasingThreshold, 1.0, abs(v_halfLength)));
color.rgb = mix(color.rgb, mask.rgb * mix(u_lightArrowColor, u_darkArrowColor, step(alphaCode, 0.6)), mask.a * kMaskOpacity); color.rgb = mix(color.rgb, mask.rgb * mix(u_lightArrowColor.rgb, u_darkArrowColor.rgb, step(alphaCode, 0.6)), mask.a * kMaskOpacity);
if (u_outline > 0.0) if (u_outline > 0.0)
{ {
color.rgb = mix(color.rgb, u_outlineColor, step(kOutlineThreshold1, abs(v_halfLength))); color.rgb = mix(color.rgb, u_outlineColor.rgb, step(kOutlineThreshold1, abs(v_halfLength)));
color.rgb = mix(color.rgb, u_outlineColor, smoothstep(kOutlineThreshold2, kOutlineThreshold1, abs(v_halfLength))); color.rgb = mix(color.rgb, u_outlineColor.rgb, smoothstep(kOutlineThreshold2, kOutlineThreshold1, abs(v_halfLength)));
} }
v_FragColor = color; v_FragColor = color;
} }

View File

@@ -1,16 +1,23 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec4 a_normal; layout (location = 1) in vec4 a_normal;
in vec4 a_colorTexCoord; layout (location = 2) in vec4 a_colorTexCoord;
uniform mat4 u_modelView; layout (location = 0) out vec2 v_colorTexCoord;
uniform mat4 u_projection; layout (location = 1) out vec2 v_maskTexCoord;
uniform mat4 u_pivotTransform; layout (location = 2) out float v_halfLength;
uniform vec4 u_trafficParams; layout (binding = 0) uniform UBO
{
out vec2 v_colorTexCoord; mat4 u_modelView;
out vec2 v_maskTexCoord; mat4 u_projection;
out float v_halfLength; mat4 u_pivotTransform;
vec4 u_trafficParams;
vec4 u_outlineColor;
vec4 u_lightArrowColor;
vec4 u_darkArrowColor;
float u_outline;
float u_opacity;
};
const float kArrowVSize = 0.25; const float kArrowVSize = 0.25;
@@ -26,7 +33,6 @@ void main()
transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + norm, transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + norm,
u_modelView, length(norm)); u_modelView, length(norm));
} }
float uOffset = length(vec4(kShapeCoordScalar, 0, 0, 0) * u_modelView) * a_normal.w; float uOffset = length(vec4(kShapeCoordScalar, 0, 0, 0) * u_modelView) * a_normal.w;
v_colorTexCoord = a_colorTexCoord.xy; v_colorTexCoord = a_colorTexCoord.xy;
float v = mix(a_colorTexCoord.z, a_colorTexCoord.z + kArrowVSize, 0.5 * a_normal.z + 0.5); float v = mix(a_colorTexCoord.z, a_colorTexCoord.z + kArrowVSize, 0.5 * a_normal.z + 0.5);

View File

@@ -1,17 +1,28 @@
// Warning! Beware to use this shader. "discard" command may significally reduce performance. // Warning! Beware to use this shader. "discard" command may significally reduce performance.
// Unfortunately some CG algorithms cannot be implemented on OpenGL ES 2.0 without discarding // Unfortunately some CG algorithms cannot be implemented without discarding fragments from depth buffer.
// fragments from depth buffer.
in vec2 v_colorTexCoord; layout (location = 0) in vec2 v_colorTexCoord;
in vec3 v_radius; layout (location = 1) in vec3 v_radius;
uniform sampler2D u_colorTex; layout (location = 0) out vec4 v_FragColor;
uniform float u_opacity;
layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec4 u_trafficParams;
vec4 u_outlineColor;
vec4 u_lightArrowColor;
vec4 u_darkArrowColor;
float u_outline;
float u_opacity;
};
layout (binding = 1) uniform sampler2D u_colorTex;
const float kAntialiasingThreshold = 0.92; const float kAntialiasingThreshold = 0.92;
out vec4 v_FragColor;
void main() void main()
{ {
vec4 color = texture(u_colorTex, v_colorTexCoord); vec4 color = texture(u_colorTex, v_colorTexCoord);

View File

@@ -1,16 +1,22 @@
in vec4 a_position; layout (location = 0) in vec4 a_position;
in vec4 a_normal; layout (location = 1) in vec4 a_normal;
in vec2 a_colorTexCoord; layout (location = 2) in vec2 a_colorTexCoord;
uniform mat4 u_modelView; layout (location = 0) out vec2 v_colorTexCoord;
uniform mat4 u_projection; layout (location = 1) out vec3 v_radius;
uniform mat4 u_pivotTransform;
uniform vec3 u_lightArrowColor; // Here we store left sizes by road classes. layout (binding = 0) uniform UBO
uniform vec3 u_darkArrowColor; // Here we store right sizes by road classes. {
mat4 u_modelView;
out vec2 v_colorTexCoord; mat4 u_projection;
out vec3 v_radius; mat4 u_pivotTransform;
vec4 u_trafficParams;
vec4 u_outlineColor;
vec4 u_lightArrowColor;
vec4 u_darkArrowColor;
float u_outline;
float u_opacity;
};
void main() void main()
{ {
@@ -28,7 +34,6 @@ void main()
} }
// radius = (leftSize + rightSize) / 2 // radius = (leftSize + rightSize) / 2
v_radius = vec3(a_normal.zw, 1.0) * 0.5 * (leftSize + rightSize); v_radius = vec3(a_normal.zw, 1.0) * 0.5 * (leftSize + rightSize);
vec2 finalPos = transformedAxisPos + v_radius.xy; vec2 finalPos = transformedAxisPos + v_radius.xy;
v_colorTexCoord = a_colorTexCoord; v_colorTexCoord = a_colorTexCoord;
vec4 pos = vec4(finalPos, a_position.z, 1.0) * u_projection; vec4 pos = vec4(finalPos, a_position.z, 1.0) * u_projection;

View File

@@ -1,9 +1,21 @@
uniform sampler2D u_colorTex; layout (location = 0) in vec2 v_colorTexCoord;
uniform float u_opacity;
in vec2 v_colorTexCoord; layout (location = 0) out vec4 v_FragColor;
out vec4 v_FragColor; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec4 u_trafficParams;
vec4 u_outlineColor;
vec4 u_lightArrowColor;
vec4 u_darkArrowColor;
float u_outline;
float u_opacity;
};
layout (binding = 1) uniform sampler2D u_colorTex;
void main() void main()
{ {

View File

@@ -1,11 +1,20 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec2 a_colorTexCoord; layout (location = 1) in vec2 a_colorTexCoord;
uniform mat4 u_modelView; layout (location = 0) out vec2 v_colorTexCoord;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
out vec2 v_colorTexCoord; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec4 u_trafficParams;
vec4 u_outlineColor;
vec4 u_lightArrowColor;
vec4 u_darkArrowColor;
float u_outline;
float u_opacity;
};
void main() void main()
{ {

View File

@@ -1,6 +1,6 @@
in vec4 v_color; layout (location = 0) in vec4 v_color;
out vec4 v_FragColor; layout (location = 0) out vec4 v_FragColor;
void main() void main()
{ {

View File

@@ -1,14 +1,18 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec4 a_normal; layout (location = 1) in vec4 a_normal;
in vec4 a_color; layout (location = 2) in vec4 a_color;
uniform mat4 u_modelView; layout (location = 0) out vec4 v_color;
uniform mat4 u_projection;
uniform mat4 u_pivotTransform;
uniform float u_lineHalfWidth; layout (binding = 0) uniform UBO
{
out vec4 v_color; mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec4 u_params;
float u_lineHalfWidth;
float u_maxRadius;
};
void main() void main()
{ {

View File

@@ -1,18 +1,16 @@
// Warning! Beware to use this shader. "discard" command may significally reduce performance. // Warning! Beware to use this shader. "discard" command may significally reduce performance.
// Unfortunately some CG algorithms cannot be implemented on OpenGL ES 2.0 without discarding // Unfortunately some CG algorithms cannot be implemented without discarding fragments from depth buffer.
// fragments from depth buffer.
in vec3 v_radius; layout (location = 0) in vec3 v_radius;
in vec4 v_color; layout (location = 1) in vec4 v_color;
layout (location = 0) out vec4 v_FragColor;
const float aaPixelsCount = 2.5; const float aaPixelsCount = 2.5;
out vec4 v_FragColor;
void main() void main()
{ {
vec4 finalColor = v_color; vec4 finalColor = v_color;
float smallRadius = v_radius.z - aaPixelsCount; float smallRadius = v_radius.z - aaPixelsCount;
float stepValue = smoothstep(smallRadius * smallRadius, v_radius.z * v_radius.z, float stepValue = smoothstep(smallRadius * smallRadius, v_radius.z * v_radius.z,
dot(v_radius.xy, v_radius.xy)); dot(v_radius.xy, v_radius.xy));

View File

@@ -1,16 +1,19 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec4 a_normal; layout (location = 1) in vec4 a_normal;
in vec4 a_color; layout (location = 2) in vec4 a_color;
uniform mat4 u_modelView; layout (location = 0) out vec3 v_radius;
uniform mat4 u_projection; layout (location = 1) out vec4 v_color;
uniform mat4 u_pivotTransform;
uniform float u_lineHalfWidth; layout (binding = 0) uniform UBO
uniform float u_maxRadius; {
mat4 u_modelView;
out vec3 v_radius; mat4 u_projection;
out vec4 v_color; mat4 u_pivotTransform;
vec4 u_params;
float u_lineHalfWidth;
float u_maxRadius;
};
void main() void main()
{ {

View File

@@ -1,7 +1,7 @@
in vec4 v_offsets; layout (location = 0) in vec4 v_offsets;
in vec4 v_color; layout (location = 1) in vec4 v_color;
out vec4 v_FragColor; layout (location = 0) out vec4 v_FragColor;
void main() void main()
{ {
@@ -9,11 +9,9 @@ void main()
vec2 radius; vec2 radius;
radius.x = max(0.0, abs(v_offsets.x) - v_offsets.z); radius.x = max(0.0, abs(v_offsets.x) - v_offsets.z);
radius.y = max(0.0, abs(v_offsets.y) - v_offsets.w); radius.y = max(0.0, abs(v_offsets.y) - v_offsets.w);
float maxRadius = 1.0; float maxRadius = 1.0;
float aaRadius = 0.9; float aaRadius = 0.9;
float stepValue = smoothstep(aaRadius * aaRadius, maxRadius * maxRadius, dot(radius.xy, radius.xy)); float stepValue = smoothstep(aaRadius * aaRadius, maxRadius * maxRadius, dot(radius.xy, radius.xy));
finalColor.a = finalColor.a * (1.0 - stepValue); finalColor.a = finalColor.a * (1.0 - stepValue);
v_FragColor = finalColor; v_FragColor = finalColor;
} }

View File

@@ -1,15 +1,19 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec4 a_normal; layout (location = 1) in vec4 a_normal;
in vec4 a_color; layout (location = 2) in vec4 a_color;
uniform mat4 u_modelView; layout (location = 0) out vec4 v_offsets;
uniform mat4 u_projection; layout (location = 1) out vec4 v_color;
uniform mat4 u_pivotTransform;
uniform vec3 u_params; layout (binding = 0) uniform UBO
{
out vec4 v_offsets; mat4 u_modelView;
out vec4 v_color; mat4 u_projection;
mat4 u_pivotTransform;
vec4 u_params;
float u_lineHalfWidth;
float u_maxRadius;
};
void main() void main()
{ {

View File

@@ -1,14 +1,24 @@
// Warning! Beware to use this shader. "discard" command may significally reduce performance. // Warning! Beware to use this shader. "discard" command may significally reduce performance.
// Unfortunately some CG algorithms cannot be implemented on OpenGL ES 2.0 without discarding // Unfortunately some CG algorithms cannot be implemented without discarding fragments from depth buffer.
// fragments from depth buffer.
uniform sampler2D u_colorTex; layout (location = 0) in vec4 v_texCoords;
uniform float u_opacity; layout (location = 1) in vec4 v_maskColor;
in vec4 v_texCoords; layout (location = 0) out vec4 v_FragColor;
in vec4 v_maskColor;
out vec4 v_FragColor; layout (binding = 0) uniform UBO
{
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
layout (binding = 1) uniform sampler2D u_colorTex;
void main() void main()
{ {

View File

@@ -1,22 +1,28 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec3 a_normalAndAnimateOrZ; layout (location = 1) in vec3 a_normalAndAnimateOrZ;
in vec4 a_texCoords; layout (location = 2) in vec4 a_texCoords;
in vec4 a_color; layout (location = 3) in vec4 a_color;
uniform mat4 u_modelView; layout (location = 0) out vec4 v_texCoords;
uniform mat4 u_projection; layout (location = 1) out vec4 v_maskColor;
uniform mat4 u_pivotTransform;
uniform float u_interpolation;
out vec4 v_texCoords; layout (binding = 0) uniform UBO
out vec4 v_maskColor; {
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
void main() void main()
{ {
vec2 normal = a_normalAndAnimateOrZ.xy; vec2 normal = a_normalAndAnimateOrZ.xy;
if (a_normalAndAnimateOrZ.z > 0.0) if (a_normalAndAnimateOrZ.z > 0.0)
normal = u_interpolation * normal; normal = u_interpolation * normal;
vec4 p = vec4(a_position, 1.0) * u_modelView; vec4 p = vec4(a_position, 1.0) * u_modelView;
vec4 pos = vec4(normal, 0.0, 0.0) + p; vec4 pos = vec4(normal, 0.0, 0.0) + p;
vec4 projectedPivot = p * u_projection; vec4 projectedPivot = p * u_projection;

View File

@@ -1,22 +1,28 @@
in vec3 a_position; layout (location = 0) in vec3 a_position;
in vec3 a_normalAndAnimateOrZ; layout (location = 1) in vec3 a_normalAndAnimateOrZ;
in vec4 a_texCoords; layout (location = 2) in vec4 a_texCoords;
in vec4 a_color; layout (location = 3) in vec4 a_color;
uniform mat4 u_modelView; layout (location = 0) out vec4 v_texCoords;
uniform mat4 u_projection; layout (location = 1) out vec4 v_maskColor;
uniform mat4 u_pivotTransform;
uniform float u_interpolation;
out vec4 v_texCoords; layout (binding = 0) uniform UBO
out vec4 v_maskColor; {
mat4 u_modelView;
mat4 u_projection;
mat4 u_pivotTransform;
vec2 u_contrastGamma;
float u_opacity;
float u_zScale;
float u_interpolation;
float u_isOutlinePass;
};
void main() void main()
{ {
vec2 normal = a_normalAndAnimateOrZ.xy; vec2 normal = a_normalAndAnimateOrZ.xy;
if (a_normalAndAnimateOrZ.z > 0.0) if (a_normalAndAnimateOrZ.z > 0.0)
normal = u_interpolation * normal; normal = u_interpolation * normal;
vec4 pivot = vec4(a_position, 1.0) * u_modelView; vec4 pivot = vec4(a_position, 1.0) * u_modelView;
vec4 offset = vec4(normal, 0.0, 0.0) * u_projection; vec4 offset = vec4(normal, 0.0, 0.0) * u_projection;
vec4 projectedPivot = pivot * u_projection; vec4 projectedPivot = pivot * u_projection;

View File

@@ -8,11 +8,11 @@ typedef struct
float4x4 u_modelView; float4x4 u_modelView;
float4x4 u_projection; float4x4 u_projection;
float4x4 u_pivotTransform; float4x4 u_pivotTransform;
packed_float2 u_contrastGamma;
float u_opacity; float u_opacity;
float u_zScale; float u_zScale;
float u_interpolation; float u_interpolation;
float u_isOutlinePass; float u_isOutlinePass;
packed_float2 u_contrastGamma;
} Uniforms_T; } Uniforms_T;
// Area/AreaOutline // Area/AreaOutline

View File

@@ -12,13 +12,13 @@ typedef struct
float4 u_color; float4 u_color;
float4 u_maskColor; float4 u_maskColor;
float4 u_outlineColor; float4 u_outlineColor;
float4 u_fakeColor;
float4 u_fakeOutlineColor;
packed_float2 u_fakeBorders;
packed_float2 u_pattern; packed_float2 u_pattern;
packed_float2 u_angleCosSin; packed_float2 u_angleCosSin;
float u_arrowHalfWidth; float u_arrowHalfWidth;
float u_opacity; float u_opacity;
packed_float2 u_fakeBorders;
float4 u_fakeColor;
float4 u_fakeOutlineColor;
} Uniforms_T; } Uniforms_T;
// Route/RouteDash // Route/RouteDash

View File

@@ -10,8 +10,9 @@ typedef struct
float4x4 u_projection; float4x4 u_projection;
float4x4 u_pivotTransform; float4x4 u_pivotTransform;
packed_float3 u_position; packed_float3 u_position;
float u_accuracy; float u_dummy1;
packed_float2 u_lineParams; packed_float2 u_lineParams;
float u_accuracy;
float u_zScale; float u_zScale;
float u_opacity; float u_opacity;
float u_azimut; float u_azimut;

View File

@@ -10,10 +10,13 @@ typedef struct
float4x4 u_pivotTransform; float4x4 u_pivotTransform;
float4 u_trafficParams; float4 u_trafficParams;
packed_float3 u_outlineColor; packed_float3 u_outlineColor;
float u_outline; float u_dummy1; // alignment
packed_float3 u_lightArrowColor; packed_float3 u_lightArrowColor;
float u_opacity; float u_dummy2; // alignment
packed_float3 u_darkArrowColor; packed_float3 u_darkArrowColor;
float u_dummy3; // alignment
float u_outline;
float u_opacity;
} Uniforms_T; } Uniforms_T;
// Traffic // Traffic

View File

@@ -9,6 +9,7 @@ typedef struct
float4x4 u_projection; float4x4 u_projection;
float4x4 u_pivotTransform; float4x4 u_pivotTransform;
packed_float3 u_params; packed_float3 u_params;
float u_dummy1;
float u_lineHalfWidth; float u_lineHalfWidth;
float u_maxRadius; float u_maxRadius;
} Uniforms_T; } Uniforms_T;

View File

@@ -46,12 +46,12 @@ template <typename ParamType> class GLTypeWrapper;
BIND_GL_TYPE(float, gl_const::GLFloatType) BIND_GL_TYPE(float, gl_const::GLFloatType)
BIND_GL_TYPE(glsl::vec2, gl_const::GLFloatVec2) BIND_GL_TYPE(glsl::vec2, gl_const::GLFloatVec2)
BIND_GL_TYPE(glsl::vec3, gl_const::GLFloatVec3) BIND_GL_TYPE(glsl::vec3, gl_const::GLFloatVec4)
BIND_GL_TYPE(glsl::vec4, gl_const::GLFloatVec4) BIND_GL_TYPE(glsl::vec4, gl_const::GLFloatVec4)
BIND_GL_TYPE(glsl::mat4, gl_const::GLFloatMat4) BIND_GL_TYPE(glsl::mat4, gl_const::GLFloatMat4)
BIND_GL_TYPE(int, gl_const::GLIntType) BIND_GL_TYPE(int, gl_const::GLIntType)
BIND_GL_TYPE(glsl::ivec2, gl_const::GLIntVec2) BIND_GL_TYPE(glsl::ivec2, gl_const::GLIntVec2)
BIND_GL_TYPE(glsl::ivec3, gl_const::GLIntVec3) BIND_GL_TYPE(glsl::ivec3, gl_const::GLIntVec4)
BIND_GL_TYPE(glsl::ivec4, gl_const::GLIntVec4) BIND_GL_TYPE(glsl::ivec4, gl_const::GLIntVec4)
class Parameter class Parameter

View File

@@ -11,6 +11,9 @@ HIGHP_SEARCH = "highp"
VERTEX_SHADER_EXT = ".vsh.glsl" VERTEX_SHADER_EXT = ".vsh.glsl"
FRAG_SHADER_EXT = ".fsh.glsl" FRAG_SHADER_EXT = ".fsh.glsl"
UBO_KEY = "UBO"
UNIFORMS_KEY = "Uniforms"
SHADERS_LIB_COMMON_PATTERN = "// Common" SHADERS_LIB_COMMON_PATTERN = "// Common"
SHADERS_LIB_VS_PATTERN = "// VS" SHADERS_LIB_VS_PATTERN = "// VS"
SHADERS_LIB_FS_PATTERN = "// FS" SHADERS_LIB_FS_PATTERN = "// FS"
@@ -125,7 +128,7 @@ def write_definition_file(defines_file, generation_dir):
output_file.write("{\n") output_file.write("{\n")
output_file.write("extern char const * GL3_SHADER_VERSION;\n") output_file.write("extern char const * GL3_SHADER_VERSION;\n")
output_file.write("extern char const * GLES3_SHADER_VERSION;\n\n") output_file.write("extern char const * GLES3_SHADER_VERSION;\n\n")
output_file.write("extern GLProgramInfo GetProgramInfo(dp::ApiVersion apiVersion, Program program);\n") output_file.write("extern GLProgramInfo const & GetProgramInfo(dp::ApiVersion apiVersion, Program program);\n")
output_file.write("} // namespace gpu\n") output_file.write("} // namespace gpu\n")
if not os.path.isfile(defines_file) or not filecmp.cmp(defines_file, defines_file_tmp, False): if not os.path.isfile(defines_file) or not filecmp.cmp(defines_file, defines_file_tmp, False):
@@ -162,41 +165,107 @@ def get_shaders_lib_content(shader_file, shaders_library):
return lib_content return lib_content
def write_shader_line(output_file, line): def write_shader_line(output_file, line, shader_file, binding_info):
if line.lstrip().startswith("//") or line == '\n' or len(line) == 0: if line.lstrip().startswith("//") or line == '\n' or len(line) == 0:
return return False
if line.find(LOWP_SEARCH) >= 0: if line.find(LOWP_SEARCH) >= 0:
print("Incorrect shader. Do not use lowp in shader, use LOW_P instead.") print(f"Incorrect shader {shader_file}. Do not use lowp in shader, use LOW_P instead.")
exit(2) exit(2)
if line.find(MEDIUMP_SEARCH) >= 0: if line.find(MEDIUMP_SEARCH) >= 0:
print("Incorrect shader. Do not use mediump in shader, use MEDIUM_P instead.") print(f"Incorrect shader {shader_file}. Do not use mediump in shader, use MEDIUM_P instead.")
exit(2) exit(2)
if line.find(HIGHP_SEARCH) >= 0: if line.find(HIGHP_SEARCH) >= 0:
print("Incorrect shader. Do not use highp in shader, use HIGH_P instead.") print(f"Incorrect shader {shader_file}. Do not use highp in shader, use HIGH_P instead.")
exit(2) exit(2)
output_line = line.rstrip() output_line = line.rstrip()
# Extract and remove layout binding
binding_match = re.search(r"layout\s*\(\s*binding\s*=\s*(\d+)\s*\)", output_line)
if binding_match:
binding_index = int(binding_match.group(1))
# Remove the matched layout part from the string
output_line = re.sub(r"layout\s*\(\s*binding\s*=\s*\d+\s*\)\s*", "", output_line)
else:
binding_index = None
# Remove lauout(location = X) part. Mali compiler may not support it.
output_line = re.sub(r"layout\s*\(\s*location\s*=\s*\d+\s*\)\s*", "", output_line)
# Extract sampler name
sampler_match = re.search(r"sampler2D\s+(\w+)", output_line)
sampler_name = sampler_match.group(1) if sampler_match else None
if binding_index is None and sampler_name is not None:
print(f"Incorrect shader {shader_file}. Sampler must have binding index")
exit(2)
ubo_started = False
if line.find("uniform UBO") >= 0:
if binding_index is not None:
binding_info[shader_file].append({UBO_KEY: binding_index})
ubo_started = True
else:
print(f"Incorrect shader {shader_file}. Uniform block must have binding index")
exit(2)
if binding_index and sampler_name:
binding_info[shader_file].append({sampler_name: binding_index})
if not ubo_started:
output_file.write(" %s \\n\\\n" % output_line) output_file.write(" %s \\n\\\n" % output_line)
return ubo_started
def write_shader_body(output_file, shader_file, shader_dir, shaders_library):
def find_by_name_in_list(lst, name):
return next((item[name] for item in lst if name in item), None)
def write_uniform_shader_line(output_file, line, shader_file, binding_info):
if line.lstrip().startswith("//") or line == '\n' or len(line) == 0:
return False
output_line = line.lstrip().rstrip()
if output_line.find("};") >= 0:
return True
if output_line.find("{") >= 0:
return False
if output_line.find(",") >= 0 or output_line.count("u_") > 1:
print(f"Incorrect shader {shader_file}. Only one uniform per line")
exit(2)
find_by_name_in_list(binding_info[shader_file], UNIFORMS_KEY).append(output_line)
output_file.write(" uniform %s \\n\\\n" % output_line)
return False
def write_shader_body(output_file, shader_file, shader_dir, shaders_library, binding_info):
lib_content = get_shaders_lib_content(shader_file, shaders_library) lib_content = get_shaders_lib_content(shader_file, shaders_library)
ubo_started = False
for line in open(os.path.join(shader_dir, shader_file)): for line in open(os.path.join(shader_dir, shader_file)):
if ubo_started:
if write_uniform_shader_line(output_file, line, shader_file, binding_info):
ubo_started = False
continue
if line.lstrip().startswith("void main"): if line.lstrip().startswith("void main"):
for lib_line in lib_content.splitlines(): for lib_line in lib_content.splitlines():
write_shader_line(output_file, lib_line) write_shader_line(output_file, lib_line, shader_file, binding_info)
write_shader_line(output_file, line) ubo_started = write_shader_line(output_file, line, shader_file, binding_info)
if ubo_started:
binding_info[shader_file].append({UNIFORMS_KEY: []})
output_file.write("\";\n\n") output_file.write("\";\n\n")
def write_shader(output_file, shader_file, shader_dir, shaders_library): def write_shader(output_file, shader_file, shader_dir, shaders_library, binding_info):
output_file.write("char const %s[] = \" \\\n" % format_shader_source_name(shader_file)) output_file.write("char const %s[] = \" \\\n" % format_shader_source_name(shader_file))
write_shader_gles_header(output_file) write_shader_gles_header(output_file)
write_shader_body(output_file, shader_file, shader_dir, shaders_library) write_shader_body(output_file, shader_file, shader_dir, shaders_library, binding_info)
def write_gpu_programs_map(file, programs_def): def write_gpu_programs_map(file, programs_def, binding_info):
for program in programs_def.keys(): for program in programs_def.keys():
vertex_shader = programs_def[program][0] vertex_shader = programs_def[program][0]
vertex_source_name = format_shader_source_name(vertex_shader) vertex_source_name = format_shader_source_name(vertex_shader)
@@ -204,15 +273,38 @@ def write_gpu_programs_map(file, programs_def):
fragment_shader = programs_def[program][1] fragment_shader = programs_def[program][1]
fragment_source_name = format_shader_source_name(fragment_shader) fragment_source_name = format_shader_source_name(fragment_shader)
check_bindings(vertex_shader, fragment_shader, binding_info[vertex_shader], binding_info[fragment_shader])
file.write(" GLProgramInfo(\"%s\", \"%s\", %s, %s),\n" % ( file.write(" GLProgramInfo(\"%s\", \"%s\", %s, %s),\n" % (
vertex_source_name, fragment_source_name, vertex_source_name, fragment_source_name)) vertex_source_name, fragment_source_name, vertex_source_name, fragment_source_name))
def check_bindings(vs, fs, vs_bindings, fs_bindings):
dict1 = {k: v for d in vs_bindings for k, v in d.items()}
dict2 = {k: v for d in fs_bindings for k, v in d.items()}
if UBO_KEY in dict1 and UBO_KEY in dict2:
if dict1[UBO_KEY] != dict2[UBO_KEY]:
print(f"Shaders {vs} and {fs} must use the same binding indexes for the UBO. VS:{dict1[UBO_KEY]}, FS:{dict2[UBO_KEY]}")
exit(2)
if UNIFORMS_KEY in dict1 and UNIFORMS_KEY in dict2:
if dict1[UNIFORMS_KEY] != dict2[UNIFORMS_KEY]:
print(f"Shaders {vs} and {fs} must use the same unforms inside the UBO. VS:{dict1[UNIFORMS_KEY]}, FS:{dict2[UNIFORMS_KEY]}")
exit(2)
common_keys = dict1.keys() & dict2.keys()
for key in common_keys:
if key == UBO_KEY or key == UNIFORMS_KEY:
continue
if dict1[key] != dict2[key]:
print(f"Shaders {vs} and {fs} must use the same binding indexes for textures. VS:{dict1[key]}, FS:{dict2[key]}")
exit(2)
def write_implementation_file(programs_def, shader_index, shader_dir, impl_file, def_file, generation_dir, def write_implementation_file(programs_def, shader_index, shader_dir, impl_file, def_file, generation_dir,
shaders_library): shaders_library):
impl_file = os.path.join(generation_dir, impl_file) impl_file = os.path.join(generation_dir, impl_file)
# Write to temporary file first, and then compare if its content has changed to avoid unnecessary code rebuilds. # Write to temporary file first, and then compare if its content has changed to avoid unnecessary code rebuilds.
impl_file_tmp = impl_file + ".tmp" impl_file_tmp = impl_file + ".tmp"
binding_info = dict()
with open(impl_file_tmp, 'w') as file: with open(impl_file_tmp, 'w') as file:
file.write("#include \"shaders/%s\"\n\n" % (def_file)) file.write("#include \"shaders/%s\"\n\n" % (def_file))
file.write("#include \"base/assert.hpp\"\n\n") file.write("#include \"base/assert.hpp\"\n\n")
@@ -221,17 +313,22 @@ def write_implementation_file(programs_def, shader_index, shader_dir, impl_file,
file.write("namespace gpu\n") file.write("namespace gpu\n")
file.write("{\n") file.write("{\n")
file.write("char const * GL3_SHADER_VERSION = \"#version 150 core \\n\";\n") file.write("#if defined(OMIM_OS_LINUX)\n")
file.write(" char const * GL3_SHADER_VERSION = \"#version 310 es \\n\";\n")
file.write("#else\n")
file.write(" char const * GL3_SHADER_VERSION = \"#version 410 core \\n\";\n")
file.write("#endif\n")
file.write("char const * GLES3_SHADER_VERSION = \"#version 300 es \\n\";\n\n") file.write("char const * GLES3_SHADER_VERSION = \"#version 300 es \\n\";\n\n")
for shader in shader_index.keys(): for shader in shader_index.keys():
write_shader(file, shader, shader_dir, shaders_library) binding_info[shader] = []
write_shader(file, shader, shader_dir, shaders_library, binding_info)
file.write("GLProgramInfo GetProgramInfo(dp::ApiVersion apiVersion, Program program)\n") file.write("GLProgramInfo const & GetProgramInfo(dp::ApiVersion apiVersion, Program program)\n")
file.write("{\n") file.write("{\n")
file.write(" CHECK_EQUAL(apiVersion, dp::ApiVersion::OpenGLES3, ());\n") file.write(" CHECK_EQUAL(apiVersion, dp::ApiVersion::OpenGLES3, ());\n")
file.write(" static std::array<GLProgramInfo, static_cast<size_t>(Program::ProgramsCount)> gpuIndex = {{\n") file.write(" static std::array<GLProgramInfo, static_cast<size_t>(Program::ProgramsCount)> gpuIndex = {{\n")
write_gpu_programs_map(file, programs_def) write_gpu_programs_map(file, programs_def, binding_info)
file.write(" }};\n") file.write(" }};\n")
file.write(" return gpuIndex[static_cast<size_t>(program)];\n") file.write(" return gpuIndex[static_cast<size_t>(program)];\n")
file.write("}\n") file.write("}\n")
@@ -260,13 +357,13 @@ if __name__ == '__main__':
shaders = [file for file in os.listdir(shader_dir) if shaders = [file for file in os.listdir(shader_dir) if
os.path.isfile(os.path.join(shader_dir, file)) and ( os.path.isfile(os.path.join(shader_dir, file)) and (
file.endswith(VERTEX_SHADER_EXT) or file.endswith(FRAG_SHADER_EXT))] file.endswith(VERTEX_SHADER_EXT) or file.endswith(FRAG_SHADER_EXT))]
shaderIndex = generate_shader_indexes(shaders) shader_index = generate_shader_indexes(shaders)
programs_order = read_programs_file(os.path.join(shader_dir, '..', programs_file_name)) programs_order = read_programs_file(os.path.join(shader_dir, '..', programs_file_name))
programDefinition = read_index_file(os.path.join(shader_dir, index_file_name), programs_order) program_definition = read_index_file(os.path.join(shader_dir, index_file_name), programs_order)
shaders_library = read_shaders_lib_file(os.path.join(shader_dir, shaders_lib_file)) shaders_library = read_shaders_lib_file(os.path.join(shader_dir, shaders_lib_file))
write_definition_file(defines_file, generation_dir) write_definition_file(defines_file, generation_dir)
write_implementation_file(programDefinition, shaderIndex, shader_dir, impl_file, defines_file, generation_dir, write_implementation_file(program_definition, shader_index, shader_dir, impl_file, defines_file, generation_dir,
shaders_library) shaders_library)

View File

@@ -48,16 +48,21 @@ private:
#define ALIGNMENT alignas(16) #define ALIGNMENT alignas(16)
// NOTE: structs may contain dummy elements to fit MSL and GLSL struct alignment rules
// 1. Add new fields in order from the highest byte size to the lowest, it minimizes alignment overhead
// 2. Keep 16 bytes alignment for the whole struct, it complements the size of the latest element to vec4
// 3. Consider vec3 as vec4, add float complement and don't reuse it
struct ALIGNMENT MapProgramParams struct ALIGNMENT MapProgramParams
{ {
glsl::mat4 m_modelView; glsl::mat4 m_modelView;
glsl::mat4 m_projection; glsl::mat4 m_projection;
glsl::mat4 m_pivotTransform; glsl::mat4 m_pivotTransform;
glsl::vec2 m_contrastGamma;
float m_opacity = 1.0f; float m_opacity = 1.0f;
float m_zScale = 1.0f; float m_zScale = 1.0f;
float m_interpolation = 1.0f; float m_interpolation = 1.0f;
float m_isOutlinePass = 1.0f; float m_isOutlinePass = 1.0f;
glsl::vec2 m_contrastGamma;
BIND_PROGRAMS(MapProgramParams, BIND_PROGRAMS(MapProgramParams,
Program::Area, Program::Area,
@@ -100,13 +105,13 @@ struct ALIGNMENT RouteProgramParams
glsl::vec4 m_color; glsl::vec4 m_color;
glsl::vec4 m_maskColor; glsl::vec4 m_maskColor;
glsl::vec4 m_outlineColor; glsl::vec4 m_outlineColor;
glsl::vec4 m_fakeColor;
glsl::vec4 m_fakeOutlineColor;
glsl::vec2 m_fakeBorders;
glsl::vec2 m_pattern; glsl::vec2 m_pattern;
glsl::vec2 m_angleCosSin; glsl::vec2 m_angleCosSin;
float m_arrowHalfWidth = 0.0f; float m_arrowHalfWidth = 0.0f;
float m_opacity = 1.0f; float m_opacity = 1.0f;
glsl::vec2 m_fakeBorders;
glsl::vec4 m_fakeColor;
glsl::vec4 m_fakeOutlineColor;
BIND_PROGRAMS(RouteProgramParams, BIND_PROGRAMS(RouteProgramParams,
Program::Route, Program::Route,
@@ -122,10 +127,13 @@ struct ALIGNMENT TrafficProgramParams
glsl::mat4 m_pivotTransform; glsl::mat4 m_pivotTransform;
glsl::vec4 m_trafficParams; glsl::vec4 m_trafficParams;
glsl::vec3 m_outlineColor; glsl::vec3 m_outlineColor;
float m_outline = 0.0f; float m_dummy1; // alignment
glsl::vec3 m_lightArrowColor; glsl::vec3 m_lightArrowColor;
float m_opacity = 1.0f; float m_dummy2; // alignment
glsl::vec3 m_darkArrowColor; glsl::vec3 m_darkArrowColor;
float m_dummy3; // alignment
float m_outline = 0.0f;
float m_opacity = 1.0f;
BIND_PROGRAMS(TrafficProgramParams, BIND_PROGRAMS(TrafficProgramParams,
Program::Traffic, Program::Traffic,
@@ -139,6 +147,7 @@ struct ALIGNMENT TransitProgramParams
glsl::mat4 m_projection; glsl::mat4 m_projection;
glsl::mat4 m_pivotTransform; glsl::mat4 m_pivotTransform;
glsl::vec3 m_params; glsl::vec3 m_params;
float m_dummy1; // alignment
float m_lineHalfWidth = 0.0f; float m_lineHalfWidth = 0.0f;
float m_maxRadius = 0.0f; float m_maxRadius = 0.0f;
@@ -171,8 +180,9 @@ struct ALIGNMENT ShapesProgramParams
glsl::mat4 m_projection; glsl::mat4 m_projection;
glsl::mat4 m_pivotTransform; glsl::mat4 m_pivotTransform;
glsl::vec3 m_position; glsl::vec3 m_position;
float m_accuracy = 0.0; float m_dummy1; // alignment
glsl::vec2 m_lineParams; glsl::vec2 m_lineParams;
float m_accuracy = 0.0;
float m_zScale = 1.0f; float m_zScale = 1.0f;
float m_opacity = 1.0f; float m_opacity = 1.0f;
float m_azimut = 0.0; float m_azimut = 0.0;

View File

@@ -16,8 +16,6 @@ SHADERS_LIB_COMMON_INDEX = 0
SHADERS_LIB_VS_INDEX = 1 SHADERS_LIB_VS_INDEX = 1
SHADERS_LIB_FS_INDEX = 2 SHADERS_LIB_FS_INDEX = 2
IN = 'in'
OUT = 'out'
UNIFORMS = 'uniforms' UNIFORMS = 'uniforms'
SAMPLERS = 'samplers' SAMPLERS = 'samplers'
@@ -25,7 +23,7 @@ debug_output = False
# Read index file which contains program to shaders bindings. # Read index file which contains program to shaders bindings.
def read_index_file(file_path, programs_order): def read_index_file(file_path):
gpu_programs = dict() gpu_programs = dict()
with open(file_path, 'r') as f: with open(file_path, 'r') as f:
index = 0 index = 0
@@ -35,10 +33,6 @@ def read_index_file(file_path, programs_order):
print('Incorrect GPU program definition : ' + line) print('Incorrect GPU program definition : ' + line)
exit(1) exit(1)
if line_parts[0] != programs_order[index]:
print('Incorrect GPU program order or name : ' + line)
exit(1)
vertex_shader = next(f for f in line_parts if f.endswith(VERTEX_SHADER_EXT)) vertex_shader = next(f for f in line_parts if f.endswith(VERTEX_SHADER_EXT))
fragment_shader = next(f for f in line_parts if f.endswith(FRAG_SHADER_EXT)) fragment_shader = next(f for f in line_parts if f.endswith(FRAG_SHADER_EXT))
@@ -64,76 +58,6 @@ def read_index_file(file_path, programs_order):
return gpu_programs_cache return gpu_programs_cache
# Read hpp-file with programs enumeration.
def read_programs_file(file_path):
gpu_programs = []
with open(file_path, 'r') as f:
found = False
for line in f:
if not found and line.find('enum class Program') >= 0:
found = True
continue
if found and line.find('}') >= 0:
break
if found and line.find('{') == -1:
line_parts = re.split(',|=', line)
name = line_parts[0].strip()
if name and name != 'ProgramsCount':
gpu_programs.append(name)
return gpu_programs
def drop_variable_initialization(line):
equal_found = line.find('=')
if equal_found:
return line[:equal_found - 1]
return line.replace(';', '')
def get_program_param(line):
glsl_found = line.find('glsl::')
if glsl_found >= 0:
return drop_variable_initialization(line[glsl_found + 6:].replace('m_', 'u_'))
if line.find('float ') >= 0 or line.find('int ') >= 0:
return drop_variable_initialization(line.lstrip().replace('m_', 'u_'))
return None
def get_program(line):
program_found = line.find('Program::')
if program_found >= 0:
return line[program_found + 9:].replace(',', '').replace(')', '').replace('\n', '')
return None
# Read hpp-file with program parameters declaration.
def read_program_params_file(file_path):
program_params = []
programs = []
result = dict()
with open(file_path, 'r') as f:
block_found = False
for line in f:
if line.find('struct') >= 0 and line.find('ProgramParams') >= 0:
block_found = True
program_params = []
programs = []
continue
if block_found and line.find('}') >= 0:
block_found = False
for p in programs:
result[p] = program_params
continue
if block_found:
param = get_program_param(line)
if param:
program_params.append(param.split(' '))
program = get_program(line)
if program:
programs.append(program)
return result
# Read GLSL-file with common shader functions. # Read GLSL-file with common shader functions.
def read_shaders_lib_file(file_path): def read_shaders_lib_file(file_path):
shaders_library = ['', '', ''] shaders_library = ['', '', '']
@@ -174,112 +98,43 @@ def get_shaders_lib_content(shader_file, shaders_library):
return lib_content return lib_content
def get_shader_line(line, layout_counters, is_fragment_shader): def get_shader_line(line, layout_counters):
if line.lstrip().startswith('//') or line == '\n' or len(line) == 0: if line.lstrip().startswith('//') or line == '\n' or len(line) == 0:
return None return None
output_line = line.rstrip() output_line = line.rstrip()
if output_line.find('uniform ') >= 0: if output_line.find('layout (binding') >= 0:
if output_line.find('sampler') >= 0: if output_line.find('sampler') >= 0:
layout_counters[SAMPLERS][1].append(output_line) match = re.search(r"binding\s*=\s*(\d+)", output_line)
sampler_match = re.search(r"sampler2D\s+(\w+)", output_line)
if match and sampler_match:
binding_index = int(match.group(1))
sampler_name = sampler_match.group(1)
if binding_index == 0:
print('Binding index must not be 0 for sampler in the line: ' + line)
exit(1)
layout_counters[SAMPLERS][sampler_name] = binding_index
else: else:
print('Sampler name or binding index is not found in the line: ' + line)
exit(1)
else:
match = re.search(r"binding\s*=\s*(\d+)", output_line)
if match:
binding_index = int(match.group(1))
if binding_index != 0:
print('Binding index must be 0 in the line: ' + line)
exit(1)
else:
print('Binding index is not found in the line: ' + line)
exit(1)
layout_counters[UNIFORMS] += 1 layout_counters[UNIFORMS] += 1
return None
if output_line.find('attribute ') >= 0:
location = layout_counters[IN]
layout_counters[IN] += 1
output_line = output_line.replace('attribute', 'layout (location = {0}) in'.format(location))
if output_line.find('varying ') >= 0:
if is_fragment_shader:
location = layout_counters[IN]
layout_counters[IN] += 1
output_line = output_line.replace('varying', 'layout (location = {0}) in'.format(location))
else:
location = layout_counters[OUT]
layout_counters[OUT] += 1
output_line = output_line.replace('varying', 'layout (location = {0}) out'.format(location))
output_line = output_line.replace('texture2D', 'texture')
output_line = output_line.replace('gl_FragColor', 'v_FragColor')
return output_line return output_line
def get_size_by_type(type):
if type == 'float' or type == 'int':
return 1
if type == 'vec2':
return 2
if type == 'vec3':
return 3
if type == 'vec4':
return 4
if type == 'mat4':
return 16
print('Type is not supported' + type)
exit(1)
def get_subscript(offset, param):
symbols = ['x', 'y', 'z', 'w']
subscript = ''
for i in range(0, get_size_by_type(param[0])):
subscript += symbols[offset + i]
return subscript
def write_uniform_block(output_file, program_params):
groups = []
c = 0
group_index = 0
group_params = []
for p in program_params:
sz = get_size_by_type(p[0])
if sz % 4 == 0:
groups.append((p[0], p[1], [p]))
else:
if c + sz < 4:
group_params.append(p)
c += sz
elif c + sz == 4:
group_params.append(p)
groups.append(('vec4', 'u_grouped{0}'.format(group_index), group_params))
group_index += 1
group_params = []
c = 0
else:
print('Must be possible to unite sequential variables to vec4')
exit(1)
if c != 0:
groups.append(('vec4', 'u_grouped{0}'.format(group_index), group_params))
output_file.write('layout (binding = 0) uniform UBO\n')
output_file.write('{\n')
for g in groups:
output_file.write(' {0} {1};\n'.format(g[0], g[1]))
output_file.write('} uniforms;\n')
for k in groups:
name = k[1]
params = k[2]
offset = 0
if len(params) == 1 and get_size_by_type(params[0][0]) % 4 == 0:
output_file.write('#define {0} uniforms.{1}\n'.format(params[0][1], name))
continue
for param in params:
output_file.write('#define {0} uniforms.{1}.{2}\n'.format(param[1], name, get_subscript(offset, param)))
offset += get_size_by_type(param[0])
def get_size_of_attributes_block(lines_before_main):
for i, line in reversed(list(enumerate(lines_before_main))):
if line.find('layout (location') >= 0:
return i + 1
return len(lines_before_main)
def generate_spirv_compatible_glsl_shader(output_file, shader_file, shader_dir, shaders_library, def generate_spirv_compatible_glsl_shader(output_file, shader_file, shader_dir, shaders_library,
program_params, layout_counters, reflection_dict): layout_counters, reflection_dict):
output_file.write('#version 310 es\n') output_file.write('#version 310 es\n')
output_file.write('precision highp float;\n') output_file.write('precision highp float;\n')
output_file.write('#define LOW_P lowp\n') output_file.write('#define LOW_P lowp\n')
@@ -290,8 +145,6 @@ def generate_spirv_compatible_glsl_shader(output_file, shader_file, shader_dir,
lib_content = get_shaders_lib_content(shader_file, shaders_library) lib_content = get_shaders_lib_content(shader_file, shaders_library)
conditional_started = False conditional_started = False
conditional_skip = False conditional_skip = False
lines_before_main = []
main_found = False
for line in open(os.path.join(shader_dir, shader_file)): for line in open(os.path.join(shader_dir, shader_file)):
# Remove some useless conditional compilation. # Remove some useless conditional compilation.
if conditional_started and line.lstrip().startswith('#else'): if conditional_started and line.lstrip().startswith('#else'):
@@ -303,67 +156,40 @@ def generate_spirv_compatible_glsl_shader(output_file, shader_file, shader_dir,
continue continue
if conditional_skip: if conditional_skip:
continue continue
if line.lstrip().startswith('#ifdef ENABLE_VTF') or line.lstrip().startswith('#ifdef GLES3'): if line.lstrip().startswith('#ifdef ENABLE_VTF'):
conditional_started = True conditional_started = True
continue continue
if line.lstrip().startswith('void main'): if line.lstrip().startswith('void main'):
main_found = True # Write reflection for uniforms block.
# Write attributes.
sz = get_size_of_attributes_block(lines_before_main)
for i in range(0, sz):
output_file.write('%s\n' % lines_before_main[i])
if is_fragment_shader:
output_file.write('layout (location = 0) out vec4 v_FragColor;\n')
# Write uniforms block.
uniforms_index = 'vs_uni'; uniforms_index = 'vs_uni';
if is_fragment_shader: if is_fragment_shader:
uniforms_index = 'fs_uni' uniforms_index = 'fs_uni'
if layout_counters[UNIFORMS] > 0: if layout_counters[UNIFORMS] > 0:
write_uniform_block(output_file, program_params)
reflection_dict[uniforms_index] = 0 reflection_dict[uniforms_index] = 0
else: else:
reflection_dict[uniforms_index] = -1 reflection_dict[uniforms_index] = -1
# Write samplers. # Write reflection for samplers.
sample_index = 'tex' sample_index = 'tex'
samplers_offset = layout_counters[SAMPLERS][0]
if layout_counters[UNIFORMS] > 0 and samplers_offset == 0:
samplers_offset = 1
for idx, s in enumerate(layout_counters[SAMPLERS][1]):
output_file.write('layout (binding = {0}) {1}\n'.format(samplers_offset + idx, s))
sampler = {'name': s[s.find('u_'):-1], 'idx': samplers_offset + idx, 'frag':int(is_fragment_shader)}
if not sample_index in reflection_dict: if not sample_index in reflection_dict:
reflection_dict[sample_index] = [sampler] reflection_dict[sample_index] = []
else: for (s, idx) in layout_counters[SAMPLERS].items():
sampler = {'name': s, 'idx': idx, 'frag':int(is_fragment_shader)}
reflection_dict[sample_index].append(sampler) reflection_dict[sample_index].append(sampler)
layout_counters[SAMPLERS][0] = samplers_offset + len(layout_counters[SAMPLERS][1])
layout_counters[SAMPLERS][1] = []
# Write shaders library. # Write shaders library.
for lib_line in lib_content.splitlines(): for lib_line in lib_content.splitlines():
shader_line = get_shader_line(lib_line, layout_counters, is_fragment_shader) shader_line = get_shader_line(lib_line, layout_counters)
if shader_line: if shader_line:
output_file.write('%s\n' % shader_line) output_file.write('%s\n' % shader_line)
# Write rest lines. shader_line = get_shader_line(line, layout_counters)
for i in range(sz, len(lines_before_main)): if shader_line:
output_file.write('%s\n' % lines_before_main[i])
shader_line = get_shader_line(line, layout_counters, is_fragment_shader)
if not shader_line:
continue
if main_found:
output_file.write('%s\n' % shader_line) output_file.write('%s\n' % shader_line)
else:
lines_before_main.append(shader_line)
layout_counters[IN] = 0
layout_counters[OUT] = 0
layout_counters[UNIFORMS] = 0 layout_counters[UNIFORMS] = 0
layout_counters[SAMPLERS] = dict()
# Execute external program. # Execute external program.
@@ -377,12 +203,12 @@ def execute_external(options):
# Generate SPIR-V shader from GLSL source. # Generate SPIR-V shader from GLSL source.
def generate_shader(shader, shader_dir, generation_dir, shaders_library, program_name, program_params, def generate_shader(shader, shader_dir, generation_dir, shaders_library, program_name,
layout_counters, output_name, reflection_dict, glslc_path): layout_counters, output_name, reflection_dict, glslc_path):
output_path = os.path.join(generation_dir, output_name) output_path = os.path.join(generation_dir, output_name)
with open(output_path, 'w') as file: with open(output_path, 'w') as file:
generate_spirv_compatible_glsl_shader(file, shader, shader_dir, shaders_library, generate_spirv_compatible_glsl_shader(file, shader, shader_dir, shaders_library,
program_params, layout_counters, reflection_dict) layout_counters, reflection_dict)
spv_path = output_path + '.spv' spv_path = output_path + '.spv'
try: try:
execute_external([glslc_path, '-c', output_path, '-o', spv_path, '-std=310es', '--target-env=vulkan']) execute_external([glslc_path, '-c', output_path, '-o', spv_path, '-std=310es', '--target-env=vulkan'])
@@ -402,21 +228,6 @@ def generate_shader(shader, shader_dir, generation_dir, shaders_library, program
return spv_path return spv_path
# Check if varying are in the same order in vertex and fragment shaders.
def check_varying_consistency(vs_file_name, fs_file_name):
vs_varyings = []
for line in open(vs_file_name):
line = line.lstrip().rstrip()
if line.startswith('varying '):
vs_varyings.append(line)
fs_varyings = []
for line in open(fs_file_name):
line = line.lstrip().rstrip()
if line.startswith('varying '):
fs_varyings.append(line)
return vs_varyings == fs_varyings
def write_shader_to_pack(pack_file, shader_file_name): def write_shader_to_pack(pack_file, shader_file_name):
offset = pack_file.tell() offset = pack_file.tell()
with open(shader_file_name, 'rb') as shader_file: with open(shader_file_name, 'rb') as shader_file:
@@ -427,48 +238,38 @@ def write_shader_to_pack(pack_file, shader_file_name):
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) < 7: if len(sys.argv) < 7:
print('Usage : ' + sys.argv[0] + ' <shader_dir> <index_file> <programs_file> <program_params_file> <shaders_lib> <generation_dir> <glslc_path> [--debug]') print('Usage : ' + sys.argv[0] + ' <shader_dir> <index_file> <shaders_lib> <generation_dir> <glslc_path> [--debug]')
exit(1) exit(1)
shader_dir = sys.argv[1] shader_dir = sys.argv[1]
index_file_name = sys.argv[2] index_file_name = sys.argv[2]
programs_file_name = sys.argv[3] shaders_lib_file = sys.argv[3]
program_params_file_name = sys.argv[4] generation_dir = sys.argv[4]
shaders_lib_file = sys.argv[5] glslc_path = sys.argv[5]
generation_dir = sys.argv[6]
glslc_path = sys.argv[7]
if len(sys.argv) >= 9: if len(sys.argv) >= 7:
debug_output = (sys.argv[8] == '--debug') debug_output = (sys.argv[6] == '--debug')
shaders = [file for file in os.listdir(shader_dir) if shaders = [file for file in os.listdir(shader_dir) if
os.path.isfile(os.path.join(shader_dir, file)) and ( os.path.isfile(os.path.join(shader_dir, file)) and (
file.endswith(VERTEX_SHADER_EXT) or file.endswith(FRAG_SHADER_EXT))] file.endswith(VERTEX_SHADER_EXT) or file.endswith(FRAG_SHADER_EXT))]
programs_order = read_programs_file(os.path.join(shader_dir, '..', programs_file_name)) gpu_programs_cache = read_index_file(os.path.join(shader_dir, index_file_name))
program_params = read_program_params_file(os.path.join(shader_dir, '..', program_params_file_name))
gpu_programs_cache = read_index_file(os.path.join(shader_dir, index_file_name), programs_order)
shaders_library = read_shaders_lib_file(os.path.join(shader_dir, shaders_lib_file)) shaders_library = read_shaders_lib_file(os.path.join(shader_dir, shaders_lib_file))
reflection = [] reflection = []
current_offset = 0 current_offset = 0
with open(os.path.join(generation_dir, 'shaders_pack.spv'), 'wb') as pack_file: with open(os.path.join(generation_dir, 'shaders_pack.spv'), 'wb') as pack_file:
for (k, v) in gpu_programs_cache.items(): for (k, v) in gpu_programs_cache.items():
if not k in program_params: layout_counters = {UNIFORMS: 0, SAMPLERS: dict()}
print('Program params were not found for the shader ' + k)
exit(1)
if not check_varying_consistency(os.path.join(shader_dir, v[0]), os.path.join(shader_dir, v[1])):
print('Varyings must be in the same order in VS and FS. Shaders: {0}, {1} / Program: {2}.'.format(v[0], v[1], k))
exit(1)
layout_counters = {IN: 0, OUT: 0, UNIFORMS: 0, SAMPLERS: [0, list()]}
reflection_dict = {'prg': v[2], 'info': dict()} reflection_dict = {'prg': v[2], 'info': dict()}
vs_offset = write_shader_to_pack(pack_file, generate_shader(v[0], shader_dir, generation_dir, vs_offset = write_shader_to_pack(pack_file, generate_shader(v[0], shader_dir, generation_dir,
shaders_library, k, program_params[k], shaders_library, k,
layout_counters, k + VERTEX_SHADER_EXT_OUT, layout_counters, k + VERTEX_SHADER_EXT_OUT,
reflection_dict['info'], glslc_path)) reflection_dict['info'], glslc_path))
reflection_dict['vs_off'] = vs_offset[0] reflection_dict['vs_off'] = vs_offset[0]
reflection_dict['vs_size'] = vs_offset[1] reflection_dict['vs_size'] = vs_offset[1]
fs_offset = write_shader_to_pack(pack_file, generate_shader(v[1], shader_dir, generation_dir, fs_offset = write_shader_to_pack(pack_file, generate_shader(v[1], shader_dir, generation_dir,
shaders_library, k, program_params[k], shaders_library, k,
layout_counters, k + FRAG_SHADER_EXT_OUT, layout_counters, k + FRAG_SHADER_EXT_OUT,
reflection_dict['info'], glslc_path)) reflection_dict['info'], glslc_path))
reflection_dict['fs_off'] = fs_offset[0] reflection_dict['fs_off'] = fs_offset[0]

View File

@@ -29,4 +29,4 @@ fi
OMIM_PATH="${OMIM_PATH:-$(cd "$(dirname "$0")/../.."; pwd)}" OMIM_PATH="${OMIM_PATH:-$(cd "$(dirname "$0")/../.."; pwd)}"
SHADERS_GENERATOR="$OMIM_PATH/shaders/vulkan_shaders_preprocessor.py" SHADERS_GENERATOR="$OMIM_PATH/shaders/vulkan_shaders_preprocessor.py"
python3 "$SHADERS_GENERATOR" "$OMIM_PATH/shaders/GL" shader_index.txt programs.hpp program_params.hpp shaders_lib.glsl "$OMIM_PATH/data/vulkan_shaders" "$GLSLC_PATH" "$DEBUG" python3 "$SHADERS_GENERATOR" "$OMIM_PATH/shaders/GL" shader_index.txt shaders_lib.glsl "$OMIM_PATH/data/vulkan_shaders" "$GLSLC_PATH" "$DEBUG"