Pixi.js Clouds Shader

Developer
Size
3,491 Kb
Views
107,272

How do I make an pixi.js clouds shader?

Shader from https://www.shadertoy.com/view/XslGRrTake no credit for the shader, just wanted to see what pixi v2 could do.. What is a pixi.js clouds shader? How do you make a pixi.js clouds shader? This script and codes were developed by David Hartley on 18 November 2022, Friday.

Pixi.js Clouds Shader Previews

Pixi.js Clouds Shader - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Pixi.js Clouds Shader</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ body { overflow: hidden;
}
canvas { width: 100%; height: 100%;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <!--Shader from https://www.shadertoy.com/view/XslGRr-->
<!--Lag? Try making the width and height smaller--> <script src='https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/pixi.js/2.0.0/pixi.js'></script> <script src="js/index.js"></script>
</body>
</html>

Pixi.js Clouds Shader - Script Codes CSS Codes

body { overflow: hidden;
}
canvas { width: 100%; height: 100%;
}

Pixi.js Clouds Shader - Script Codes JS Codes

console.clear();
var width = window.innerWidth / 2;
var height = window.innerHeight / 2;
var stage = new PIXI.Stage(0x0, true);
var renderer = PIXI.autoDetectRenderer(width, height);
document.body.appendChild(renderer.view);
var uniforms = { iResolution: { type: "2f", value: { x: width, y: height } }, iGlobalTime: { type: "1f", value: 0 }, iMouse: { type: "2f", value: { x: 0, y: 0 } }
};
var fragmentSrc = [ "precision mediump float;", "uniform vec2 iResolution;", "uniform float iGlobalTime;", "uniform vec2 iMouse;", "float hash( float n ) {", "return fract(sin(n)*43758.5453);", "}", "float noise( in vec3 x ) {", "vec3 p = floor(x);", "vec3 f = fract(x);", "f = f*f*(3.0-2.0*f);", "float n = p.x + p.y*57.0 + 113.0*p.z;", "return mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),", "mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y),", "mix(mix( hash(n+113.0), hash(n+114.0),f.x),", "mix( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z);", "}", "vec4 map( in vec3 p ) {", "float d = 0.2 - p.y;", "vec3 q = p - vec3(1.0,0.1,0.0)*iGlobalTime;", "float f;", "f = 0.5000*noise( q ); q = q*2.02;", "f += 0.2500*noise( q ); q = q*2.03;", "f += 0.1250*noise( q ); q = q*2.01;", "f += 0.0625*noise( q );", "d += 3.0 * f;", "d = clamp( d, 0.0, 1.0 );", "vec4 res = vec4( d );", "res.xyz = mix( 1.15*vec3(1.0,0.95,0.8), vec3(0.7,0.7,0.7), res.x );", "return res;", "}", "vec3 sundir = vec3(-1.0,0.0,0.0);", "vec4 raymarch( in vec3 ro, in vec3 rd ) {", "vec4 sum = vec4(0, 0, 0, 0);", "float t = 0.0;", "for(int i=0; i<64; i++) {", "if( sum.a > 0.99 ) continue;", "vec3 pos = ro + t*rd;", "vec4 col = map( pos );", "#if 1", "float dif = clamp((col.w - map(pos+0.3*sundir).w)/0.6, 0.0, 1.0 );", "vec3 lin = vec3(0.65,0.68,0.7)*1.35 + 0.45*vec3(0.7, 0.5, 0.3)*dif;", "col.xyz *= lin;", "#endif", "col.a *= 0.35;", "col.rgb *= col.a;", "sum = sum + col*(1.0 - sum.a);	", "#if 0", "t += 0.1;", "#else", "t += max(0.1,0.025*t);", "#endif", "}", "sum.xyz /= (0.001+sum.w);", "return clamp( sum, 0.0, 1.0 );", "}", "void main(void) {", "vec2 q = gl_FragCoord.xy / iResolution.xy;", "vec2 p = -1.0 + 2.0*q;", "p.x *= iResolution.x/ iResolution.y;", "vec2 mo = -1.0 + 2.0*iMouse.xy / iResolution.xy;", // camera "vec3 ro = 4.0*normalize(vec3(cos(2.75-3.0*mo.x), 0.7+(mo.y+1.0), sin(2.75-3.0*mo.x)));", "vec3 ta = vec3(0.0, 1.0, 0.0);", "vec3 ww = normalize( ta - ro);", "vec3 uu = normalize(cross( vec3(0.0,1.0,0.0), ww ));", "vec3 vv = normalize(cross(ww,uu));", "vec3 rd = normalize( p.x*uu + p.y*vv + 1.5*ww );", "vec4 res = raymarch( ro, rd );", "float sun = clamp( dot(sundir,rd), 0.0, 1.0 );", "vec3 col = vec3(0.6,0.71,0.75) - rd.y*0.2*vec3(1.0,0.5,1.0) + 0.15*0.5;", "col += 0.2*vec3(1.0,.6,0.1)*pow( sun, 8.0 );", "col *= 0.95;", "col = mix( col, res.xyz, res.w );", "col += 0.1*vec3(1.0,0.4,0.2)*pow( sun, 3.0 );", "gl_FragColor = vec4( col, 1.0 );", "}"
];
var shader = new PIXI.AbstractFilter(fragmentSrc, uniforms);
var bg = PIXI.Sprite.fromImage("https://s3-us-west-2.amazonaws.com/s.cdpn.io/167451/test_BG.jpg");
bg.width = width;
bg.height = height;
bg.shader = shader;
stage.addChild(bg);
var logo = PIXI.Sprite.fromImage("https://s3-us-west-2.amazonaws.com/s.cdpn.io/167451/pixiJsV2.png");
logo.width = 472 / 3;
logo.height = 174 / 3;
logo.x = width - logo.width - 10;
logo.y = height - logo.height - 10;
stage.addChild(logo);
var count = 0;
var mouse;
function animate() { count += 0.01; mouse = stage.getMousePosition(); shader.uniforms.iGlobalTime.value = count; if (mouse.x > 0 && mouse.y > 0) { // If mouse is over stage shader.uniforms.iMouse.value = { x: mouse.x, y: mouse.y }; } shader.syncUniforms(); renderer.render(stage); requestAnimFrame(animate);
}
requestAnimFrame(animate);
Pixi.js Clouds Shader - Script Codes
Pixi.js Clouds Shader - Script Codes
Home Page Home
Developer David Hartley
Username davidhartley
Uploaded November 18, 2022
Rating 3.5
Size 3,491 Kb
Views 107,272
Do you need developer help for Pixi.js Clouds Shader?

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!

David Hartley (davidhartley) Script Codes
Create amazing art & images with AI!

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!