Webgl / add a fixed fragment shader builder for symbols
This commit is contained in:
@@ -26,7 +26,7 @@ export function formatNumber(v) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a symbol shader, i.e. a shader intended to be used on point geometries.
|
* Generates a symbol vertex shader, i.e. a shader intended to be used on point geometries.
|
||||||
*
|
*
|
||||||
* Expected the following attributes to be present in the attribute array:
|
* Expected the following attributes to be present in the attribute array:
|
||||||
* `vec2 a_position`, `float a_index` (being the index of the vertex in the quad, 0 to 3).
|
* `vec2 a_position`, `float a_index` (being the index of the vertex in the quad, 0 to 3).
|
||||||
@@ -80,3 +80,31 @@ void main(void) {
|
|||||||
|
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a symbol fragment shader, i.e. a shader intended to be used on point geometries.
|
||||||
|
*
|
||||||
|
* Expected the following varyings to be transmitted by the vertex shader:
|
||||||
|
* `vec2 v_texCoord`, `float v_opacity`, `vec4 v_color`
|
||||||
|
*
|
||||||
|
* @returns {string} The full shader as a string.
|
||||||
|
*/
|
||||||
|
export function getSymbolFragmentShader() {
|
||||||
|
const body = `precision mediump float;
|
||||||
|
uniform sampler2D u_texture;
|
||||||
|
varying vec2 v_texCoord;
|
||||||
|
varying float v_opacity;
|
||||||
|
varying vec4 v_color;
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
if (v_opacity == 0.0) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
vec4 textureColor = texture2D(u_texture, v_texCoord);
|
||||||
|
gl_FragColor = v_color * textureColor;
|
||||||
|
gl_FragColor.a *= v_opacity;
|
||||||
|
gl_FragColor.rgb *= gl_FragColor.a;
|
||||||
|
}`;
|
||||||
|
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {getSymbolVertexShader, formatNumber} from '../../../../src/ol/webgl/ShaderBuilder.js';
|
import {getSymbolVertexShader, formatNumber, getSymbolFragmentShader} from '../../../../src/ol/webgl/ShaderBuilder.js';
|
||||||
|
|
||||||
describe('ol.webgl.ShaderBuilder', function() {
|
describe('ol.webgl.ShaderBuilder', function() {
|
||||||
|
|
||||||
@@ -138,4 +138,24 @@ void main(void) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getSymbolFragmentShader', function() {
|
||||||
|
it('generates a fixed shader', function() {
|
||||||
|
expect(getSymbolFragmentShader()).to.eql(`precision mediump float;
|
||||||
|
uniform sampler2D u_texture;
|
||||||
|
varying vec2 v_texCoord;
|
||||||
|
varying float v_opacity;
|
||||||
|
varying vec4 v_color;
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
if (v_opacity == 0.0) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
vec4 textureColor = texture2D(u_texture, v_texCoord);
|
||||||
|
gl_FragColor = v_color * textureColor;
|
||||||
|
gl_FragColor.a *= v_opacity;
|
||||||
|
gl_FragColor.rgb *= gl_FragColor.a;
|
||||||
|
}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user