webgl+canvas实现三个不同形状三维立体棒棒糖旋转动画效果代码
代码语言:html
所属分类:三维
代码描述:webgl+canvas实现三个不同形状三维立体棒棒糖旋转动画效果代码
代码标签: webgl canvas 三个 不同 形状 三维 立体 棒棒糖 旋转 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
body { margin: 0; overflow: hidden; }
</style>
</head>
<body translate="no">
<canvas id="myCanvas"></canvas>
<script >
const canvas = document.getElementById('myCanvas');
const gl = canvas.getContext('webgl2');
const vertexShaderSource = `#version 300 es
in vec2 a_position;
void main() {
gl_Position = vec4(a_position, 0.0, 1.0);
}
`;
const fragmentShaderSource = `#version 300 es
precision highp float;
uniform vec2 iResolution; // Declare as vec2 (canvas width and height)
uniform vec2 iMouse;
uniform float iTime;
out vec4 fragColor;
// Shadertoy code here
#define PI 3.14159265359
#define RES iResolution
#define smax smoothmax
#define rot(a) mat2(cos(a-vec4(0,11,33,0))) // shorthand for rotating objects
#define orbit p.x+=cos(pos +iTime/5.)*pivot/2., p.z+=sin(pos +iTime/5.)*pivot // rotating the objects by setting their x and z coordinates using sine and cosine; using this because I want the x to be scaled by 2
float smoothmax(float d1, float d2, float k) {
float h = max(k - abs(d1 - d2.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0