Pipes

Developer
Size
3,300 Kb
Views
6,072

How do I make an pipes?

Shadertoy remix of davidope's excellent work for codevember 2016 https://www.shadertoy.com/view/4ldXR4. What is a pipes? How do you make a pipes? This script and codes were developed by XORXOR on 27 January 2023, Friday.

Pipes Previews

Pipes - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Pipes</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="container"></div>
<script id="vertexShader" type="x-shader/x-vertex"> void main() { gl_Position = vec4( position, 1.0 ); }
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
// Created by XORXOR, 2016
// Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
uniform vec2 iResolution;
uniform float iGlobalTime;
float cylinder( vec3 p )
{ return length( p.xy ) - 0.9;
}
vec3 opTwist( vec3 p )
{ float a = -0.1 * iGlobalTime - 0.02 * p.z; float c = cos( a ); float s = sin( a ); mat2 m = mat2( c, -s, s, c ); return vec3( m * p.xy, p.z );
}
vec2 opRep( vec2 p, float size, float start, float stop )
{ float halfSize = size * 0.5; vec2 c = floor( p / size ); p = mod( p, size ) - halfSize; if ( ( c.x > stop ) || ( c.y > stop ) ) { p += size * ( c - stop ); } if ( ( c.x < start ) || ( c.y < start ) ) { p += size * ( c - start ); } return p;
}
float map( vec3 p )
{ p = opTwist( p ); p.xy = opRep( p.xy, 10.0, -7.0, 7.0 ); float d = cylinder( p ); return d;
}
float scene( vec3 ro, vec3 rd )
{ float t = 0.01; for ( int i = 0; i < 200; i++ ) { vec3 p = ro + t * rd; float d = map( p ); if ( d < 0.001 ) { return t; } t += d; } return -1.0;
}
vec3 calcNormal( vec3 pos )
{ vec3 eps = vec3( 0.001, 0.0, 0.0 ); float pd = map( pos ); vec3 n = vec3( pd - map( pos - eps.xyy ), pd - map( pos - eps.yxy ), pd - map( pos - eps.yyx ) ); return normalize( n );
}
float calcAo( vec3 pos, vec3 n )
{ float occ = 0.0; for ( int i = 0; i < 5; i++ ) { float hp = 0.1 + 2.0 * float( i ); float dp = map( pos + n * hp ); occ += ( hp - dp ); } return clamp( 1.0 - 0.04 * occ, 0.0, 1.0 );
}
vec3 render( vec3 ro, vec3 rd )
{ float d = scene( ro, rd ); vec3 col = vec3( 0 ); if ( d > 0.0 ) { vec3 pos = ro + d * rd; vec3 twistPos = opTwist( pos ); float t = -15.0 * iGlobalTime; col = vec3( floor( 0.3 * mod( twistPos.z + t, 6.0 ) ) ); vec3 nor = calcNormal( pos ); float ao = calcAo( pos, nor ); col *= vec3( ao ); float fog = ( 400.0 + pos.z ) / 300.0; col *= fog; }	return col;
}
void main()
{ vec3 eye = vec3( 0.0, 0.0, 20.0 ); vec3 target = vec3( 0.0 ); vec3 cw = normalize( target - eye ); vec3 cu = cross( cw, vec3( 0, 1, 0 ) ); vec3 cv = cross( cu, cw ); mat3 cm = mat3( cu, cv, cw ); vec3 col = vec3( 0.0 ); for ( int i = 0; i < 4; i++ ) { vec2 off = vec2( mod( float( i ), 2.0 ), mod( float( i / 2 ), 2.0 ) ) / 2.0; vec2 uv = ( gl_FragCoord.xy + off - 0.5 * iResolution.xy ) / iResolution.y; vec3 rd = cm * normalize( vec3( uv, 2.5 ) ); col += render( eye, rd ); } col *= 0.25; gl_FragColor = vec4( col, 1.0 );
}
</script> <script src='https://threejs.org/build/three.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Pipes - Script Codes CSS Codes

*{ padding:0; margin:0;
}

Pipes - Script Codes JS Codes

var container;
var camera, scene, renderer;
var uniforms;
var startTime;
init();
animate();
function init() { container = document.getElementById( 'container' ); startTime = Date.now(); camera = new THREE.Camera(); camera.position.z = 1; scene = new THREE.Scene(); var geometry = new THREE.PlaneBufferGeometry( 16, 9 ); uniforms = { iGlobalTime: { type: "f", value: 1.0 }, iResolution: { type: "v2", value: new THREE.Vector2() } }; var material = new THREE.ShaderMaterial( { uniforms: uniforms, vertexShader: document.getElementById( 'vertexShader' ).textContent, fragmentShader: document.getElementById( 'fragmentShader' ).textContent } ); var mesh = new THREE.Mesh( geometry, material ); scene.add( mesh ); renderer = new THREE.WebGLRenderer(); container.appendChild( renderer.domElement ); onWindowResize(); window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize( event ) { uniforms.iResolution.value.x = window.innerWidth; uniforms.iResolution.value.y = window.innerHeight; renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() { requestAnimationFrame( animate ); render();
}
function render() { var currentTime = Date.now(); uniforms.iGlobalTime.value = (currentTime - startTime) * 0.001; renderer.render( scene, camera );
}
Pipes - Script Codes
Pipes - Script Codes
Home Page Home
Developer XORXOR
Username xorxor_hu
Uploaded January 27, 2023
Rating 4.5
Size 3,300 Kb
Views 6,072
Do you need developer help for Pipes?

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!

XORXOR (xorxor_hu) Script Codes
Create amazing blog posts 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!