鱼眼镜头

news/2024/11/25 15:55:05/

鱼眼镜头

  • 示例
  • 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 vec2 u_mouse;uniform float u_time;uniform sampler2D u_noise;vec2 hash2(vec2 p){vec2 o = texture2D( u_noise, (p+0.5)/256.0, -100.0 ).xy;return o;}float sigmoid(float x) {return x / ( 1. + abs(x));}vec2 sigmoidDistort(in vec2 uv, inout vec2 polar, inout float distortion) {polar = vec2( atan(uv.y, uv.x), length(uv) );float a = sin(polar.y * .8);distortion = sigmoid(a * -.2);polar.x += sigmoid(a * .2) * 1.;polar.y += sigmoid(a * -.5) * 3.;return vec2( cos(polar.x) * polar.y, sin(polar.x) * polar.y );}void main() {vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / min(u_resolution.y, u_resolution.x);vec2 subuv;uv *= 10.;vec2 polar = vec2(0.);float distortion = 0.;uv = sigmoidDistort(uv, polar, distortion);float t = u_time * .1;uv *= mat2(sin(t), -cos(t),cos(t), sin(t)         );uv.x += u_time;uv += .5;vec2 grid = floor(uv);vec2 subgrid = fract(uv) - .5;float c = mod(grid.x + grid.y, 2.);// c = smoothstep(.44, .4, length(subgrid));vec3 colour = vec3(c);uv += distortion * .3;grid = floor(uv);subgrid = fract(uv) - .5;colour.g = mod(grid.x + grid.y, 2.);// colour.r = smoothstep(.44, .4, length(subgrid));uv += distortion * .3;grid = floor(uv);subgrid = fract(uv) - .5;colour.b = mod(grid.x + grid.y, 2.);// colour.b = smoothstep(.44, .4, length(subgrid));gl_FragColor = vec4(colour,1.0);}
</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;
loader.setCrossOrigin("anonymous");
loader.load('https://s3-us-west-2.amazonaws.com/s.cdpn.io/982762/noise.png',function do_something_with_texture(tex) {texture = tex;texture.wrapS = THREE.RepeatWrapping;texture.wrapT = THREE.RepeatWrapping;texture.minFilter = THREE.LinearFilter;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_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 / 1) / 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() {requestAnimationFrame( animate );render();
}function render() {uniforms.u_time.value += 0.01;renderer.render( scene, camera );
}

http://www.ppmy.cn/news/543065.html

相关文章

鱼眼镜头校准

01.简介 当我们使用的鱼眼镜头视角大于160时,OpenCV中用于校准镜头“经典”方法的效果可能就不是和理想了。即使我们仔细遵循OpenCV文档中的步骤,也可能会得到下面这个奇奇怪怪的照片: 从3.0版开始,OpenCV包含了cv2.fisheye可以很好地处理鱼眼镜头校准的软件包。但是,该模…

交通 | 考虑供需交互下的航空网络优化问题

编者按&#xff1a; 本文提出了一种包含供需交互作用的航空网络规划模型 (ANPSD)&#xff0c;该模型同时考虑了航线选择、航班频率和机队组成等问题&#xff0c;还捕捉了航空公司的供应和乘客需求之间的相互依赖关系。作者将需求实证函数与 ANPSD 模型相结合&#xff0c;开发了…

搜狗地图 android wear,Android Wear多款来袭!搜狗地图独家内置

原标题&#xff1a;Android Wear多款来袭&#xff01;搜狗地图独家内置 随着多款配置AndroidWear的手表在国内上线&#xff0c;谷歌和苹果在智能手表上的国内“大战”一触即发。虽然&#xff0c;两位“大佬”在诸多方面有着不同的发展方向&#xff0c;但在智能手表上却不约而同…

百度地图android wear,Android Wear多款搜狗地图标注内置

跟着多款装备AndroidWear的手表在国内上线&#xff0c;谷歌和苹果在智能手表上的国内“大战”剑拔弩张。尽管&#xff0c;两位“大佬”在诸多方面有着不一样的发展方向&#xff0c;但在智能手表上却不谋而合的挑选搜狗地图标注作为其合作伙伴。据了解&#xff0c;搜狗地图标注与…

android 调用搜狗地图api,搜狗地图API2.0版本正式上线:推一键搬家功能

搜狗地图API2.0版本正式上线 7月20日&#xff0c;搜狗地图API2.0版本正式上线( http://map.sogou.com/api /)&#xff0c;在此前API1.0的基础上&#xff0c;在易用性和灵活性方面全面优化&#xff0c;并将公交、自驾、目的地搜索&#xff0c;以及路桥费、打车费计算、生活信息服…

【总结整理】openlayer加载搜狗地图,qq地图,mapabc

qq http://www.cnblogs.com/gisvip/archive/2012/11/01/2750493.html mapabc http://www.cnblogs.com/gisvip/archive/2012/03/25/2417240.html 天地图 http://www.cnblogs.com/gisvip/archive/2012/03/25/2417229.html http://www.cnblogs.com/gisvip/archive/2013/0…

搜狗地图下载|搜狗地图app下载

搜狗地图除了搜索、公交、自驾导航等地图的基本功能之外&#xff0c;另外还有多功能商店、路书、卫星图、手机地图等其他特色应用&#xff0c;全方位地满足了人们随时随地掌握出行生活的需要。搜狗地图链接应用简介搜狗地图是国内最早的地图网站&#xff0c;数据覆盖全国将近40…

OpenLayers加载搜狗地图

从目前国内的地图服务商提供的地图来看&#xff0c;地图瓦片切图规则只少分为三种。其中Google Map、Bing地图、MapABC、QQ地图是一类&#xff0c;而百度地图、搜狗地图是使用的另一类&#xff0c;他们是在GCJ02 基础上又进行了自己的偏移 &#xff0c;还有一类应该是mapbar的地…