Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
418a6da7
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,发现更多精彩内容 >>
提交
418a6da7
编写于
2月 02, 2011
作者:
A
alteredq
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Moved convolution shader from example into ShaderUtils.
上级
1d9c3405
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
281 addition
and
246 deletion
+281
-246
build/ThreeExtras.js
build/ThreeExtras.js
+7
-6
examples/postprocessing.html
examples/postprocessing.html
+12
-86
src/extras/ShaderUtils.js
src/extras/ShaderUtils.js
+262
-154
未找到文件。
build/ThreeExtras.js
浏览文件 @
418a6da7
...
...
@@ -227,12 +227,13 @@ vertex_shader:"uniform float mRefractionRatio;\nuniform float mFresnelBias;\nuni
normal
:{
uniforms
:{
enableAO
:{
type
:
"
i
"
,
value
:
0
},
enableDiffuse
:{
type
:
"
i
"
,
value
:
0
},
tDiffuse
:{
type
:
"
t
"
,
value
:
0
,
texture
:
null
},
tNormal
:{
type
:
"
t
"
,
value
:
2
,
texture
:
null
},
tAO
:{
type
:
"
t
"
,
value
:
3
,
texture
:
null
},
uNormalScale
:{
type
:
"
f
"
,
value
:
1
},
tDisplacement
:{
type
:
"
t
"
,
value
:
4
,
texture
:
null
},
uDisplacementBias
:{
type
:
"
f
"
,
value
:
-
0.5
},
uDisplacementScale
:{
type
:
"
f
"
,
value
:
2.5
},
uPointLightPos
:{
type
:
"
v3
"
,
value
:
new
THREE
.
Vector3
},
uPointLightColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
15658734
)},
uDirLightPos
:{
type
:
"
v3
"
,
value
:
new
THREE
.
Vector3
},
uDirLightColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
15658734
)},
uAmbientLightColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
328965
)},
uDiffuseColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
15658734
)},
uSpecularColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
1118481
)},
uAmbientColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
328965
)},
uShininess
:{
type
:
"
f
"
,
value
:
30
}},
fragment_shader
:
"
uniform vec3 uDirLightPos;
\n
uniform vec3 uAmbientLightColor;
\n
uniform vec3 uDirLightColor;
\n
uniform vec3 uPointLightColor;
\n
uniform vec3 uAmbientColor;
\n
uniform vec3 uDiffuseColor;
\n
uniform vec3 uSpecularColor;
\n
uniform float uShininess;
\n
uniform bool enableDiffuse;
\n
uniform bool enableAO;
\n
uniform sampler2D tDiffuse;
\n
uniform sampler2D tNormal;
\n
uniform sampler2D tAO;
\n
uniform float uNormalScale;
\n
varying vec3 vTangent;
\n
varying vec3 vBinormal;
\n
varying vec3 vNormal;
\n
varying vec2 vUv;
\n
varying vec3 vPointLightVector;
\n
varying vec3 vViewPosition;
\n
void main() {
\n
vec3 diffuseTex = vec3( 1.0, 1.0, 1.0 );
\n
vec3 aoTex = vec3( 1.0, 1.0, 1.0 );
\n
vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;
\n
normalTex.xy *= uNormalScale;
\n
normalTex = normalize( normalTex );
\n
if( enableDiffuse )
\n
diffuseTex = texture2D( tDiffuse, vUv ).xyz;
\n
if( enableAO )
\n
aoTex = texture2D( tAO, vUv ).xyz;
\n
mat3 tsb = mat3( vTangent, vBinormal, vNormal );
\n
vec3 finalNormal = tsb * normalTex;
\n
vec3 normal = normalize( finalNormal );
\n
vec3 viewPosition = normalize( vViewPosition );
\n
vec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );
\n
vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );
\n
vec3 pointVector = normalize( vPointLightVector );
\n
vec3 pointHalfVector = normalize( vPointLightVector + vViewPosition );
\n
float pointDotNormalHalf = dot( normal, pointHalfVector );
\n
float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );
\n
float pointSpecularWeight = 0.0;
\n
if ( pointDotNormalHalf >= 0.0 )
\n
pointSpecularWeight = pow( pointDotNormalHalf, uShininess );
\n
pointDiffuse += vec4( uDiffuseColor, 1.0 ) * pointDiffuseWeight;
\n
pointSpecular += vec4( uSpecularColor, 1.0 ) * pointSpecularWeight;
\n
vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );
\n
vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );
\n
vec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );
\n
vec3 dirVector = normalize( lDirection.xyz );
\n
vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );
\n
float dirDotNormalHalf = dot( normal, dirHalfVector );
\n
float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );
\n
float dirSpecularWeight = 0.0;
\n
if ( dirDotNormalHalf >= 0.0 )
\n
dirSpecularWeight = pow( dirDotNormalHalf, uShininess );
\n
dirDiffuse += vec4( uDiffuseColor, 1.0 ) * dirDiffuseWeight;
\n
dirSpecular += vec4( uSpecularColor, 1.0 ) * dirSpecularWeight;
\n
vec4 totalLight = vec4( uAmbientLightColor * uAmbientColor, 1.0 );
\n
totalLight += vec4( uDirLightColor, 1.0 ) * ( dirDiffuse + dirSpecular );
\n
totalLight += vec4( uPointLightColor, 1.0 ) * ( pointDiffuse + pointSpecular );
\n
gl_FragColor = vec4( totalLight.xyz * aoTex * diffuseTex, 1.0 );
\n
}
"
,
vertex_shader
:
"
attribute vec4 tangent;
\n
uniform vec3 uPointLightPos;
\n
#ifdef VERTEX_TEXTURES
\n
uniform sampler2D tDisplacement;
\n
uniform float uDisplacementScale;
\n
uniform float uDisplacementBias;
\n
#endif
\n
varying vec3 vTangent;
\n
varying vec3 vBinormal;
\n
varying vec3 vNormal;
\n
varying vec2 vUv;
\n
varying vec3 vPointLightVector;
\n
varying vec3 vViewPosition;
\n
void main() {
\n
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
\n
vViewPosition = cameraPosition - mPosition.xyz;
\n
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
\n
vNormal = normalize( normalMatrix * normal );
\n
vTangent = normalize( normalMatrix * tangent.xyz );
\n
vBinormal = cross( vNormal, vTangent ) * tangent.w;
\n
vBinormal = normalize( vBinormal );
\n
vUv = uv;
\n
vec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );
\n
vPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );
\n
#ifdef VERTEX_TEXTURES
\n
vec3 dv = texture2D( tDisplacement, uv ).xyz;
\n
float df = uDisplacementScale * dv.x + uDisplacementBias;
\n
vec4 displacedPosition = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;
\n
gl_Position = projectionMatrix * displacedPosition;
\n
#else
\n
gl_Position = projectionMatrix * mvPosition;
\n
#endif
\n
}
"
},
cube
:{
uniforms
:{
tCube
:{
type
:
"
t
"
,
value
:
1
,
texture
:
null
}},
vertex_shader
:
"
varying vec3 vViewPosition;
\n
void main() {
\n
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
\n
vViewPosition = cameraPosition - mPosition.xyz;
\n
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
\n
}
"
,
fragment_shader
:
"
uniform samplerCube tCube;
\n
varying vec3 vViewPosition;
\n
void main() {
\n
vec3 wPos = cameraPosition - vViewPosition;
\n
gl_FragColor = textureCube( tCube, vec3( - wPos.x, wPos.yz ) );
\n
}
"
},
basic
:{
uniforms
:{},
vertex_shader
:
"
void main() {
\n
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
\n
}
"
,
fragment_shader
:
"
void main() {
\n
gl_FragColor = vec4(1.0, 0.0, 0.0, 0.5);
\n
}
"
}}},
Cube
=
function
(
a
,
c
,
d
,
e
,
g
,
b
,
l
,
j
){
function
h
(
B
,
G
,
t
,
k
,
f
,
m
,
n
,
C
){
var
w
,
p
,
F
=
e
||
1
,
y
=
g
||
1
,
J
=
F
+
1
,
E
=
y
+
1
,
A
=
f
/
2
,
M
=
m
/
2
;
f
=
f
/
F
;
var
aa
=
m
/
y
,
N
=
o
.
vertices
.
length
;
if
(
B
==
"
x
"
&&
G
==
"
y
"
||
B
==
"
y
"
&&
G
==
"
x
"
)
w
=
"
z
"
;
else
if
(
B
==
"
x
"
&&
G
==
"
z
"
||
B
==
"
z
"
&&
G
==
"
x
"
)
w
=
"
y
"
;
else
if
(
B
==
"
z
"
&&
G
==
"
y
"
||
B
==
"
y
"
&&
G
==
"
z
"
)
w
=
"
x
"
;
for
(
p
=
0
;
p
<
E
;
p
++
)
for
(
m
=
0
;
m
<
J
;
m
++
){
var
U
=
new
THREE
.
Vector3
;
U
[
B
]
=
(
m
*
f
-
A
)
*
t
;
U
[
G
]
=
(
p
*
aa
-
M
)
*
k
;
U
[
w
]
=
n
;
o
.
vertices
.
push
(
new
THREE
.
Vertex
(
U
))}
for
(
p
=
0
;
p
<
y
;
p
++
)
for
(
m
=
0
;
m
<
F
;
m
++
){
o
.
faces
.
push
(
new
THREE
.
Face4
(
m
+
J
*
p
+
N
,
m
+
J
*
(
p
+
1
)
+
N
,
m
+
1
+
J
*
(
p
+
1
)
+
N
,
m
+
1
+
J
*
p
+
N
,
null
,
C
));
o
.
uvs
.
push
([
new
THREE
.
UV
(
m
/
F
,
p
/
y
),
new
THREE
.
UV
(
m
/
F
,(
p
+
1
)
/
y
),
new
THREE
.
UV
((
m
+
1
)
/
F
,(
p
+
1
)
/
y
),
new
THREE
.
UV
((
m
+
1
)
/
F
,
p
/
y
)])}}
THREE
.
Geometry
.
call
(
this
);
var
o
=
this
,
v
=
a
/
2
,
z
=
c
/
2
,
u
=
d
/
2
;
l
=
l
?
-
1
:
1
;
if
(
b
!==
undefined
)
if
(
b
instanceof
Array
)
this
.
materials
=
b
;
else
{
this
.
materials
=
[];
for
(
var
q
=
0
;
q
<
6
;
q
++
)
this
.
materials
.
push
([
b
])}
else
this
.
materials
=
[];
this
.
sides
=
{
px
:
true
,
nx
:
true
,
py
:
true
,
ny
:
true
,
pz
:
true
,
nz
:
true
};
if
(
j
!=
undefined
)
for
(
var
x
in
j
)
if
(
this
.
sides
[
x
]
!=
undefined
)
this
.
sides
[
x
]
=
j
[
x
];
this
.
sides
.
px
&&
h
(
"
z
"
,
"
y
"
,
1
*
l
,
-
1
,
d
,
c
,
-
v
,
this
.
materials
[
0
]);
this
.
sides
.
nx
&&
h
(
"
z
"
,
"
y
"
,
-
1
*
l
,
-
1
,
d
,
c
,
v
,
this
.
materials
[
1
]);
this
.
sides
.
py
&&
h
(
"
x
"
,
"
z
"
,
1
*
l
,
1
,
a
,
d
,
z
,
this
.
materials
[
2
]);
this
.
sides
.
ny
&&
h
(
"
x
"
,
"
z
"
,
1
*
l
,
-
1
,
a
,
d
,
-
z
,
this
.
materials
[
3
]);
this
.
sides
.
pz
&&
h
(
"
x
"
,
"
y
"
,
1
*
l
,
-
1
,
a
,
c
,
u
,
this
.
materials
[
4
]);
this
.
sides
.
nz
&&
h
(
"
x
"
,
"
y
"
,
-
1
*
l
,
-
1
,
a
,
c
,
-
u
,
this
.
materials
[
5
]);(
function
(){
for
(
var
B
=
[],
G
=
[],
t
=
0
,
k
=
o
.
vertices
.
length
;
t
<
k
;
t
++
){
for
(
var
f
=
o
.
vertices
[
t
],
m
=
false
,
n
=
0
,
C
=
B
.
length
;
n
<
C
;
n
++
){
var
w
=
B
[
n
];
if
(
f
.
position
.
x
==
w
.
position
.
x
&&
f
.
position
.
y
==
w
.
position
.
y
&&
f
.
position
.
z
==
w
.
position
.
z
){
G
[
t
]
=
n
;
m
=
true
;
break
}}
if
(
!
m
){
G
[
t
]
=
B
.
length
;
B
.
push
(
new
THREE
.
Vertex
(
f
.
position
.
clone
()))}}
t
=
0
;
for
(
k
=
o
.
faces
.
length
;
t
<
k
;
t
++
){
f
=
o
.
faces
[
t
];
f
.
a
=
G
[
f
.
a
];
f
.
b
=
G
[
f
.
b
];
f
.
c
=
G
[
f
.
c
];
f
.
d
=
G
[
f
.
d
]}
o
.
vertices
=
B
})();
this
.
computeCentroids
();
this
.
computeFaceNormals
();
this
.
sortFacesByMaterial
()};
Cube
.
prototype
=
new
THREE
.
Geometry
;
Cube
.
prototype
.
constructor
=
Cube
;
cube
:{
uniforms
:{
tCube
:{
type
:
"
t
"
,
value
:
1
,
texture
:
null
}},
vertex_shader
:
"
varying vec3 vViewPosition;
\n
void main() {
\n
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
\n
vViewPosition = cameraPosition - mPosition.xyz;
\n
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
\n
}
"
,
fragment_shader
:
"
uniform samplerCube tCube;
\n
varying vec3 vViewPosition;
\n
void main() {
\n
vec3 wPos = cameraPosition - vViewPosition;
\n
gl_FragColor = textureCube( tCube, vec3( - wPos.x, wPos.yz ) );
\n
}
"
},
convolution
:{
uniforms
:{
tDiffuse
:{
type
:
"
t
"
,
value
:
0
,
texture
:
null
},
uImageIncrement
:{
type
:
"
v2
"
,
value
:
new
THREE
.
Vector2
(
0.001953125
,
0
)},
cKernel
:{
type
:
"
fv1
"
,
value
:[]}},
vertex_shader
:
"
varying vec2 vUv;
\n
uniform vec2 uImageIncrement;
\n
#define KERNEL_SIZE 25.0
\n
void main(void) {
\n
vUv = uv - ((KERNEL_SIZE - 1.0) / 2.0) * uImageIncrement;
\n
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
\n
}
"
,
fragment_shader
:
"
varying vec2 vUv;
\n
uniform sampler2D tDiffuse;
\n
uniform vec2 uImageIncrement;
\n
#define KERNEL_SIZE 25
\n
uniform float cKernel[KERNEL_SIZE];
\n
void main(void) {
\n
vec2 imageCoord = vUv;
\n
vec4 sum = vec4( 0.0, 0.0, 0.0, 0.0 );
\n
for( int i=0; i<KERNEL_SIZE; ++i ) {
\n
sum += texture2D( tDiffuse, imageCoord ) * cKernel[i];
\n
imageCoord += uImageIncrement;
\n
}
\n
gl_FragColor = sum;
\n
}
"
},
basic
:{
uniforms
:{},
vertex_shader
:
"
void main() {
\n
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
\n
}
"
,
fragment_shader
:
"
void main() {
\n
gl_FragColor = vec4(1.0, 0.0, 0.0, 0.5);
\n
}
"
}},
buildKernel
:
function
(
a
){
var
c
,
d
,
e
,
g
,
b
=
2
*
Math
.
ceil
(
a
*
3
)
+
1
;
if
(
b
>
25
)
b
=
25
;
g
=
(
b
-
1
)
*
0.5
;
d
=
Array
(
b
);
for
(
c
=
e
=
0
;
c
<
b
;
++
c
){
d
[
c
]
=
Math
.
exp
(
-
((
c
-
g
)
*
(
c
-
g
))
/
(
2
*
a
*
a
));
e
+=
d
[
c
]}
for
(
c
=
0
;
c
<
b
;
++
c
)
d
[
c
]
/=
e
;
return
d
}},
Cube
=
function
(
a
,
c
,
d
,
e
,
g
,
b
,
l
,
j
){
function
h
(
B
,
G
,
t
,
k
,
f
,
m
,
n
,
C
){
var
w
,
p
,
F
=
e
||
1
,
y
=
g
||
1
,
J
=
F
+
1
,
E
=
y
+
1
,
A
=
f
/
2
,
M
=
m
/
2
;
f
=
f
/
F
;
var
aa
=
m
/
y
,
N
=
o
.
vertices
.
length
;
if
(
B
==
"
x
"
&&
G
==
"
y
"
||
B
==
"
y
"
&&
G
==
"
x
"
)
w
=
"
z
"
;
else
if
(
B
==
"
x
"
&&
G
==
"
z
"
||
B
==
"
z
"
&&
G
==
"
x
"
)
w
=
"
y
"
;
else
if
(
B
==
"
z
"
&&
G
==
"
y
"
||
B
==
"
y
"
&&
G
==
"
z
"
)
w
=
"
x
"
;
for
(
p
=
0
;
p
<
E
;
p
++
)
for
(
m
=
0
;
m
<
J
;
m
++
){
var
U
=
new
THREE
.
Vector3
;
U
[
B
]
=
(
m
*
f
-
A
)
*
t
;
U
[
G
]
=
(
p
*
aa
-
M
)
*
k
;
U
[
w
]
=
n
;
o
.
vertices
.
push
(
new
THREE
.
Vertex
(
U
))}
for
(
p
=
0
;
p
<
y
;
p
++
)
for
(
m
=
0
;
m
<
F
;
m
++
){
o
.
faces
.
push
(
new
THREE
.
Face4
(
m
+
J
*
p
+
N
,
m
+
J
*
(
p
+
1
)
+
N
,
m
+
1
+
J
*
(
p
+
1
)
+
N
,
m
+
1
+
J
*
p
+
N
,
null
,
C
));
o
.
uvs
.
push
([
new
THREE
.
UV
(
m
/
F
,
p
/
y
),
new
THREE
.
UV
(
m
/
F
,(
p
+
1
)
/
y
),
new
THREE
.
UV
((
m
+
1
)
/
F
,(
p
+
1
)
/
y
),
new
THREE
.
UV
((
m
+
1
)
/
F
,
p
/
y
)])}}
THREE
.
Geometry
.
call
(
this
);
var
o
=
this
,
v
=
a
/
2
,
z
=
c
/
2
,
u
=
d
/
2
;
l
=
l
?
-
1
:
1
;
if
(
b
!==
undefined
)
if
(
b
instanceof
Array
)
this
.
materials
=
b
;
else
{
this
.
materials
=
[];
for
(
var
q
=
0
;
q
<
6
;
q
++
)
this
.
materials
.
push
([
b
])}
else
this
.
materials
=
[];
this
.
sides
=
{
px
:
true
,
nx
:
true
,
py
:
true
,
ny
:
true
,
pz
:
true
,
nz
:
true
};
if
(
j
!=
undefined
)
for
(
var
x
in
j
)
if
(
this
.
sides
[
x
]
!=
undefined
)
this
.
sides
[
x
]
=
j
[
x
];
this
.
sides
.
px
&&
h
(
"
z
"
,
"
y
"
,
1
*
l
,
-
1
,
d
,
c
,
-
v
,
this
.
materials
[
0
]);
this
.
sides
.
nx
&&
h
(
"
z
"
,
"
y
"
,
-
1
*
l
,
-
1
,
d
,
c
,
v
,
this
.
materials
[
1
]);
this
.
sides
.
py
&&
h
(
"
x
"
,
"
z
"
,
1
*
l
,
1
,
a
,
d
,
z
,
this
.
materials
[
2
]);
this
.
sides
.
ny
&&
h
(
"
x
"
,
"
z
"
,
1
*
l
,
-
1
,
a
,
d
,
-
z
,
this
.
materials
[
3
]);
this
.
sides
.
pz
&&
h
(
"
x
"
,
"
y
"
,
1
*
l
,
-
1
,
a
,
c
,
u
,
this
.
materials
[
4
]);
this
.
sides
.
nz
&&
h
(
"
x
"
,
"
y
"
,
-
1
*
l
,
-
1
,
a
,
c
,
-
u
,
this
.
materials
[
5
]);(
function
(){
for
(
var
B
=
[],
G
=
[],
t
=
0
,
k
=
o
.
vertices
.
length
;
t
<
k
;
t
++
){
for
(
var
f
=
o
.
vertices
[
t
],
m
=
false
,
n
=
0
,
C
=
B
.
length
;
n
<
C
;
n
++
){
var
w
=
B
[
n
];
if
(
f
.
position
.
x
==
w
.
position
.
x
&&
f
.
position
.
y
==
w
.
position
.
y
&&
f
.
position
.
z
==
w
.
position
.
z
){
G
[
t
]
=
n
;
m
=
true
;
break
}}
if
(
!
m
){
G
[
t
]
=
B
.
length
;
B
.
push
(
new
THREE
.
Vertex
(
f
.
position
.
clone
()))}}
t
=
0
;
for
(
k
=
o
.
faces
.
length
;
t
<
k
;
t
++
){
f
=
o
.
faces
[
t
];
f
.
a
=
G
[
f
.
a
];
f
.
b
=
G
[
f
.
b
];
f
.
c
=
G
[
f
.
c
];
f
.
d
=
G
[
f
.
d
]}
o
.
vertices
=
B
})();
this
.
computeCentroids
();
this
.
computeFaceNormals
();
this
.
sortFacesByMaterial
()};
Cube
.
prototype
=
new
THREE
.
Geometry
;
Cube
.
prototype
.
constructor
=
Cube
;
var
Cylinder
=
function
(
a
,
c
,
d
,
e
,
g
){
function
b
(
o
,
v
,
z
){
l
.
vertices
.
push
(
new
THREE
.
Vertex
(
new
THREE
.
Vector3
(
o
,
v
,
z
)))}
THREE
.
Geometry
.
call
(
this
);
var
l
=
this
,
j
=
Math
.
PI
,
h
;
for
(
h
=
0
;
h
<
a
;
h
++
)
b
(
Math
.
sin
(
2
*
j
*
h
/
a
)
*
c
,
Math
.
cos
(
2
*
j
*
h
/
a
)
*
c
,
0
);
for
(
h
=
0
;
h
<
a
;
h
++
)
b
(
Math
.
sin
(
2
*
j
*
h
/
a
)
*
d
,
Math
.
cos
(
2
*
j
*
h
/
a
)
*
d
,
e
);
for
(
h
=
0
;
h
<
a
;
h
++
)
l
.
faces
.
push
(
new
THREE
.
Face4
(
h
,
h
+
a
,
a
+
(
h
+
1
)
%
a
,(
h
+
1
)
%
a
));
if
(
d
!=
0
){
b
(
0
,
0
,
-
g
);
for
(
h
=
a
;
h
<
a
+
a
/
2
;
h
++
)
l
.
faces
.
push
(
new
THREE
.
Face4
(
2
*
a
,(
2
*
h
-
2
*
a
)
%
a
,(
2
*
h
-
2
*
a
+
1
)
%
a
,(
2
*
h
-
2
*
a
+
2
)
%
a
))}
if
(
c
!=
0
){
b
(
0
,
0
,
e
+
g
);
for
(
h
=
a
+
a
/
2
;
h
<
2
*
a
;
h
++
)
l
.
faces
.
push
(
new
THREE
.
Face4
((
2
*
h
-
2
*
a
+
2
)
%
a
+
a
,(
2
*
h
-
2
*
a
+
1
)
%
a
+
a
,(
2
*
h
-
2
*
a
)
%
a
+
a
,
2
*
a
+
1
))}
this
.
computeCentroids
();
this
.
computeFaceNormals
();
this
.
sortFacesByMaterial
()};
Cylinder
.
prototype
=
new
THREE
.
Geometry
;
Cylinder
.
prototype
.
constructor
=
Cylinder
;
var
Plane
=
function
(
a
,
c
,
d
,
e
){
THREE
.
Geometry
.
call
(
this
);
var
g
,
b
=
a
/
2
,
l
=
c
/
2
;
d
=
d
||
1
;
e
=
e
||
1
;
var
j
=
d
+
1
,
h
=
e
+
1
;
a
=
a
/
d
;
var
o
=
c
/
e
;
for
(
g
=
0
;
g
<
h
;
g
++
)
for
(
c
=
0
;
c
<
j
;
c
++
)
this
.
vertices
.
push
(
new
THREE
.
Vertex
(
new
THREE
.
Vector3
(
c
*
a
-
b
,
-
(
g
*
o
-
l
),
0
)));
for
(
g
=
0
;
g
<
e
;
g
++
)
for
(
c
=
0
;
c
<
d
;
c
++
){
this
.
faces
.
push
(
new
THREE
.
Face4
(
c
+
j
*
g
,
c
+
j
*
(
g
+
1
),
c
+
1
+
j
*
(
g
+
1
),
c
+
1
+
j
*
g
));
this
.
uvs
.
push
([
new
THREE
.
UV
(
c
/
d
,
g
/
e
),
new
THREE
.
UV
(
c
/
d
,(
g
+
1
)
/
e
),
new
THREE
.
UV
((
c
+
1
)
/
d
,(
g
+
1
)
/
e
),
new
THREE
.
UV
((
c
+
1
)
/
d
,
g
/
e
)])}
this
.
computeCentroids
();
this
.
computeFaceNormals
();
this
.
sortFacesByMaterial
()};
...
...
examples/postprocessing.html
浏览文件 @
418a6da7
...
...
@@ -66,48 +66,6 @@
<script
type=
"text/javascript"
src=
"js/Stats.js"
></script>
<script
type=
"text/javascript"
src=
"../build/ThreeExtras.js"
></script>
<!-- -----------------------------------------------------------------
Convolution shader
- ported from o3d sample to WebGL / GLSL
http://o3d.googlecode.com/svn/trunk/samples/convolution.html
----------------------------------------------------------------- ->
<!-- Convolution fragment shader -->
<script
id=
"fs-convolution"
type=
"x-shader/x-fragment"
>
varying
vec2
vUv
;
uniform
sampler2D
tDiffuse
;
uniform
vec2
uImageIncrement
;
#
define
KERNEL_SIZE
25
uniform
float
cKernel
[
KERNEL_SIZE
];
void
main
(
void
)
{
vec2
imageCoord
=
vUv
;
vec4
sum
=
vec4
(
0.0
,
0.0
,
0.0
,
0.0
);
for
(
int
i
=
0
;
i
<
KERNEL_SIZE
;
++
i
)
{
sum
+=
texture2D
(
tDiffuse
,
imageCoord
)
*
cKernel
[
i
];
imageCoord
+=
uImageIncrement
;
}
gl_FragColor
=
sum
;
}
</script>
<!-- Convolution vertex shader -->
<script
id=
"vs-convolution"
type=
"x-shader/x-vertex"
>
varying
vec2
vUv
;
uniform
vec2
uImageIncrement
;
#
define
KERNEL_SIZE
25.0
void
main
(
void
)
{
//vUv = vec2( uv.x, 1.0 - uv.y ) - ((KERNEL_SIZE - 1.0) / 2.0) * uImageIncrement;
vUv
=
uv
-
((
KERNEL_SIZE
-
1.0
)
/
2.0
)
*
uImageIncrement
;
gl_Position
=
projectionMatrix
*
modelViewMatrix
*
vec4
(
position
,
1.0
);
}
</script>
<!-- -----------------------------------------------------------------
Film grain & scanlines shader
- ported from HLSL to WebGL / GLSL
...
...
@@ -282,19 +240,23 @@
}
);
var
kernel
=
buildKernel
(
4.0
),
increment
=
0.001953125
;
var
increment
=
0.001953125
;
blurx
=
new
THREE
.
Vector2
(
increment
,
0.0
),
blury
=
new
THREE
.
Vector2
(
0.0
,
increment
);
var
shader
=
ShaderUtils
.
lib
[
"
convolution
"
];
var
uniforms
=
Uniforms
.
clone
(
shader
.
uniforms
);
uniforms
[
"
tDiffuse
"
].
texture
=
rtTexture1
;
uniforms
[
"
uImageIncrement
"
].
value
=
blurx
;
uniforms
[
"
cKernel
"
].
value
=
ShaderUtils
.
buildKernel
(
4.0
);
materialConvolution
=
new
THREE
.
MeshShaderMaterial
(
{
uniforms
:
{
tDiffuse
:
{
type
:
"
t
"
,
value
:
0
,
texture
:
rtTexture1
},
uImageIncrement
:
{
type
:
"
v2
"
,
value
:
blury
},
cKernel
:
{
type
:
"
fv1
"
,
value
:
kernel
}
},
vertex_shader
:
document
.
getElementById
(
'
vs-convolution
'
).
textContent
,
fragment_shader
:
document
.
getElementById
(
'
fs-convolution
'
).
textContent
uniforms
:
uniforms
,
vertex_shader
:
shader
.
vertex_shader
,
fragment_shader
:
shader
.
fragment_shader
}
);
...
...
@@ -375,42 +337,6 @@
}
/*****************************************************************************************/
// Convolution
// - ported from o3d convolution shader sample
// http://o3d.googlecode.com/svn/trunk/samples/convolution.html
/*****************************************************************************************/
// We lop off the sqrt(2 * pi) * sigma term, since we're going to normalize anyway.
function
gauss
(
x
,
sigma
)
{
return
Math
.
exp
(
-
(
x
*
x
)
/
(
2.0
*
sigma
*
sigma
)
);
}
function
buildKernel
(
sigma
)
{
var
kMaxKernelSize
=
25
;
var
kernelSize
=
2
*
Math
.
ceil
(
sigma
*
3.0
)
+
1
;
if
(
kernelSize
>
kMaxKernelSize
)
kernelSize
=
kMaxKernelSize
;
var
halfWidth
=
(
kernelSize
-
1
)
*
0.5
var
values
=
new
Array
(
kernelSize
);
var
sum
=
0.0
;
for
(
var
i
=
0
;
i
<
kernelSize
;
++
i
)
{
values
[
i
]
=
gauss
(
i
-
halfWidth
,
sigma
);
sum
+=
values
[
i
];
}
// normalize the kernel
for
(
var
i
=
0
;
i
<
kernelSize
;
++
i
)
values
[
i
]
/=
sum
;
return
values
;
}
var
delta
=
0.01
;
var
start
=
0
;
...
...
src/extras/ShaderUtils.js
浏览文件 @
418a6da7
var
ShaderUtils
=
{
lib
:
{
'
fresnel
'
:
{
lib
:
{
/* -------------------------------------------------------------------------
Fresnel shader
- based on Nvidia Cg tutorial
------------------------------------------------------------------------- */
'
fresnel
'
:
{
uniforms
:
{
...
...
@@ -66,6 +73,13 @@ var ShaderUtils = {
},
/* -------------------------------------------------------------------------
Normal map shader
- Blinn-Phong
- normal + diffuse + AO + displacement maps
- 1 point and 1 directional lights
------------------------------------------------------------------------- */
'
normal
'
:
{
uniforms
:
{
...
...
@@ -263,6 +277,10 @@ var ShaderUtils = {
},
/* -------------------------------------------------------------------------
Cube map shader
------------------------------------------------------------------------- */
'
cube
'
:
{
uniforms
:
{
"
tCube
"
:
{
type
:
"
t
"
,
value
:
1
,
texture
:
null
}
},
...
...
@@ -299,6 +317,64 @@ var ShaderUtils = {
},
/* ------------------------------------------------------------------------
Convolution shader
- ported from o3d sample to WebGL / GLSL
http://o3d.googlecode.com/svn/trunk/samples/convolution.html
------------------------------------------------------------------------ */
'
convolution
'
:
{
uniforms
:
{
"
tDiffuse
"
:
{
type
:
"
t
"
,
value
:
0
,
texture
:
null
},
"
uImageIncrement
"
:
{
type
:
"
v2
"
,
value
:
new
THREE
.
Vector2
(
0.001953125
,
0.0
)
},
"
cKernel
"
:
{
type
:
"
fv1
"
,
value
:
[]
}
},
vertex_shader
:
[
"
varying vec2 vUv;
"
,
"
uniform vec2 uImageIncrement;
"
,
"
#define KERNEL_SIZE 25.0
"
,
"
void main(void) {
"
,
"
vUv = uv - ((KERNEL_SIZE - 1.0) / 2.0) * uImageIncrement;
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
}
"
].
join
(
"
\n
"
),
fragment_shader
:
[
"
varying vec2 vUv;
"
,
"
uniform sampler2D tDiffuse;
"
,
"
uniform vec2 uImageIncrement;
"
,
"
#define KERNEL_SIZE 25
"
,
"
uniform float cKernel[KERNEL_SIZE];
"
,
"
void main(void) {
"
,
"
vec2 imageCoord = vUv;
"
,
"
vec4 sum = vec4( 0.0, 0.0, 0.0, 0.0 );
"
,
"
for( int i=0; i<KERNEL_SIZE; ++i ) {
"
,
"
sum += texture2D( tDiffuse, imageCoord ) * cKernel[i];
"
,
"
imageCoord += uImageIncrement;
"
,
"
}
"
,
"
gl_FragColor = sum;
"
,
"
}
"
].
join
(
"
\n
"
)
},
/* -------------------------------------------------------------------------
Simple test shader
------------------------------------------------------------------------- */
'
basic
'
:
{
uniforms
:
{},
...
...
@@ -325,6 +401,38 @@ var ShaderUtils = {
}
},
buildKernel
:
function
(
sigma
)
{
// We lop off the sqrt(2 * pi) * sigma term, since we're going to normalize anyway.
function
gauss
(
x
,
sigma
)
{
return
Math
.
exp
(
-
(
x
*
x
)
/
(
2.0
*
sigma
*
sigma
)
);
}
var
i
,
values
,
sum
,
halfWidth
,
kMaxKernelSize
=
25
,
kernelSize
=
2
*
Math
.
ceil
(
sigma
*
3.0
)
+
1
;
if
(
kernelSize
>
kMaxKernelSize
)
kernelSize
=
kMaxKernelSize
;
halfWidth
=
(
kernelSize
-
1
)
*
0.5
values
=
new
Array
(
kernelSize
);
sum
=
0.0
;
for
(
i
=
0
;
i
<
kernelSize
;
++
i
)
{
values
[
i
]
=
gauss
(
i
-
halfWidth
,
sigma
);
sum
+=
values
[
i
];
}
// normalize the kernel
for
(
i
=
0
;
i
<
kernelSize
;
++
i
)
values
[
i
]
/=
sum
;
return
values
;
}
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录