Pixijs.v3 Sending Data to Shader
How do I make an pixijs.v3 sending data to shader?
What is a pixijs.v3 sending data to shader? How do you make a pixijs.v3 sending data to shader? This script and codes were developed by Omar Shehata on 13 August 2022, Saturday.
Pixijs.v3 Sending Data to Shader - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Pixijs.v3 Sending Data to Shader</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script id="shader" type="shader"> precision mediump float; uniform vec2 mouse; uniform vec2 resolution; uniform float time; void main(){ gl_FragColor = vec4(sin(time),mouse.x/resolution.x,mouse.y/resolution.y,1.0); }
</script> <script src='https://cdn.jsdelivr.net/pixi.js/3.0.7/pixi.js'></script> <script src="js/index.js"></script>
</body>
</html>
Pixijs.v3 Sending Data to Shader - Script Codes CSS Codes
body { margin: 0; overflow: hidden;
}
Pixijs.v3 Sending Data to Shader - Script Codes JS Codes
var width = window.innerWidth;//Get the screen width and height
var height = window.innerHeight;
var renderer = new PIXI.autoDetectRenderer(width, height);//Chooses either WebGL if supported or falls back to Canvas rendering
document.body.appendChild(renderer.view);//Add the render view object into the page
var stage = new PIXI.Container();//The stage is the root container that will hold everything in our scene
//Load an image and create an object
var logo = PIXI.Sprite.fromImage("http://www.goodboydigital.com/pixijs/pixi_v3_github-pad.png");
logo.x = width / 2;//Set it at the center of the screen
logo.y = height / 2;
logo.anchor.set(0.5);//Make sure the center point of the image is at its center, instead of the default top left
stage.addChild(logo)//Add it to the screen
//Create a uniforms object to send to the shader
var uniforms = {}
uniforms.mouse = { type:'v2', value: {x:0,y:0}
}
uniforms.time = { type:"f", value:0
}
uniforms.resolution = { type:"v2", value:{x:width,y:height}
}
function animate() { // start the timer for the next animation loop requestAnimationFrame(animate); // this is the main render call that makes pixi draw your container and its children. renderer.render(stage); uniforms.time.value += 0.1
}
animate()
//Get shader code as a string
var shaderCode = document.getElementById("shader").innerHTML
//Create our Pixi filter using our custom shader code
var simpleShader = new PIXI.AbstractFilter('',shaderCode,uniforms);
//Apply it to our object
logo.filters = [simpleShader]
document.onmousemove = function(evt){ //Get the mouse position mousePos = {x:evt.clientX,y:evt.clientY} //Assigning a new value lets Pixi know to update the uniform in the shader // But doing something like uniforms.mouse.x = 0, won't update in this current version of Pixi uniforms.mouse.value = mousePos;
}
Developer | Omar Shehata |
Username | omarshe7ta |
Uploaded | August 13, 2022 |
Rating | 3 |
Size | 2,599 Kb |
Views | 26,312 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Framebuffer - Texture Render | 2,402 Kb |
Pixijs.v3 Shader Example | 3,213 Kb |
Initial Scene | 2,545 Kb |
Basic Threejs Scene | 2,188 Kb |
ACM Drawing Practice | 1,802 Kb |
Featherlight Zoom Test | 1,695 Kb |
Framebuffer - Final | 2,491 Kb |
Simple Lighting Model | 3,365 Kb |
Smoke Shader - Diffuse | 3,283 Kb |
Framebuffer - Basic Scene | 2,217 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Image Stack Test SCSS | CalvinMorett | 2,799 Kb |
Mosaic transition effect between two photos using jQuery | Stathisg | 2,518 Kb |
NeeilTimer | Neeilan | 2,836 Kb |
Wikipedia viewer | Chpecson | 2,865 Kb |
FCC - Tribute Page | Cmwebby | 0 Kb |
AngularJS Datalist Directive | M-e-conroy | 2,366 Kb |
A Pen by Mohomed Anees | Mohomedanees | 12,597 Kb |
E-mail Template | SoloMDFK | 4,871 Kb |
RSW | JordanC | 3,726 Kb |
PNotify Demo | Adittmar | 1,731 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!