larry babby and threejs for glsl

This commit is contained in:
Sam
2024-06-24 21:24:00 +12:00
parent 87d5dc634d
commit 907ebae4c0
6474 changed files with 1279596 additions and 8 deletions

View File

@@ -0,0 +1,12 @@
The MIT License (MIT)
=====================
Copyright (c) 2014 [stackgl](http://github.com/stackgl/) contributors
*stackgl contributors listed at <https://github.com/stackgl/contributing/blob/master/CONTRIBUTING.md#contributors>*
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,78 @@
# glsl-inject-defines
[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)
Safely inject `#define` statements into a shader source.
If the shader contains any `#version` or `#extension` statements, the defines are added after them.
## Example
```glsl
// Your cool shader
#version 330
#extension GL_OES_standard_derivatives : enable
void main() {
#ifdef BLUE
gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);
#else
gl_FragColor = vec4(0.0);
#endif
}
```
You can process it at runtime, like so:
```js
var injectDefines = require('glsl-inject-defines')
var fs = require('fs')
var source = fs.readFileSync(__dirname + '/shader.glsl', 'utf8')
var transformed = injectDefines(source, {
PI: 3.14,
BLUE: ''
})
console.log(transformed)
```
The resulting shader:
```glsl
// Your cool shader
#version 330
#extension GL_OES_standard_derivatives : enable
#define PI 3.14
#define BLUE
void main() {
#ifdef BLUE
gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);
#else
gl_FragColor = vec4(0.0);
#endif
}
```
Works in the browser with browserify and [glslify](https://www.npmjs.com/package/glslify).
## Install
```sh
npm install glsl-inject-defines
```
## Usage
[![NPM](https://nodei.co/npm/glsl-inject-defines.png)](https://www.npmjs.com/package/glsl-inject-defines)
#### `newSource = injectDefines(source, defines)`
Injects the set of `defines`, an object with `<name, value>` pairs that will get turned into strings for the shader source.
Returns the transformed source, with defines injected after extension and version statements.
## License
MIT. See [LICENSE.md](http://github.com/stackgl/glsl-inject-defines/blob/master/LICENSE.md) for details.

View File

@@ -0,0 +1,42 @@
{
"name": "glsl-inject-defines",
"version": "1.0.3",
"description": "injects a #define statement into a shader source",
"main": "string.js",
"license": "MIT",
"scripts": {
"test": "node test/test.js | faucet"
},
"author": {
"name": "Matt DesLauriers",
"email": "dave.des@gmail.com",
"url": "http://github.com/mattdesl"
},
"dependencies": {
"glsl-token-inject-block": "^1.0.0",
"glsl-token-string": "^1.0.1",
"glsl-tokenizer": "^2.0.2"
},
"devDependencies": {
"faucet": "0.0.1",
"tape": "^4.0.0"
},
"repository": {
"type": "git",
"url": "git://github.com/mattdesl/glsl-inject-defines.git"
},
"keywords": [
"ecosystem:stackgl",
"inject",
"define",
"shader",
"stackgl",
"webgl",
"shader",
"glsl"
],
"homepage": "https://github.com/mattdesl/glsl-inject-defines",
"bugs": {
"url": "https://github.com/mattdesl/glsl-inject-defines/issues"
}
}

View File

@@ -0,0 +1,30 @@
var tokenize = require('glsl-tokenizer')
var stringify = require('glsl-token-string')
var inject = require('glsl-token-inject-block')
module.exports = function glslInjectDefine (source, defines) {
if (!defines) {
return source
}
var keys = Object.keys(defines)
if (keys.length === 0) {
return source
}
var tokens = tokenize(source)
for (var i=keys.length-1; i>=0; i--) {
var key = keys[i]
var val = String(defines[key])
if (val) { // allow empty value
val = ' ' + val
}
inject(tokens, {
type: 'preprocessor',
data: '#define ' + key + val
})
}
return stringify(tokens)
}