Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
3faf6566
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,发现更多精彩内容 >>
提交
3faf6566
编写于
12月 18, 2010
作者:
A
alteredq
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Experimenting with Fresnel demo using just MeshShaderMaterials.
Instant performance boost by 50% ;).
上级
d14ed35a
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
71 addition
and
15 deletion
+71
-15
build/Three.js
build/Three.js
+2
-2
build/ThreeDebug.js
build/ThreeDebug.js
+2
-2
build/ThreeExtras.js
build/ThreeExtras.js
+10
-8
examples/materials_shaders_fresnel.html
examples/materials_shaders_fresnel.html
+2
-1
src/extras/SceneUtils.js
src/extras/SceneUtils.js
+18
-0
src/extras/ShaderUtils.js
src/extras/ShaderUtils.js
+36
-0
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+1
-2
未找到文件。
build/Three.js
浏览文件 @
3faf6566
...
...
@@ -133,7 +133,7 @@ q.setAttribute("y1",N.positionScreen.y);q.setAttribute("x2",S.positionScreen.x);
-
A
;
u
.
positionScreen
.
x
*=
B
;
u
.
positionScreen
.
y
*=-
A
;
G
.
positionScreen
.
x
*=
B
;
G
.
positionScreen
.
y
*=-
A
;
I
.
addPoint
(
v
.
positionScreen
.
x
,
v
.
positionScreen
.
y
);
I
.
addPoint
(
u
.
positionScreen
.
x
,
u
.
positionScreen
.
y
);
I
.
addPoint
(
G
.
positionScreen
.
x
,
G
.
positionScreen
.
y
);
if
(
J
.
instersects
(
I
)){
y
=
0
;
for
(
r
=
M
.
meshMaterial
.
length
;
y
<
r
;){
T
=
M
.
meshMaterial
[
y
++
];
if
(
T
instanceof
THREE
.
MeshFaceMaterial
){
N
=
0
;
for
(
S
=
M
.
faceMaterial
.
length
;
N
<
S
;)(
T
=
M
.
faceMaterial
[
N
++
])
&&
b
(
v
,
u
,
G
,
M
,
T
,
P
)}
else
T
&&
b
(
v
,
u
,
G
,
M
,
T
,
P
)}}}
else
if
(
M
instanceof
THREE
.
RenderableFace4
){
v
=
M
.
v1
;
u
=
M
.
v2
;
G
=
M
.
v3
;
L
=
M
.
v4
;
v
.
positionScreen
.
x
*=
B
;
v
.
positionScreen
.
y
*=-
A
;
u
.
positionScreen
.
x
*=
B
;
u
.
positionScreen
.
y
*=-
A
;
G
.
positionScreen
.
x
*=
B
;
G
.
positionScreen
.
y
*=-
A
;
L
.
positionScreen
.
x
*=
B
;
L
.
positionScreen
.
y
*=-
A
;
I
.
addPoint
(
v
.
positionScreen
.
x
,
v
.
positionScreen
.
y
);
I
.
addPoint
(
u
.
positionScreen
.
x
,
u
.
positionScreen
.
y
);
I
.
addPoint
(
G
.
positionScreen
.
x
,
G
.
positionScreen
.
y
);
I
.
addPoint
(
L
.
positionScreen
.
x
,
L
.
positionScreen
.
y
);
if
(
J
.
instersects
(
I
)){
y
=
0
;
for
(
r
=
M
.
meshMaterial
.
length
;
y
<
r
;){
T
=
M
.
meshMaterial
[
y
++
];
if
(
T
instanceof
THREE
.
MeshFaceMaterial
){
N
=
0
;
for
(
S
=
M
.
faceMaterial
.
length
;
N
<
S
;)(
T
=
M
.
faceMaterial
[
N
++
])
&&
g
(
v
,
u
,
G
,
L
,
M
,
T
,
P
)}
else
T
&&
g
(
v
,
u
,
G
,
L
,
M
,
T
,
P
)}}}}}};
THREE
.
WebGLRenderer
=
function
(
a
){
function
b
(
f
,
m
){
var
d
=
c
.
createProgram
(),
p
=
[
c
.
getParameter
(
c
.
MAX_VERTEX_TEXTURE_IMAGE_UNITS
)
>
0
?
"
#define VERTEX_TEXTURES
"
:
""
,
"
uniform mat4 objectMatrix;
\n
uniform mat4 modelViewMatrix;
\n
uniform mat4 projectionMatrix;
\n
uniform mat4 viewMatrix;
\n
uniform mat3 normalMatrix;
\n
uniform vec3 cameraPosition;
\n
attribute vec3 position;
\n
attribute vec3 normal;
\n
attribute vec2 uv;
\n
"
].
join
(
"
\n
"
);
c
.
attachShader
(
d
,
o
(
"
fragment
"
,
"
#ifdef GL_ES
\n
precision highp float;
\n
#endif
\n
uniform mat4 viewMatrix;
\n
"
+
THREE
.
WebGLRenderer
=
function
(
a
){
function
b
(
f
,
m
){
var
d
=
c
.
createProgram
(),
p
=
[
c
.
getParameter
(
c
.
MAX_VERTEX_TEXTURE_IMAGE_UNITS
)
>
0
?
"
#define VERTEX_TEXTURES
"
:
""
,
"
uniform mat4 objectMatrix;
\n
uniform mat4 modelViewMatrix;
\n
uniform mat4 projectionMatrix;
\n
uniform mat4 viewMatrix;
\n
uniform mat3 normalMatrix;
\n
uniform vec3 cameraPosition;
\n
attribute vec3 position;
\n
attribute vec3 normal;
\n
attribute vec2 uv;
\n
"
].
join
(
"
\n
"
);
c
.
attachShader
(
d
,
o
(
"
fragment
"
,
"
#ifdef GL_ES
\n
precision highp float;
\n
#endif
\n
uniform mat4 viewMatrix;
\n
uniform vec3 cameraPosition;
\n
"
+
f
));
c
.
attachShader
(
d
,
o
(
"
vertex
"
,
p
+
m
));
c
.
linkProgram
(
d
);
c
.
getProgramParameter
(
d
,
c
.
LINK_STATUS
)
||
alert
(
"
Could not initialise shaders
\n
VALIDATE_STATUS:
"
+
c
.
getProgramParameter
(
d
,
c
.
VALIDATE_STATUS
)
+
"
, gl error [
"
+
c
.
getError
()
+
"
]
"
);
d
.
uniforms
=
{};
d
.
attributes
=
{};
return
d
}
function
g
(
f
,
m
){
if
(
f
.
image
.
length
==
6
){
if
(
!
f
.
image
.
__webGLTextureCube
&&!
f
.
image
.
__cubeMapInitialized
&&
f
.
image
.
loadCount
==
6
){
f
.
image
.
__webGLTextureCube
=
c
.
createTexture
();
c
.
bindTexture
(
c
.
TEXTURE_CUBE_MAP
,
f
.
image
.
__webGLTextureCube
);
c
.
texParameteri
(
c
.
TEXTURE_CUBE_MAP
,
c
.
TEXTURE_WRAP_S
,
c
.
CLAMP_TO_EDGE
);
c
.
texParameteri
(
c
.
TEXTURE_CUBE_MAP
,
c
.
TEXTURE_WRAP_T
,
c
.
CLAMP_TO_EDGE
);
c
.
texParameteri
(
c
.
TEXTURE_CUBE_MAP
,
c
.
TEXTURE_MAG_FILTER
,
c
.
LINEAR
);
c
.
texParameteri
(
c
.
TEXTURE_CUBE_MAP
,
c
.
TEXTURE_MIN_FILTER
,
c
.
LINEAR_MIPMAP_LINEAR
);
for
(
var
d
=
0
;
d
<
6
;
++
d
)
c
.
texImage2D
(
c
.
TEXTURE_CUBE_MAP_POSITIVE_X
+
d
,
0
,
c
.
RGBA
,
c
.
RGBA
,
c
.
UNSIGNED_BYTE
,
f
.
image
[
d
]);
c
.
generateMipmap
(
c
.
TEXTURE_CUBE_MAP
);
c
.
bindTexture
(
c
.
TEXTURE_CUBE_MAP
,
null
);
f
.
image
.
__cubeMapInitialized
=
true
}
c
.
activeTexture
(
c
.
TEXTURE0
+
m
);
c
.
bindTexture
(
c
.
TEXTURE_CUBE_MAP
,
f
.
image
.
__webGLTextureCube
)}}
function
e
(
f
,
m
){
if
(
!
f
.
__webGLTexture
&&
f
.
image
.
loaded
){
f
.
__webGLTexture
=
c
.
createTexture
();
c
.
bindTexture
(
c
.
TEXTURE_2D
,
f
.
__webGLTexture
);
c
.
texImage2D
(
c
.
TEXTURE_2D
,
0
,
c
.
RGBA
,
c
.
RGBA
,
c
.
UNSIGNED_BYTE
,
f
.
image
);
c
.
texParameteri
(
c
.
TEXTURE_2D
,
c
.
TEXTURE_WRAP_S
,
l
(
f
.
wrap_s
));
c
.
texParameteri
(
c
.
TEXTURE_2D
,
c
.
TEXTURE_WRAP_T
,
l
(
f
.
wrap_t
));
c
.
texParameteri
(
c
.
TEXTURE_2D
,
c
.
TEXTURE_MAG_FILTER
,
l
(
f
.
mag_filter
));
c
.
texParameteri
(
c
.
TEXTURE_2D
,
c
.
TEXTURE_MIN_FILTER
,
l
(
f
.
min_filter
));
c
.
generateMipmap
(
c
.
TEXTURE_2D
);
...
...
@@ -146,7 +146,7 @@ c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0)
f
?
"
for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {
"
:
""
,
f
?
"
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
"
:
""
,
f
?
"
float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );
"
:
""
,
f
?
"
vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;
"
:
""
,
f
?
"
}
"
:
""
,
m
?
"
for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {
"
:
""
,
m
?
"
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
"
:
""
,
m
?
"
vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );
"
:
""
,
m
?
"
float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );
"
:
""
,
m
?
"
vLightWeighting += pointLightColor[ i ] * pointLightWeighting;
"
:
""
,
m
?
"
}
"
:
""
,
"
}
\n
vNormal = transformedNormal;
\n
vUv = uv;
\n
if ( useRefract ) {
\n
vReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );
\n
} else {
\n
vReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );
\n
}
\n
gl_Position = projectionMatrix * mvPosition;
\n
}
"
].
join
(
"
\n
"
),
p
=
[
f
?
"
#define MAX_DIR_LIGHTS
"
+
f
:
""
,
m
?
"
#define MAX_POINT_LIGHTS
"
+
m
:
""
,
"
uniform int material;
\n
uniform bool enableMap;
\n
uniform bool enableCubeMap;
\n
uniform bool mixEnvMap;
\n
uniform samplerCube tCube;
\n
uniform float mReflectivity;
\n
uniform sampler2D tMap;
\n
uniform vec4 mColor;
\n
uniform float mOpacity;
\n
uniform vec4 mAmbient;
\n
uniform vec4 mSpecular;
\n
uniform float mShininess;
\n
uniform float m2Near;
\n
uniform float mFarPlusNear;
\n
uniform float mFarMinusNear;
\n
uniform int pointLightNumber;
\n
uniform int directionalLightNumber;
"
,
f
?
"
uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
"
:
""
,
"
varying vec3 vNormal;
\n
varying vec2 vUv;
\n
varying vec3 vLightWeighting;
"
,
m
?
"
varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];
"
:
""
,
"
varying vec3 vViewPosition;
\n
varying vec3 vReflect;
\n
uniform vec3 cameraPosition;
\n
void main() {
\n
vec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );
\n
vec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );
\n
if ( enableMap ) {
\n
mapColor = texture2D( tMap, vUv );
\n
}
\n
if ( enableCubeMap ) {
\n
cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );
\n
}
\n
if ( material == 5 ) {
\n
vec3 wPos = cameraPosition - vViewPosition;
\n
gl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );
\n
} else if ( material == 4 ) {
\n
gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, mOpacity );
\n
} else if ( material == 3 ) {
\n
float w = 0.5;
\n
gl_FragColor = vec4( w, w, w, mOpacity );
\n
} else if ( material == 2 ) {
\n
vec3 normal = normalize( vNormal );
\n
vec3 viewPosition = normalize( vViewPosition );
"
,
f
?
"
uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
"
:
""
,
"
varying vec3 vNormal;
\n
varying vec2 vUv;
\n
varying vec3 vLightWeighting;
"
,
m
?
"
varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];
"
:
""
,
"
varying vec3 vViewPosition;
\n
varying vec3 vReflect;
\n
void main() {
\n
vec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );
\n
vec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );
\n
if ( enableMap ) {
\n
mapColor = texture2D( tMap, vUv );
\n
}
\n
if ( enableCubeMap ) {
\n
cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );
\n
}
\n
if ( material == 5 ) {
\n
vec3 wPos = cameraPosition - vViewPosition;
\n
gl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );
\n
} else if ( material == 4 ) {
\n
gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, mOpacity );
\n
} else if ( material == 3 ) {
\n
float w = 0.5;
\n
gl_FragColor = vec4( w, w, w, mOpacity );
\n
} else if ( material == 2 ) {
\n
vec3 normal = normalize( vNormal );
\n
vec3 viewPosition = normalize( vViewPosition );
"
,
m
?
"
vec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );
"
:
""
,
m
?
"
vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );
"
:
""
,
m
?
"
for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {
"
:
""
,
m
?
"
vec3 pointVector = normalize( vPointLightVector[ i ] );
"
:
""
,
m
?
"
vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );
"
:
""
,
m
?
"
float pointDotNormalHalf = dot( normal, pointHalfVector );
"
:
""
,
m
?
"
float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );
"
:
""
,
m
?
"
float pointSpecularWeight = 0.0;
"
:
""
,
m
?
"
if ( pointDotNormalHalf >= 0.0 )
"
:
""
,
m
?
"
pointSpecularWeight = pow( pointDotNormalHalf, mShininess );
"
:
""
,
m
?
"
pointDiffuse += mColor * pointDiffuseWeight;
"
:
""
,
m
?
"
pointSpecular += mSpecular * pointSpecularWeight;
"
:
""
,
m
?
"
}
"
:
""
,
f
?
"
vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );
"
:
""
,
f
?
"
vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );
"
:
""
,
f
?
"
for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {
"
:
""
,
f
?
"
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
"
:
""
,
f
?
"
vec3 dirVector = normalize( lDirection.xyz );
"
:
""
,
f
?
"
vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );
"
:
""
,
f
?
"
float dirDotNormalHalf = dot( normal, dirHalfVector );
"
:
""
,
f
?
"
float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );
"
:
""
,
f
?
"
float dirSpecularWeight = 0.0;
"
:
""
,
f
?
"
if ( dirDotNormalHalf >= 0.0 )
"
:
""
,
f
?
"
dirSpecularWeight = pow( dirDotNormalHalf, mShininess );
"
:
""
,
f
?
"
dirDiffuse += mColor * dirDiffuseWeight;
"
:
""
,
f
?
"
dirSpecular += mSpecular * dirSpecularWeight;
"
:
""
,
f
?
"
}
"
:
""
,
"
vec4 totalLight = mAmbient;
"
,
f
?
"
totalLight += dirDiffuse + dirSpecular;
"
:
""
,
m
?
"
totalLight += pointDiffuse + pointSpecular;
"
:
...
...
build/ThreeDebug.js
浏览文件 @
3faf6566
...
...
@@ -134,7 +134,7 @@ q.setAttribute("y1",N.positionScreen.y);q.setAttribute("x2",S.positionScreen.x);
-
A
;
v
.
positionScreen
.
x
*=
B
;
v
.
positionScreen
.
y
*=-
A
;
H
.
positionScreen
.
x
*=
B
;
H
.
positionScreen
.
y
*=-
A
;
I
.
addPoint
(
x
.
positionScreen
.
x
,
x
.
positionScreen
.
y
);
I
.
addPoint
(
v
.
positionScreen
.
x
,
v
.
positionScreen
.
y
);
I
.
addPoint
(
H
.
positionScreen
.
x
,
H
.
positionScreen
.
y
);
if
(
J
.
instersects
(
I
)){
w
=
0
;
for
(
r
=
M
.
meshMaterial
.
length
;
w
<
r
;){
T
=
M
.
meshMaterial
[
w
++
];
if
(
T
instanceof
THREE
.
MeshFaceMaterial
){
N
=
0
;
for
(
S
=
M
.
faceMaterial
.
length
;
N
<
S
;)(
T
=
M
.
faceMaterial
[
N
++
])
&&
b
(
x
,
v
,
H
,
M
,
T
,
P
)}
else
T
&&
b
(
x
,
v
,
H
,
M
,
T
,
P
)}}}
else
if
(
M
instanceof
THREE
.
RenderableFace4
){
x
=
M
.
v1
;
v
=
M
.
v2
;
H
=
M
.
v3
;
L
=
M
.
v4
;
x
.
positionScreen
.
x
*=
B
;
x
.
positionScreen
.
y
*=-
A
;
v
.
positionScreen
.
x
*=
B
;
v
.
positionScreen
.
y
*=-
A
;
H
.
positionScreen
.
x
*=
B
;
H
.
positionScreen
.
y
*=-
A
;
L
.
positionScreen
.
x
*=
B
;
L
.
positionScreen
.
y
*=-
A
;
I
.
addPoint
(
x
.
positionScreen
.
x
,
x
.
positionScreen
.
y
);
I
.
addPoint
(
v
.
positionScreen
.
x
,
v
.
positionScreen
.
y
);
I
.
addPoint
(
H
.
positionScreen
.
x
,
H
.
positionScreen
.
y
);
I
.
addPoint
(
L
.
positionScreen
.
x
,
L
.
positionScreen
.
y
);
if
(
J
.
instersects
(
I
)){
w
=
0
;
for
(
r
=
M
.
meshMaterial
.
length
;
w
<
r
;){
T
=
M
.
meshMaterial
[
w
++
];
if
(
T
instanceof
THREE
.
MeshFaceMaterial
){
N
=
0
;
for
(
S
=
M
.
faceMaterial
.
length
;
N
<
S
;)(
T
=
M
.
faceMaterial
[
N
++
])
&&
g
(
x
,
v
,
H
,
L
,
M
,
T
,
P
)}
else
T
&&
g
(
x
,
v
,
H
,
L
,
M
,
T
,
P
)}}}}}};
THREE
.
WebGLRenderer
=
function
(
a
){
function
b
(
f
,
m
){
var
d
=
c
.
createProgram
(),
p
=
[
c
.
getParameter
(
c
.
MAX_VERTEX_TEXTURE_IMAGE_UNITS
)
>
0
?
"
#define VERTEX_TEXTURES
"
:
""
,
"
uniform mat4 objectMatrix;
\n
uniform mat4 modelViewMatrix;
\n
uniform mat4 projectionMatrix;
\n
uniform mat4 viewMatrix;
\n
uniform mat3 normalMatrix;
\n
uniform vec3 cameraPosition;
\n
attribute vec3 position;
\n
attribute vec3 normal;
\n
attribute vec2 uv;
\n
"
].
join
(
"
\n
"
);
c
.
attachShader
(
d
,
o
(
"
fragment
"
,
"
#ifdef GL_ES
\n
precision highp float;
\n
#endif
\n
uniform mat4 viewMatrix;
\n
"
+
THREE
.
WebGLRenderer
=
function
(
a
){
function
b
(
f
,
m
){
var
d
=
c
.
createProgram
(),
p
=
[
c
.
getParameter
(
c
.
MAX_VERTEX_TEXTURE_IMAGE_UNITS
)
>
0
?
"
#define VERTEX_TEXTURES
"
:
""
,
"
uniform mat4 objectMatrix;
\n
uniform mat4 modelViewMatrix;
\n
uniform mat4 projectionMatrix;
\n
uniform mat4 viewMatrix;
\n
uniform mat3 normalMatrix;
\n
uniform vec3 cameraPosition;
\n
attribute vec3 position;
\n
attribute vec3 normal;
\n
attribute vec2 uv;
\n
"
].
join
(
"
\n
"
);
c
.
attachShader
(
d
,
o
(
"
fragment
"
,
"
#ifdef GL_ES
\n
precision highp float;
\n
#endif
\n
uniform mat4 viewMatrix;
\n
uniform vec3 cameraPosition;
\n
"
+
f
));
c
.
attachShader
(
d
,
o
(
"
vertex
"
,
p
+
m
));
c
.
linkProgram
(
d
);
c
.
getProgramParameter
(
d
,
c
.
LINK_STATUS
)
||
alert
(
"
Could not initialise shaders
\n
VALIDATE_STATUS:
"
+
c
.
getProgramParameter
(
d
,
c
.
VALIDATE_STATUS
)
+
"
, gl error [
"
+
c
.
getError
()
+
"
]
"
);
d
.
uniforms
=
{};
d
.
attributes
=
{};
return
d
}
function
g
(
f
,
m
){
if
(
f
.
image
.
length
==
6
){
if
(
!
f
.
image
.
__webGLTextureCube
&&!
f
.
image
.
__cubeMapInitialized
&&
f
.
image
.
loadCount
==
6
){
f
.
image
.
__webGLTextureCube
=
c
.
createTexture
();
c
.
bindTexture
(
c
.
TEXTURE_CUBE_MAP
,
f
.
image
.
__webGLTextureCube
);
c
.
texParameteri
(
c
.
TEXTURE_CUBE_MAP
,
c
.
TEXTURE_WRAP_S
,
c
.
CLAMP_TO_EDGE
);
c
.
texParameteri
(
c
.
TEXTURE_CUBE_MAP
,
c
.
TEXTURE_WRAP_T
,
c
.
CLAMP_TO_EDGE
);
c
.
texParameteri
(
c
.
TEXTURE_CUBE_MAP
,
c
.
TEXTURE_MAG_FILTER
,
c
.
LINEAR
);
c
.
texParameteri
(
c
.
TEXTURE_CUBE_MAP
,
c
.
TEXTURE_MIN_FILTER
,
c
.
LINEAR_MIPMAP_LINEAR
);
for
(
var
d
=
0
;
d
<
6
;
++
d
)
c
.
texImage2D
(
c
.
TEXTURE_CUBE_MAP_POSITIVE_X
+
d
,
0
,
c
.
RGBA
,
c
.
RGBA
,
c
.
UNSIGNED_BYTE
,
f
.
image
[
d
]);
c
.
generateMipmap
(
c
.
TEXTURE_CUBE_MAP
);
c
.
bindTexture
(
c
.
TEXTURE_CUBE_MAP
,
null
);
f
.
image
.
__cubeMapInitialized
=
true
}
c
.
activeTexture
(
c
.
TEXTURE0
+
m
);
c
.
bindTexture
(
c
.
TEXTURE_CUBE_MAP
,
f
.
image
.
__webGLTextureCube
)}}
function
e
(
f
,
m
){
if
(
!
f
.
__webGLTexture
&&
f
.
image
.
loaded
){
f
.
__webGLTexture
=
c
.
createTexture
();
c
.
bindTexture
(
c
.
TEXTURE_2D
,
f
.
__webGLTexture
);
c
.
texImage2D
(
c
.
TEXTURE_2D
,
0
,
c
.
RGBA
,
c
.
RGBA
,
c
.
UNSIGNED_BYTE
,
f
.
image
);
c
.
texParameteri
(
c
.
TEXTURE_2D
,
c
.
TEXTURE_WRAP_S
,
j
(
f
.
wrap_s
));
c
.
texParameteri
(
c
.
TEXTURE_2D
,
c
.
TEXTURE_WRAP_T
,
j
(
f
.
wrap_t
));
c
.
texParameteri
(
c
.
TEXTURE_2D
,
c
.
TEXTURE_MAG_FILTER
,
j
(
f
.
mag_filter
));
c
.
texParameteri
(
c
.
TEXTURE_2D
,
c
.
TEXTURE_MIN_FILTER
,
j
(
f
.
min_filter
));
c
.
generateMipmap
(
c
.
TEXTURE_2D
);
...
...
@@ -147,7 +147,7 @@ c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0)
f
?
"
for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {
"
:
""
,
f
?
"
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
"
:
""
,
f
?
"
float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );
"
:
""
,
f
?
"
vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;
"
:
""
,
f
?
"
}
"
:
""
,
m
?
"
for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {
"
:
""
,
m
?
"
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
"
:
""
,
m
?
"
vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );
"
:
""
,
m
?
"
float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );
"
:
""
,
m
?
"
vLightWeighting += pointLightColor[ i ] * pointLightWeighting;
"
:
""
,
m
?
"
}
"
:
""
,
"
}
\n
vNormal = transformedNormal;
\n
vUv = uv;
\n
if ( useRefract ) {
\n
vReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );
\n
} else {
\n
vReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );
\n
}
\n
gl_Position = projectionMatrix * mvPosition;
\n
}
"
].
join
(
"
\n
"
),
p
=
[
f
?
"
#define MAX_DIR_LIGHTS
"
+
f
:
""
,
m
?
"
#define MAX_POINT_LIGHTS
"
+
m
:
""
,
"
uniform int material;
\n
uniform bool enableMap;
\n
uniform bool enableCubeMap;
\n
uniform bool mixEnvMap;
\n
uniform samplerCube tCube;
\n
uniform float mReflectivity;
\n
uniform sampler2D tMap;
\n
uniform vec4 mColor;
\n
uniform float mOpacity;
\n
uniform vec4 mAmbient;
\n
uniform vec4 mSpecular;
\n
uniform float mShininess;
\n
uniform float m2Near;
\n
uniform float mFarPlusNear;
\n
uniform float mFarMinusNear;
\n
uniform int pointLightNumber;
\n
uniform int directionalLightNumber;
"
,
f
?
"
uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
"
:
""
,
"
varying vec3 vNormal;
\n
varying vec2 vUv;
\n
varying vec3 vLightWeighting;
"
,
m
?
"
varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];
"
:
""
,
"
varying vec3 vViewPosition;
\n
varying vec3 vReflect;
\n
uniform vec3 cameraPosition;
\n
void main() {
\n
vec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );
\n
vec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );
\n
if ( enableMap ) {
\n
mapColor = texture2D( tMap, vUv );
\n
}
\n
if ( enableCubeMap ) {
\n
cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );
\n
}
\n
if ( material == 5 ) {
\n
vec3 wPos = cameraPosition - vViewPosition;
\n
gl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );
\n
} else if ( material == 4 ) {
\n
gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, mOpacity );
\n
} else if ( material == 3 ) {
\n
float w = 0.5;
\n
gl_FragColor = vec4( w, w, w, mOpacity );
\n
} else if ( material == 2 ) {
\n
vec3 normal = normalize( vNormal );
\n
vec3 viewPosition = normalize( vViewPosition );
"
,
f
?
"
uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
"
:
""
,
"
varying vec3 vNormal;
\n
varying vec2 vUv;
\n
varying vec3 vLightWeighting;
"
,
m
?
"
varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];
"
:
""
,
"
varying vec3 vViewPosition;
\n
varying vec3 vReflect;
\n
void main() {
\n
vec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );
\n
vec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );
\n
if ( enableMap ) {
\n
mapColor = texture2D( tMap, vUv );
\n
}
\n
if ( enableCubeMap ) {
\n
cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );
\n
}
\n
if ( material == 5 ) {
\n
vec3 wPos = cameraPosition - vViewPosition;
\n
gl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );
\n
} else if ( material == 4 ) {
\n
gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, mOpacity );
\n
} else if ( material == 3 ) {
\n
float w = 0.5;
\n
gl_FragColor = vec4( w, w, w, mOpacity );
\n
} else if ( material == 2 ) {
\n
vec3 normal = normalize( vNormal );
\n
vec3 viewPosition = normalize( vViewPosition );
"
,
m
?
"
vec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );
"
:
""
,
m
?
"
vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );
"
:
""
,
m
?
"
for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {
"
:
""
,
m
?
"
vec3 pointVector = normalize( vPointLightVector[ i ] );
"
:
""
,
m
?
"
vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );
"
:
""
,
m
?
"
float pointDotNormalHalf = dot( normal, pointHalfVector );
"
:
""
,
m
?
"
float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );
"
:
""
,
m
?
"
float pointSpecularWeight = 0.0;
"
:
""
,
m
?
"
if ( pointDotNormalHalf >= 0.0 )
"
:
""
,
m
?
"
pointSpecularWeight = pow( pointDotNormalHalf, mShininess );
"
:
""
,
m
?
"
pointDiffuse += mColor * pointDiffuseWeight;
"
:
""
,
m
?
"
pointSpecular += mSpecular * pointSpecularWeight;
"
:
""
,
m
?
"
}
"
:
""
,
f
?
"
vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );
"
:
""
,
f
?
"
vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );
"
:
""
,
f
?
"
for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {
"
:
""
,
f
?
"
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
"
:
""
,
f
?
"
vec3 dirVector = normalize( lDirection.xyz );
"
:
""
,
f
?
"
vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );
"
:
""
,
f
?
"
float dirDotNormalHalf = dot( normal, dirHalfVector );
"
:
""
,
f
?
"
float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );
"
:
""
,
f
?
"
float dirSpecularWeight = 0.0;
"
:
""
,
f
?
"
if ( dirDotNormalHalf >= 0.0 )
"
:
""
,
f
?
"
dirSpecularWeight = pow( dirDotNormalHalf, mShininess );
"
:
""
,
f
?
"
dirDiffuse += mColor * dirDiffuseWeight;
"
:
""
,
f
?
"
dirSpecular += mSpecular * dirSpecularWeight;
"
:
""
,
f
?
"
}
"
:
""
,
"
vec4 totalLight = mAmbient;
"
,
f
?
"
totalLight += dirDiffuse + dirSpecular;
"
:
""
,
m
?
"
totalLight += pointDiffuse + pointSpecular;
"
:
...
...
build/ThreeExtras.js
浏览文件 @
3faf6566
此差异已折叠。
点击以展开。
examples/materials_shaders_fresnel.html
浏览文件 @
3faf6566
...
...
@@ -113,7 +113,8 @@
scene
.
addObject
(
mesh
);
}
SceneUtils
.
addPanoramaCubeWebGL
(
sceneCube
,
100000
,
textureCube
);
//SceneUtils.addPanoramaCubeWebGL( sceneCube, 100000, textureCube );
SceneUtils
.
addPanoramaCubeWebGL2
(
sceneCube
,
100000
,
textureCube
);
webglRenderer
=
new
THREE
.
WebGLRenderer
(
scene
);
webglRenderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
...
...
src/extras/SceneUtils.js
浏览文件 @
3faf6566
...
...
@@ -27,6 +27,24 @@ var SceneUtils = {
},
addPanoramaCubeWebGL2
:
function
(
scene
,
size
,
textureCube
)
{
var
shader
=
ShaderUtils
.
lib
[
"
cube
"
];
shader
.
uniforms
[
"
tCube
"
].
texture
=
textureCube
;
var
material
=
new
THREE
.
MeshShaderMaterial
(
{
fragment_shader
:
shader
.
fragment_shader
,
vertex_shader
:
shader
.
vertex_shader
,
uniforms
:
shader
.
uniforms
}
),
mesh
=
new
THREE
.
Mesh
(
new
Cube
(
size
,
size
,
size
,
1
,
1
,
null
,
true
),
material
);
scene
.
addObject
(
mesh
);
return
mesh
;
},
addPanoramaCube
:
function
(
scene
,
size
,
images
)
{
var
materials
=
[];
...
...
src/extras/ShaderUtils.js
浏览文件 @
3faf6566
...
...
@@ -372,6 +372,42 @@ var ShaderUtils = {
].
join
(
"
\n
"
)
},
'
cube
'
:
{
uniforms
:
{
"
tCube
"
:
{
type
:
"
t
"
,
value
:
1
,
texture
:
null
}
},
vertex_shader
:
[
"
varying vec3 vViewPosition;
"
,
"
void main() {
"
,
"
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
"
,
"
vViewPosition = cameraPosition - mPosition.xyz;
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
}
"
].
join
(
"
\n
"
),
fragment_shader
:
[
"
uniform samplerCube tCube;
"
,
"
varying vec3 vViewPosition;
"
,
"
void main() {
"
,
"
vec3 wPos = cameraPosition - vViewPosition;
"
,
"
gl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );
"
,
"
}
"
].
join
(
"
\n
"
)
}
}
...
...
src/renderers/WebGLRenderer.js
浏览文件 @
3faf6566
...
...
@@ -967,8 +967,6 @@ THREE.WebGLRenderer = function ( scene ) {
"
varying vec3 vReflect;
"
,
"
uniform vec3 cameraPosition;
"
,
"
void main() {
"
,
"
vec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );
"
,
...
...
@@ -1244,6 +1242,7 @@ THREE.WebGLRenderer = function ( scene ) {
"
precision highp float;
"
,
"
#endif
"
,
"
uniform mat4 viewMatrix;
"
,
"
uniform vec3 cameraPosition;
"
,
""
].
join
(
"
\n
"
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录