diff --git a/demo/demo.js b/demo/demo.js
index 47af982..c43420d 100644
--- a/demo/demo.js
+++ b/demo/demo.js
@@ -8,8 +8,18 @@ animate();
// init demo
function init() {
- // renderer
- renderer = new THREE.WebGLRenderer();
+ // init as webgl2
+ if (window.webgl2) {
+ var canvas = document.createElement( 'canvas' );
+ var context = canvas.getContext( 'webgl2', { alpha: false } );
+ renderer = new THREE.WebGLRenderer( { canvas: canvas, context: context } );
+ }
+ // init as webgl1
+ else {
+ renderer = new THREE.WebGLRenderer();
+ }
+
+ // set size and clearcolor
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( 0x001122, 1 )
document.body.appendChild( renderer.domElement );
diff --git a/demo/index_webgl2.html b/demo/index_webgl2.html
new file mode 100644
index 0000000..0d4711f
--- /dev/null
+++ b/demo/index_webgl2.html
@@ -0,0 +1,26 @@
+
+
+
+
+ Partykals Demo - WebGL 2
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Controls:
+ WASD / Arrows: Move camera.
+ Z / X: Zoom in and out.
+
+
+
diff --git a/dist/partykals.js b/dist/partykals.js
index 62ba73a..f05481c 100644
--- a/dist/partykals.js
+++ b/dist/partykals.js
@@ -134,7 +134,7 @@ class ParticlesMaterial
}
if (options.map) {
flags += "#define TEXTURE\n";
- uniforms.texture = { value: options.map };
+ uniforms._texture = { value: options.map };
}
if (options.perParticleColor) {
flags += "#define COLORING\n";
@@ -210,7 +210,7 @@ varying float vAlpha;
// diffuse texture
#ifdef TEXTURE
- uniform sampler2D texture;
+ uniform sampler2D _texture;
#endif
// fragment shader main
@@ -229,15 +229,15 @@ void main()
float mid = 0.5;
vec2 rotated = vec2(cos(vRotation) * (gl_PointCoord.x - mid) + sin(vRotation) * (gl_PointCoord.y - mid) + mid,
cos(vRotation) * (gl_PointCoord.y - mid) - sin(vRotation) * (gl_PointCoord.x - mid) + mid);
- vec4 texture = texture2D(texture, rotated);
+ vec4 textureCol = texture2D(_texture, rotated);
// no rotation
#else
vec2 coords = vec2((gl_PointCoord.x - 0.5) + 0.5, (gl_PointCoord.y - 0.5) + 0.5);
- vec4 texture = texture2D(texture, coords);
+ vec4 textureCol = texture2D(_texture, coords);
#endif
// get color with texture
- gl_FragColor = vec4( globalColor * vColor, vAlpha ) * texture;
+ gl_FragColor = vec4( globalColor * vColor, vAlpha ) * textureCol;
// no texture (colors only)
#else
diff --git a/partykals/material/material.js b/partykals/material/material.js
index 0d99301..4d28f58 100644
--- a/partykals/material/material.js
+++ b/partykals/material/material.js
@@ -45,7 +45,7 @@ class ParticlesMaterial
}
if (options.map) {
flags += "#define TEXTURE\n";
- uniforms.texture = { value: options.map };
+ uniforms._texture = { value: options.map };
}
if (options.perParticleColor) {
flags += "#define COLORING\n";
diff --git a/partykals/material/shaders/fragment.js b/partykals/material/shaders/fragment.js
index 331b740..cc0e73a 100644
--- a/partykals/material/shaders/fragment.js
+++ b/partykals/material/shaders/fragment.js
@@ -22,7 +22,7 @@ varying float vAlpha;
// diffuse texture
#ifdef TEXTURE
- uniform sampler2D texture;
+ uniform sampler2D _texture;
#endif
// fragment shader main
@@ -41,15 +41,15 @@ void main()
float mid = 0.5;
vec2 rotated = vec2(cos(vRotation) * (gl_PointCoord.x - mid) + sin(vRotation) * (gl_PointCoord.y - mid) + mid,
cos(vRotation) * (gl_PointCoord.y - mid) - sin(vRotation) * (gl_PointCoord.x - mid) + mid);
- vec4 texture = texture2D(texture, rotated);
+ vec4 textureCol = texture2D(_texture, rotated);
// no rotation
#else
vec2 coords = vec2((gl_PointCoord.x - 0.5) + 0.5, (gl_PointCoord.y - 0.5) + 0.5);
- vec4 texture = texture2D(texture, coords);
+ vec4 textureCol = texture2D(_texture, coords);
#endif
// get color with texture
- gl_FragColor = vec4( globalColor * vColor, vAlpha ) * texture;
+ gl_FragColor = vec4( globalColor * vColor, vAlpha ) * textureCol;
// no texture (colors only)
#else
diff --git a/readme.md b/readme.md
index 505abd7..a6de674 100644
--- a/readme.md
+++ b/readme.md
@@ -209,6 +209,7 @@ For more info, check out the randomizers under `randomizers/` folder, or under `
### 1.0.2 [WIP]
- Fixed `dispose` to also dispose the material.
+- Fixed shaders to work with WebGL2 as well.
## License