Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
b20e021b
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,发现更多精彩内容 >>
提交
b20e021b
编写于
8月 22, 2015
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7028 from tschw/PerPixelLighting
Less resource-hungry per-pixel lighting
上级
20a81f16
0671faa1
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
40 addition
and
45 deletion
+40
-45
examples/js/ShaderSkin.js
examples/js/ShaderSkin.js
+3
-9
examples/js/ShaderTerrain.js
examples/js/ShaderTerrain.js
+3
-4
examples/js/shaders/NormalDisplacementShader.js
examples/js/shaders/NormalDisplacementShader.js
+5
-9
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+12
-8
src/renderers/shaders/ShaderChunk/common.glsl
src/renderers/shaders/ShaderChunk/common.glsl
+7
-1
src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
+5
-7
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
+5
-7
未找到文件。
examples/js/ShaderSkin.js
浏览文件 @
b20e021b
...
...
@@ -197,9 +197,7 @@ THREE.ShaderSkin = {
"
for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
"
,
"
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
"
,
"
vec3 lVector = lPosition.xyz + vViewPosition.xyz;
"
,
"
vec3 lVector = pointLightPosition[ i ] + vViewPosition.xyz;
"
,
"
float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[i] );
"
,
...
...
@@ -628,9 +626,7 @@ THREE.ShaderSkin = {
"
for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {
"
,
"
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
"
,
"
vec3 lVector = lPosition.xyz - mvPosition.xyz;
"
,
"
vec3 lVector = pointLightPosition[ i ] - mvPosition.xyz;
"
,
"
float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[i] );
"
,
...
...
@@ -717,9 +713,7 @@ THREE.ShaderSkin = {
"
for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {
"
,
"
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
"
,
"
vec3 lVector = lPosition.xyz - mvPosition.xyz;
"
,
"
vec3 lVector = pointLightPosition[ i ] - mvPosition.xyz;
"
,
"
float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[i] );
"
,
...
...
examples/js/ShaderTerrain.js
浏览文件 @
b20e021b
...
...
@@ -168,8 +168,7 @@ THREE.ShaderTerrain = {
"
for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
"
,
"
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
"
,
"
vec3 lVector = lPosition.xyz + vViewPosition.xyz;
"
,
"
vec3 lVector = pointLightPosition[ i ] + vViewPosition.xyz;
"
,
"
float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[i] );
"
,
...
...
@@ -198,7 +197,7 @@ THREE.ShaderTerrain = {
"
for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {
"
,
"
vec3 dirVector =
transformDirection( directionalLightDirection[ i ], viewMatrix )
;
"
,
"
vec3 dirVector =
directionalLightDirection[ i ]
;
"
,
"
vec3 dirHalfVector = normalize( dirVector + viewPosition );
"
,
"
float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );
"
,
...
...
@@ -222,7 +221,7 @@ THREE.ShaderTerrain = {
"
for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {
"
,
"
vec3 lVector =
transformDirection( hemisphereLightDirection[ i ], viewMatrix )
;
"
,
"
vec3 lVector =
hemisphereLightDirection[ i ]
;
"
,
// diffuse
...
...
examples/js/shaders/NormalDisplacementShader.js
浏览文件 @
b20e021b
...
...
@@ -186,8 +186,7 @@ THREE.NormalDisplacementShader = {
"
for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
"
,
"
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
"
,
"
vec3 pointVector = lPosition.xyz + vViewPosition.xyz;
"
,
"
vec3 pointVector = pointLightPosition[ i ] + vViewPosition.xyz;
"
,
"
float pointDistance = 1.0;
"
,
"
if ( pointLightDistance[ i ] > 0.0 )
"
,
...
...
@@ -222,8 +221,7 @@ THREE.NormalDisplacementShader = {
"
for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {
"
,
"
vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );
"
,
"
vec3 spotVector = lPosition.xyz + vViewPosition.xyz;
"
,
"
vec3 spotVector = spotLightPosition[ i ] + vViewPosition.xyz;
"
,
"
float spotDistance = 1.0;
"
,
"
if ( spotLightDistance[ i ] > 0.0 )
"
,
...
...
@@ -231,7 +229,7 @@ THREE.NormalDisplacementShader = {
"
spotVector = normalize( spotVector );
"
,
"
float spotEffect = dot( spotLightDirection[ i ],
normalize( spotLightPosition[ i ] - vWorldPosition )
);
"
,
"
float spotEffect = dot( spotLightDirection[ i ],
spotVector
);
"
,
"
if ( spotEffect > spotLightAngleCos[ i ] ) {
"
,
...
...
@@ -267,8 +265,7 @@ THREE.NormalDisplacementShader = {
"
for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
"
,
"
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
"
,
"
vec3 dirVector = normalize( lDirection.xyz );
"
,
"
vec3 dirVector = directionalLightDirection[ i ];
"
,
// diffuse
...
...
@@ -297,8 +294,7 @@ THREE.NormalDisplacementShader = {
"
for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {
"
,
"
vec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );
"
,
"
vec3 lVector = normalize( lDirection.xyz );
"
,
"
vec3 lVector = hemisphereLightDirection[ i ];
"
,
// diffuse
...
...
src/renderers/WebGLRenderer.js
浏览文件 @
b20e021b
...
...
@@ -1873,7 +1873,7 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
_lightsNeedUpdate
)
{
refreshLights
=
true
;
setupLights
(
lights
);
setupLights
(
lights
,
camera
);
_lightsNeedUpdate
=
false
;
}
...
...
@@ -2585,7 +2585,7 @@ THREE.WebGLRenderer = function ( parameters ) {
}
function
setupLights
(
lights
)
{
function
setupLights
(
lights
,
camera
)
{
var
l
,
ll
,
light
,
r
=
0
,
g
=
0
,
b
=
0
,
...
...
@@ -2595,6 +2595,8 @@ THREE.WebGLRenderer = function ( parameters ) {
zlights
=
_lights
,
viewMatrix
=
camera
.
matrixWorldInverse
,
dirColors
=
zlights
.
directional
.
colors
,
dirPositions
=
zlights
.
directional
.
positions
,
...
...
@@ -2657,7 +2659,7 @@ THREE.WebGLRenderer = function ( parameters ) {
_direction
.
setFromMatrixPosition
(
light
.
matrixWorld
);
_vector3
.
setFromMatrixPosition
(
light
.
target
.
matrixWorld
);
_direction
.
sub
(
_vector3
);
_direction
.
normalize
(
);
_direction
.
transformDirection
(
viewMatrix
);
dirOffset
=
dirLength
*
3
;
...
...
@@ -2680,6 +2682,7 @@ THREE.WebGLRenderer = function ( parameters ) {
setColorLinear
(
pointColors
,
pointOffset
,
color
,
intensity
);
_vector3
.
setFromMatrixPosition
(
light
.
matrixWorld
);
_vector3
.
applyMatrix4
(
viewMatrix
);
pointPositions
[
pointOffset
+
0
]
=
_vector3
.
x
;
pointPositions
[
pointOffset
+
1
]
=
_vector3
.
y
;
...
...
@@ -2702,16 +2705,17 @@ THREE.WebGLRenderer = function ( parameters ) {
setColorLinear
(
spotColors
,
spotOffset
,
color
,
intensity
);
_direction
.
setFromMatrixPosition
(
light
.
matrixWorld
);
_vector3
.
copy
(
_direction
).
applyMatrix4
(
viewMatrix
);
spotPositions
[
spotOffset
+
0
]
=
_
direction
.
x
;
spotPositions
[
spotOffset
+
1
]
=
_
direction
.
y
;
spotPositions
[
spotOffset
+
2
]
=
_
direction
.
z
;
spotPositions
[
spotOffset
+
0
]
=
_
vector3
.
x
;
spotPositions
[
spotOffset
+
1
]
=
_
vector3
.
y
;
spotPositions
[
spotOffset
+
2
]
=
_
vector3
.
z
;
spotDistances
[
spotLength
]
=
distance
;
_vector3
.
setFromMatrixPosition
(
light
.
target
.
matrixWorld
);
_direction
.
sub
(
_vector3
);
_direction
.
normalize
(
);
_direction
.
transformDirection
(
viewMatrix
);
spotDirections
[
spotOffset
+
0
]
=
_direction
.
x
;
spotDirections
[
spotOffset
+
1
]
=
_direction
.
y
;
...
...
@@ -2730,7 +2734,7 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
!
light
.
visible
)
continue
;
_direction
.
setFromMatrixPosition
(
light
.
matrixWorld
);
_direction
.
normalize
(
);
_direction
.
transformDirection
(
viewMatrix
);
hemiOffset
=
hemiLength
*
3
;
...
...
src/renderers/shaders/ShaderChunk/common.glsl
浏览文件 @
b20e021b
...
...
@@ -54,7 +54,13 @@ float calcLightAttenuation( float lightDistance, float cutoffDistance, float dec
vec3
F_Schlick
(
in
vec3
specularColor
,
in
float
dotLH
)
{
return
(
1
.
0
-
specularColor
)
*
pow
(
1
.
0
-
dotLH
,
5
.
0
)
+
specularColor
;
// Original approximation by Christophe Schlick '94
//;float fresnel = pow( 1.0 - dotLH, 5.0 );
// Optimized variant (presented by Epic at SIGGRAPH '13)
float
fresnel
=
exp2
(
(
-
5
.
55437
*
dotLH
-
6
.
98316
)
*
dotLH
);
return
(
1
.
0
-
specularColor
)
*
fresnel
+
specularColor
;
}
...
...
src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
浏览文件 @
b20e021b
...
...
@@ -14,8 +14,7 @@ vec3 normal = normalize( transformedNormal );
vec3
lightColor
=
pointLightColor
[
i
];
vec4
lPosition
=
viewMatrix
*
vec4
(
pointLightPosition
[
i
],
1
.
0
);
vec3
lVector
=
lPosition
.
xyz
-
mvPosition
.
xyz
;
vec3
lVector
=
pointLightPosition
[
i
]
-
mvPosition
.
xyz
;
vec3
lightDir
=
normalize
(
lVector
);
// attenuation
...
...
@@ -45,11 +44,10 @@ vec3 normal = normalize( transformedNormal );
vec3
lightColor
=
spotLightColor
[
i
];
vec3
lightPosition
=
spotLightPosition
[
i
];
vec4
lPosition
=
viewMatrix
*
vec4
(
lightPosition
,
1
.
0
);
vec3
lVector
=
lPosition
.
xyz
-
mvPosition
.
xyz
;
vec3
lVector
=
lightPosition
-
mvPosition
.
xyz
;
vec3
lightDir
=
normalize
(
lVector
);
float
spotEffect
=
dot
(
spotLightDirection
[
i
],
normalize
(
lightPosition
-
worldPosition
.
xyz
)
);
float
spotEffect
=
dot
(
spotLightDirection
[
i
],
lightDir
);
if
(
spotEffect
>
spotLightAngleCos
[
i
]
)
{
...
...
@@ -85,7 +83,7 @@ vec3 normal = normalize( transformedNormal );
vec3
lightColor
=
directionalLightColor
[
i
];
vec3
lightDir
=
transformDirection
(
directionalLightDirection
[
i
],
viewMatrix
)
;
vec3
lightDir
=
directionalLightDirection
[
i
]
;
// diffuse
...
...
@@ -107,7 +105,7 @@ vec3 normal = normalize( transformedNormal );
for
(
int
i
=
0
;
i
<
MAX_HEMI_LIGHTS
;
i
++
)
{
vec3
lightDir
=
transformDirection
(
hemisphereLightDirection
[
i
],
viewMatrix
)
;
vec3
lightDir
=
hemisphereLightDirection
[
i
]
;
// diffuse
...
...
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
浏览文件 @
b20e021b
...
...
@@ -38,8 +38,7 @@ vec3 totalSpecularLight = vec3( 0.0 );
vec3
lightColor
=
pointLightColor
[
i
];
vec3
lightPosition
=
pointLightPosition
[
i
];
vec4
lPosition
=
viewMatrix
*
vec4
(
lightPosition
,
1
.
0
);
vec3
lVector
=
lPosition
.
xyz
+
vViewPosition
.
xyz
;
vec3
lVector
=
lightPosition
+
vViewPosition
.
xyz
;
vec3
lightDir
=
normalize
(
lVector
);
// attenuation
...
...
@@ -70,11 +69,10 @@ vec3 totalSpecularLight = vec3( 0.0 );
vec3
lightColor
=
spotLightColor
[
i
];
vec3
lightPosition
=
spotLightPosition
[
i
];
vec4
lPosition
=
viewMatrix
*
vec4
(
lightPosition
,
1
.
0
);
vec3
lVector
=
lPosition
.
xyz
+
vViewPosition
.
xyz
;
vec3
lVector
=
lightPosition
+
vViewPosition
.
xyz
;
vec3
lightDir
=
normalize
(
lVector
);
float
spotEffect
=
dot
(
spotLightDirection
[
i
],
normalize
(
lightPosition
-
vWorldPosition
)
);
float
spotEffect
=
dot
(
spotLightDirection
[
i
],
lightDir
);
if
(
spotEffect
>
spotLightAngleCos
[
i
]
)
{
...
...
@@ -110,7 +108,7 @@ vec3 totalSpecularLight = vec3( 0.0 );
vec3
lightColor
=
directionalLightColor
[
i
];
vec3
lightDir
=
transformDirection
(
directionalLightDirection
[
i
],
viewMatrix
)
;
vec3
lightDir
=
directionalLightDirection
[
i
]
;
// diffuse
...
...
@@ -132,7 +130,7 @@ vec3 totalSpecularLight = vec3( 0.0 );
for
(
int
i
=
0
;
i
<
MAX_HEMI_LIGHTS
;
i
++
)
{
vec3
lightDir
=
transformDirection
(
hemisphereLightDirection
[
i
],
viewMatrix
)
;
vec3
lightDir
=
hemisphereLightDirection
[
i
]
;
// diffuse
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录