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,21 @@
The MIT License (MIT)
Copyright (c) 2015 Hugh Kennedy
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,33 @@
# glsl-token-whitespace-trim
[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)
Trim the whitespace within an array of GLSL tokens provided by [glsl-tokenizer](https://github.com/stackgl/glsl-tokenizer). Useful for minimising shader source size, especially after heavy processing steps such as seen in [glslify](http://github.com/stackgl/glslify) or as part of a GLSL minifier.
## Usage
[![NPM](https://nodei.co/npm/glsl-token-whitespace-trim.png)](https://www.npmjs.com/package/glsl-token-whitespace-trim)
### `trim(tokens, [all])`
Trims the whitespace in an array of GLSL `tokens`. By default, this will trim repeated to newlines such that no more than two newlines will appear in a row.
If you're more concerned about size than aesthetics, you can pass `true` as the second argument to remove *all* extraneous whitespace (more or less).
``` javascript
const tokenize = require('glsl-tokenizer')
const string = require('glsl-token-string')
const trim = require('glsl-token-whitespace-trim')
const fs = require('fs')
const src = fs.readFileSync('shader.glsl', 'utf8')
const tokens = tokenize(src)
trim(tokens, true)
const trimmed = string(tokens)
```
## License
MIT, see [LICENSE.md](http://github.com/hughsk/glsl-token-whitespace-trim/blob/master/LICENSE.md) for details.

View File

@@ -0,0 +1,3 @@
precision mediump float;
#define GLSLIFY 1
struct Thing{float b;float c;};vec4 someFunction(vec2 b,vec2 c,vec3 d){return vec4(d,c.y);}void main(){gl_FragColor=someFunction(vec2(0),vec2(1),vec3(2));}

View File

@@ -0,0 +1,27 @@
precision mediump float;
#define GLSLIFY 1
struct Thing {
float b;
float c;
}
;
vec4 someFunction (
vec2 b,
vec2 c, vec3 d
) {
return vec4( d , c.y );
}
void main(
) {
gl_FragColor = someFunction ( vec2(0), vec2(1), vec3(2) );
}

View File

@@ -0,0 +1,551 @@
precision
mediump
float;
#define GLSLIFY 1
struct
Thing
{
float
b;
float
c;
}
;
vec4
someFunction
(
vec2
b,
vec2
c,
vec3
d
)
{
return
vec4(
d
,
c.y
);
}
void
main(
)
{
gl_FragColor
=
someFunction
(
vec2(0),
vec2(1),
vec3(2)
);
}

View File

@@ -0,0 +1,35 @@
precision mediump float;
#define GLSLIFY 1
struct Thing {
float b;
float c;
}
;
vec4 someFunction (
vec2 b,
vec2 c, vec3 d
) {
return vec4( d , c.y );
}
void main(
) {
gl_FragColor = someFunction ( vec2(0), vec2(1), vec3(2) );
}

View File

@@ -0,0 +1,7 @@
precision mediump float;
attribute vec2 position;
void main() {
gl_Position = vec4(position, 1, 1);
}

View File

@@ -0,0 +1,63 @@
module.exports = trim
function trim (tokens, everything) {
return trim[everything ? 'all' : 'newlines'](collapse(tokens))
}
function collapse (tokens) {
for (var i = 1; i < tokens.length; i++) {
var curr = tokens[i]
if (curr.type !== 'whitespace') continue
var prev = tokens[i - 1]
if (prev.type !== 'whitespace') continue
tokens.splice(--i, 1)
curr.data = prev.data + curr.data
}
return tokens
}
var newlines = /(?:\n|\r\n|\r){2,}/g
trim.newlines = function (tokens) {
for (var i = 0; i < tokens.length; i++) {
var token = tokens[i]
if (token.type !== 'whitespace') continue
token.data = token.data.replace(newlines, '\n\n')
}
return tokens
}
var all = /\s+/g
trim.all = function (tokens) {
var l = tokens.length
for (var i = 0; i < l; i++) {
var token = tokens[i]
if (token.type !== 'whitespace') continue
var next = tokens[i + 1]
var prev = tokens[i - 1]
if (next && next.type === 'preprocessor' || prev && prev.type === 'preprocessor') {
token.data = token.data.replace(all, '\n')
} else {
token.data = token.data.replace(all, ' ')
switch (next && next.data) {
case '(': case ';': case ')':
case '{': case '=': case '}': case ',':
token.data = token.data.replace(all, '')
}
switch (prev && prev.data) {
case '(': case ';': case ')':
case '{': case '=': case '}': case ',':
token.data = token.data.replace(all, '')
}
}
}
return tokens
}

View File

@@ -0,0 +1,42 @@
{
"name": "glsl-token-whitespace-trim",
"version": "1.0.0",
"description": "Trim the whitespace within an array of GLSL tokens",
"main": "index.js",
"license": "MIT",
"author": {
"name": "Hugh Kennedy",
"email": "hughskennedy@gmail.com",
"url": "https://github.com/hughsk"
},
"dependencies": {},
"devDependencies": {
"gl": "^2.1.5",
"gl-shader": "^4.0.6",
"glsl-token-string": "^1.0.1",
"glsl-tokenizer": "^2.0.2",
"standard": "^5.4.1",
"tap-spec": "^4.1.1",
"tape": "^4.2.2"
},
"scripts": {
"test": "standard && node test.js | tspec"
},
"keywords": [
"glsl",
"token",
"tokenizer",
"glslify",
"ecosystem:stackgl",
"whitespace",
"trim"
],
"repository": {
"type": "git",
"url": "git://github.com/hughsk/glsl-token-whitespace-trim.git"
},
"homepage": "https://github.com/hughsk/glsl-token-whitespace-trim",
"bugs": {
"url": "https://github.com/hughsk/glsl-token-whitespace-trim/issues"
}
}