Buggy Smoke
How do I make an buggy smoke?
What is a buggy smoke? How do you make a buggy smoke? This script and codes were developed by Omar Shehata on 13 August 2022, Saturday.
Buggy Smoke - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Buggy Smoke</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script id="fragShader" type="shader-code"> uniform vec2 res;//The width and height of our screen uniform sampler2D bufferTexture;//Our input texture uniform vec3 smokeSource;//The x,y are the posiiton. The z is the power/density void main() { vec2 pixel = gl_FragCoord.xy / res.xy; gl_FragColor = texture2D( bufferTexture, pixel ); //Get the distance of the current pixel from the smoke source float dist = distance(smokeSource.xy,gl_FragCoord.xy); //Generate smoke when mouse is pressed //gl_FragColor.r += smokeSource.z * max(15.0-dist,0.0); if(dist < 10.0 && smokeSource.z > 0.0){ gl_FragColor.r = 1.0; } //Smoke diffuse float xPixel = 1.0/res.x;//The size of a single pixel float yPixel = 1.0/res.y; vec4 rightColor = texture2D(bufferTexture,vec2(pixel.x+xPixel,pixel.y)); vec4 leftColor = texture2D(bufferTexture,vec2(pixel.x-xPixel,pixel.y)); vec4 upColor = texture2D(bufferTexture,vec2(pixel.x,pixel.y+yPixel)); vec4 downColor = texture2D(bufferTexture,vec2(pixel.x,pixel.y-yPixel)); //Diffuse equation float factor = 0.21 * (leftColor.r + rightColor.r + downColor.r + upColor.r - 4.0 * gl_FragColor.r); float minimum = 0.003; if(factor >= -minimum && factor < 0.0) factor = -minimum; if(factor <= minimum && factor > 0.0) factor = minimum*2.0; gl_FragColor.r += factor; } </script> <script src='http://cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Buggy Smoke - Script Codes CSS Codes
body { margin: 0; }
Buggy Smoke - Script Codes JS Codes
//@author Omar Shehata. 2015. //We are loading the Three.js library from the cdn here: http://cdnjs.com/libraries/three.js/ var scene; var camera; var renderer; function scene_setup(){ //This is the basic scene setup scene = new THREE.Scene(); var width = window.innerWidth; var height = window.innerHeight; //Note that we're using an orthographic camera here rather than a prespective camera = new THREE.OrthographicCamera( width / - 2, width / 2, height / 2, height / - 2, 1, 1000 ); camera.position.z = 2; renderer = new THREE.WebGLRenderer(); renderer.setSize( window.innerWidth, window.innerHeight ); document.body.appendChild( renderer.domElement ); } //Initialize the Threejs scene scene_setup(); var bufferScene; var textureA; var textureB; var bufferMaterial; var plane; var bufferObject; var finalMaterial; var quad; function buffer_texture_setup(){ //Create buffer scene bufferScene = new THREE.Scene(); //Create 2 buffer textures textureA = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, { minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter}); textureB = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, { minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter} ); //Pass textureA to shader bufferMaterial = new THREE.ShaderMaterial( { uniforms: { bufferTexture: { type: "t", value: textureA }, res : {type: 'v2',value:new THREE.Vector2(window.innerWidth,window.innerHeight)},//Keeps the resolution smokeSource: {type:"v3",value:new THREE.Vector3(0,0,0)}///This keeps the position of the mouse and whether it was clicked or not }, fragmentShader: document.getElementById( 'fragShader' ).innerHTML } ); plane = new THREE.PlaneBufferGeometry( window.innerWidth, window.innerHeight ); bufferObject = new THREE.Mesh( plane, bufferMaterial ); bufferScene.add(bufferObject); //Draw textureB to screen finalMaterial = new THREE.MeshBasicMaterial({map: textureB}); quad = new THREE.Mesh( plane, finalMaterial ); scene.add(quad); } buffer_texture_setup(); //Send position of smoke source with value var mouseDown = false; function UpdateMousePosition(X,Y){ var mouseX = X; var mouseY = window.innerHeight - Y; bufferMaterial.uniforms.smokeSource.value.x = mouseX; bufferMaterial.uniforms.smokeSource.value.y = mouseY; } document.onmousemove = function(event){ UpdateMousePosition(event.clientX,event.clientY) } document.onmousedown = function(event){ mouseDown = true; bufferMaterial.uniforms.smokeSource.value.z = 0.1; } document.onmouseup = function(event){ mouseDown = false; bufferMaterial.uniforms.smokeSource.value.z = 0; } //Render everything! function render() { requestAnimationFrame( render ); //Draw to textureB renderer.render(bufferScene,camera,textureB,true); //Swap textureA and B var t = textureA; textureA = textureB; textureB = t; quad.material.map = textureB; bufferMaterial.uniforms.bufferTexture.value = textureA; //Finally, draw to the screen renderer.render( scene, camera ); } render();
Developer | Omar Shehata |
Username | omarshe7ta |
Uploaded | August 13, 2022 |
Rating | 3 |
Size | 3,213 Kb |
Views | 36,432 |
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 - Basic Scene | 2,217 Kb |
WebMonkey Test | 8,206 Kb |
Featherlight Zoom Test | 1,695 Kb |
Framebuffer - Final | 2,491 Kb |
Smoke Shader - Diffuse | 3,283 Kb |
Smoke Shader Algorithm Demo | 14,358 Kb |
Smoke Shader - Setup | 2,339 Kb |
Pixijs.v3 Basic Shader | 2,269 Kb |
Rotating Cube | 2,151 Kb |
Smoke Shader - Frame Buffer | 2,672 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 |
Wrap_Test | Mscfourn | 7,503 Kb |
Test | Dviate | 2,668 Kb |
Incremental game | Eprouver | 5,868 Kb |
Formations | Cantelope | 5,731 Kb |
Page Transitions in Backbone | Mikefowler | 3,691 Kb |
Cartoon Bomb | Tcmulder | 4,929 Kb |
Canvas snow | Win7killer | 2,572 Kb |
Eunice A | Ejbronze | 2,203 Kb |
Client-side Email Validation | Collizo4sky | 1,538 Kb |
Get third wednesday | Wojtek1150 | 2,691 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!