Skip to content
Snippets Groups Projects
Commit 43fc8e94 authored by Alexander Rose's avatar Alexander Rose
Browse files

require shaders from files using glslify and webpack

parent 7ca8b1e1
Branches
Tags
No related merge requests found
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
"scripts": { "scripts": {
"lint": "tslint src/**/*.ts", "lint": "tslint src/**/*.ts",
"build": "tsc", "build": "tsc",
"postbuild": "copyfiles --up 1 src/mol-gl/shader/*.vert src/mol-gl/shader/*.frag build/node_modules/",
"watch": "tsc -watch", "watch": "tsc -watch",
"test": "jest", "test": "jest",
"script": "node build/node_modules/script.js", "script": "node build/node_modules/script.js",
...@@ -31,13 +32,14 @@ ...@@ -31,13 +32,14 @@
"build/node_modules" "build/node_modules"
], ],
"moduleNameMapper": { "moduleNameMapper": {
"mol-task($|/.*)": "<rootDir>/src/mol-task$1",
"mol-comp($|/.*)": "<rootDir>/src/mol-comp$1",
"mol-util($|/.*)": "<rootDir>/src/mol-util$1",
"mol-data($|/.*)": "<rootDir>/src/mol-data$1", "mol-data($|/.*)": "<rootDir>/src/mol-data$1",
"mol-math($|/.*)": "<rootDir>/src/mol-math$1", "mol-gl($|/.*)": "<rootDir>/src/mol-gl$1",
"mol-io($|/.*)": "<rootDir>/src/mol-io$1", "mol-io($|/.*)": "<rootDir>/src/mol-io$1",
"mol-model($|/.*)": "<rootDir>/src/mol-model$1" "mol-math($|/.*)": "<rootDir>/src/mol-math$1",
"mol-model($|/.*)": "<rootDir>/src/mol-model$1",
"mol-ql($|/.*)": "<rootDir>/src/mol-ql$1",
"mol-task($|/.*)": "<rootDir>/src/mol-task$1",
"mol-util($|/.*)": "<rootDir>/src/mol-util$1"
}, },
"testRegex": "\\.spec\\.ts$" "testRegex": "\\.spec\\.ts$"
}, },
...@@ -53,7 +55,10 @@ ...@@ -53,7 +55,10 @@
"@types/react": "^16.0.4", "@types/react": "^16.0.4",
"@types/react-dom": "^16.0.4", "@types/react-dom": "^16.0.4",
"benchmark": "^2.1.4", "benchmark": "^2.1.4",
"copyfiles": "^2.0.0",
"glslify-loader": "^1.0.2",
"jest": "^22.4.2", "jest": "^22.4.2",
"raw-loader": "^0.5.1",
"regl": "git+https://github.com/regl-project/regl.git#45c6ec570232420fca21567499c9c5a2a054432e", "regl": "git+https://github.com/regl-project/regl.git#45c6ec570232420fca21567499c9c5a2a054432e",
"rollup": "^0.56.2", "rollup": "^0.56.2",
"rollup-plugin-buble": "^0.19.2", "rollup-plugin-buble": "^0.19.2",
......
...@@ -9,6 +9,9 @@ import * as glContext from 'mol-gl/context' ...@@ -9,6 +9,9 @@ import * as glContext from 'mol-gl/context'
import { Camera } from 'mol-gl/camera' import { Camera } from 'mol-gl/camera'
import { Vec3 } from 'mol-math/linear-algebra' import { Vec3 } from 'mol-math/linear-algebra'
const pointVert = require('mol-gl/shader/point.vert')
const pointFrag = require('mol-gl/shader/point.frag')
export default class State { export default class State {
regl: REGL.Regl regl: REGL.Regl
...@@ -28,33 +31,21 @@ export default class State { ...@@ -28,33 +31,21 @@ export default class State {
center: Vec3.create(0, 0, 0) center: Vec3.create(0, 0, 0)
}) })
const drawTriangle = regl({ const drawPoints = regl({
frag: ` vert: pointVert,
void main() { frag: pointFrag,
gl_FragColor = vec4(1, 0, 0, 1);
}`,
vert: `
precision mediump float;
uniform mat4 projection, view;
attribute vec3 position;
void main () {
gl_Position = projection * view * vec4(position, 1.0);
}`,
attributes: { attributes: {
position: [[0, -1, 0], [-1, 0, 0], [1, 1, 0]] position: [[0, -1, 0], [-1, 0, 0], [1, 1, 0]]
}, },
count: 3,
count: 3 primitive: 'points'
}) })
regl.frame(() => { regl.frame(() => {
camera.update((state: any) => { camera.update((state: any) => {
if (!camera.isDirty()) return if (!camera.isDirty()) return
console.log(state, camera)
regl.clear({color: [0, 0, 0, 1]}) regl.clear({color: [0, 0, 0, 1]})
drawTriangle() drawPoints()
}, undefined) }, undefined)
}) })
......
...@@ -177,9 +177,6 @@ export namespace Camera { ...@@ -177,9 +177,6 @@ export namespace Camera {
function update (props: any, block: any) { function update (props: any, block: any) {
setState() setState()
injectContext(props, block) injectContext(props, block)
if (dirty) {
console.log(view)
}
dirty = false dirty = false
} }
......
void main(){
gl_FragColor = vec4(1, 0, 0, 1);
}
\ No newline at end of file
precision mediump float;
uniform mat4 projection, view;
attribute vec3 position;
varying vec3 vPosition;
void main(){
gl_PointSize = 20.0;
gl_Position = projection * view * vec4(position, 1.0);
}
\ No newline at end of file
...@@ -14,13 +14,14 @@ ...@@ -14,13 +14,14 @@
"outDir": "build/node_modules", "outDir": "build/node_modules",
"baseUrl": "src", "baseUrl": "src",
"paths": { "paths": {
"mol-task": ["./mol-task", "./mol-task/index.ts"],
"mol-comp": ["./mol-comp", "./mol-comp/index.ts"],
"mol-util": ["./mol-util", "./mol-util/index.ts"],
"mol-data": ["./mol-data", "./mol-data/index.ts"], "mol-data": ["./mol-data", "./mol-data/index.ts"],
"mol-math": ["./mol-math"], "mol-gl": ["./mol-gl"],
"mol-io": ["./mol-io"], "mol-io": ["./mol-io"],
"mol-model": ["./mol-model"] "mol-math": ["./mol-math"],
"mol-model": ["./mol-model"],
"mol-ql": ["./mol-ql"],
"mol-task": ["./mol-task", "./mol-task/index.ts"],
"mol-util": ["./mol-util", "./mol-util/index.ts"],
} }
}, },
"include": [ "**/*" ] "include": [ "**/*" ]
......
module.exports = {
module: {
rules: [
{
test: /\.(glsl|frag|vert)$/,
loader: 'raw-loader',
},
{
test: /\.(glsl|frag|vert)$/,
loader: 'glslify-loader',
}
]
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment