switch to ShortBuffer for half-float, shader tweaks,..

This commit is contained in:
Hannes Janetzek
2012-06-20 17:24:38 +02:00
parent 5da8c6ed0d
commit f977fec1ae
12 changed files with 376 additions and 227 deletions

View File

@@ -17,60 +17,78 @@ package org.mapsforge.android.glrenderer;
class Shaders {
final static String gLineVertexShader = ""
+ "precision highp float; \n"
+ "precision mediump float; \n"
+ "uniform mat4 u_center;"
+ "uniform float u_width;"
// + "uniform float u_width;"
+ "attribute vec4 a_position;"
+ "attribute vec2 a_st;"
+ "varying vec2 v_st;"
+ "void main() {"
+ " gl_Position = u_center * a_position;"
+ " v_st = a_st;" + "}";
+ " v_st = a_st;"
+ "}";
final static String gLineFragmentShader = ""
+ "#extension GL_OES_standard_derivatives : enable\n"
+ "precision mediump float;"
+ "uniform float u_width;"
+ "uniform int u_mode;"
+ "uniform vec2 u_mode;"
+ "uniform vec4 u_color;"
+ "const float zero = 0.0;"
+ "const int standard = 0;"
+ "const int fixed_width = 2;"
+ "const vec4 blank = vec4(1.0, 0.0, 0.0, 1.0);"
+ "const vec4 blank2 = vec4(0.0, 1.0, 0.0, 1.0);"
+ "varying vec2 v_st;"
+ "void main() {"
+ " if (u_mode != fixed_width) {"
// + " gl_FragColor = u_color;"
// + " float fuzz;"
// + " float len;"
+ " if (v_st.t == zero){ "
// + " fuzz = - sqrt(dFdx(v_st.s) * dFdx(v_st.s) + dFdy(v_st.s) * dFdy(v_st.s));"
+ " float fuzz = -fwidth(v_st.s) * 1.5;"
+ " float len = abs(v_st.s) - u_width;"
// + " if (len < fuzz)"
+ " gl_FragColor = u_color * smoothstep(zero, fuzz, len);"
+ " } else {"
+ " float fuzz = -max(fwidth(v_st.s), fwidth(v_st.t)) * 1.5;"
+ " float len = length(v_st) - u_width;"
// + " if (len < fuzz)"
+ " gl_FragColor = u_color * smoothstep(zero, fuzz, len);"
+ " } "
// + " if (len > zero)"
// + " gl_FragColor = blank;"
// + " discard;"
// + " gl_FragColor = u_color;"
// + " else if (len < fuzz)"
// + " gl_FragColor = blank2;"
// + " else "
+ " } else { "
+ " float fuzz = fwidth(v_st.s);"
// + " gl_FragColor = u_color * smoothstep(fuzz, zero, abs(v_st.s) - u_width + fuzz);"
// + " fuzz = - sqrt(dFdx(v_st.s) * dFdx(v_st.s) + dFdy(v_st.s) * dFdy(v_st.s)) * 1.5;"
+ " gl_FragColor = u_color * smoothstep(fuzz*0.5, -fuzz, abs(v_st.s) - u_width);"
+ " }"
+ "float width = u_mode[1];"
// + " if (v_st.t == zero){ "
// + " float fuzz = fwidth(v_st.s) * 1.5;"
// + " gl_FragColor = u_color * smoothstep(-fuzz * u_mode[0], fuzz, width - abs(v_st.s));"
// + " } else {"
+ " float fuzz = max(fwidth(v_st.s), fwidth(v_st.t)) * 1.5;"
+ " gl_FragColor = u_color * smoothstep(-fuzz * u_mode[0], fuzz, width - length(v_st));"
// + " } "
+ "}";
// final static String gLineFragmentShader = ""
// + "#extension GL_OES_standard_derivatives : enable\n"
// + "precision mediump float;"
// + "uniform float u_width;"
// + "uniform vec2 u_mode;"
// + "uniform vec4 u_color;"
// + "const float zero = 0.0;"
// // + "const vec4 blank = vec4(1.0, 0.0, 0.0, 1.0);"
// + "varying vec2 v_st;"
// + "void main() {"
// + "float width = u_mode[1];"
// // + "float alpha = 1.0;"
// + " if (u_mode[0] == zero) {"
// // + " gl_FragColor = u_color;"
// // + " float fuzz;"
// // + " float len;"
// + " if (v_st.t == zero){ "
// // + " fuzz = - sqrt(dFdx(v_st.s) * dFdx(v_st.s) + dFdy(v_st.s) * dFdy(v_st.s));"
// + " float fuzz = -fwidth(v_st.s) * 1.5;"
// + " float len = abs(v_st.s) - width;"
// // + " if (len < fuzz)"
// + " gl_FragColor = u_color * smoothstep(zero, fuzz, len);"
// + " } else {"
// + " float fuzz = -max(fwidth(v_st.s), fwidth(v_st.t)) * 1.5;"
// + " float len = length(v_st) - width;"
// // + " if (len < fuzz)"
// + " gl_FragColor = u_color * smoothstep(zero, fuzz, len);"
// + " } "
// // + " if (len > zero)"
// // + " gl_FragColor = blank;"
// // + " discard;"
// // + " gl_FragColor = u_color;"
// // + " else if (len < fuzz)"
// // + " gl_FragColor = blank2;"
// // + " else "
// + " } else { "
// + " float fuzz = fwidth(v_st.s);"
// // + " gl_FragColor = u_color * smoothstep(fuzz, zero, abs(v_st.s) - u_width + fuzz);"
// // + " fuzz = - sqrt(dFdx(v_st.s) * dFdx(v_st.s) + dFdy(v_st.s) * dFdy(v_st.s)) * 1.5;"
// + " gl_FragColor = u_color * smoothstep(fuzz*0.5, -fuzz, abs(v_st.s) - width);"
// + " }"
// + "}";
// final static String gLineFragmentShader = "" +
// "#extension GL_OES_standard_derivatives : enable\n" +
// "precision mediump float;" +