webgl实现三维水晶金色方块旋转效果代码
代码语言:html
所属分类:三维
代码描述:webgl实现三维水晶金色方块旋转效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body { background: #333; color: #fff; font-family: sans-serif; } body, html { margin: 0; overflow: hidden; padding: 0; } canvas { width:100%; height:100%; } </style> </head> <body > <script type="text/fragment" id="vertShader"> attribute vec3 position; attribute vec3 normal; attribute vec2 uv; uniform mat4 u_viewMatrix; uniform mat4 u_modelMatrix; uniform mat4 u_modelViewMatrix; uniform mat4 u_projectionMatrix; uniform mat3 u_normalMatrix; varying vec3 vNormal; varying vec3 vPosition; varying vec3 vWorldPosition; varying vec2 vUV; void main() { vNormal = normalize(u_normalMatrix * normal); vUV = uv; vec4 camPos = u_projectionMatrix * u_modelViewMatrix * vec4(position, 1.0); gl_Position = camPos; vWorldPosition = (u_modelMatrix * vec4(0,0,0, 1.0)).xyz; vPosition = (u_modelMatrix * vec4(position, 1.0)).xyz; } </script> <script type="text/fragment" id="fragShader"> precision highp float; varying vec3 vNormal; varying vec2 vUV; varying vec4 camPos; varying vec3 vPosition; varying vec3 vWorldPosition; uniform vec3 u_cameraPosition; uniform mat4 u_matrix; /* Raymarching constants */ /* --------------------- */ const float MAX_TRACE_DISTANCE = 10.; // max trace distance const float INTERSECTION_PRECISION = 0.001; // precision of the intersection const int NUM_OF_TRACE_STEPS = 64; // max number of trace steps const float STEP_MULTIPLIER = 1.; /* Structures */ /* ---------- */ struct Camera { vec3 ro; vec3 rd; float FOV; }; struct Surface { float len; vec3 position; vec3 colour; float id; float steps; float AO; }; struct Model { float dist; vec3 colour; float id; }; Camera getCamera(in vec3 ro, in vec3 rd, in float FOV) { return Camera( .........完整代码请登录后点击上方下载按钮下载查看
网友评论0