Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
110bd08e
T
three.js
项目概览
Ablesons
/
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,发现更多精彩内容 >>
提交
110bd08e
编写于
1月 01, 2012
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'alteredq/dev' into dev
上级
0a10d079
be829f4a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
698 addition
and
422 deletion
+698
-422
build/Three.js
build/Three.js
+212
-212
build/custom/ThreeExtras.js
build/custom/ThreeExtras.js
+189
-189
examples/js/ShaderExtras.js
examples/js/ShaderExtras.js
+253
-0
examples/js/ctm/CTMLoader.js
examples/js/ctm/CTMLoader.js
+1
-1
examples/webgl_geometries.html
examples/webgl_geometries.html
+3
-1
src/extras/geometries/IcosahedronGeometry.js
src/extras/geometries/IcosahedronGeometry.js
+40
-19
未找到文件。
build/Three.js
浏览文件 @
110bd08e
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
build/custom/ThreeExtras.js
浏览文件 @
110bd08e
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
examples/js/ShaderExtras.js
浏览文件 @
110bd08e
...
...
@@ -23,6 +23,7 @@
* luminosity
* colorCorrection
* normalmap
* ssao
*/
THREE
.
ShaderExtras
=
{
...
...
@@ -1383,6 +1384,258 @@ THREE.ShaderExtras = {
},
/* -------------------------------------------------------------------------
// Screen-space ambient occlusion shader
// - ported from
// SSAO GLSL shader v1.2
// assembled by Martins Upitis (martinsh) (http://devlog-martinsh.blogspot.com)
// original technique is made by ArKano22 (http://www.gamedev.net/topic/550699-ssao-no-halo-artifacts/)
// - modifications
// - modified to use RGBA packed depth texture (use clear color 1,1,1,1 for depth pass)
// - made fog more compatible with three.js linear fog
// - refactoring and optimizations
------------------------------------------------------------------------- */
'
ssao
'
:
{
uniforms
:
{
"
tDiffuse
"
:
{
type
:
"
t
"
,
value
:
0
,
texture
:
null
},
"
tDepth
"
:
{
type
:
"
t
"
,
value
:
1
,
texture
:
null
},
"
size
"
:
{
type
:
"
v2
"
,
value
:
new
THREE
.
Vector2
(
512
,
512
)
},
"
cameraNear
"
:
{
type
:
"
f
"
,
value
:
1
},
"
cameraFar
"
:
{
type
:
"
f
"
,
value
:
100
},
"
fogNear
"
:
{
type
:
"
f
"
,
value
:
5
},
"
fogFar
"
:
{
type
:
"
f
"
,
value
:
100
},
"
fogEnabled
"
:
{
type
:
"
i
"
,
value
:
0
},
"
aoClamp
"
:
{
type
:
"
f
"
,
value
:
0.3
}
},
vertexShader
:
[
"
varying vec2 vUv;
"
,
"
void main() {
"
,
"
vUv = vec2( uv.x, 1.0 - uv.y );
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
}
"
].
join
(
"
\n
"
),
fragmentShader
:
[
"
uniform float cameraNear;
"
,
"
uniform float cameraFar;
"
,
"
uniform float fogNear;
"
,
"
uniform float fogFar;
"
,
"
uniform bool fogEnabled;
"
,
"
uniform vec2 size;
"
,
// texture width, height
"
uniform float aoClamp;
"
,
// depth clamp - reduces haloing at screen edges
"
uniform sampler2D tDiffuse;
"
,
"
uniform sampler2D tDepth;
"
,
"
varying vec2 vUv;
"
,
//"#define PI 3.14159265",
"
#define DL 2.399963229728653
"
,
// PI * ( 3.0 - sqrt( 5.0 ) )
"
#define EULER 2.718281828459045
"
,
// helpers
"
float width = size.x;
"
,
// texture width
"
float height = size.y;
"
,
// texture height
"
float cameraFarPlusNear = cameraFar + cameraNear;
"
,
"
float cameraFarMinusNear = cameraFar - cameraNear;
"
,
"
float cameraCoef = 2.0 * cameraNear;
"
,
// user variables
"
const int samples = 8;
"
,
// ao sample count
"
const float radius = 5.0;
"
,
// ao radius
"
const bool useNoise = false;
"
,
// use noise instead of pattern for sample dithering
"
const float noiseAmount = 0.0002;
"
,
// dithering amount
"
const float diffArea = 0.4;
"
,
// self-shadowing reduction
"
const float gDisplace = 0.4;
"
,
// gauss bell center
"
const bool onlyAO = false;
"
,
// use only ambient occlusion pass?
"
const float lumInfluence = 0.3;
"
,
// how much luminance affects occlusion
// RGBA depth
"
float unpackDepth( const in vec4 rgba_depth ) {
"
,
"
const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );
"
,
"
float depth = dot( rgba_depth, bit_shift );
"
,
"
return depth;
"
,
"
}
"
,
// generating noise / pattern texture for dithering
"
vec2 rand( const vec2 coord ) {
"
,
"
vec2 noise;
"
,
"
if ( useNoise ) {
"
,
"
float nx = dot ( coord, vec2( 12.9898, 78.233 ) );
"
,
"
float ny = dot ( coord, vec2( 12.9898, 78.233 ) * 2.0 );
"
,
"
noise = clamp( fract ( 43758.5453 * sin( vec2( nx, ny ) ) ), 0.0, 1.0 );
"
,
"
} else {
"
,
"
float ff = fract( 1.0 - coord.s * ( width / 2.0 ) );
"
,
"
float gg = fract( coord.t * ( height / 2.0 ) );
"
,
"
noise = vec2( 0.25, 0.75 ) * vec2( ff ) + vec2( 0.75, 0.25 ) * gg;
"
,
"
}
"
,
"
return ( noise * 2.0 - 1.0 ) * noiseAmount;
"
,
"
}
"
,
"
float doFog() {
"
,
"
float zdepth = unpackDepth( texture2D( tDepth, vUv ) );
"
,
"
float depth = -cameraFar * cameraNear / ( zdepth * cameraFarMinusNear - cameraFar );
"
,
"
return smoothstep( fogNear, fogFar, depth );
"
,
"
}
"
,
"
float readDepth( const in vec2 coord ) {
"
,
//"return ( 2.0 * cameraNear ) / ( cameraFar + cameraNear - unpackDepth( texture2D( tDepth, coord ) ) * ( cameraFar - cameraNear ) );",
"
return cameraCoef / ( cameraFarPlusNear - unpackDepth( texture2D( tDepth, coord ) ) * cameraFarMinusNear );
"
,
"
}
"
,
"
float compareDepths( const in float depth1, const in float depth2, inout int far ) {
"
,
"
float garea = 2.0;
"
,
// gauss bell width
"
float diff = ( depth1 - depth2 ) * 100.0;
"
,
// depth difference (0-100)
// reduce left bell width to avoid self-shadowing
"
if ( diff < gDisplace ) {
"
,
"
garea = diffArea;
"
,
"
} else {
"
,
"
far = 1;
"
,
"
}
"
,
"
float dd = diff - gDisplace;
"
,
"
float gauss = pow( EULER, -2.0 * dd * dd / ( garea * garea ) );
"
,
"
return gauss;
"
,
"
}
"
,
"
float calcAO( float depth, float dw, float dh ) {
"
,
"
float dd = radius - depth * radius;
"
,
"
vec2 vv = vec2( dw, dh );
"
,
"
vec2 coord1 = vUv + dd * vv;
"
,
"
vec2 coord2 = vUv - dd * vv;
"
,
"
float temp1 = 0.0;
"
,
"
float temp2 = 0.0;
"
,
"
int far = 0;
"
,
"
temp1 = compareDepths( depth, readDepth( coord1 ), far );
"
,
// DEPTH EXTRAPOLATION
"
if ( far > 0 ) {
"
,
"
temp2 = compareDepths( readDepth( coord2 ), depth, far );
"
,
"
temp1 += ( 1.0 - temp1 ) * temp2;
"
,
"
}
"
,
"
return temp1;
"
,
"
}
"
,
"
void main() {
"
,
"
vec2 noise = rand( vUv );
"
,
"
float depth = readDepth( vUv );
"
,
"
float tt = clamp( depth, aoClamp, 1.0 );
"
,
"
float w = ( 1.0 / width ) / tt + ( noise.x * ( 1.0 - noise.x ) );
"
,
"
float h = ( 1.0 / height ) / tt + ( noise.y * ( 1.0 - noise.y ) );
"
,
"
float pw;
"
,
"
float ph;
"
,
"
float ao;
"
,
"
float dz = 1.0 / float( samples );
"
,
"
float z = 1.0 - dz / 2.0;
"
,
"
float l = 0.0;
"
,
"
for ( int i = 0; i <= samples; i ++ ) {
"
,
"
float r = sqrt( 1.0 - z );
"
,
"
pw = cos( l ) * r;
"
,
"
ph = sin( l ) * r;
"
,
"
ao += calcAO( depth, pw * w, ph * h );
"
,
"
z = z - dz;
"
,
"
l = l + DL;
"
,
"
}
"
,
"
ao /= float( samples );
"
,
"
ao = 1.0 - ao;
"
,
"
if ( fogEnabled ) {
"
,
"
ao = mix( ao, 1.0, doFog() );
"
,
"
}
"
,
"
vec3 color = texture2D( tDiffuse, vUv ).rgb;
"
,
"
vec3 lumcoeff = vec3( 0.299, 0.587, 0.114 );
"
,
"
float lum = dot( color.rgb, lumcoeff );
"
,
"
vec3 luminance = vec3( lum );
"
,
"
vec3 final = vec3( color * mix( vec3( ao ), vec3( 1.0 ), luminance * lumInfluence ) );
"
,
// mix( color * ao, white, luminance )
"
if ( onlyAO ) {
"
,
"
final = vec3( mix( vec3( ao ), vec3( 1.0 ), luminance * lumInfluence ) );
"
,
// ambient occlusion only
"
}
"
,
"
gl_FragColor = vec4( final, 1.0 );
"
,
"
}
"
].
join
(
"
\n
"
)
},
// METHODS
buildKernel
:
function
(
sigma
)
{
...
...
examples/js/ctm/CTMLoader.js
浏览文件 @
110bd08e
...
...
@@ -75,7 +75,7 @@ THREE.CTMLoader.prototype.loadParts = function( url, callback, useWorker, useBuf
}
xhr
.
open
(
"
GET
"
,
url
,
true
);
xhr
.
overrideMimeType
(
"
text/plain; charset=x-user-defined
"
);
if
(
xhr
.
overrideMimeType
)
xhr
.
overrideMimeType
(
"
text/plain; charset=x-user-defined
"
);
xhr
.
setRequestHeader
(
"
Content-Type
"
,
"
text/plain
"
);
xhr
.
send
(
null
);
...
...
examples/webgl_geometries.html
浏览文件 @
110bd08e
...
...
@@ -52,7 +52,7 @@
materials
=
[
new
THREE
.
MeshLambertMaterial
(
{
ambient
:
0xbbbbbb
,
map
:
THREE
.
ImageUtils
.
loadTexture
(
'
textures/ash_uvgrid01.jpg
'
)
}
),
new
THREE
.
MeshBasicMaterial
(
{
color
:
0xffffff
,
wireframe
:
true
,
transparent
:
true
,
opacity
:
0.
3
}
)
new
THREE
.
MeshBasicMaterial
(
{
color
:
0xffffff
,
wireframe
:
true
,
transparent
:
true
,
opacity
:
0.
1
}
)
];
object
=
THREE
.
SceneUtils
.
createMultiMaterialObject
(
new
THREE
.
CubeGeometry
(
100
,
100
,
100
,
4
,
4
,
4
),
materials
);
...
...
@@ -69,6 +69,7 @@
scene
.
add
(
object
);
object
=
THREE
.
SceneUtils
.
createMultiMaterialObject
(
new
THREE
.
PlaneGeometry
(
100
,
100
,
4
,
4
),
materials
);
object
.
children
[
0
].
doubleSided
=
true
;
object
.
position
.
set
(
-
200
,
0
,
0
);
scene
.
add
(
object
);
...
...
@@ -85,6 +86,7 @@
}
object
=
THREE
.
SceneUtils
.
createMultiMaterialObject
(
new
THREE
.
LatheGeometry
(
points
,
20
),
materials
);
object
.
children
[
0
].
doubleSided
=
true
;
object
.
position
.
set
(
200
,
0
,
0
);
scene
.
add
(
object
);
...
...
src/extras/geometries/IcosahedronGeometry.js
浏览文件 @
110bd08e
/**
* @author oosmoxiecode
*
* uvs are messed up in this one, and commented away for now. There is an ugly "seam" by the shared vertices
* when it "wraps" around, that needs to be fixed. It's because they share the first and the last vertices
* so it draws the entire texture on the seam-faces, I think...
*/
THREE
.
IcosahedronGeometry
=
function
(
subdivisions
)
{
...
...
@@ -9,10 +13,11 @@ THREE.IcosahedronGeometry = function ( subdivisions ) {
var
tempFaces
;
this
.
subdivisions
=
subdivisions
||
0
;
THREE
.
Geometry
.
call
(
this
);
THREE
.
Geometry
.
call
(
this
);
// create 12 vertices of a Icosahedron
var
t
=
(
1
+
Math
.
sqrt
(
5
))
/
2
;
var
t
=
(
1
+
Math
.
sqrt
(
5
)
)
/
2
;
v
(
-
1
,
t
,
0
);
v
(
1
,
t
,
0
);
...
...
@@ -30,6 +35,7 @@ THREE.IcosahedronGeometry = function ( subdivisions ) {
v
(
-
t
,
0
,
1
);
// 5 faces around point 0
f3
(
0
,
11
,
5
,
tempScope
);
f3
(
0
,
5
,
1
,
tempScope
);
f3
(
0
,
1
,
7
,
tempScope
);
...
...
@@ -37,6 +43,7 @@ THREE.IcosahedronGeometry = function ( subdivisions ) {
f3
(
0
,
10
,
11
,
tempScope
);
// 5 adjacent faces
f3
(
1
,
5
,
9
,
tempScope
);
f3
(
5
,
11
,
4
,
tempScope
);
f3
(
11
,
10
,
2
,
tempScope
);
...
...
@@ -44,6 +51,7 @@ THREE.IcosahedronGeometry = function ( subdivisions ) {
f3
(
7
,
1
,
8
,
tempScope
);
// 5 faces around point 3
f3
(
3
,
9
,
4
,
tempScope
);
f3
(
3
,
4
,
2
,
tempScope
);
f3
(
3
,
2
,
6
,
tempScope
);
...
...
@@ -51,6 +59,7 @@ THREE.IcosahedronGeometry = function ( subdivisions ) {
f3
(
3
,
8
,
9
,
tempScope
);
// 5 adjacent faces
f3
(
4
,
9
,
5
,
tempScope
);
f3
(
2
,
4
,
11
,
tempScope
);
f3
(
6
,
2
,
10
,
tempScope
);
...
...
@@ -58,21 +67,31 @@ THREE.IcosahedronGeometry = function ( subdivisions ) {
f3
(
9
,
8
,
1
,
tempScope
);
// subdivide faces to refine the triangles
for
(
var
i
=
0
;
i
<
this
.
subdivisions
;
i
++
)
{
for
(
var
i
=
0
;
i
<
this
.
subdivisions
;
i
++
)
{
tempFaces
=
new
THREE
.
Geometry
();
for
(
var
tri
in
tempScope
.
faces
)
{
for
(
var
tri
=
0
;
tri
<
tempScope
.
faces
.
length
;
tri
++
)
{
// replace each triangle by 4 triangles
var
a
=
getMiddlePoint
(
tempScope
.
faces
[
tri
].
a
,
tempScope
.
faces
[
tri
].
b
);
var
b
=
getMiddlePoint
(
tempScope
.
faces
[
tri
].
b
,
tempScope
.
faces
[
tri
].
c
);
var
c
=
getMiddlePoint
(
tempScope
.
faces
[
tri
].
c
,
tempScope
.
faces
[
tri
].
a
);
f3
(
tempScope
.
faces
[
tri
].
a
,
a
,
c
,
tempFaces
);
f3
(
tempScope
.
faces
[
tri
].
b
,
b
,
a
,
tempFaces
);
f3
(
tempScope
.
faces
[
tri
].
c
,
c
,
b
,
tempFaces
);
f3
(
a
,
b
,
c
,
tempFaces
);
var
face
=
tempScope
.
faces
[
tri
];
var
a
=
getMiddlePoint
(
face
.
a
,
face
.
b
);
var
b
=
getMiddlePoint
(
face
.
b
,
face
.
c
);
var
c
=
getMiddlePoint
(
face
.
c
,
face
.
a
);
f3
(
face
.
a
,
a
,
c
,
tempFaces
);
f3
(
face
.
b
,
b
,
a
,
tempFaces
);
f3
(
face
.
c
,
c
,
b
,
tempFaces
);
f3
(
a
,
b
,
c
,
tempFaces
);
}
tempScope
.
faces
=
tempFaces
.
faces
;
tempScope
.
faceVertexUvs
[
0
]
=
tempFaces
.
faceVertexUvs
[
0
];
}
scope
.
faces
=
tempScope
.
faces
;
...
...
@@ -84,7 +103,7 @@ THREE.IcosahedronGeometry = function ( subdivisions ) {
function
v
(
x
,
y
,
z
)
{
var
length
=
Math
.
sqrt
(
x
*
x
+
y
*
y
+
z
*
z
);
var
length
=
Math
.
sqrt
(
x
*
x
+
y
*
y
+
z
*
z
);
var
i
=
scope
.
vertices
.
push
(
new
THREE
.
Vertex
(
new
THREE
.
Vector3
(
x
/
length
,
y
/
length
,
z
/
length
)
)
);
return
i
-
1
;
...
...
@@ -109,16 +128,18 @@ THREE.IcosahedronGeometry = function ( subdivisions ) {
}
function
getMiddlePoint
(
p1
,
p2
)
{
var
pos1
=
scope
.
vertices
[
p1
].
position
;
var
pos2
=
scope
.
vertices
[
p2
].
position
;
function
getMiddlePoint
(
p1
,
p2
)
{
var
x
=
(
pos1
.
x
+
pos2
.
x
)
/
2
;
var
y
=
(
pos1
.
y
+
pos2
.
y
)
/
2
;
var
z
=
(
pos1
.
z
+
pos2
.
z
)
/
2
;
var
pos1
=
scope
.
vertices
[
p1
].
position
;
var
pos2
=
scope
.
vertices
[
p2
].
position
;
var
x
=
(
pos1
.
x
+
pos2
.
x
)
/
2
;
var
y
=
(
pos1
.
y
+
pos2
.
y
)
/
2
;
var
z
=
(
pos1
.
z
+
pos2
.
z
)
/
2
;
var
i
=
v
(
x
,
y
,
z
);
return
i
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录