Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
e21dd086
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,发现更多精彩内容 >>
提交
e21dd086
编写于
10月 10, 2015
作者:
B
Ben Houston
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
further cleanup to simplify usage, avoiding premature optimization.
上级
28754cf1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
44 addition
and
87 deletion
+44
-87
src/renderers/shaders/ShaderChunk/common.glsl
src/renderers/shaders/ShaderChunk/common.glsl
+13
-8
src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
+17
-34
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
+13
-44
src/renderers/shaders/UniformsLib.js
src/renderers/shaders/UniformsLib.js
+1
-1
未找到文件。
src/renderers/shaders/ShaderChunk/common.glsl
浏览文件 @
e21dd086
...
...
@@ -4,7 +4,7 @@
#define RECIPROCAL_PI2 0.15915494
#define LOG2 1.442695
#define EPSILON 1e-6
#define PHYSICALLY_BASED_RENDERING
#define saturate(a) clamp( a, 0.0, 1.0 )
#define whiteCompliment(a) ( 1.0 - saturate( a ) )
...
...
@@ -82,13 +82,13 @@ vec3 linearToOutput( in vec3 a ) {
}
vec3
BRDF_Lambert
(
in
vec3
diffuseColor
,
in
float
dotLN
)
{
vec3
BRDF_Lambert
(
const
in
vec3
incomingLight
,
const
in
vec3
diffuseColor
,
const
in
vec3
normal
,
const
in
vec3
lightDir
)
{
return
diffuseColor
*
(
dotLN
*
RECIPROCAL_PI
);
return
incomingLight
*
diffuseColor
*
(
saturate
(
dot
(
normal
,
lightDir
)
)
*
RECIPROCAL_PI
);
}
vec3
F_Schlick
(
in
vec3
specularColor
,
in
float
dotLH
)
{
vec3
F_Schlick
(
const
in
vec3
F0
,
const
in
float
dotLH
)
{
// Original approximation by Christophe Schlick '94
//;float fresnel = pow( 1.0 - dotLH, 5.0 );
...
...
@@ -96,7 +96,7 @@ vec3 F_Schlick( in vec3 specularColor, in float dotLH ) {
// Optimized variant (presented by Epic at SIGGRAPH '13)
float
fresnel
=
exp2
(
(
-
5
.
55437
*
dotLH
-
6
.
98316
)
*
dotLH
);
return
(
1
.
0
-
specularColor
)
*
fresnel
+
specularColor
;
return
F0
+
(
1
.
0
-
F0
)
*
fresnel
;
}
...
...
@@ -108,7 +108,7 @@ float G_BlinnPhong_Implicit( /* in float dotNL, in float dotNV */ ) {
}
float
D_BlinnPhong
(
in
float
shininess
,
in
float
dotNH
)
{
float
D_BlinnPhong
(
const
in
float
shininess
,
const
in
float
dotNH
)
{
// factor of 1/PI in distribution term omitted
...
...
@@ -116,13 +116,17 @@ float D_BlinnPhong( in float shininess, in float dotNH ) {
}
vec3
BRDF_BlinnPhong
(
in
vec3
specularColor
,
in
float
shininess
,
in
float
dotNH
,
in
float
dotLH
)
{
vec3
BRDF_BlinnPhong
(
const
in
vec3
incomingLight
,
const
in
vec3
specularColor
,
const
in
float
shininess
,
const
in
vec3
normal
,
const
in
vec3
lightDir
,
const
in
vec3
viewDir
)
{
vec3
halfDir
=
normalize
(
lightDir
+
viewDir
)
*
singleTestPointLight
.
distance
;
float
dotNH
=
saturate
(
dot
(
normal
,
halfDir
)
);
float
dotLH
=
saturate
(
dot
(
lightDir
,
halfDir
)
);
vec3
F
=
F_Schlick
(
specularColor
,
dotLH
);
float
G
=
G_BlinnPhong_Implicit
(
/* dotNL, dotNV */
);
float
D
=
D_BlinnPhong
(
shininess
,
dotNH
);
return
F
*
G
*
D
;
return
incomingLight
*
F
*
(
G
*
D
)
;
}
...
...
@@ -222,6 +226,7 @@ vec3 BRDF_BlinnPhong( in vec3 specularColor, in float shininess, in float dotNH,
float
hemiDiffuseWeight
=
0
.
5
*
dotNL
+
0
.
5
;
return
mix
(
hemiLight
.
groundColor
,
hemiLight
.
skyColor
,
hemiDiffuseWeight
);
}
#endif
src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
浏览文件 @
e21dd086
...
...
@@ -12,21 +12,16 @@ vec3 normal = normalize( transformedNormal );
for
(
int
i
=
0
;
i
<
MAX_POINT_LIGHTS
;
i
++
)
{
vec3
lightDir
,
lightIntensity
;
getPointLight
(
pointLights
[
i
],
-
vViewPosition
,
lightDir
,
lightIntensity
);
if
(
dot
(
lightIntensity
,
lightIntensity
)
>
0
.
0
)
{
vec3
lightDir
,
lightColor
;
getPointLightDirect
(
pointLights
[
i
],
mvPosition
.
xyz
,
lightDir
,
lightColor
);
float
dotNL
=
dot
(
normal
,
lightDir
);
vLightFront
+=
BRDF_Lambert
(
lightColor
,
vec3
(
1
.
0
),
normal
,
lightDir
);
vLightFront
+=
lightIntensity
*
saturate
(
dotNL
);
#ifdef DOUBLE_SIDED
#ifdef DOUBLE_SIDED
vLightBack
+=
lightIntensity
*
saturate
(
-
dotNL
);
vLightBack
+=
BRDF_Lambert
(
lightColor
,
vec3
(
1
.
0
),
-
normal
,
lightDir
);
#endif
}
#endif
}
...
...
@@ -37,21 +32,15 @@ vec3 normal = normalize( transformedNormal );
for
(
int
i
=
0
;
i
<
MAX_SPOT_LIGHTS
;
i
++
)
{
vec3
lightDir
,
lightIntensity
;
getSpotLight
(
spotLights
[
i
],
-
vViewPosition
,
lightDir
,
lightIntensity
);
if
(
dot
(
lightIntensity
,
lightIntensity
)
>
0
.
0
)
{
float
dotNL
=
saturate
(
dot
(
normal
,
lightDir
)
);
vLightFront
+=
lightIntensity
*
saturate
(
dotNL
);
getSpotLightDirect
(
spotLights
[
i
],
mvPosition
.
xyz
,
lightDir
,
lightIntensity
);
#ifdef DOUBLE_SIDED
vLightFront
+=
BRDF_Lambert
(
lightColor
,
vec3
(
1
.
0
),
normal
,
lightDir
);
vLightBack
+=
lightIntensity
*
saturate
(
-
dotNL
);
#ifdef DOUBLE_SIDED
#endif
vLightBack
+=
BRDF_Lambert
(
lightColor
,
vec3
(
1
.
0
),
-
normal
,
lightDir
);
}
#endif
}
...
...
@@ -64,19 +53,13 @@ vec3 normal = normalize( transformedNormal );
vec3
lightDir
,
lightIntensity
;
getDirLightDirect
(
directionalLights
[
i
],
lightDir
,
lightIntensity
);
if
(
dot
(
lightIntensity
,
lightIntensity
)
>
0
.
0
)
{
float
dotNL
=
dot
(
normal
,
lightDir
);
vLightFront
+=
lightIntensity
*
saturate
(
dotNL
);
vLightFront
+=
BRDF_Lambert
(
lightColor
,
vec3
(
1
.
0
),
normal
,
lightDir
);
#ifdef DOUBLE_SIDED
vLightBack
+=
lightIntensity
*
saturate
(
-
dotNL
);
#ifdef DOUBLE_SIDED
#endif
vLightBack
+=
BRDF_Lambert
(
lightColor
,
vec3
(
1
.
0
),
-
normal
,
lightDir
);
}
#endif
}
...
...
@@ -86,11 +69,11 @@ vec3 normal = normalize( transformedNormal );
for
(
int
i
=
0
;
i
<
MAX_HEMI_LIGHTS
;
i
++
)
{
vLightFront
+=
getHemisphereLightIndirect
(
hemisphereLights
[
i
],
normal
);
vLightFront
+=
getHemisphereLightIndirect
(
hemisphereLights
[
i
],
normal
)
*
RECIPROCAL_PI
;
#ifdef DOUBLE_SIDED
vLightBack
+=
getHemisphereLightIndirect
(
hemisphereLights
[
i
],
-
normal
);
vLightBack
+=
getHemisphereLightIndirect
(
hemisphereLights
[
i
],
-
normal
)
*
RECIPROCAL_PI
;
#endif
...
...
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
浏览文件 @
e21dd086
...
...
@@ -14,23 +14,12 @@ vec3 diffuse = diffuseColor.rgb;
for
(
int
i
=
0
;
i
<
MAX_POINT_LIGHTS
;
i
++
)
{
vec3
lightDir
,
lightIntensity
;
getPointLightDirect
(
pointLights
[
i
],
-
vViewPosition
,
lightDir
,
lightIntensity
);
if
(
dot
(
lightIntensity
,
lightIntensity
)
>
0
.
0
)
{
vec3
lightDir
,
lightColor
;
getPointLightDirect
(
pointLights
[
i
],
-
vViewPosition
,
lightDir
,
lightColor
);
vec3
halfDir
=
normalize
(
lightDir
+
viewDir
)
*
singleTestPointLight
.
distance
;
float
dotNL
=
saturate
(
dot
(
normal
,
lightDir
)
);
float
dotNH
=
saturate
(
dot
(
normal
,
halfDir
)
);
float
dotLH
=
saturate
(
dot
(
lightDir
,
halfDir
)
);
totalReflectedLight
+=
(
BRDF_Lambert
(
diffuse
,
dotNL
)
+
BRDF_BlinnPhong
(
specular
,
shininess
,
dotNH
,
dotLH
)
)
*
lightIntensity
;
}
totalReflectedLight
+=
BRDF_Lambert
(
lightColor
,
diffuse
,
normal
,
lightDir
)
+
BRDF_BlinnPhong
(
lightColor
,
specular
,
shininess
,
normal
,
lightDir
,
viewDir
);
}
...
...
@@ -40,22 +29,12 @@ vec3 diffuse = diffuseColor.rgb;
for
(
int
i
=
0
;
i
<
MAX_SPOT_LIGHTS
;
i
++
)
{
vec3
lightDir
,
lightIntensity
;
getSpotLightDirect
(
spotLights
[
i
],
-
vViewPosition
,
lightDir
,
lightIntensity
);
if
(
dot
(
lightIntensity
,
lightIntensity
)
>
0
.
0
)
{
vec3
halfDir
=
normalize
(
lightDir
+
viewDir
);
float
dotNL
=
saturate
(
dot
(
normal
,
lightDir
)
);
float
dotNH
=
saturate
(
dot
(
normal
,
halfDir
)
);
float
dotLH
=
saturate
(
dot
(
lightDir
,
halfDir
)
);
totalReflectedLight
+=
(
BRDF_Lambert
(
diffuse
,
dotNL
)
+
BRDF_BlinnPhong
(
specular
,
shininess
,
dotNH
,
dotLH
)
)
*
lightIntensity
;
vec3
lightDir
,
lightColor
;
getSpotLightDirect
(
spotLights
[
i
],
-
vViewPosition
,
lightDir
,
lightColor
);
}
totalReflectedLight
+=
BRDF_Lambert
(
lightColor
,
diffuse
,
normal
,
lightDir
)
+
BRDF_BlinnPhong
(
lightColor
,
specular
,
shininess
,
normal
,
lightDir
,
viewDir
);
}
...
...
@@ -68,19 +47,9 @@ vec3 diffuse = diffuseColor.rgb;
vec3
lightDir
,
lightIntensity
;
getDirLightDirect
(
directionalLights
[
i
],
lightDir
,
lightIntensity
);
if
(
dot
(
lightIntensity
,
lightIntensity
)
>
0
.
0
)
{
vec3
halfDir
=
normalize
(
lightDir
+
viewDir
);
float
dotNL
=
saturate
(
dot
(
normal
,
lightDir
)
);
float
dotNH
=
saturate
(
dot
(
normal
,
halfDir
)
);
float
dotLH
=
saturate
(
dot
(
lightDir
,
halfDir
)
);
totalReflectedLight
+=
(
BRDF_Lambert
(
diffuse
,
dotNL
)
+
BRDF_BlinnPhong
(
specular
,
shininess
,
dotNH
,
dotLH
)
)
*
lightIntensity
;
}
totalReflectedLight
+=
BRDF_Lambert
(
lightColor
,
diffuse
,
normal
,
lightDir
)
+
BRDF_BlinnPhong
(
lightColor
,
specular
,
shininess
,
normal
,
lightDir
,
viewDir
);
}
...
...
src/renderers/shaders/UniformsLib.js
浏览文件 @
e21dd086
...
...
@@ -91,7 +91,7 @@ THREE.UniformsLib = {
"
pointLights
"
:
{
type
:
"
sa
"
,
value
:
[],
properties
:
{
"
color
"
:
{
type
:
"
c
"
},
"
position
"
:
{
type
:
"
v3
"
},
"
d
irection
"
:
{
type
:
"
v3
"
},
"
d
ecay
"
:
{
type
:
"
f
"
},
"
distance
"
:
{
type
:
"
f
"
}
}
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录