-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #615 from Golmote/prism-glsl
Add support for GLSL (OpenGL Shading Language)
- Loading branch information
Showing
10 changed files
with
442 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Prism.languages.glsl = Prism.languages.extend('clike', { | ||
'comment': [ | ||
/\/\*[\w\W]*?\*\//, | ||
/\/\/(?:\\(?:\r\n|[\s\S])|.)*/ | ||
], | ||
'number': /\b(?:0x[\da-f]+|(?:\.\d+|\d+\.?\d*)(?:e[+-]?\d+)?)[ulf]*\b/i, | ||
'keyword': /\b(?:attribute|const|uniform|varying|buffer|shared|coherent|volatile|restrict|readonly|writeonly|atomic_uint|layout|centroid|flat|smooth|noperspective|patch|sample|break|continue|do|for|while|switch|case|default|if|else|subroutine|in|out|inout|float|double|int|void|bool|true|false|invariant|precise|discard|return|d?mat[234](?:x[234])?|[ibdu]?vec[234]|uint|lowp|mediump|highp|precision|[iu]?sampler[123]D|[iu]?samplerCube|sampler[12]DShadow|samplerCubeShadow|[iu]?sampler[12]DArray|sampler[12]DArrayShadow|[iu]?sampler2DRect|sampler2DRectShadow|[iu]?samplerBuffer|[iu]?sampler2DMS(?:Array)?|[iu]?samplerCubeArray|samplerCubeArrayShadow|[iu]?image[123]D|[iu]?image2DRect|[iu]?imageCube|[iu]?imageBuffer|[iu]?image[12]DArray|[iu]?imageCubeArray|[iu]?image2DMS(?:Array)?|struct|common|partition|active|asm|class|union|enum|typedef|template|this|resource|goto|inline|noinline|public|static|extern|external|interface|long|short|half|fixed|unsigned|superp|input|output|hvec[234]|fvec[234]|sampler3DRect|filter|sizeof|cast|namespace|using)\b/ | ||
}); | ||
|
||
Prism.languages.insertBefore('glsl', 'comment', { | ||
'preprocessor': { | ||
pattern: /(^[ \t]*)#(?:(?:define|undef|if|ifdef|ifndef|else|elif|endif|error|pragma|extension|version|line)\b)?/m, | ||
lookbehind: true, | ||
alias: 'builtin' | ||
} | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,68 @@ | ||
<h1>GLSL (OpenGL Shading Language)</h1> | ||
<p>To use this language, use the class "language-glsl".</p> | ||
|
||
<h2>Vertex shader example</h2> | ||
<pre><code>attribute vec3 vertex; | ||
attribute vec3 normal; | ||
|
||
uniform mat4 _mvProj; | ||
uniform mat3 _norm; | ||
|
||
varying vec3 vColor; | ||
varying vec3 localPos; | ||
|
||
#pragma include "light.glsl" | ||
|
||
// constants | ||
vec3 materialColor = vec3(1.0,0.7,0.8); | ||
vec3 specularColor = vec3(1.0,1.0,1.0); | ||
|
||
void main(void) { | ||
// compute position | ||
gl_Position = _mvProj * vec4(vertex, 1.0); | ||
|
||
localPos = vertex; | ||
|
||
// compute light info | ||
vec3 n = normalize(_norm * normal); | ||
vec3 diffuse; | ||
float specular; | ||
float glowingSpecular = 50.0; | ||
getDirectionalLight(n, _dLight, glowingSpecular, diffuse, specular); | ||
vColor = max(diffuse,_ambient.xyz)*materialColor+specular*specularColor+_ambient; | ||
}</code></pre> | ||
|
||
<h2>Fragment shader example</h2> | ||
<pre><code>#ifdef GL_ES | ||
precision highp float; | ||
#endif | ||
|
||
uniform vec3 BrickColor, MortarColor; | ||
uniform vec3 BrickSize; | ||
uniform vec3 BrickPct; | ||
|
||
varying vec3 vColor; | ||
varying vec3 localPos; | ||
void main() | ||
{ | ||
vec3 color; | ||
vec3 position, useBrick; | ||
|
||
|
||
position = localPos / BrickSize.xyz; | ||
|
||
if (fract(position.y * 0.5) > 0.5){ | ||
position.x += 0.5; | ||
position.z += 0.5; | ||
} | ||
|
||
position = fract(position); | ||
|
||
useBrick = step(position, BrickPct.xyz); | ||
|
||
color = mix(MortarColor, BrickColor, useBrick.x * useBrick.y * useBrick.z); | ||
color *= vColor; | ||
|
||
gl_FragColor = vec4(color, 1.0); | ||
} | ||
</code></pre> |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,21 @@ | ||
/**/ | ||
/* foo | ||
bar */ | ||
// | ||
// foo | ||
// foo\ | ||
bar | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "/**/"], | ||
["comment", "/* foo\r\nbar */"], | ||
["comment", "//"], | ||
["comment", "// foo"], | ||
["comment", "// foo\\\r\nbar"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
Oops, something went wrong.