diff --git a/drape/shaders/doc/normalize_vertex_shader_vsh.txt b/drape/shaders/doc/normalize_vertex_shader_vsh.txt new file mode 100644 index 0000000000..a7fe31b62a --- /dev/null +++ b/drape/shaders/doc/normalize_vertex_shader_vsh.txt @@ -0,0 +1,23 @@ +Transform point from mercator to current model view and forming triangles by normals + +mercatorPoint -> currentModelViewPoint +currentModelViewPoint + normal; + +Example: +vertex number 1 2 3 4 +pt stream = [{ 0.0, 0.0}, { 0.0, 0.0} , {0.0, 0.0} , {0.0, 0.0}] +normal stream = [{-1.0, 1.0}, {-1.0, -1.0} , {1.0, 1.0} , {1.0, -1.0}] +Type = Triangle strip + +1 3 +_____ +| /| +| . | +|/__| +2 4 + +attribute a_position + [x, y] - mercator position + [z ] - depth +attribute a_normal + [x, y] - forming normal diff --git a/drape/shaders/normalize_vertex_shader.vsh b/drape/shaders/normalize_vertex_shader.vsh new file mode 100644 index 0000000000..0c5e92434f --- /dev/null +++ b/drape/shaders/normalize_vertex_shader.vsh @@ -0,0 +1,10 @@ +attribute vec4 a_position; +attribute vec4 a_normal; + +uniform mat4 modelView; +uniform mat4 projection; + +void main(void) +{ + gl_Position = ((a_position * modelView) + a_normal) * projection; +} diff --git a/drape/shaders/shader_index.txt b/drape/shaders/shader_index.txt index 30d85fae78..5358bb47ae 100644 --- a/drape/shaders/shader_index.txt +++ b/drape/shaders/shader_index.txt @@ -1,3 +1,4 @@ SOLID_AREA_PROGRAM simple_vertex_shader.vsh solid_color_fragment_shader.fsh +SOLID_SHAPE_PROGRAM normalize_vertex_shader.vsh solid_color_fragment_shader.fsh TEXTURING_PROGRAM texturing_vertex_shader.vsh texturing_fragment_shader.fsh -SOLID_LINE_PROGRAM line_vertex_shader.vsh line_fragment_shader.fsh \ No newline at end of file +SOLID_LINE_PROGRAM line_vertex_shader.vsh line_fragment_shader.fsh diff --git a/drape/shaders/simple_vertex_shader.vsh b/drape/shaders/simple_vertex_shader.vsh index 9453d24bae..dfa459d4ba 100644 --- a/drape/shaders/simple_vertex_shader.vsh +++ b/drape/shaders/simple_vertex_shader.vsh @@ -1,9 +1,9 @@ -attribute vec4 position; +attribute vec4 a_position; uniform mat4 modelView; uniform mat4 projection; void main(void) { - gl_Position = position * modelView * projection; + gl_Position = a_position * modelView * projection; } diff --git a/drape/shaders/solid_color_fragment_shader.fsh b/drape/shaders/solid_color_fragment_shader.fsh index d37ec3bb67..5b7fc961a5 100644 --- a/drape/shaders/solid_color_fragment_shader.fsh +++ b/drape/shaders/solid_color_fragment_shader.fsh @@ -1,6 +1,6 @@ -uniform lowp vec4 color; +uniform lowp vec4 u_color; void main(void) { - gl_FragColor = color; + gl_FragColor = u_color; } diff --git a/drape/shaders/texturing_fragment_shader.fsh b/drape/shaders/texturing_fragment_shader.fsh index 9fa5f292f8..ee76888deb 100644 --- a/drape/shaders/texturing_fragment_shader.fsh +++ b/drape/shaders/texturing_fragment_shader.fsh @@ -1,7 +1,35 @@ -uniform sampler2D textureUnit; -varying highp vec4 varTexCoords; +uniform sampler2D u_textures[8]; +varying highp vec4 v_texCoords; + +const int Index0 = 0; +const int Index1 = 1; +const int Index2 = 2; +const int Index3 = 3; +const int Index4 = 4; +const int Index5 = 5; +const int Index6 = 6; +const int Index7 = 7; void main(void) { - gl_FragColor = texture2D(textureUnit, varTexCoords.st); + int index = int(floor(v_texCoords.z)); + highp vec4 color; + if (index == Index0) + color = texture2D(u_textures[Index0], v_texCoords.st); + else if (index == Index1) + color = texture2D(u_textures[Index1], v_texCoords.st); + else if (index == Index2) + color = texture2D(u_textures[Index2], v_texCoords.st); + else if (index == Index3) + color = texture2D(u_textures[Index3], v_texCoords.st); + else if (index == Index4) + color = texture2D(u_textures[Index4], v_texCoords.st); + else if (index == Index5) + color = texture2D(u_textures[Index5], v_texCoords.st); + else if (index == Index6) + color = texture2D(u_textures[Index6], v_texCoords.st); + else if (index == Index7) + color = texture2D(u_textures[Index7], v_texCoords.st); + + gl_FragColor = color; } diff --git a/drape/shaders/texturing_vertex_shader.vsh b/drape/shaders/texturing_vertex_shader.vsh index ba602d6eab..ceb6ac5ad1 100644 --- a/drape/shaders/texturing_vertex_shader.vsh +++ b/drape/shaders/texturing_vertex_shader.vsh @@ -1,13 +1,14 @@ -attribute mediump vec2 position; -attribute mediump float depth; -attribute mediump vec4 texCoords; +attribute highp vec4 a_position; +attribute highp vec4 a_normal; +attribute highp vec4 a_texCoords; -uniform highp mat4 modelViewProjectionMatrix; +uniform highp mat4 modelView; +uniform highp mat4 projection; -varying highp vec4 varTexCoords; +varying highp vec4 v_texCoords; void main(void) { - gl_Position = modelViewProjectionMatrix * vec4(position, depth, 1.0); - varTexCoords = texCoords; + gl_Position = ((a_position * modelView) + a_normal) * projection; + v_texCoords = a_texCoords; }