Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
897a2938
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,发现更多精彩内容 >>
提交
897a2938
编写于
12月 27, 2010
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merged with alteredq's normal shader improvements.
Tweaked normalmap2 demo parameters.
上级
4a486f85
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
23 addition
and
61 deletion
+23
-61
build/ThreeExtras.js
build/ThreeExtras.js
+2
-2
examples/materials_normalmap2.html
examples/materials_normalmap2.html
+15
-33
src/extras/ShaderUtils.js
src/extras/ShaderUtils.js
+6
-26
未找到文件。
build/ThreeExtras.js
浏览文件 @
897a2938
...
...
@@ -194,8 +194,8 @@ mesh=new THREE.Mesh(new Cube(b,b,b,1,1,d,true),new THREE.MeshFaceMaterial);a.add
b
,
1
,
0
,
d
,
0
,
g
,
0
,
f
,
new
THREE
.
MeshBasicMaterial
({
map
:
new
THREE
.
Texture
(
e
[
2
])}));
SceneUtils
.
addMesh
(
a
,
b
,
1
,
0
,
-
d
,
0
,
-
g
,
0
,
f
,
new
THREE
.
MeshBasicMaterial
({
map
:
new
THREE
.
Texture
(
e
[
3
])}))}},
ShaderUtils
=
{
lib
:{
fresnel
:{
uniforms
:{
mRefractionRatio
:{
type
:
"
f
"
,
value
:
1.02
},
mFresnelBias
:{
type
:
"
f
"
,
value
:
0.1
},
mFresnelPower
:{
type
:
"
f
"
,
value
:
2
},
mFresnelScale
:{
type
:
"
f
"
,
value
:
1
},
tCube
:{
type
:
"
t
"
,
value
:
1
,
texture
:
null
}},
fragment_shader
:
"
uniform samplerCube tCube;
\n
varying vec3 vReflect;
\n
varying vec3 vRefract[3];
\n
varying float vReflectionFactor;
\n
void main() {
\n
vec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );
\n
vec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );
\n
refractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;
\n
refractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;
\n
refractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;
\n
refractedColor.a = 1.0;
\n
gl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );
\n
}
"
,
vertex_shader
:
"
uniform float mRefractionRatio;
\n
uniform float mFresnelBias;
\n
uniform float mFresnelScale;
\n
uniform float mFresnelPower;
\n
varying vec3 vReflect;
\n
varying vec3 vRefract[3];
\n
varying float vReflectionFactor;
\n
void main(void) {
\n
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
\n
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
\n
vec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );
\n
vec3 I = mPosition.xyz - cameraPosition;
\n
vReflect = reflect( I, nWorld );
\n
vRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );
\n
vRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );
\n
vRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );
\n
vReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );
\n
gl_Position = projectionMatrix * mvPosition;
\n
}
"
},
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 u
DirLightColor;
\n
uniform vec3 uPointLightPos;
\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 vLightWeighting;
\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( uAmbientColor, 1.0 );
\n
totalLight += dirDiffuse + dirSpecular;
\n
totalLight += pointDiffuse + pointSpecular;
\n
gl_FragColor = vec4( totalLight.xyz * vLightWeighting
* aoTex * diffuseTex, 1.0 );
\n
}
"
,
vertex_shader
:
"
attribute vec4 tangent;
\n
uniform vec3 u
DirLightPos;
\n
uniform vec3 uDirLightColor;
\n
uniform vec3 uPointLightPos;
\n
uniform vec3 uPointLightColor;
\n
uniform vec3 uAmbientLightColor;
\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 vLightWeighting;
\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
vLightWeighting = uAmbientLightColor;
\n
vec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );
\n
vPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );
\n
float pointLightWeighting = max( dot( vNormal, vPointLightVector ), 0.0 );
\n
vLightWeighting += uPointLightColor * pointLightWeighting;
\n
vec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );
\n
float directionalLightWeighting = max( dot( vNormal, normalize( lDirection.xyz ) ), 0.0 );
\n
vLightWeighting += uDirLightColor * directionalLightWeighting
;
\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
}
"
},
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 u
AmbientLightColor;
\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 u
PointLightPos;
\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
}
"
},
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
:{
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
}
"
}}},
Cube
=
function
(
a
,
b
,
e
,
d
,
g
,
f
,
j
,
h
){
function
k
(
A
,
I
,
v
,
D
,
m
,
O
,
L
,
i
){
var
o
,
l
=
d
||
1
,
n
=
g
||
1
,
r
=
l
+
1
,
s
=
n
+
1
,
y
=
m
/
2
,
B
=
O
/
2
;
m
=
m
/
l
;
O
=
O
/
n
;
var
G
=
w
.
vertices
.
length
;
if
(
A
==
"
x
"
&&
I
==
"
y
"
||
A
==
"
y
"
&&
I
==
"
x
"
)
o
=
"
z
"
;
else
if
(
A
==
"
x
"
&&
I
==
"
z
"
||
A
==
"
z
"
&&
I
==
"
x
"
)
o
=
"
y
"
;
else
if
(
A
==
"
z
"
&&
I
==
"
y
"
||
A
==
"
y
"
&&
I
==
"
z
"
)
o
=
"
x
"
;
for
(
iy
=
0
;
iy
<
s
;
iy
++
)
for
(
ix
=
0
;
ix
<
r
;
ix
++
){
var
Q
=
new
THREE
.
Vector3
;
Q
[
A
]
=
(
ix
*
m
-
y
)
*
v
;
Q
[
I
]
=
(
iy
*
O
-
B
)
*
D
;
Q
[
o
]
=
L
;
w
.
vertices
.
push
(
new
THREE
.
Vertex
(
Q
))}
for
(
iy
=
0
;
iy
<
n
;
iy
++
)
for
(
ix
=
0
;
ix
<
l
;
ix
++
){
w
.
faces
.
push
(
new
THREE
.
Face4
(
ix
+
r
*
iy
+
G
,
ix
+
r
*
(
iy
+
1
)
+
G
,
ix
+
1
+
r
*
(
iy
+
1
)
+
G
,
ix
+
1
+
r
*
iy
+
G
,
null
,
i
));
w
.
uvs
.
push
([
new
THREE
.
UV
(
ix
/
l
,
iy
/
n
),
new
THREE
.
UV
(
ix
/
l
,(
iy
+
1
)
/
n
),
new
THREE
.
UV
((
ix
+
1
)
/
l
,(
iy
+
1
)
/
n
),
new
THREE
.
UV
((
ix
+
1
)
/
l
,
iy
/
n
)])}}
THREE
.
Geometry
.
call
(
this
);
var
w
=
this
,
c
=
a
/
2
,
C
=
b
/
2
,
t
=
e
/
2
;
j
=
j
?
-
1
:
1
;
if
(
f
!==
undefined
)
if
(
f
instanceof
Array
)
this
.
materials
=
f
;
else
{
this
.
materials
=
...
...
examples/materials_normalmap2.html
浏览文件 @
897a2938
...
...
@@ -105,8 +105,6 @@
var
windowHalfX
=
window
.
innerWidth
/
2
;
var
windowHalfY
=
window
.
innerHeight
/
2
;
var
r
=
0.0
;
document
.
addEventListener
(
'
mousemove
'
,
onDocumentMouseMove
,
false
);
init
();
...
...
@@ -117,45 +115,38 @@
container
=
document
.
createElement
(
'
div
'
);
document
.
body
.
appendChild
(
container
);
camera
=
new
THREE
.
Camera
(
6
0
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
10000
);
camera
.
position
.
z
=
8
00
;
camera
=
new
THREE
.
Camera
(
5
0
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
10000
);
camera
.
position
.
z
=
9
00
;
scene
=
new
THREE
.
Scene
();
// LIGHTS
ambientLight
=
new
THREE
.
AmbientLight
(
0x
555566
);
ambientLight
=
new
THREE
.
AmbientLight
(
0x
444444
);
scene
.
addLight
(
ambientLight
);
pointLight
=
new
THREE
.
PointLight
(
0x888877
);
pointLight
.
position
.
z
=
400
;
pointLight
=
new
THREE
.
PointLight
(
0xffffff
);
pointLight
.
position
.
z
=
600
;
scene
.
addLight
(
pointLight
);
directionalLight
=
new
THREE
.
DirectionalLight
(
0x
999955
);
directionalLight
=
new
THREE
.
DirectionalLight
(
0x
ffffff
);
directionalLight
.
position
.
x
=
1
;
directionalLight
.
position
.
y
=
1
;
directionalLight
.
position
.
z
=
0.5
;
directionalLight
.
position
.
z
=
-
1
;
directionalLight
.
position
.
normalize
();
scene
.
addLight
(
directionalLight
);
// light representation
var
sphere
=
new
Sphere
(
50
,
16
,
8
);
lightMesh
=
new
THREE
.
Mesh
(
sphere
,
new
THREE
.
MeshBasicMaterial
(
{
color
:
0xffffff
,
opacity
:
0.5
}
)
);
lightMesh
.
position
=
pointLight
.
position
;
lightMesh
.
scale
.
x
=
lightMesh
.
scale
.
y
=
lightMesh
.
scale
.
z
=
0.05
;
scene
.
addObject
(
lightMesh
);
// material parameters
var
ambient
=
0x
666677
,
diffuse
=
0x666666
,
specular
=
0x111111
,
shininess
=
2
;
var
ambient
=
0x
444444
,
diffuse
=
0x555555
,
specular
=
0x181820
,
shininess
=
2
;
var
fragment_shader
=
ShaderUtils
.
lib
[
"
normal
"
].
fragment_shader
;
var
vertex_shader
=
ShaderUtils
.
lib
[
"
normal
"
].
vertex_shader
;
var
uniforms
=
ShaderUtils
.
lib
[
"
normal
"
].
uniforms
;
uniforms
[
"
tNormal
"
].
texture
=
ImageUtils
.
loadTexture
(
"
obj/leeperrysmith/Infinite-Level_02_Tangent_SmoothUV.jpg
"
);
uniforms
[
"
uNormalScale
"
].
value
=
-
1.
5
;
uniforms
[
"
uNormalScale
"
].
value
=
-
0.7
5
;
uniforms
[
"
tDiffuse
"
].
texture
=
ImageUtils
.
loadTexture
(
"
obj/leeperrysmith/Map-COL.jpg
"
);
...
...
@@ -176,12 +167,10 @@
uniforms
[
"
uShininess
"
].
value
=
shininess
;
var
material
=
new
THREE
.
MeshShaderMaterial
(
{
fragment_shader
:
fragment_shader
,
vertex_shader
:
vertex_shader
,
uniforms
:
uniforms
}
);
//var material = new THREE.MeshLambertMaterial( { map: ImageUtils.loadTexture( "obj/leeperrysmith/Map-COL.jpg" ) } );
var
material
=
new
THREE
.
MeshShaderMaterial
(
{
fragment_shader
:
fragment_shader
,
vertex_shader
:
vertex_shader
,
uniforms
:
uniforms
}
);
loader
=
new
THREE
.
Loader
(
true
);
document
.
body
.
appendChild
(
loader
.
statusDomElement
);
...
...
@@ -232,13 +221,6 @@
}
/*
lightMesh.position.x = 2500 * Math.cos( r );
lightMesh.position.z = 2500 * Math.sin( r );
r += 0.01;
*/
webglRenderer
.
render
(
scene
,
camera
);
if
(
statsEnabled
)
stats
.
update
();
...
...
src/extras/ShaderUtils.js
浏览文件 @
897a2938
...
...
@@ -101,9 +101,9 @@ var ShaderUtils = {
fragment_shader
:
[
"
uniform vec3 uDirLightPos;
"
,
"
uniform vec3 uAmbientLightColor;
"
,
"
uniform vec3 uDirLightColor;
"
,
"
uniform vec3 uPointLightPos;
"
,
"
uniform vec3 uPointLightColor;
"
,
"
uniform vec3 uAmbientColor;
"
,
...
...
@@ -125,7 +125,6 @@ var ShaderUtils = {
"
varying vec3 vNormal;
"
,
"
varying vec2 vUv;
"
,
"
varying vec3 vLightWeighting;
"
,
"
varying vec3 vPointLightVector;
"
,
"
varying vec3 vViewPosition;
"
,
...
...
@@ -190,11 +189,11 @@ var ShaderUtils = {
// all lights contribution summation
"
vec4 totalLight = vec4( uAmbientColor, 1.0 );
"
,
"
totalLight +=
dirDiffuse + dirSpecular
;
"
,
"
totalLight +=
pointDiffuse + pointSpecular
;
"
,
"
vec4 totalLight = vec4( uAmbient
LightColor * uAmbient
Color, 1.0 );
"
,
"
totalLight +=
vec4( uDirLightColor, 1.0 ) * ( dirDiffuse + dirSpecular )
;
"
,
"
totalLight +=
vec4( uPointLightColor, 1.0 ) * ( pointDiffuse + pointSpecular )
;
"
,
"
gl_FragColor = vec4( totalLight.xyz *
vLightWeighting *
aoTex * diffuseTex, 1.0 );
"
,
"
gl_FragColor = vec4( totalLight.xyz * aoTex * diffuseTex, 1.0 );
"
,
"
}
"
].
join
(
"
\n
"
),
...
...
@@ -203,13 +202,7 @@ var ShaderUtils = {
"
attribute vec4 tangent;
"
,
"
uniform vec3 uDirLightPos;
"
,
"
uniform vec3 uDirLightColor;
"
,
"
uniform vec3 uPointLightPos;
"
,
"
uniform vec3 uPointLightColor;
"
,
"
uniform vec3 uAmbientLightColor;
"
,
"
#ifdef VERTEX_TEXTURES
"
,
...
...
@@ -224,7 +217,6 @@ var ShaderUtils = {
"
varying vec3 vNormal;
"
,
"
varying vec2 vUv;
"
,
"
varying vec3 vLightWeighting;
"
,
"
varying vec3 vPointLightVector;
"
,
"
varying vec3 vViewPosition;
"
,
...
...
@@ -245,22 +237,10 @@ var ShaderUtils = {
"
vUv = uv;
"
,
// ambient light
"
vLightWeighting = uAmbientLightColor;
"
,
// point light
"
vec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );
"
,
"
vPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );
"
,
"
float pointLightWeighting = max( dot( vNormal, vPointLightVector ), 0.0 );
"
,
"
vLightWeighting += uPointLightColor * pointLightWeighting;
"
,
// directional light
"
vec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );
"
,
"
float directionalLightWeighting = max( dot( vNormal, normalize( lDirection.xyz ) ), 0.0 );
"
,
"
vLightWeighting += uDirLightColor * directionalLightWeighting;
"
,
// displacement mapping
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录