From c1643850ceadfd9a25864a72056db4058d4c2869 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Wed, 20 Feb 2013 00:54:56 +0100 Subject: [PATCH] no need to multiply extrusion scale factor in shader --- src/org/oscim/renderer/LineRenderer.java | 17 ++++++++++------- src/org/oscim/renderer/layer/LineLayer.java | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/org/oscim/renderer/LineRenderer.java b/src/org/oscim/renderer/LineRenderer.java index 365d987b..b8ef15c4 100644 --- a/src/org/oscim/renderer/LineRenderer.java +++ b/src/org/oscim/renderer/LineRenderer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 OpenScienceMap + * Copyright 2013 Hannes Janetzek * * This program is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General License as published by the Free Software @@ -43,6 +43,10 @@ public final class LineRenderer { private static final int LINE_VERTICES_DATA_POS_OFFSET = 0; + // factor to normalize extrusion vector and scale to coord scale + private final static float COORD_SCALE_BY_DIR_SCALE = + GLRenderer.COORD_MULTIPLIER / LineLayer.DIR_SCALE; + // shader handles private static int[] lineProgram = new int[2]; private static int[] hLineVertexPosition = new int[2]; @@ -188,7 +192,7 @@ public final class LineRenderer { continue; } - glUniform1f(uLineWidth, width); + glUniform1f(uLineWidth, width * COORD_SCALE_BY_DIR_SCALE); if (line.blur != 0) { glUniform1f(uLineScale, 1f - (line.blur / s)); @@ -221,7 +225,7 @@ public final class LineRenderer { width = (ll.width - 0.2f) / lineScale; } - glUniform1f(uLineWidth, width); + glUniform1f(uLineWidth, width * COORD_SCALE_BY_DIR_SCALE); if (line.blur != 0) { glUniform1f(uLineScale, line.blur); @@ -250,17 +254,18 @@ public final class LineRenderer { private final static String lineVertexShader = "" + "precision mediump float;" + "uniform mat4 u_mvp;" + // factor to increase line width relative to scale + "uniform float u_width;" + // xy hold position, zw extrusion vector + "attribute vec4 a_pos;" + "uniform float u_mode;" + "varying vec2 v_st;" + "varying vec2 v_mode;" - + "const float dscale = 8.0/2048.0;" + "void main() {" // scale extrusion to u_width pixel // just ignore the two most insignificant bits of a_st :) + " vec2 dir = a_pos.zw;" - + " gl_Position = u_mvp * vec4(a_pos.xy + (dscale * u_width * dir), 0.0, 1.0);" + + " gl_Position = u_mvp * vec4(a_pos.xy + (u_width * dir), 0.0, 1.0);" // last two bits of a_st hold the texture coordinates // ..maybe one could wrap texture so that `abs` is not required + " v_st = abs(mod(dir, 4.0)) - 1.0;" @@ -270,7 +275,6 @@ public final class LineRenderer { private final static String lineSimpleFragmentShader = "" + "precision mediump float;" + "uniform sampler2D tex;" - + "uniform float u_width;" + "uniform float u_wscale;" + "uniform vec4 u_color;" + "varying vec2 v_st;" @@ -297,7 +301,6 @@ public final class LineRenderer { + "uniform sampler2D tex;" + "uniform float u_mode;" + "uniform vec4 u_color;" - + "uniform float u_width;" + "uniform float u_wscale;" + "varying vec2 v_st;" + "void main() {" diff --git a/src/org/oscim/renderer/layer/LineLayer.java b/src/org/oscim/renderer/layer/LineLayer.java index 881d710d..5bef69fc 100644 --- a/src/org/oscim/renderer/layer/LineLayer.java +++ b/src/org/oscim/renderer/layer/LineLayer.java @@ -29,7 +29,7 @@ public final class LineLayer extends Layer { private static final float COORD_SCALE = GLRenderer.COORD_MULTIPLIER; // scale factor mapping extrusion vector to short values - private static final float DIR_SCALE = 2048; + public static final float DIR_SCALE = 2048; // mask for packing last two bits of extrusion vector with texture // coordinates private static final int DIR_MASK = 0xFFFFFFFC;