forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ShaderToyDecoder, example and revision
- Loading branch information
Showing
10 changed files
with
503 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Return, VariableDeclaration, Accessor } from './AST.js'; | ||
import GLSLDecoder from './GLSLDecoder.js'; | ||
|
||
const keywords = [ | ||
{ name: 'iTime', polyfill: 'float iTime = timerLocal();' }, | ||
{ name: 'iResolution', polyfill: 'vec3 iResolution = viewportResolution;' }, | ||
{ name: 'fragCoord', polyfill: 'vec2 fragCoord = viewportCoordinate.setY( viewportCoordinate.y.oneMinus() ).toVar();' } | ||
]; | ||
|
||
class ShaderToyDecoder extends GLSLDecoder { | ||
|
||
constructor() { | ||
|
||
super(); | ||
|
||
} | ||
|
||
parseFunction() { | ||
|
||
const node = super.parseFunction(); | ||
|
||
if ( node.name === 'mainImage' ) { | ||
|
||
node.params = []; | ||
node.type = 'vec4'; | ||
node.layout = false; // for now | ||
|
||
node.body.unshift( new VariableDeclaration( 'vec4', 'fragColor' ) ); | ||
node.body.push( new Return( new Accessor( 'fragColor' ) ) ); | ||
|
||
} | ||
|
||
return node; | ||
|
||
} | ||
|
||
parse( source ) { | ||
|
||
let polyfill = ''; | ||
|
||
for ( const keyword of keywords ) { | ||
|
||
if ( new RegExp( `(^|\\b)${ keyword.name }($|\\b)`, 'gm' ).test( source ) ) { | ||
|
||
polyfill += keyword.polyfill + '\n'; | ||
|
||
} | ||
|
||
} | ||
|
||
if ( polyfill ) { | ||
|
||
polyfill = '// Polyfills\n\n' + polyfill + '\n'; | ||
|
||
} | ||
|
||
return super.parse( polyfill + source ); | ||
|
||
} | ||
|
||
} | ||
|
||
export default ShaderToyDecoder; |
Oops, something went wrong.