three+webgl实现文字悬浮拖拽水滴效果代码

代码语言:html

所属分类:其他

代码描述:three+webgl实现文字悬浮拖拽水滴效果代码

代码标签: three webgl 文字 悬浮 拖拽 水滴

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
<style>
    body { margin: 0;  overflow: hidden; position: fixed;}
canvas { width: 100%; height: 100% }
</style>

</head>
<body>
<!-- partial:index.partial.html -->
<script id="vertexShader" type="x-shader/x-vertex">
varying vec2 vUv;
void main() {
	vUv = uv;
	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
</script>

<script id="fragmentShader" type="x-shader/x-fragment">
varying vec2 vUv;

uniform sampler2D texture;
uniform sampler2D mask;
uniform sampler2D blur;
uniform float scale;


uniform float frequency;
uniform float amplitude;
uniform float speed;


uniform sampler2D uDistortionTexture;
uniform float time;
uniform float uDistortionFactor; // Factor used to control severity of the effect
uniform float uRiseFactor; // Factor used to control how fast air rises

void main() {

		vec2 uv = vUv;

	vec4 mask = texture2D(mask, uv);
	vec4 blur = texture2D(blur, uv);


		vec2 scaleCenter = vec2(0.5, 0.5);

		vec2 distMapUV = uv;
		// distMapUV.x -= time / 14.0;//* uRiseFactor;
	distMapUV.y -= time / 20.0;//* uRiseFactor;

	vec4 distMap = texture2D(uDistortionTexture, distMapUV);


	vec2 distPositionOffset = distMap.xy - vec2(0.1, 0.1);
		distPositionOffset -= vec2(0.25, 0.25);
		distPositionOffset.y *= 1.5;
		distPositionOffset.x *= -1.0;

	distPositionOffset *= 0.005 * (mask.a * 26.0);
	// distPositionOffset *= uDistortionFactor * 6.0 + (mask.a * 0.15);
	// distPositionOffset *= (mask.a) * (0.05 * 16.0);//uDistortionFactor * 16.0 + (mask.a * 0.55);

		vec2 distortedTextureCoordinate = uv.xy - vec2(0.0, 0.0) + distPositionOffset;

	vec4 final = texture2D(texture, (distortedTextureCoordinate - scaleCenter) * scale + scaleCenter );
	gl_FragColor = final;
}
</script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.84.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/TweenMax.min.js"></script>

<script >
    var mobileAndTabletcheck = function() {
		var check = false;
		(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
		return check;
	};

	var canvas = document.createElement( 'canvas' );
	var ctx = canvas.getContext( '2d' );

	var canvas2 = document.createElement( 'canvas' );
	var ctx2 = canvas2.getContext( '2d' );

	var w = 300;
	var h = 300;
	var width = window.innerWidth;
	var height = window.innerHeight;
	var planeSize = 300;
	var radius = 200;

	canvas.setAttribute('width', w);
	canvas.setAttribute('height', h);

	canvas2.setAttribute('width', w);
	canvas2.setAttribute('height', h);

	window.addEventListener('resize', onWindowResize);

	var maskImage = new Image();
	maskImage.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhE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