Skip to content

Commit

Permalink
Line texture: fix fragment shader, #105
Browse files Browse the repository at this point in the history
  • Loading branch information
devemux86 committed Aug 7, 2016
1 parent c926a71 commit a4934a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
22 changes: 19 additions & 3 deletions vtm/resources/assets/shaders/linetex_layer_tex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,25 @@ uniform vec4 u_bgcolor;
uniform float u_pwidth;
varying vec2 v_st;
uniform sampler2D tex;
uniform float u_mode;
void
main(){
vec4 c=texture2D(tex,vec2(abs(mod(v_st.s+1.0,2.0)),(v_st.t+1.0)*0.5));
float fuzz=fwidth(c.a);
gl_FragColor=(c * u_color) *smoothstep(0.5-fuzz,0.5+fuzz,c.a);
if (u_mode == 1.0) {
vec4 c=texture2D(tex,vec2(abs(mod(v_st.s+1.0,2.0)),(v_st.t+1.0)*0.5));
float fuzz=fwidth(c.a);
gl_FragColor=(c * u_color) *smoothstep(0.5-fuzz,0.5+fuzz,c.a);
}
else {
/* distance on perpendicular to the line */
float dist = abs(v_st.t);
float fuzz = fwidth(v_st.t);
float fuzz_p = fwidth(v_st.s);
float line_w = smoothstep(0.0, fuzz, 1.0 - dist);
float stipple_w = smoothstep(0.0, fuzz, u_pwidth - dist);
/* triangle waveform in the range 0..1 for regular pattern */
float phase = abs(mod(v_st.s, 2.0) - 1.0);
/* interpolate between on/off phase, 0.5 = equal phase length */
float stipple_p = smoothstep(0.5 - fuzz_p, 0.5 + fuzz_p, phase);
gl_FragColor = line_w * mix(u_bgcolor, u_color, min(stipple_w, stipple_p));
}
}
5 changes: 4 additions & 1 deletion vtm/src/org/oscim/renderer/bucket/LineTexBucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected void compile(ShortBuffer vboData, ShortBuffer iboData) {
}

static class Shader extends GLShader {
int uMVP, uColor, uWidth, uBgColor, uScale;
int uMVP, uColor, uWidth, uBgColor, uScale, uMode;
int uPatternWidth, uPatternScale;
int aPos0, aPos1, aLen0, aLen1, aFlip;

Expand All @@ -231,6 +231,7 @@ static class Shader extends GLShader {
uColor = getUniform("u_color");
uWidth = getUniform("u_width");
uBgColor = getUniform("u_bgcolor");
uMode = getUniform("u_mode");

uPatternWidth = getUniform("u_pwidth");
uPatternScale = getUniform("u_pscale");
Expand Down Expand Up @@ -360,6 +361,8 @@ public static RenderBucket draw(RenderBucket b, GLViewport v,
LineTexBucket lb = (LineTexBucket) b;
LineStyle line = lb.line.current();

gl.uniform1f(shader.uMode, line.texture != null ? 1 : 0);

if (line.texture != null)
line.texture.bind();

Expand Down

0 comments on commit a4934a5

Please sign in to comment.