aframe实现三维玻璃立方体视差着色器代码

代码语言:html

所属分类:三维

代码描述:aframe实现三维玻璃立方体视差着色器代码

代码标签: aframe 三维 玻璃 立方体 视差 着色器 代码

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

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

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">
<script>console.clear();</script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/aframe.1.3.0.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/aframe-orbit-controls.1.3.0.js"></script>


  
  
<style>
.tip {
  position: fixed;
  top: 4px;
  z-index: 1;
  pointer-events: none;
  width: 100%;
  padding: 12px;
  font-family: system-ui, sans-serif;
  font-size: clamp(0.75rem, 3.5vw, 1.25rem);
  text-align: center;
  color: #fff;
  opacity: 0.25;
}
</style>




</head>

<body  >
  <script>

AFRAME.registerComponent('glass-cube', {
  schema: {},
  init() {
		const mesh = this.el.getObject3D('mesh');
		mesh.geometry.computeTangents();
		mesh.material = this.generateMaterial();
	},
	generateMaterial() {
		const colorTex = new THREE.TextureLoader().load('//repo.bfw.wiki/bfwrepo/images/cube/colored_squares.png');
		const normalTex = new THREE.TextureLoader().load('//repo.bfw.wiki/bfwrepo/images/cube/glass_frosted_normal_tex.jpg');
		// const normalTex = new THREE.TextureLoader().load('//repo.bfw.wiki/bfwrepo/images/cube/tiles_normal_map.jpg');
		return new THREE.ShaderMaterial({
			uniforms: {
				u_colorTex: { type: 't', value: colorTex },
				u_normalTex: { type: 't', value: normalTex }
			},
			// I learned a lot about normal/parallax mapping from this article + demo:
			// https://apoorvaj.io/exploring-bump-mapping-with-webgl/
			vertexShader: `
				// THREE doesn't seem to add the "tangent" attribute automatically when we compute the tangents.
				// The attribute data is there, we just need to declare it here.
				attribute vec4 tangent;
				
				varying vec3 v_normal;
				varying vec2 v_uv;
				varying vec3 v_fragPos;
				varying vec3 v_viewPos;
			.........完整代码请登录后点击上方下载按钮下载查看

网友评论0