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 *= depth;
vUV = uv;
vNormal = (inverseTranspose * vec4(normal,1)).xyz;
vCol = faceoffset+id;
facecol = fract(facecolour+colour);
}
</script>
<script type="text/fragment" id="fragShader">#version 300 es
precision highp float;
in vec3 vNormal;
in vec2 vUV;
in vec4 camPos;
in vec3 vPosition;
in vec3 vWorldPosition;
in float vCol;
in float depth;
in vec3 facecol;
out vec4 colour;
uniform float u_time;
uniform bool u_outlinestage;
uniform float u_logDepthDelta;
// Procedural colour palettes curtesy Inigo Quilez
// https://iquilezles.org/www/articles/palettes/palettes.htm
vec3 palette( in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d ) {
return a + b*cos( 6.28318*(c*t+d) );
}
// Simplex 2D noise
//
vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }
float snoise(vec2 v){
const vec4 C = vec4(0.211324865405187, 0.366025403784439,
-0.577350269189626, 0.02439024390243.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0