Skip to content

Commit

Permalink
more brfs cleanup (visgl#431)
Browse files Browse the repository at this point in the history
* glsl clean up

* more brfs cleanup
  • Loading branch information
gnavvy authored Mar 16, 2017
1 parent 691d9cf commit 3e192d3
Show file tree
Hide file tree
Showing 39 changed files with 248 additions and 427 deletions.
1 change: 0 additions & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-2": "^6.3.13",
"brfs-babel": "^1.0.0",
"css-loader": "^0.26.1",
"eslint": "^3.0.0",
"eslint-config-uber-es2015": "^3.0.0",
Expand Down
3 changes: 0 additions & 3 deletions demo/webpack/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ module.exports = {
loader: 'raw-loader',
include: demoSources,
enforce: 'post'
}, {
test: /\.js$/,
loader: 'transform-loader?brfs-babel'
}]
},

Expand Down
2 changes: 1 addition & 1 deletion examples/layer-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"build": "webpack app bundle.js --env.local --display-error-details"
},
"dependencies": {
"deck.gl": "^4.0.0-beta.3",
"deck.gl": "^4.0.0-rc1",
"extrude-polyline": "^1.0.6",
"immutable": "^3.8.1",
"luma.gl": "3.0.0-beta.11",
Expand Down
6 changes: 0 additions & 6 deletions examples/layer-browser/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ module.exports = {
test: /\.json$/,
loader: 'json-loader',
exclude: [/node_modules/]
},
{
// Needed to inline deck.gl GLSL shaders
include: [resolve(__dirname, '../sample-layers')],
loader: 'transform-loader',
options: 'brfs-babel'
}
]
},
Expand Down
15 changes: 9 additions & 6 deletions examples/sample-layers/plot-layer/axes-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import {Layer, assembleShaders} from 'deck.gl';
import {GL, Model, Geometry} from 'luma.gl';

import {scaleLinear} from 'd3-scale';
import {readFileSync} from 'fs';
import {join} from 'path';
import {textMatrixToTexture} from './utils';

import fragmentShader from './fragment.glsl';
import gridVertex from './grid-vertex.glsl';
import labelVertex from './label-vertex.glsl';
import labelFragment from './label-fragment.glsl';

/* Constants */
const FONT_SIZE = 48;

Expand Down Expand Up @@ -120,8 +123,8 @@ export default class AxesLayer extends Layer {
* show/hide is toggled by the vertex shader
*/
const gridShaders = assembleShaders(gl, {
vs: readFileSync(join(__dirname, './grid-vertex.glsl'), 'utf8'),
fs: readFileSync(join(__dirname, './fragment.glsl'), 'utf8')
vs: gridVertex,
fs: fragmentShader
});

/*
Expand Down Expand Up @@ -178,8 +181,8 @@ export default class AxesLayer extends Layer {
* show/hide is toggled by the vertex shader
*/
const labelShaders = assembleShaders(gl, {
vs: readFileSync(join(__dirname, './label-vertex.glsl'), 'utf8'),
fs: readFileSync(join(__dirname, './label-fragment.glsl'), 'utf8')
vs: labelVertex,
fs: labelFragment
});

let labelTexCoords = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

export default `\
#define SHADER_NAME graph-layer-fragment-shader
#ifdef GL_ES
Expand All @@ -33,3 +34,4 @@ void main(void) {
}
gl_FragColor = vColor;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

export default `\
#define SHADER_NAME graph-layer-axis-vertex-shader
attribute vec3 positions;
Expand All @@ -40,7 +41,7 @@ float frontFacing(vec3 v) {
}
void main(void) {
// rotated rectangle to align with slice:
// for each x tick, draw rectangle on yz plane
// for each y tick, draw rectangle on zx plane
Expand All @@ -63,7 +64,8 @@ void main(void) {
// do not draw grid line in front of the graph
shouldDiscard = frontFacing(gridLineNormal);
vec3 position_modelspace = (vec3(instancePositions.x) - modelCenter) * instanceNormals + gridVertexOffset * modelDim / 2.0;
vec3 position_modelspace = (vec3(instancePositions.x) - modelCenter) *
instanceNormals + gridVertexOffset * modelDim / 2.0;
// scale bounding box to fit into a unit cube that centers at [0, 0, 0]
float scale = 1.0 / max(modelDim.x, max(modelDim.y, modelDim.z));
Expand All @@ -76,3 +78,4 @@ void main(void) {
vColor = strokeColor / 255.0;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

export default `\
#define SHADER_NAME graph-layer-fragment-shader
#ifdef GL_ES
Expand All @@ -39,3 +40,4 @@ void main(void) {
}
gl_FragColor = color;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

export default `\
#define SHADER_NAME graph-layer-axis-vertex-shader
attribute vec3 positions;
Expand Down Expand Up @@ -55,7 +56,7 @@ float frontFacing(vec3 v) {
}
void main(void) {
// rotated rectangle to align with slice:
// for each x tick, draw rectangle on yz plane
// for each y tick, draw rectangle on zx plane
Expand Down Expand Up @@ -95,8 +96,9 @@ void main(void) {
vTexCoords = (textureOrigin + textureSize * texCoords) / labelTextureDim;
vTexCoords.y = 1.0 - vTexCoords.y;
vec3 position_modelspace = (vec3(instancePositions.x) - modelCenter) * instanceNormals + gridVertexOffset * modelDim / 2.0;

vec3 position_modelspace = (vec3(instancePositions.x) - modelCenter) *
instanceNormals + gridVertexOffset * modelDim / 2.0;
// scale bounding box to fit into a unit cube that centers at [0, 0, 0]
float scale = 1.0 / max(modelDim.x, max(modelDim.y, modelDim.z));
position_modelspace *= scale;
Expand All @@ -116,3 +118,4 @@ void main(void) {
gl_Position = position_clipspace + vec4(labelVertexOffset, 0.0, 0.0);
}
`;
10 changes: 5 additions & 5 deletions examples/sample-layers/plot-layer/surface-layer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Layer, assembleShaders} from 'deck.gl';

import {GL, Model, Geometry} from 'luma.gl';
import {readFileSync} from 'fs';
import {join} from 'path';

import surfaceVertex from './surface-vertex.glsl';
import fragmentShader from './fragment.glsl';

const DEFAULT_COLOR = [0, 0, 0, 255];

Expand Down Expand Up @@ -84,8 +84,8 @@ export default class SurfaceLayer extends Layer {
getModel(gl) {
// 3d surface
const graphShaders = assembleShaders(gl, {
vs: readFileSync(join(__dirname, './surface-vertex.glsl'), 'utf8'),
fs: readFileSync(join(__dirname, './fragment.glsl'), 'utf8')
vs: surfaceVertex,
fs: fragmentShader
});

return new Model({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

export default `\
#define SHADER_NAME graph-layer-vertex-shader
attribute vec4 positions;
Expand All @@ -44,10 +45,11 @@ void main(void) {
// when creating the perspective projection matrix.
vec4 center_clipspace = project_to_clipspace(vec4(0.0, 0.0, 0.0, 1.0));
float fadeFactor = 1.0 - (gl_Position.z - center_clipspace.z) * lightStrength;
vec4 color = vec4(colors.rgb * fadeFactor, colors.a * opacity) / 255.0;
vec4 pickingColor = vec4(pickingColors / 255.0, 1.0);
vColor = mix(color, pickingColor, renderPickingBuffer);
shouldDiscard = positions.w;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

export default `\
#define SHADER_NAME trips-layer-fragment-shader
#ifdef GL_ES
Expand All @@ -33,3 +34,4 @@ void main(void) {
}
gl_FragColor = vec4(vColor.rgb, vColor.a * vTime);
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

export default `\
#define SHADER_NAME trips-layer-vertex-shader
attribute vec3 positions;
Expand All @@ -40,3 +41,4 @@ void main(void) {
vColor = vec4(colors / 255.0, opacity);
vTime = 1.0 - (currentTime - positions.z) / trailLength;
}
`;
9 changes: 5 additions & 4 deletions examples/sample-layers/trips-layer/trips-layer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {Layer, assembleShaders} from 'deck.gl';

import {Model, Program, Geometry} from 'luma.gl';
import {readFileSync} from 'fs';
import {join} from 'path';

import tripsVertex from './trips-layer-vertex.glsl';
import tripsFragment from './trips-layer-fragment.glsl';

const defaultProps = {
trailLength: 120,
Expand Down Expand Up @@ -39,8 +40,8 @@ export default class TripsLayer extends Layer {
getModel(gl) {
return new Model({
program: new Program(gl, assembleShaders(gl, {
vs: readFileSync(join(__dirname, './trips-layer-vertex.glsl'), 'utf8'),
fs: readFileSync(join(__dirname, './trips-layer-fragment.glsl'), 'utf8')
vs: tripsVertex,
fs: tripsFragment
})),
geometry: new Geometry({
id: this.props.id,
Expand Down
5 changes: 0 additions & 5 deletions examples/svg-interoperability/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ module.exports = {
options: {
objectAssign: 'Object.assign'
}
}, {
// Needed to inline deck.gl GLSL shaders
include: [resolve(__dirname, '../../src')],
loader: 'transform-loader',
options: 'brfs-babel'
}]
},
node: {
Expand Down
6 changes: 0 additions & 6 deletions examples/webpack.config.local.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ const LOCAL_DEVELOPMENT_CONFIG = {
test: /\.glsl$/,
loader: 'raw-loader',
exclude: [/node_modules/]
},
{
// Needed to inline deck.gl GLSL shaders
include: [SRC_DIR],
loader: 'transform-loader',
options: 'brfs-babel'
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

export default `\
#define SHADER_NAME reflection-effect-fs
#ifdef GL_ES
Expand Down Expand Up @@ -45,10 +46,10 @@ vec4 sample_gaussian(sampler2D tex, vec2 dim, vec2 uv, float sigma) {
if (sigma == 0.0) {
return texture2D(tex, uv);
}
vec2 delta = 1.0 / dim;
vec2 top_left = uv - delta * float(KERNEL_SIZE+1) / 2.0;
vec4 color = vec4(0);
float sum = 0.0;
for (int i = 0; i < KERNEL_SIZE; ++i) {
Expand All @@ -74,10 +75,12 @@ void main(void) {
//let this be our standard deviation in terms of screen-widths.
//rewrite this in terms of pixels.
sigma *= float(reflectionTextureWidth);


gl_FragColor = sample_gaussian(reflectionTexture, vec2(reflectionTextureWidth, reflectionTextureHeight), vec2(uv.x, 1. - uv.y), sigma);
gl_FragColor = sample_gaussian(reflectionTexture, vec2(reflectionTextureWidth,
reflectionTextureHeight), vec2(uv.x, 1. - uv.y), sigma);
//because our canvas expects alphas to be pre-multiplied, we multiply by whole
//color vector by reflectivity, not just the alpha channel
gl_FragColor *= reflectivity;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

export default `\
#define SHADER_NAME reflection-effect-vs
attribute vec3 vertices;
Expand All @@ -28,3 +29,4 @@ void main(void) {
uv = vertices.xy;
gl_Position = vec4(2. * vertices.xy - vec2(1., 1.), 1., 1.);
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import {GL, Framebuffer, Model, Geometry} from 'luma.gl';
import {assembleShaders} from '../../../shader-utils';
import {Effect} from '../../lib';
import {readFileSync} from 'fs';
import {join} from 'path';
import {WebMercatorViewport} from '../../../lib/viewports';

import reflectionVertex from './reflection-effect-vertex.glsl';
import reflectionFragment from './reflection-effect-fragment.glsl';

export default class ReflectionEffect extends Effect {

/**
Expand All @@ -27,8 +28,8 @@ export default class ReflectionEffect extends Effect {

getShaders() {
return {
vs: readFileSync(join(__dirname, './reflection-effect-vertex.glsl'), 'utf8'),
fs: readFileSync(join(__dirname, './reflection-effect-fragment.glsl'), 'utf8')
vs: reflectionVertex,
fs: reflectionFragment
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/shaderlib/fp64/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import path from 'path';
import mathFp64 from './math-fp64.glsl';

export const fp64 = {
interface: 'fp64',
source: fs.readFileSync(path.join(__dirname, 'math-fp64.glsl'), 'utf8')
source: mathFp64
};
Loading

0 comments on commit 3e192d3

Please sign in to comment.