水晶球 crystal ball

  • 示例
  • HTML
  • CSS
  • JS

更多有趣示例 尽在知屋安砖社区

示例

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/88/three.min.js"></script>
<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">uniform vec2 u_resolution;uniform float u_time;uniform vec2 u_mouse;uniform sampler2D u_noise;uniform sampler2D u_env;const int octaves = 2;const float seed = 43758.5453123;const float seed2 = 73156.8473192;// Epsilon valueconst float eps = 0.005;const vec3 ambientLight = 0.99 * vec3(1.0, 1.0, 1.0);const vec3 light1Pos = vec3(10., 5.0, -25.0);const vec3 light1Intensity = vec3(0.35);const vec3 light2Pos = vec3(-20., -25.0, 85.0);const vec3 light2Intensity = vec3(0.2);// movement variablesvec3 movement = vec3(.0);// Gloable variables for the raymarching algorithm.const int maxIterations = 256;const int maxIterationsShad = 16;const float stepScale = .7;const float stopThreshold = 0.001;vec3 hash33(vec3 p){ return texture2D(u_noise, p.xy * p.z * 256.).rgb;}float pn( in vec3 p ) {vec3 i = floor(p); p -= i; p *= p*(3. - 2.*p);p.xy = texture2D(u_noise, (p.xy + i.xy + vec2(37, 17)*i.z + .5)/256., -100.).yx;return mix(p.x, p.y, p.z);}// Thanks to Shane for this one.// Basic low quality noise consisting of three layers of rotated, mutated // trigonometric functions. Needs work, but sufficient for this example.float trigNoise3D(in vec3 p){float res = 0., sum = 0.;// IQ's cheap, texture-lookup noise function. Very efficient, but still // a little too processor intensive for multiple layer usage in a largish // "for loop" setup. Therefore, just one layer is being used here.float n = pn(p*8. + u_time*.5);// Two sinusoidal layers. I'm pretty sure you could get rid of one of // the swizzles (I have a feeling the GPU doesn't like them as much), // which I'll try to do later.vec3 t = sin(p.yzx*3.14159265 + cos(p.zxy*3.14159265+1.57/2.))*0.5 + 0.5;p = p*1.5 + (t - 1.5); //  + u_time*0.1res += (dot(t, vec3(0.333)));t = sin(p.yzx*3.14159265 + cos(p.zxy*3.14159265+1.57/2.))*0.5 + 0.5;res += (dot(t, vec3(0.333)))*0.7071;    return ((res/1.7071))*0.85 + n*0.15;}mat4 rotationMatrix(vec3 axis, float angle){axis = normalize(axis);float s = sin(angle);float c = cos(angle);float oc = 1.0 - c;return mat4(oc * axis.x * axis.x + c,           oc * axis.x * axis.y - axis.z * s,  oc * axis.z * axis.x + axis.y * s,  0.0,oc * axis.x * axis.y + axis.z * s,  oc * axis.y * axis.y + c,           oc * axis.y * axis.z - axis.x * s,  0.0,oc * axis.z * axis.x - axis.y * s,  oc * axis.y * axis.z + axis.x * s,  oc * axis.z * axis.z + c,           0.0,0.0,                                0.0,                                0.0,                                1.0);}float length2( vec2 p ){return sqrt( p.x*p.x + p.y*p.y );}float length6( vec2 p ){p = p*p*p; p = p*p;return pow( p.x + p.y, 1.0/6.0 );}float length8( vec2 p ){p = p*p; p = p*p; p = p*p;return pow( p.x + p.y, 1.0/8.0 );}// Distance function primitives// Reference: http://iquilezles.org/www/articles/distfunctions/distfunctions.htmfloat sdBox( vec3 p, vec3 b ){vec3 d = abs(p) - b;return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0));}float udBox( vec3 p, vec3 b ){return length(max(abs(p)-b,0.0));}float udRoundBox( vec3 p, vec3 b, float r ){return length(max(abs(p)-b,0.0))-r;}float sdSphere( vec3 p, float s ){return length(p)-s;}float sdCylinder( vec3 p, vec3 c ){return length(p.xz-c.xy)-c.z;}float sdCappedCylinder( vec3 p, vec2 h ){vec2 d = abs(vec2(length(p.xz),p.y)) - h;return min(max(d.x,d.y),0.0) + length(max(d,0.0));}float sdTorus82( vec3 p, vec2 t ){vec2 q = vec2(length2(p.xz)-t.x,p.y);return length8(q)-t.y;}float sdPlane( vec3 p){return p.y;}// smooth min// reference: http://iquilezles.org/www/articles/smin/smin.htmfloat smin(float a, float b, float k) {float res = exp(-k*a) + exp(-k*b);return -log(res)/k;}vec3 random3( vec3 p ) {return fract(sin(vec3(dot(p,vec3(127.1,311.7,319.8)),dot(p,vec3(269.5,183.3, 415.2)),dot(p,vec3(362.9,201.5,134.7))))*43758.5453);}vec2 random2( vec2 p ) {return fract(sin(vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3))))*43758.5453);}float tri( float x ){ return abs( fract(x) - .5 );
}vec3 tri3( vec3 p ){return vec3( tri( p.z + tri( p.y * 1. ) ), tri( p.z + tri( p.x * 1. ) ), tri( p.y + tri( p.x * 1. ) ));}float triNoise3D( vec3 p, float spd , float time){float z  = 1.4;float rz =  0.;vec3  bp =   p;for( float i = 0.; i <= 3.; i++ ){vec3 dg = tri3( bp * 2. );p += ( dg + time * .1 * spd );bp *= 1.8;z  *= 1.5;p  *= 1.2; float t = tri( p.z + tri( p.x + tri( p.y )));rz += t / z;bp += 0.14;}return rz;}struct Obj {float distance;float innerDistance;vec4 colour;};mat4 rotmat;// The world!Obj world_sdf(in vec3 p) {float world = 10.;// p += 1.;// p = mod(p, 2.) -1.;p = (vec4(p, 1.) * rotmat).xyz;world = length(p) - .5;float innerDist = 0.;if(world < 0.) {innerDist = triNoise3D(p*(.4), 1., u_time);// innerDist = sin(p.x * 20.) * sin(p.y * 20.) * sin(p.z * 20.) * .2 + .3;float multi = smoothstep(0., 1.5, length(p*6.)); // a fade at the centre of the ballinnerDist *= multi*multi*multi;innerDist *= smoothstep(.6, .4, length(p)); // a little fade near the edge of the ballinnerDist *= sqrt(innerDist*2.);// innerDist *= innerDist*innerDist*4.;}return Obj(world, innerDist, vec4(.5));}float world_normals(in vec3 p) {float world = 10.;p = (vec4(p, 1.) * rotmat).xyz;world = length(p) - .5;return world;}// Fuck yeah, normals!vec3 calculate_normal(in vec3 p){const vec3 small_step = vec3(0.0001, 0.0, 0.0);float gradient_x = world_normals(vec3(p.x + eps, p.y, p.z)) - world_normals(vec3(p.x - eps, p.y, p.z));float gradient_y = world_normals(vec3(p.x, p.y + eps, p.z)) - world_normals(vec3(p.x, p.y - eps, p.z));float gradient_z = world_normals(vec3(p.x, p.y, p.z  + eps)) - world_normals(vec3(p.x, p.y, p.z - eps));vec3 normal = vec3(gradient_x, gradient_y, gradient_z);return normalize(normal);}// Raymarching.float rayMarching( vec3 origin, vec3 dir, float start, float end, inout float field ) {float sceneDist = 1e4;float rayDepth = start;float surfaceDepth = 0.;Obj rtn;Obj model;for ( int i = 0; i < maxIterations; i++ ) {model = world_sdf( origin + dir * rayDepth );sceneDist = model.distance; // Distance from the point along the ray to the nearest surface point in the scene.if (( field >= 1. )) {break;}if ((rayDepth >= end)) {if(surfaceDepth == 0.) {surfaceDepth = end;}break;}if(sceneDist <= 0.001) {if(surfaceDepth == 0.) {surfaceDepth = rayDepth + sceneDist;}field += abs(model.innerDistance) * .04;rayDepth += (1. - model.innerDistance) * .01;} else {rayDepth += sceneDist * stepScale;}}if ( sceneDist >= stopThreshold ) rayDepth = end;else rayDepth += sceneDist;// We've used up our maximum iterations. Return the maximum distance.return surfaceDepth;}/*** Lighting* This stuff is way way better than the model I was using.* Courtesy Shane Warne* Reference: http://raymarching.com/* -------------------------------------* */// Lighting.vec3 lighting( vec3 sp, vec3 camPos, int reflectionPass, float dist, float field, vec3 rd) {// Start with black.vec3 sceneColor = vec3(0.0);vec3 objColor = vec3(.95, .9, 1.) * (1. - field);// objColor = mix(objColor, vec3(1.1, .8, .5), (1. - sin(field*2.)));// Obtain the surface normal at the scene position "sp."vec3 surfNormal = calculate_normal(sp);// objColor = mix(objColor, vec3(1.1, .8, .5), (1. - sin(field * surfNormal.z)) * .5);// Lighting.// lp - Light position. Keeping it in the vacinity of the camera, but away from the objects in the scene.// vec3 lp = vec3(sin(u_time+.8)*-1., 1., cos(u_time+.8)*-1.0) + movement;vec3 lp = vec3(-1.5, 1.5, -1.0) + movement;// ld - Light direction.vec3 ld = lp-sp;// lcolor - Light color.vec3 lcolor = vec3(1.,0.97,0.92) * .8;// Light falloff (attenuation).float len = length( ld ); // Distance from the light to the surface point.ld /= len; // Normalizing the light-to-surface, aka light-direction, vector.// float lightAtten = min( 1.0 / ( 0.15*len*len ), 1.0 ); // Removed light attenuation for this because I want the fade to whitefloat sceneLen = length(camPos - sp); // Distance of the camera to the surface pointfloat sceneAtten = min( 1.0 / ( 0.015*sceneLen*sceneLen ), 1.0 ); // Keeps things between 0 and 1.   // Obtain the reflected vector at the scene position "sp."vec3 ref = reflect(-ld, surfNormal);float ao = 1.0; // Ambient occlusion.float ambient = .5; //The object's ambient property.float specularPower = 200.; // The power of the specularity. Higher numbers can give the object a harder, shinier look.float diffuse = max( 0.0, dot(surfNormal, ld) ); //The object's diffuse value.float specular = max( 0.0, dot( ref, normalize(camPos-sp)) ); //The object's specular value.specular = pow(specular, specularPower); // Ramping up the specular value to the specular power for a bit of shininess.// Bringing all the lighting components togethr to color the screen pixel.sceneColor += (objColor*(diffuse*0.8+ambient)+specular*0.5)*lcolor*1.3;sceneColor = mix(sceneColor, vec3(1.), 1.-sceneAtten*sceneAtten); // fogsceneColor += texture2D(u_env, surfNormal.xz * 2.).rgb * .3 * clamp(dist, 0., 1.);return sceneColor;}void main() {rotmat = rotationMatrix(vec3(0., 1., 0.), u_time);// Setting up our screen coordinates.vec2 aspect = vec2(u_resolution.x/u_resolution.y, 1.0); //vec2 uv = (2.0*gl_FragCoord.xy/u_resolution.xy - 1.0)*aspect;// This just gives us a touch of fisheye// uv *= 1. + dot(uv, uv) * 0.4;// movementmovement = vec3(0.);// The sin in here is to make it look like a walk.vec3 lookAt = vec3(-0., -.0, 0.);  // This is the point you look towards, or at, if you prefer.vec3 camera_position = vec3(sin(u_time)*-2., 1., cos(u_time)*-2.0); // This is the point you look from, or camera you look at the scene through. Whichever way you wish to look at it.camera_position = vec3(0., 1., -2.);camera_position *= sin(u_time*.5) * .5 + .6;lookAt += movement;// lookAt.z += sin(u_time / 10.) * .5;// lookAt.x += cos(u_time / 10.) * .5;camera_position += movement;vec3 forward = normalize(lookAt-camera_position); // Forward vector.vec3 right = normalize(vec3(forward.z, 0., -forward.x )); // Right vector... or is it left? Either way, so long as the correct-facing up-vector is produced.vec3 up = normalize(cross(forward,right)); // Cross product the two vectors above to get the up vector.// FOV - Field of view.float FOV = 0.4;// ro - Ray origin.vec3 ro = camera_position; // rd - Ray direction.vec3 rd = normalize(forward + FOV*uv.x*right + FOV*uv.y*up);// Ray marching.const float clipNear = 0.0;const float clipFar = 16.0;float field = 0.;float dist = rayMarching(ro, rd, clipNear, clipFar, field );if ( dist >= clipFar ) {gl_FragColor = vec4(vec3(1.), 1.0);return;}// sp - Surface position. If we've made it this far, we've hit something.vec3 sp = ro + rd*dist;// Light the pixel that corresponds to the surface position. The last entry indicates that it's not a reflection pass// which we're not up to yet.vec3 sceneColor = lighting( sp, camera_position, 0, dist, field, rd);// Clamping the lit pixel, then put it on the screen.gl_FragColor = vec4(clamp(sceneColor, 0.0, 1.0), 1.0);// gl_FragColor = vec4(field);}
</script><div id="container" touch-action="none"></div>

CSS

body {margin: 0;padding: 0;
}#container {position: fixed;touch-action: none;
}

JS

/*
Most of the stuff in here is just bootstrapping. Essentially it's just
setting ThreeJS up so that it renders a flat surface upon which to draw
the shader. The only thing to see here really is the uniforms sent to
the shader. Apart from that all of the magic happens in the HTML view
under the fragment shader.
*/let container;
let camera, scene, renderer;
let uniforms;let loader=new THREE.TextureLoader();
let texture, environment;
loader.setCrossOrigin("anonymous");
loader.load('https://s3-us-west-2.amazonaws.com/s.cdpn.io/982762/noise.png',(tex) => {texture = tex;texture.wrapS = THREE.RepeatWrapping;texture.wrapT = THREE.RepeatWrapping;texture.minFilter = THREE.LinearFilter;loader.load('https://s3-us-west-2.amazonaws.com/s.cdpn.io/982762/env_lat-lon.png', (tex) => {environment = tex;environment.wrapS = THREE.RepeatWrapping;environment.wrapT = THREE.RepeatWrapping;init();animate();})}
);function init() {container = document.getElementById( 'container' );camera = new THREE.Camera();camera.position.z = 1;scene = new THREE.Scene();var geometry = new THREE.PlaneBufferGeometry( 2, 2 );uniforms = {u_time: { type: "f", value: 1.0 },u_resolution: { type: "v2", value: new THREE.Vector2() },u_noise: { type: "t", value: texture },u_env: { type: "t", value: environment },u_mouse: { type: "v2", value: new THREE.Vector2() }};var material = new THREE.ShaderMaterial( {uniforms: uniforms,vertexShader: document.getElementById( 'vertexShader' ).textContent,fragmentShader: document.getElementById( 'fragmentShader' ).textContent} );material.extensions.derivatives = true;var mesh = new THREE.Mesh( geometry, material );scene.add( mesh );renderer = new THREE.WebGLRenderer();//renderer.setPixelRatio( window.devicePixelRatio );container.appendChild( renderer.domElement );onWindowResize();window.addEventListener( 'resize', onWindowResize, false );document.addEventListener('pointermove', (e)=> {let ratio = window.innerHeight / window.innerWidth;uniforms.u_mouse.value.x = (e.pageX - window.innerWidth / 2) / window.innerWidth / ratio;uniforms.u_mouse.value.y = (e.pageY - window.innerHeight / 2) / window.innerHeight * -1;e.preventDefault();});
}function onWindowResize( event ) {renderer.setSize( window.innerWidth, window.innerHeight );uniforms.u_resolution.value.x = renderer.domElement.width;uniforms.u_resolution.value.y = renderer.domElement.height;
}function animate(delta) {requestAnimationFrame( animate );render(delta);
}let capturer = new CCapture( { verbose: true, framerate: 30,// motionBlurFrames: 4,quality: 90,format: 'webm',workersPath: 'js/'} );
let capturing = false;isCapturing = function(val) {if(val === false && window.capturing === true) {capturer.stop();capturer.save();} else if(val === true && window.capturing === false) {capturer.start();}capturing = val;
}
toggleCapture = function() {isCapturing(!capturing);
}window.addEventListener('keyup', function(e) { if(e.keyCode == 68) toggleCapture(); });let then = 0;
function render(delta) {uniforms.u_time.value = -10000 + delta * 0.0005;renderer.render( scene, camera );if(capturing) {capturer.capture( renderer.domElement );}
}

水晶球 crystal ball相关推荐

  1. Crystal.Ball.Professional.v7.3.1 1CD(帮助理解风险的大小并帮你做出较好的决策)

    为什么80%的码农都做不了架构师?>>>    Crystal.Ball.Professional.v7.3.1 1CD(帮助理解风险的大小并帮你做出较好的决策) GoldSim.v ...

  2. crystal ball 软件_推荐10个堪称神器的软件工具

    1:BookxNote Pro BookxNote Pro 是一个完全免费的宝藏 PDF 笔记软件:软件仅支持 Windows 版本. 首先,它不仅支持打开 PDF 文件,也支持打开 EPUB 文件, ...

  3. Machine Learning A-Z学习笔记12-分类模型性能评级及选择

    Machine Learning A-Z学习笔记12-分类模型性能评级及选择 1.简单原理 一般认为假阴性比假阳性更严重,如核酸检测 用混淆矩阵表示如下图 准确率驳论(Accuracy Paradox ...

  4. javaone_JavaOne 2012:调查JVM水晶球

    javaone 我周一回到了希尔顿的A / B广场参加第四届会议,但首先去了希尔顿的顶层收拾午餐. 我每年都在JavaOne的第一天被提醒,对于参与的每个人来说,第一天的午餐获取过程令人惊讶地令人沮丧 ...

  5. JavaOne 2012:调查JVM水晶球

    我回到了希尔顿的A / B广场参加星期一的第四届会议,但首先去了希尔顿的顶层收拾午餐. 我每年都在JavaOne的第一天被提醒,涉及到每个人的第一天的午餐获取过程令人惊讶地令人沮丧. 我知道我在Jav ...

  6. 算命数据_未来的数据科学家或算命精神向导

    算命数据 Real Estate Sale Prices, Regression, and Classification: Data Science is the Future of Fortune ...

  7. 樊登36个问题建立亲密关系_36个问题建立亲密关系

    初次看到这个心理测试是在<生活大爆炸>中,觉得很有趣,就在网上搜索了一下. 和好朋友玩过一次,还是挺有意思的,今日奉献上完整版. Set One 第一部分 1. Given the cho ...

  8. Linux 28 岁了,我们总结了 28 个不为人知的事实

    作者丨 Joe Brockmeier 译者丨刘志勇 策划丨Tina 大约三十年前,Linus Trovalds 发送了一封电子邮件,宣布推出 Linux,这是一款免费的操作系统.他称"这只是 ...

  9. 无数的讽刺侮辱挖苦打击否定不屑与嘲笑,只有罗永浩才撑得住吧

    亲历锤子科技发布会,先不论产品,这的的确确是一场盛大的北京科技圈社交的盛会,除了技术开发者.媒体.意见领袖,相关从业者.关注者.锤友都疯狂的在社交媒体.朋友圈直播.刷屏.转发.评论,甚至对骂.互怼,一 ...

  10. BRE BRE ProMax 2.0.7047.0 工艺流程模拟软件ProMax\

    BRE BR&E ProMax 2.0.7047.0 工艺流程模拟软件ProMax\   Flac2D v4.0.257\ FLAC3D V3.0.26_FLAC3D 岩土工程软件\ FLAC ...

最新文章

  1. 算法导论之有关数论的算法
  2. 全球及中国回流冷凝管行业发展前景整体预测及十四五发展趋向展望报告2022-2027年版
  3. SpringCloud Ribbon中的7种负载均衡策略!
  4. html5的优势ie9,WebQQ升级支持IE9 充分运用HTML5优势
  5. audio插入背景音乐_网页制作中的html插入背景音乐
  6. android开发答题app,Android APP编写简单答题器
  7. java synchronized atomic_atomic 包、synchronized | Java 中线程安全
  8. 8.2捷联惯导算法仿真 代码整理分析(二)
  9. LaTeX入门学习(6)(字体)
  10. Github上优秀的开源项目
  11. PHP-Smarty
  12. 快速入门 | 篇十九:正运动技术运动控制器多轴同步与电子凸轮指令简介
  13. 银行业务分析(数据整合)
  14. Json是什么?要怎样理解?
  15. 情人节朋友圈秀恩爱九宫格配图
  16. mini2440中nand falsh的使用
  17. python 最大子序列之和
  18. Java读取单个字符
  19. 论文阅读笔记:Global-Locally Self-Attentive Dialogue State Tracker
  20. 大数据离线流程(小练习二)

热门文章

  1. 小程序快速入门:wxss的使用
  2. sqlite:WAL模式
  3. python 启动新进程执行脚本
  4. 洛谷 P4114 Qtree1 树链剖分
  5. .net 获取邮箱邮件列表和内容
  6. SpringBoot06 统一响应格式
  7. Java虚拟机的参数
  8. (X)HTML Strict 下的嵌套规则
  9. 安装无线网卡后,显示网络电缆被拔出?
  10. 光波函数和薛定谔方程