Skip to content

Instantly share code, notes, and snippets.

@clbarnes
Created February 28, 2017 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clbarnes/7c8525bb562e58ddd738ef6ef69f152f to your computer and use it in GitHub Desktop.
Save clbarnes/7c8525bb562e58ddd738ef6ef69f152f to your computer and use it in GitHub Desktop.
Simple shader
// Get the screen width and height
var width = window.innerWidth;
var height = window.innerHeight;
// Chooses either WebGL if supported or falls back to Canvas rendering
var renderer = new PIXI.autoDetectRenderer(width, height);
// Add the render view object into the page
document.body.appendChild(renderer.view);
// The stage is the root container that will hold everything in our scene
var stage = new PIXI.Container();
// Load an image and create an object
var logo = PIXI.Sprite.fromImage('tst_im.png');
// Set it at the center of the screen
logo.x = width / 2;
logo.y = height / 2;
// Make sure the center point of the image is at its center, instead of the default top left
logo.anchor.set(0.5);
// Add it to the screen
stage.addChild(logo);
$.get('shader.glsl', function(shaderCode) {
var simpleShader = new PIXI.AbstractFilter('', shaderCode);
logo.filters = [simpleShader];
renderer.render(stage);
});
void main(){
gl_FragColor.rgba = vec4(1,1,1,1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment