wtc-gl+webgl实现三维立方体 对数深度缓冲(Z-抗锯齿)和阴影/轮廓效果代码
代码语言:html
所属分类:三维
代码描述:wtc-gl+webgl实现三维立方体 对数深度缓冲(Z-抗锯齿)和阴影/轮廓效果代码
代码标签: wtc-gl webgl 三维 立方体 对数 深度 缓冲 抗锯齿 阴影 轮廓
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
body {
background: pink;
margin: 0;
overflow: hidden;
}
canvas {
width: 100vw;
height: 100vh;
}
</style>
</head>
<body >
<script type="text/fragment" id="vertShader">#version 300 es
in vec3 position;
in vec2 uv;
in vec3 normal;
in mat4 translation;
in mat4 inverseTranspose;
in float scale;
in float id;
in float faceoffset;
in vec3 facecolour;
in vec3 colour;
uniform mat4 u_viewMatrix;
uniform mat4 u_modelMatrix;
uniform mat4 u_modelViewMatrix;
uniform mat4 u_projectionMatrix;
uniform mat3 u_normalMatrix;
uniform float u_time;
uniform float u_logDepthDelta;
out vec3 vNormal;
out vec3 vPosition;
out vec3 vWorldPosition;
out vec2 vUV;
out float vCol;
out float depth;
out vec3 facecol;
#define EPSILON 0.01
void main() {
vec3 pos = (translation*vec4(scale*position, 1.)).xyz;
// vec3 pos = position;
// vec3 pos = mat3(translation)*(scale*position);
vec4 camPos = u_projectionMatrix * u_modelViewMatrix * vec4(pos, 1.0);
// Modify the depth in clip space
depth = log2( max( EPSILON, camPos.w + 1.0 ) ) * u_logDepthDelta - 1.0;
// depth = (2.0 * depth - 1.0) * camPos.w; // debug
// depth = camPos.w;
// camPos.z = (2.0 * depth - 1.0) * camPos.w;
gl_Position = camPos;
// gl_Position.w = depth;
gl_Position.z.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0