Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
d74d66dc
T
three.js
项目概览
车家大少爷
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d74d66dc
编写于
9月 18, 2019
作者:
G
Garrett Johnson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix indents
上级
e693ce2c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
110 addition
and
110 deletion
+110
-110
examples/js/shaders/LuminosityShader.js
examples/js/shaders/LuminosityShader.js
+5
-5
examples/js/shaders/MirrorShader.js
examples/js/shaders/MirrorShader.js
+14
-14
examples/js/shaders/NormalMapShader.js
examples/js/shaders/NormalMapShader.js
+6
-6
examples/js/shaders/ParallaxShader.js
examples/js/shaders/ParallaxShader.js
+70
-70
examples/js/shaders/RGBShiftShader.js
examples/js/shaders/RGBShiftShader.js
+7
-7
examples/js/shaders/SepiaShader.js
examples/js/shaders/SepiaShader.js
+8
-8
未找到文件。
examples/js/shaders/LuminosityShader.js
浏览文件 @
d74d66dc
...
...
@@ -19,9 +19,9 @@ THREE.LuminosityShader = {
"
void main() {
"
,
"
vUv = uv;
"
,
"
vUv = uv;
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
}
"
...
...
@@ -37,11 +37,11 @@ THREE.LuminosityShader = {
"
void main() {
"
,
"
vec4 texel = texture2D( tDiffuse, vUv );
"
,
"
vec4 texel = texture2D( tDiffuse, vUv );
"
,
"
float l = linearToRelativeLuminance( texel.rgb );
"
,
"
float l = linearToRelativeLuminance( texel.rgb );
"
,
"
gl_FragColor = vec4( l, l, l, texel.w );
"
,
"
gl_FragColor = vec4( l, l, l, texel.w );
"
,
"
}
"
...
...
examples/js/shaders/MirrorShader.js
浏览文件 @
d74d66dc
...
...
@@ -22,8 +22,8 @@ THREE.MirrorShader = {
"
void main() {
"
,
"
vUv = uv;
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
vUv = uv;
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
}
"
...
...
@@ -38,18 +38,18 @@ THREE.MirrorShader = {
"
void main() {
"
,
"
vec2 p = vUv;
"
,
"
if (side == 0){
"
,
"
if (p.x > 0.5) p.x = 1.0 - p.x;
"
,
"
}else if (side == 1){
"
,
"
if (p.x < 0.5) p.x = 1.0 - p.x;
"
,
"
}else if (side == 2){
"
,
"
if (p.y < 0.5) p.y = 1.0 - p.y;
"
,
"
}else if (side == 3){
"
,
"
if (p.y > 0.5) p.y = 1.0 - p.y;
"
,
"
}
"
,
"
vec4 color = texture2D(tDiffuse, p);
"
,
"
gl_FragColor = color;
"
,
"
vec2 p = vUv;
"
,
"
if (side == 0){
"
,
"
if (p.x > 0.5) p.x = 1.0 - p.x;
"
,
"
}else if (side == 1){
"
,
"
if (p.x < 0.5) p.x = 1.0 - p.x;
"
,
"
}else if (side == 2){
"
,
"
if (p.y < 0.5) p.y = 1.0 - p.y;
"
,
"
}else if (side == 3){
"
,
"
if (p.y > 0.5) p.y = 1.0 - p.y;
"
,
"
}
"
,
"
vec4 color = texture2D(tDiffuse, p);
"
,
"
gl_FragColor = color;
"
,
"
}
"
...
...
examples/js/shaders/NormalMapShader.js
浏览文件 @
d74d66dc
...
...
@@ -22,8 +22,8 @@ THREE.NormalMapShader = {
"
void main() {
"
,
"
vUv = uv;
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
vUv = uv;
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
}
"
...
...
@@ -39,12 +39,12 @@ THREE.NormalMapShader = {
"
void main() {
"
,
"
float val = texture2D( heightMap, vUv ).x;
"
,
"
float val = texture2D( heightMap, vUv ).x;
"
,
"
float valU = texture2D( heightMap, vUv + vec2( 1.0 / resolution.x, 0.0 ) ).x;
"
,
"
float valV = texture2D( heightMap, vUv + vec2( 0.0, 1.0 / resolution.y ) ).x;
"
,
"
float valU = texture2D( heightMap, vUv + vec2( 1.0 / resolution.x, 0.0 ) ).x;
"
,
"
float valV = texture2D( heightMap, vUv + vec2( 0.0, 1.0 / resolution.y ) ).x;
"
,
"
gl_FragColor = vec4( ( 0.5 * normalize( vec3( val - valU, val - valV, height ) ) + 0.5 ), 1.0 );
"
,
"
gl_FragColor = vec4( ( 0.5 * normalize( vec3( val - valU, val - valV, height ) ) + 0.5 ), 1.0 );
"
,
"
}
"
...
...
examples/js/shaders/ParallaxShader.js
浏览文件 @
d74d66dc
...
...
@@ -28,11 +28,11 @@ THREE.ParallaxShader = {
"
void main() {
"
,
"
vUv = uv;
"
,
"
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
"
,
"
vViewPosition = -mvPosition.xyz;
"
,
"
vNormal = normalize( normalMatrix * normal );
"
,
"
gl_Position = projectionMatrix * mvPosition;
"
,
"
vUv = uv;
"
,
"
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
"
,
"
vViewPosition = -mvPosition.xyz;
"
,
"
vNormal = normalize( normalMatrix * normal );
"
,
"
gl_Position = projectionMatrix * mvPosition;
"
,
"
}
"
...
...
@@ -52,130 +52,130 @@ THREE.ParallaxShader = {
"
#ifdef USE_BASIC_PARALLAX
"
,
"
vec2 parallaxMap( in vec3 V ) {
"
,
"
vec2 parallaxMap( in vec3 V ) {
"
,
"
float initialHeight = texture2D( bumpMap, vUv ).r;
"
,
"
float initialHeight = texture2D( bumpMap, vUv ).r;
"
,
// No Offset Limitting: messy, floating output at grazing angles.
//"vec2 texCoordOffset = parallaxScale * V.xy / V.z * initialHeight;",
// Offset Limiting
"
vec2 texCoordOffset = parallaxScale * V.xy * initialHeight;
"
,
"
return vUv - texCoordOffset;
"
,
"
vec2 texCoordOffset = parallaxScale * V.xy * initialHeight;
"
,
"
return vUv - texCoordOffset;
"
,
"
}
"
,
"
}
"
,
"
#else
"
,
"
vec2 parallaxMap( in vec3 V ) {
"
,
"
vec2 parallaxMap( in vec3 V ) {
"
,
// Determine number of layers from angle between V and N
"
float numLayers = mix( parallaxMaxLayers, parallaxMinLayers, abs( dot( vec3( 0.0, 0.0, 1.0 ), V ) ) );
"
,
"
float numLayers = mix( parallaxMaxLayers, parallaxMinLayers, abs( dot( vec3( 0.0, 0.0, 1.0 ), V ) ) );
"
,
"
float layerHeight = 1.0 / numLayers;
"
,
"
float currentLayerHeight = 0.0;
"
,
"
float layerHeight = 1.0 / numLayers;
"
,
"
float currentLayerHeight = 0.0;
"
,
// Shift of texture coordinates for each iteration
"
vec2 dtex = parallaxScale * V.xy / V.z / numLayers;
"
,
"
vec2 dtex = parallaxScale * V.xy / V.z / numLayers;
"
,
"
vec2 currentTextureCoords = vUv;
"
,
"
vec2 currentTextureCoords = vUv;
"
,
"
float heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;
"
,
"
float heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;
"
,
// while ( heightFromTexture > currentLayerHeight )
// Infinite loops are not well supported. Do a "large" finite
// loop, but not too large, as it slows down some compilers.
"
for ( int i = 0; i < 30; i += 1 ) {
"
,
"
if ( heightFromTexture <= currentLayerHeight ) {
"
,
"
break;
"
,
"
}
"
,
"
currentLayerHeight += layerHeight;
"
,
"
for ( int i = 0; i < 30; i += 1 ) {
"
,
"
if ( heightFromTexture <= currentLayerHeight ) {
"
,
"
break;
"
,
"
}
"
,
"
currentLayerHeight += layerHeight;
"
,
// Shift texture coordinates along vector V
"
currentTextureCoords -= dtex;
"
,
"
heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;
"
,
"
}
"
,
"
currentTextureCoords -= dtex;
"
,
"
heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;
"
,
"
}
"
,
"
#ifdef USE_STEEP_PARALLAX
"
,
"
#ifdef USE_STEEP_PARALLAX
"
,
"
return currentTextureCoords;
"
,
"
return currentTextureCoords;
"
,
"
#elif defined( USE_RELIEF_PARALLAX )
"
,
"
#elif defined( USE_RELIEF_PARALLAX )
"
,
"
vec2 deltaTexCoord = dtex / 2.0;
"
,
"
float deltaHeight = layerHeight / 2.0;
"
,
"
vec2 deltaTexCoord = dtex / 2.0;
"
,
"
float deltaHeight = layerHeight / 2.0;
"
,
// Return to the mid point of previous layer
"
currentTextureCoords += deltaTexCoord;
"
,
"
currentLayerHeight -= deltaHeight;
"
,
"
currentTextureCoords += deltaTexCoord;
"
,
"
currentLayerHeight -= deltaHeight;
"
,
// Binary search to increase precision of Steep Parallax Mapping
"
const int numSearches = 5;
"
,
"
for ( int i = 0; i < numSearches; i += 1 ) {
"
,
"
const int numSearches = 5;
"
,
"
for ( int i = 0; i < numSearches; i += 1 ) {
"
,
"
deltaTexCoord /= 2.0;
"
,
"
deltaHeight /= 2.0;
"
,
"
heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;
"
,
"
deltaTexCoord /= 2.0;
"
,
"
deltaHeight /= 2.0;
"
,
"
heightFromTexture = texture2D( bumpMap, currentTextureCoords ).r;
"
,
// Shift along or against vector V
"
if( heightFromTexture > currentLayerHeight ) {
"
,
// Below the surface
"
if( heightFromTexture > currentLayerHeight ) {
"
,
// Below the surface
"
currentTextureCoords -= deltaTexCoord;
"
,
"
currentLayerHeight += deltaHeight;
"
,
"
currentTextureCoords -= deltaTexCoord;
"
,
"
currentLayerHeight += deltaHeight;
"
,
"
} else {
"
,
// above the surface
"
} else {
"
,
// above the surface
"
currentTextureCoords += deltaTexCoord;
"
,
"
currentLayerHeight -= deltaHeight;
"
,
"
currentTextureCoords += deltaTexCoord;
"
,
"
currentLayerHeight -= deltaHeight;
"
,
"
}
"
,
"
}
"
,
"
}
"
,
"
return currentTextureCoords;
"
,
"
}
"
,
"
return currentTextureCoords;
"
,
"
#elif defined( USE_OCLUSION_PARALLAX )
"
,
"
#elif defined( USE_OCLUSION_PARALLAX )
"
,
"
vec2 prevTCoords = currentTextureCoords + dtex;
"
,
"
vec2 prevTCoords = currentTextureCoords + dtex;
"
,
// Heights for linear interpolation
"
float nextH = heightFromTexture - currentLayerHeight;
"
,
"
float prevH = texture2D( bumpMap, prevTCoords ).r - currentLayerHeight + layerHeight;
"
,
"
float nextH = heightFromTexture - currentLayerHeight;
"
,
"
float prevH = texture2D( bumpMap, prevTCoords ).r - currentLayerHeight + layerHeight;
"
,
// Proportions for linear interpolation
"
float weight = nextH / ( nextH - prevH );
"
,
"
float weight = nextH / ( nextH - prevH );
"
,
// Interpolation of texture coordinates
"
return prevTCoords * weight + currentTextureCoords * ( 1.0 - weight );
"
,
"
return prevTCoords * weight + currentTextureCoords * ( 1.0 - weight );
"
,
"
#else
"
,
// NO_PARALLAX
"
#else
"
,
// NO_PARALLAX
"
return vUv;
"
,
"
return vUv;
"
,
"
#endif
"
,
"
#endif
"
,
"
}
"
,
"
}
"
,
"
#endif
"
,
"
vec2 perturbUv( vec3 surfPosition, vec3 surfNormal, vec3 viewPosition ) {
"
,
"
vec2 texDx = dFdx( vUv );
"
,
"
vec2 texDy = dFdy( vUv );
"
,
"
vec2 texDx = dFdx( vUv );
"
,
"
vec2 texDy = dFdy( vUv );
"
,
"
vec3 vSigmaX = dFdx( surfPosition );
"
,
"
vec3 vSigmaY = dFdy( surfPosition );
"
,
"
vec3 vR1 = cross( vSigmaY, surfNormal );
"
,
"
vec3 vR2 = cross( surfNormal, vSigmaX );
"
,
"
float fDet = dot( vSigmaX, vR1 );
"
,
"
vec3 vSigmaX = dFdx( surfPosition );
"
,
"
vec3 vSigmaY = dFdy( surfPosition );
"
,
"
vec3 vR1 = cross( vSigmaY, surfNormal );
"
,
"
vec3 vR2 = cross( surfNormal, vSigmaX );
"
,
"
float fDet = dot( vSigmaX, vR1 );
"
,
"
vec2 vProjVscr = ( 1.0 / fDet ) * vec2( dot( vR1, viewPosition ), dot( vR2, viewPosition ) );
"
,
"
vec3 vProjVtex;
"
,
"
vProjVtex.xy = texDx * vProjVscr.x + texDy * vProjVscr.y;
"
,
"
vProjVtex.z = dot( surfNormal, viewPosition );
"
,
"
vec2 vProjVscr = ( 1.0 / fDet ) * vec2( dot( vR1, viewPosition ), dot( vR2, viewPosition ) );
"
,
"
vec3 vProjVtex;
"
,
"
vProjVtex.xy = texDx * vProjVscr.x + texDy * vProjVscr.y;
"
,
"
vProjVtex.z = dot( surfNormal, viewPosition );
"
,
"
return parallaxMap( vProjVtex );
"
,
"
return parallaxMap( vProjVtex );
"
,
"
}
"
,
"
void main() {
"
,
"
vec2 mapUv = perturbUv( -vViewPosition, normalize( vNormal ), normalize( vViewPosition ) );
"
,
"
gl_FragColor = texture2D( map, mapUv );
"
,
"
vec2 mapUv = perturbUv( -vViewPosition, normalize( vNormal ), normalize( vViewPosition ) );
"
,
"
gl_FragColor = texture2D( map, mapUv );
"
,
"
}
"
...
...
examples/js/shaders/RGBShiftShader.js
浏览文件 @
d74d66dc
...
...
@@ -26,8 +26,8 @@ THREE.RGBShiftShader = {
"
void main() {
"
,
"
vUv = uv;
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
vUv = uv;
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
}
"
...
...
@@ -43,11 +43,11 @@ THREE.RGBShiftShader = {
"
void main() {
"
,
"
vec2 offset = amount * vec2( cos(angle), sin(angle));
"
,
"
vec4 cr = texture2D(tDiffuse, vUv + offset);
"
,
"
vec4 cga = texture2D(tDiffuse, vUv);
"
,
"
vec4 cb = texture2D(tDiffuse, vUv - offset);
"
,
"
gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);
"
,
"
vec2 offset = amount * vec2( cos(angle), sin(angle));
"
,
"
vec4 cr = texture2D(tDiffuse, vUv + offset);
"
,
"
vec4 cga = texture2D(tDiffuse, vUv);
"
,
"
vec4 cb = texture2D(tDiffuse, vUv - offset);
"
,
"
gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);
"
,
"
}
"
...
...
examples/js/shaders/SepiaShader.js
浏览文件 @
d74d66dc
...
...
@@ -21,8 +21,8 @@ THREE.SepiaShader = {
"
void main() {
"
,
"
vUv = uv;
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
vUv = uv;
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
}
"
...
...
@@ -38,14 +38,14 @@ THREE.SepiaShader = {
"
void main() {
"
,
"
vec4 color = texture2D( tDiffuse, vUv );
"
,
"
vec3 c = color.rgb;
"
,
"
vec4 color = texture2D( tDiffuse, vUv );
"
,
"
vec3 c = color.rgb;
"
,
"
color.r = dot( c, vec3( 1.0 - 0.607 * amount, 0.769 * amount, 0.189 * amount ) );
"
,
"
color.g = dot( c, vec3( 0.349 * amount, 1.0 - 0.314 * amount, 0.168 * amount ) );
"
,
"
color.b = dot( c, vec3( 0.272 * amount, 0.534 * amount, 1.0 - 0.869 * amount ) );
"
,
"
color.r = dot( c, vec3( 1.0 - 0.607 * amount, 0.769 * amount, 0.189 * amount ) );
"
,
"
color.g = dot( c, vec3( 0.349 * amount, 1.0 - 0.314 * amount, 0.168 * amount ) );
"
,
"
color.b = dot( c, vec3( 0.272 * amount, 0.534 * amount, 1.0 - 0.869 * amount ) );
"
,
"
gl_FragColor = vec4( min( vec3( 1.0 ), color.rgb ), color.a );
"
,
"
gl_FragColor = vec4( min( vec3( 1.0 ), color.rgb ), color.a );
"
,
"
}
"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录