{"id":20778083,"url":"https://github.com/stackgl/gl-shader-core","last_synced_at":"2025-07-28T16:10:54.175Z","repository":{"id":10506388,"uuid":"12692130","full_name":"stackgl/gl-shader-core","owner":"stackgl","description":"Core implementation of gl-shader without parser dependencies","archived":false,"fork":false,"pushed_at":"2016-04-24T17:10:41.000Z","size":37,"stargazers_count":22,"open_issues_count":3,"forks_count":3,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-07-09T20:55:11.657Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stackgl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-09-09T03:18:07.000Z","updated_at":"2022-08-16T16:36:51.000Z","dependencies_parsed_at":"2022-09-22T19:50:57.298Z","dependency_job_id":null,"html_url":"https://github.com/stackgl/gl-shader-core","commit_stats":null,"previous_names":["mikolalysenko/gl-shader-core"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stackgl/gl-shader-core","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackgl%2Fgl-shader-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackgl%2Fgl-shader-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackgl%2Fgl-shader-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackgl%2Fgl-shader-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stackgl","download_url":"https://codeload.github.com/stackgl/gl-shader-core/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackgl%2Fgl-shader-core/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267544499,"owners_count":24104775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T13:19:05.420Z","updated_at":"2025-07-28T16:10:54.144Z","avatar_url":"https://github.com/stackgl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"gl-shader-core\n==============\nThe core of [gl-shader](https://github.com/mikolalysenko/gl-shader), without the parser.  It can be used to compile shaders without including the (relatively large) glsl-parser dependencies, or invoked directly by libraries which use a transform.\n\n## Install\n\n    npm install gl-shader-core\n    \n## API\n\n### `var shader = require(\"gl-shader-core\")(gl, vertexSource, fragmentSource, uniforms, attributes)`\nConstructs a packaged gl-shader object with shims for all of the uniforms and attributes in the program.\n\n* `gl` is the webgl context in which the program will be created\n* `vertexSource` is the source code for the vertex shader\n* `fragmentSource` is the source code for the fragment shader\n* `uniforms` is a list of all uniforms exported by the shader program\n* `attributes` is a list of all attributes exported by the shader program\n\nThe uniforms and attributes arrays have the following format:\n\n```js\n{\n  uniforms: [\n    { type: 'mat4', name: 'projection' },\n    { type: 'sampler2D', name: 'texture0' }\n  ],\n  attribuets: [\n    { type: 'vec3', name: 'position' }\n  ]\n}\n```\n\nThe uniforms and attributes variables have output which is consistent with [glsl-extract](https://npmjs.org/package/glsl-extract). \n\n**Returns** A compiled shader object.\n\nYou can specify a default `location` number for each attribute, otherwise WebGL will bind it automatically. \n\n## Methods\n\n### `shader.bind()`\nBinds the shader for rendering\n\n### `shader.dispose()`\nDeletes the shader program and associated resources.\n\n## Properties\n\n### `gl`\nThe WebGL context associated to the shader\n\n### `handle`\nA handle to the underlying WebGL program object\n\n### `vertexShader`\nA handle to the underlying WebGL fragment shader object\n\n### `fragmentShader`\nA handle to the underlying WebGL vertex shader object\n\n## Uniforms\nThe uniforms for the shader program are packaged up as properties in the `shader.uniforms` object.  For example, to update a scalar uniform you can just assign to it:\n\n```javascript\nshader.uniforms.scalar = 1.0\n```\n\nWhile you can update vector uniforms by writing an array to them:\n\n```javascript\nshader.uniforms.vector = [1,0,1,0]\n```\n\nMatrix uniforms must have their arrays flattened first:\n\n```javascript\nshader.uniforms.matrix = [ 1, 0, 1, 0,\n                           0, 1, 0, 0,\n                           0, 0, 1, 1,\n                           0, 0, 0, 1 ]\n```\n\nYou can also read the value of uniform too if the underlying shader is currently bound.  For example,\n\n```javascript\nconsole.log(shader.uniforms.scalar)\nconsole.log(shader.uniforms.vector)\nconsole.log(shader.uniforms.matrix)\n```\n\nStruct uniforms can also be accessed using the normal dot property syntax.  For example,\n\n```javascript\nshader.uniforms.light[0].color = [1, 0, 0, 1]\n```\n\n## Attributes\n\nThe basic idea behind the attribute interface is similar to that for uniforms, however because attributes can be either a constant value or get values from a vertex array they have a slightly more complicated interface.  All of the attributes are stored in the `shader.attributes` property.\n\n### `attrib = constant`\nFor non-array attributes you can set the constant value to be broadcast across all vertices.  For example, to set the vertex color of a shader to a constant you could do:\n\n```javascript\nshader.attributes.color = [1, 0, 0, 1]\n```\n\nThis internally uses [`gl.vertexAttribnf`](http://www.khronos.org/opengles/sdk/docs/man/xhtml/glVertexAttrib.xml). Setting the attribute will also call `gl.disableVertexAttribArray` on the attribute's location.\n\n### `attrib.location`\nThis property accesses the location of the attribute.  You can assign/read from it to modify the location of the attribute.  For example, you can update the location by doing:\n\n```javascript\nattrib.location = 0\n```\n\nOr you can read the currently bound location back by just accessing it:\n\n```javascript\nconsole.log(attrib.location)\n```\n\nInternally, these methods just call [`gl.bindAttribLocation`](http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBindAttribLocation.xml) and access the stored location.\n\n**WARNING** Changing the attribute location requires recompiling the program.  Do not dynamically modify this variable in your render loop.\n\n### `attrib.pointer([type, normalized, stride, offset])`\nA shortcut for `gl.vertexAttribPointer`/`gl.enableVertexAttribArray`.  See the [OpenGL man page for details on how this works](http://www.khronos.org/opengles/sdk/docs/man/xhtml/glVertexAttribPointer.xml).  The main difference here is that the WebGL context, size and index are known and so these parameters are bound.\n\n* `type` is the type of the pointer (default `gl.FLOAT`)\n* `normalized` specifies whether fixed-point data values should be normalized (`true`) or converted directly as fixed-point values (`false`) when they are accessed.  (Default `false`)\n* `stride` the byte offset between consecutive generic vertex attributes.  (Default: `0`)\n* `offset` offset of the first element of the array in bytes. (Default `0`)\n\n## Reflection\n\nFinally, the library supports some reflection capabilities.  The set of all uniforms and data types are stored in the \"type\" property of the shader object,\n\n```javascript\nconsole.log(shader.types)\n```\n\nThis reflects the uniform and attribute parameters that were passed to the shader constructor.\n\n\n## Credits\n(c) 2013 Mikola Lysenko. MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackgl%2Fgl-shader-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackgl%2Fgl-shader-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackgl%2Fgl-shader-core/lists"}