diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2018-07-04 17:54:02 +0300 |
---|---|---|
committer | Vlad Mihaylenko <vxmihaylenko@gmail.com> | 2018-07-20 14:51:41 +0300 |
commit | 08dc77c19c7d91c4636b70029e6c9464469f57e1 (patch) | |
tree | 6158980ca15a980c2310bc6b6150bd6e5af312ae /shaders | |
parent | 0bd90c9362b5e2ea58903641e57be0b37e6f3f87 (diff) |
Fixed traffic rendering
Diffstat (limited to 'shaders')
-rw-r--r-- | shaders/CMakeLists.txt | 2 | ||||
-rw-r--r-- | shaders/GL/shader_index.txt | 1 | ||||
-rw-r--r-- | shaders/GL/traffic_circle.fsh.glsl | 23 | ||||
-rw-r--r-- | shaders/GL/traffic_circle.vsh.glsl | 36 | ||||
-rw-r--r-- | shaders/program_params.hpp | 5 | ||||
-rw-r--r-- | shaders/programs.hpp | 2 |
6 files changed, 67 insertions, 2 deletions
diff --git a/shaders/CMakeLists.txt b/shaders/CMakeLists.txt index 1a61cfbaa2..2c65193980 100644 --- a/shaders/CMakeLists.txt +++ b/shaders/CMakeLists.txt @@ -96,6 +96,8 @@ set( GL/texturing_gui.vsh.glsl GL/traffic.fsh.glsl GL/traffic.vsh.glsl + GL/traffic_circle.fsh.glsl + GL/traffic_circle.vsh.glsl GL/traffic_line.fsh.glsl GL/traffic_line.vsh.glsl GL/transit.fsh.glsl diff --git a/shaders/GL/shader_index.txt b/shaders/GL/shader_index.txt index 26b82eb11a..2514ad6075 100644 --- a/shaders/GL/shader_index.txt +++ b/shaders/GL/shader_index.txt @@ -43,6 +43,7 @@ TextBillboard text_billboard.vsh.glsl text.fsh.glsl TextFixedBillboard text_billboard.vsh.glsl text_fixed.fsh.glsl Traffic traffic.vsh.glsl traffic.fsh.glsl TrafficLine traffic_line.vsh.glsl traffic_line.fsh.glsl +TrafficCircle traffic_circle.vsh.glsl traffic_circle.fsh.glsl SmaaEdges smaa_edges.vsh.glsl smaa_edges.fsh.glsl SmaaBlendingWeight smaa_blending_weight.vsh.glsl smaa_blending_weight.fsh.glsl SmaaFinal smaa_final.vsh.glsl smaa_final.fsh.glsl diff --git a/shaders/GL/traffic_circle.fsh.glsl b/shaders/GL/traffic_circle.fsh.glsl new file mode 100644 index 0000000000..e26402112d --- /dev/null +++ b/shaders/GL/traffic_circle.fsh.glsl @@ -0,0 +1,23 @@ +// 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 +// fragments from depth buffer. + +varying vec2 v_colorTexCoord; +varying vec3 v_radius; + +uniform sampler2D u_colorTex; +uniform float u_opacity; + +const float kAntialiasingThreshold = 0.92; + +void main() +{ + vec4 color = texture2D(u_colorTex, v_colorTexCoord); + float smallRadius = v_radius.z * kAntialiasingThreshold; + float stepValue = smoothstep(smallRadius * smallRadius, v_radius.z * v_radius.z, + v_radius.x * v_radius.x + v_radius.y * v_radius.y); + color.a = u_opacity * (1.0 - stepValue); + if (color.a < 0.01) + discard; + gl_FragColor = color; +} diff --git a/shaders/GL/traffic_circle.vsh.glsl b/shaders/GL/traffic_circle.vsh.glsl new file mode 100644 index 0000000000..914f0ba838 --- /dev/null +++ b/shaders/GL/traffic_circle.vsh.glsl @@ -0,0 +1,36 @@ +attribute vec4 a_position; +attribute vec4 a_normal; +attribute vec2 a_colorTexCoord; + +uniform mat4 u_modelView; +uniform mat4 u_projection; +uniform mat4 u_pivotTransform; + +uniform vec3 u_lightArrowColor; // Here we store left sizes by road classes. +uniform vec3 u_darkArrowColor; // Here we store right sizes by road classes. + +varying vec2 v_colorTexCoord; +varying vec3 v_radius; + +void main() +{ + vec2 normal = a_normal.xy; + vec2 transformedAxisPos = (vec4(a_position.xy, 0.0, 1.0) * u_modelView).xy; + int index = int(a_position.w); + float leftSize = u_lightArrowColor[index]; + float rightSize = u_darkArrowColor[index]; + if (dot(normal, normal) != 0.0) + { + // offset by normal = rightVec * (rightSize - leftSize) / 2 + vec2 norm = normal * 0.5 * (rightSize - leftSize); + transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + norm, + u_modelView, length(norm)); + } + // radius = (leftSize + rightSize) / 2 + v_radius = vec3(a_normal.zw, 1.0) * 0.5 * (leftSize + rightSize); + + vec2 finalPos = transformedAxisPos + v_radius.xy; + v_colorTexCoord = a_colorTexCoord; + vec4 pos = vec4(finalPos, a_position.z, 1.0) * u_projection; + gl_Position = applyPivotTransform(pos, u_pivotTransform, 0.0); +} diff --git a/shaders/program_params.hpp b/shaders/program_params.hpp index 4dd1077bff..3ea1478c90 100644 --- a/shaders/program_params.hpp +++ b/shaders/program_params.hpp @@ -118,7 +118,8 @@ struct TrafficProgramParams BIND_PROGRAMS(TrafficProgramParams, Program::Traffic, - Program::TrafficLine) + Program::TrafficLine, + Program::TrafficCircle) }; struct TransitProgramParams @@ -163,7 +164,7 @@ struct ShapesProgramParams float m_opacity = 1.0f; float m_azimut = 0.0; - BIND_PROGRAMS(AccuracyProgramParams, + BIND_PROGRAMS(ShapesProgramParams, Program::Accuracy, Program::MyPosition) }; diff --git a/shaders/programs.hpp b/shaders/programs.hpp index 1a5379b141..0510369343 100644 --- a/shaders/programs.hpp +++ b/shaders/programs.hpp @@ -54,6 +54,7 @@ enum class Program TextFixedBillboard, Traffic, TrafficLine, + TrafficCircle, SmaaEdges, SmaaBlendingWeight, SmaaFinal, @@ -110,6 +111,7 @@ inline std::string DebugPrint(Program p) case Program::TextFixedBillboard: return "TextFixedBillboard"; case Program::Traffic: return "Traffic"; case Program::TrafficLine: return "TrafficLine"; + case Program::TrafficCircle: return "TrafficCircle"; case Program::SmaaEdges: return "SmaaEdges"; case Program::SmaaBlendingWeight: return "SmaaBlendingWeight"; case Program::SmaaFinal: return "SmaaFinal"; |