three实现三维立体被切成片的小球代码

代码语言:html

所属分类:三维

代码描述:three实现三维立体被切成片的小球代码

代码标签: three 三维 立体 切片 小球 代码

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

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  
  
  
<style>
html, body {
  padding: 0;
  margin: 0;
}

body {
  background-color: #4C22AB;
  margin: 0;
}
</style>


</head>

<body translate="no">
    
      <script type="importmap">
  {
    "imports": {
      "three": "//repo.bfw.wiki/bfwrepo/js/module/three/build/171/three.module.js",
     
      "three/addons/": "//repo.bfw.wiki/bfwrepo/js/module/three/examples/171/jsm/"
    }
  }
</script>


<script id="fragmentShader" type="x-shader/x-fragment">

	varying vec2 vUv;
	varying vec3 vPos;
	varying vec3 vNormal;
	//varying vec4 vViewMatrix;
	
	
	uniform float time;

	void main(){
		
		float l = length(vPos);
		if(l<1.){
			l=1.;
		}else{
			l=0.;
		}
		float height = (2. * (vPos.y+1.)/2.)-0.2;
		//height = (2.*height)+0.5;
		//height = 0.3*pow(height,2.) + 0.2*height;
		//height = height + 0.5;
		
		height = pow(height,2.);
		float radius = pow(length(vPos.xz)+0.5,0.5);
		
		vec3 sunDir = vec3(0,0.,1.);
		float sunNess = dot(vNormal,sunDir);
		float brightness = (height * radius) + (sunNess*0.05);
		
		vec3 colB = vec3(247., 37., 133.)/255.;
		vec3 colA = vec3(114., 9., 183.)/300.;
		vec3 col = mix(colA,colB,brightness);
		
		gl_FragColor = vec4(col,l);

	}

</script>

<script id="vertexShader" type="x-shader/x-vertex">

	uniform vec2 uvScale;
	
	varying vec2 vUv;
	varying vec3 vPos;
	varying vec3 vNormal;
	//varying vec4 vViewMatrix;
	
	void main()
	{	
		//vViewMatrix = modelViewMatrix;
		vNormal = normalMatrix * normal;
		vPos = position;
		vUv = uvScale.........完整代码请登录后点击上方下载按钮下载查看

网友评论0