Git Product home page Git Product logo

deprecated-glsl.js's Introduction

Flattr this git repo because this is a free and open-source library (Apache 2 licence).

glsl.js

schema

glsl.js is a subset* of a WebGL library which focus on making the GLSL (OpenGL Shading Language) easy and accessible for vizualisation and game purposes (2D or 3D).

* Subset, because we only focus on using a fragment shader (the vertex shader is static and take the full canvas size), But don't worry, you have a long way to go with just one fragment shader.

The concept is to split the rendering part in a GLSL fragment from the logic part in Javascript of your app/game. Both part are linked by a set of variables (the state of your app/game).

glsl.js aims to abstract every GL functions so you don't have to learn any OpenGL API. What you only need to care about is the logic in Javascript and the rendering in GLSL.

For more infos, read the blog article.

Licence

Copyright 2013 Gaetan Renaudeau

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

deprecated-glsl.js's People

Contributors

gre avatar kevinbarabash avatar r3mi avatar

Stargazers

Ancyloce avatar  avatar Yury Ershov avatar  avatar LeroyK avatar Vishesh Choudhary avatar Artur avatar mparaiso avatar Future Infinity avatar jiniC avatar cainiao1989 avatar Dewa Widyakumara avatar cailven avatar  avatar wandergis avatar Jeong Seong Dae avatar Simon Savitt avatar Rodolfo Valguarnera avatar José Pedro Dias avatar John Connors avatar Angus H. avatar Felipe Alfonso avatar Pavel Moravec avatar Simon Benjámin avatar Islam Ali avatar Alexandros Mourtziapis avatar Lin Hsu avatar David Llanos avatar  avatar Michael Anthony avatar Sohail Aj. avatar Baku 麦 avatar 平江 avatar Mark Moissette avatar Geoff Gaudreault avatar Maciej Lechowski avatar Hou Chunlei avatar Damien Seguin avatar Franco Bouly avatar Dennis Iversen avatar Hossein Mayboudi avatar Garett Bass avatar Matt Lundstrom avatar Lukasz avatar Steven Hugg avatar  avatar David Lyons avatar  avatar AMAGI / Jun Yuri avatar 墨神 avatar Robert Novo avatar Aki Miyazaki avatar  avatar timelyportfolio avatar PeterLiou avatar Corey Grunewald avatar Paul Melnikow avatar Ada Lovecraft avatar Lingjia Liu avatar Artem Kholodnyi avatar Ronan Sandford avatar Matías Agustín Méndez avatar Jared Forsyth avatar Axel avatar  avatar Yongxu Ren avatar Mauricio Poppe avatar  avatar  avatar Athan avatar Mike Tahani avatar Benjamin Devine avatar Brett Camper avatar wayne avatar Jian Cheng avatar Paul Hayes avatar  avatar alwayrun avatar  avatar Caesar73 avatar 楊文里 avatar  avatar Sean Bohan avatar Ezra Miller avatar Thomas L. avatar Michael Demarais avatar Victor Zverovich avatar Cyrille Rossant avatar nik hanselmann avatar Utensil avatar L avatar Matt Spendlove avatar Jerome Truong avatar Andrew Giles avatar Zach Schwartz avatar Jaeho Lee (Jay) avatar Kevin Zeng avatar  avatar Zolmeister avatar JT5D avatar

Watchers

Paul Bonser avatar Bruce LANE avatar Lorenzo Gatti avatar Michael W McDowell avatar  avatar finscn avatar windsturm avatar kai avatar Dave Edelhart avatar James Cloos avatar Zaphod avatar Ryder Ripps avatar John P Mayer, Jr avatar James Mathieson avatar Michael Anthony avatar  avatar zspecza avatar Ritchie J. Latimore avatar  avatar Andrea Bianco avatar gimjin avatar  avatar

deprecated-glsl.js's Issues

Texture Copy Speed

Hey there,

Love the library! I wanted to use it to copy a full screen canvas into a shader (as demonstrated in your snake game), but this was very slow.

I modified the library so it does not have to allocate the texture each time, thus speeding it up.

This:

        var texture;
        texture = this.textureForTextureUnit[textureUnit];
        if (texture) {
            gl.deleteTexture(texture);
        }

        texture = gl.createTexture();
        gl.bindTexture(gl.TEXTURE_2D, texture);
        gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, value);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
        gl.uniform1i(loc, textureUnit);
        this.textureForTextureUnit[textureUnit] = texture;

becomes this:

        var texture;
        texture = this.textureForTextureUnit[textureUnit];
        if (texture)
        {
            gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, value);
        }
        else
        {
            texture = gl.createTexture();
            gl.bindTexture(gl.TEXTURE_2D, texture);
            gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
            gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, value);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
            gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
            gl.uniform1i(loc, textureUnit);
            this.textureForTextureUnit[textureUnit] = texture;
        }

Now I get nice speedy full screen canvas copies. 👍

John

More flexibility on the vec2, vec3 and vec4 binding

today the binding is always using {x, y, z, w}:

{x, y} => vec2(x,y)
{x, y, z} => vec3(x,y,z)
{x, y, z, w} => vec4(x,y,z,w)

{r, g, b, a} and {s, t, p, q} binding should also work (introspection?).

Also a raw array type should work for these vec* types :

e.g.: Float32Array(4) => vec4(arr[0], arr[1], arr[2], arr[3])

NPM support

It'd be nice if this was on NPM so that it could be integrated with Browserify more easily.

Fall back to canvas when WebGL is not supported

If would be nice if glsl.js would automatically fall back to its standard no-WebGL canvas version when WebGL is not supported.
In doing so glsl.js could be used to spice up canvas animations on browsers that support WebGL while still offering a plain canvas animation for other browsers.

Vertex Shaders

This seemed to be only briefly mentioned in your blog post. I could see the benefit of having this same Uniform/Attribute access layer being able to support Model Matrix, Camera, Perspective for 3d models through vertex shaders. Could you expound upon the reason to only use fragment shaders?

Unable to synchronize WebGL-enabled canvas to Sampler2d

I have recently started using glsl.js, and I am very happy about this great tool. Most of my game is created using the PIXI.js framework, but to handle the shaders elegantly, I decided to use glsl.js .

However, PIXI.js renders all objects to a canvas using WebGL. When I then try to pass this canvas to the shader to be put in a Sampler2d object, it does not seem to work.
To be exact, it seems to work for one frame, that is I see it 'flicker' once and then the texture isn't shown anymore.

When I use the native canvas renderer of PIXI.js, it works fine, albeit far slower of course.

You can check my current test code with all canvases visible here: http://wmmusic.nl/codexamples/pixijs/glslwebgltest/smuv2.html

and how it looks with the canvas renderer:http://wmmusic.nl/codexamples/pixijs/v14/smuv2.html

Texture examples don't work on some machine

The mario_sprites example seems not to work for a lot of people, have to investigate this.

I hope it's a solvable issue and not something linked to the graphic card.

Mario example is here: http://greweb.fr/glsl.js/examples/mario_sprites/

If you experiment the issue too, please copy/paste the result of these tests:
http://www.browserleaks.com/webgl

Here is mine (macbookpro):

WebGL Context Info
Context Name    experimental-webgl
GL Version  WebGL 1.0 (OpenGL ES 2.0 Chromium)
Shading Language Version    WebGL GLSL ES 1.0 (OpenGL ES GLSL ES 1.0 Chromium)
Vendor  WebKit
Renderer    WebKit WebGL
Vertex Shader
Max Vertex Attributes   16
Max Vertex Uniform Vectors  1024
Max Vertex Texture Image Units  16
Max Varying Vectors 31
Rasterizer
Aliased Line Width Range    [1, 10]
Aliased Point Size Range    [1, 63]
Fragment Shader
Max Fragment Uniform Vectors    1024
Max Texture Image Units 16
Framebuffer
RGBA Bits   [8, 8, 8, 8]
Depth / Stencil Bits:   [24, 8]
Max Render Buffer Size  16384
Max Viewport Dimensions [16384, 16384]
Textures
Max Texture Size    16384
Max Cube Map Texture Size   16384
Max Combined Texture Image Units    16
Supported WebGL Extensions
OES_texture_float
OES_standard_derivatives
WEBKIT_EXT_texture_filter_anisotropic
OES_vertex_array_object
OES_element_index_uint
WEBKIT_WEBGL_lose_context
WEBKIT_WEBGL_compressed_texture_s3tc
WEBKIT_WEBGL_depth_texture

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.