Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
d8552f34
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,发现更多精彩内容 >>
提交
d8552f34
编写于
10月 10, 2015
作者:
B
Ben Houston
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
introduce IncidentLight struct
上级
56b64721
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
59 addition
and
53 deletion
+59
-53
src/renderers/shaders/ShaderChunk/common.glsl
src/renderers/shaders/ShaderChunk/common.glsl
+27
-21
src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
+17
-17
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
+15
-15
未找到文件。
src/renderers/shaders/ShaderChunk/common.glsl
浏览文件 @
d8552f34
...
@@ -82,9 +82,15 @@ vec3 linearToOutput( in vec3 a ) {
...
@@ -82,9 +82,15 @@ vec3 linearToOutput( in vec3 a ) {
}
}
vec3
BRDF_Lambert
(
const
in
vec3
lightColor
,
const
in
vec3
lightDir
,
const
in
vec3
normal
,
const
in
vec3
diffuseColor
)
{
struct
IncidentLight
{
vec3
color
;
vec3
direction
;
};
return
lightColor
*
diffuseColor
*
(
saturate
(
dot
(
normal
,
lightDir
)
)
);
vec3
BRDF_Lambert
(
const
in
IncidentLight
incidentLight
,
const
in
vec3
normal
,
const
in
vec3
diffuseColor
)
{
return
incidentLight
.
color
*
diffuseColor
*
(
saturate
(
dot
(
normal
,
incidentLight
.
direction
)
)
);
// the above should be scaled by '' * RECIPROCAL_PI'
// the above should be scaled by '' * RECIPROCAL_PI'
}
}
...
@@ -117,17 +123,17 @@ float D_BlinnPhong( const in float shininess, const in float dotNH ) {
...
@@ -117,17 +123,17 @@ float D_BlinnPhong( const in float shininess, const in float dotNH ) {
}
}
vec3
BRDF_BlinnPhong
(
const
in
vec3
lightColor
,
const
in
vec3
lightDir
,
const
in
vec3
normal
,
const
in
vec3
viewDir
,
const
in
vec3
specularColor
,
const
in
float
shininess
)
{
vec3
BRDF_BlinnPhong
(
const
in
IncidentLight
incidentLight
,
const
in
vec3
normal
,
const
in
vec3
viewDir
,
const
in
vec3
specularColor
,
const
in
float
shininess
)
{
vec3
halfDir
=
normalize
(
lightDir
+
viewDir
);
vec3
halfDir
=
normalize
(
incidentLight
.
direction
+
viewDir
);
float
dotNH
=
saturate
(
dot
(
normal
,
halfDir
)
);
float
dotNH
=
saturate
(
dot
(
normal
,
halfDir
)
);
float
dotLH
=
saturate
(
dot
(
lightDir
,
halfDir
)
);
float
dotLH
=
saturate
(
dot
(
incidentLight
.
direction
,
halfDir
)
);
vec3
F
=
F_Schlick
(
specularColor
,
dotLH
);
vec3
F
=
F_Schlick
(
specularColor
,
dotLH
);
float
G
=
G_BlinnPhong_Implicit
(
/* dotNL, dotNV */
);
float
G
=
G_BlinnPhong_Implicit
(
/* dotNL, dotNV */
);
float
D
=
D_BlinnPhong
(
shininess
,
dotNH
);
float
D
=
D_BlinnPhong
(
shininess
,
dotNH
);
return
lightC
olor
*
F
*
(
G
*
D
);
return
incidentLight
.
c
olor
*
F
*
(
G
*
D
);
}
}
...
@@ -142,10 +148,10 @@ vec3 BRDF_BlinnPhong( const in vec3 lightColor, const in vec3 lightDir, const in
...
@@ -142,10 +148,10 @@ vec3 BRDF_BlinnPhong( const in vec3 lightColor, const in vec3 lightDir, const in
uniform
DirectionalLight
directionalLights
[
MAX_DIR_LIGHTS
];
uniform
DirectionalLight
directionalLights
[
MAX_DIR_LIGHTS
];
void
getDirLightDirect
(
const
in
DirectionalLight
directionalLight
,
out
vec3
lightColor
,
out
vec3
lightDir
)
{
void
getDirLightDirect
(
const
in
DirectionalLight
directionalLight
,
out
IncidentLight
incidentLight
)
{
lightDir
=
directionalLight
.
direction
;
incidentLight
.
color
=
directionalLight
.
color
;
lightColor
=
directionalLight
.
color
;
incidentLight
.
direction
=
directionalLight
.
direction
;
}
}
...
@@ -162,15 +168,15 @@ vec3 BRDF_BlinnPhong( const in vec3 lightColor, const in vec3 lightDir, const in
...
@@ -162,15 +168,15 @@ vec3 BRDF_BlinnPhong( const in vec3 lightColor, const in vec3 lightDir, const in
uniform
PointLight
pointLights
[
MAX_POINT_LIGHTS
];
uniform
PointLight
pointLights
[
MAX_POINT_LIGHTS
];
void
getPointLightDirect
(
const
in
PointLight
pointLight
,
const
in
vec3
position
,
out
vec3
lightColor
,
out
vec3
lightDir
)
{
void
getPointLightDirect
(
const
in
PointLight
pointLight
,
const
in
vec3
position
,
out
IncidentLight
incidentLight
)
{
vec3
lightPosition
=
pointLight
.
position
;
vec3
lightPosition
=
pointLight
.
position
;
vec3
lVector
=
lightPosition
-
position
;
vec3
lVector
=
lightPosition
-
position
;
lightDir
=
normalize
(
lVector
);
incidentLight
.
direction
=
normalize
(
lVector
);
lightC
olor
=
pointLight
.
color
;
incidentLight
.
c
olor
=
pointLight
.
color
;
lightC
olor
*=
calcLightAttenuation
(
length
(
lVector
),
pointLight
.
distance
,
pointLight
.
decay
);
incidentLight
.
c
olor
*=
calcLightAttenuation
(
length
(
lVector
),
pointLight
.
distance
,
pointLight
.
decay
);
}
}
...
@@ -190,18 +196,18 @@ vec3 BRDF_BlinnPhong( const in vec3 lightColor, const in vec3 lightDir, const in
...
@@ -190,18 +196,18 @@ vec3 BRDF_BlinnPhong( const in vec3 lightColor, const in vec3 lightDir, const in
uniform
SpotLight
spotLights
[
MAX_SPOT_LIGHTS
];
uniform
SpotLight
spotLights
[
MAX_SPOT_LIGHTS
];
void
getSpotLightDirect
(
const
in
SpotLight
spotLight
,
const
in
vec3
position
,
out
vec3
lightColor
,
out
vec3
lightDir
)
{
void
getSpotLightDirect
(
const
in
SpotLight
spotLight
,
const
in
vec3
position
,
out
IncidentLight
incidentLight
)
{
vec3
lightPosition
=
spotLight
.
position
;
vec3
lightPosition
=
spotLight
.
position
;
vec3
lVector
=
lightPosition
-
position
;
vec3
lVector
=
lightPosition
-
position
;
lightDir
=
normalize
(
lVector
);
incidentLight
.
direction
=
normalize
(
lVector
);
float
spotEffect
=
dot
(
spotLight
.
direction
,
lightDir
);
float
spotEffect
=
dot
(
spotLight
.
direction
,
incidentLight
.
direction
);
spotEffect
=
saturate
(
pow
(
saturate
(
spotEffect
),
spotLight
.
exponent
)
);
spotEffect
=
saturate
(
pow
(
saturate
(
spotEffect
),
spotLight
.
exponent
)
);
lightC
olor
=
spotLight
.
color
;
incidentLight
.
c
olor
=
spotLight
.
color
;
lightC
olor
*=
(
spotEffect
*
calcLightAttenuation
(
length
(
lVector
),
spotLight
.
distance
,
spotLight
.
decay
)
);
incidentLight
.
c
olor
*=
(
spotEffect
*
calcLightAttenuation
(
length
(
lVector
),
spotLight
.
distance
,
spotLight
.
decay
)
);
}
}
...
@@ -218,15 +224,15 @@ vec3 BRDF_BlinnPhong( const in vec3 lightColor, const in vec3 lightDir, const in
...
@@ -218,15 +224,15 @@ vec3 BRDF_BlinnPhong( const in vec3 lightColor, const in vec3 lightDir, const in
uniform
HemisphereLight
hemisphereLights
[
MAX_HEMI_LIGHTS
];
uniform
HemisphereLight
hemisphereLights
[
MAX_HEMI_LIGHTS
];
void
getHemisphereLightIndirect
(
const
in
HemisphereLight
hemiLight
,
const
in
vec3
normal
,
out
vec3
lightColor
,
out
vec3
lightDir
)
{
void
getHemisphereLightIndirect
(
const
in
HemisphereLight
hemiLight
,
const
in
vec3
normal
,
out
IncidentLight
incidentLight
)
{
float
dotNL
=
dot
(
normal
,
hemiLight
.
direction
);
float
dotNL
=
dot
(
normal
,
hemiLight
.
direction
);
float
hemiDiffuseWeight
=
0
.
5
*
dotNL
+
0
.
5
;
float
hemiDiffuseWeight
=
0
.
5
*
dotNL
+
0
.
5
;
lightC
olor
=
mix
(
hemiLight
.
groundColor
,
hemiLight
.
skyColor
,
hemiDiffuseWeight
);
incidentLight
.
c
olor
=
mix
(
hemiLight
.
groundColor
,
hemiLight
.
skyColor
,
hemiDiffuseWeight
);
lightDir
=
normal
;
incidentLight
.
direction
=
normal
;
}
}
...
...
src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
浏览文件 @
d8552f34
...
@@ -13,14 +13,14 @@ vec3 diffuse = vec3( 1.0 );
...
@@ -13,14 +13,14 @@ vec3 diffuse = vec3( 1.0 );
for
(
int
i
=
0
;
i
<
MAX_POINT_LIGHTS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
MAX_POINT_LIGHTS
;
i
++
)
{
vec3
lightColor
,
lightDir
;
IncidentLight
incidentLight
;
getPointLightDirect
(
pointLights
[
i
],
mvPosition
.
xyz
,
lightColor
,
lightDir
);
getPointLightDirect
(
pointLights
[
i
],
mvPosition
.
xyz
,
incidentLight
);
vLightFront
+=
BRDF_Lambert
(
lightColor
,
lightDir
,
normal
,
diffuse
);
vLightFront
+=
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
);
#ifdef DOUBLE_SIDED
#ifdef DOUBLE_SIDED
vLightBack
+=
BRDF_Lambert
(
lightColor
,
lightDir
,
-
normal
,
diffuse
);
vLightBack
+=
BRDF_Lambert
(
incidentLight
,
-
normal
,
diffuse
);
#endif
#endif
...
@@ -32,14 +32,14 @@ vec3 diffuse = vec3( 1.0 );
...
@@ -32,14 +32,14 @@ vec3 diffuse = vec3( 1.0 );
for
(
int
i
=
0
;
i
<
MAX_SPOT_LIGHTS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
MAX_SPOT_LIGHTS
;
i
++
)
{
vec3
lightColor
,
lightDir
;
IncidentLight
incidentLight
;
getSpotLightDirect
(
spotLights
[
i
],
mvPosition
.
xyz
,
lightColor
,
lightDir
);
getSpotLightDirect
(
spotLights
[
i
],
mvPosition
.
xyz
,
incidentLight
);
vLightFront
+=
BRDF_Lambert
(
lightColor
,
lightDir
,
normal
,
diffuse
);
vLightFront
+=
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
);
#ifdef DOUBLE_SIDED
#ifdef DOUBLE_SIDED
vLightBack
+=
BRDF_Lambert
(
lightColor
,
lightDir
,
-
normal
,
diffuse
);
vLightBack
+=
BRDF_Lambert
(
incidentLight
,
-
normal
,
diffuse
);
#endif
#endif
...
@@ -51,14 +51,14 @@ vec3 diffuse = vec3( 1.0 );
...
@@ -51,14 +51,14 @@ vec3 diffuse = vec3( 1.0 );
for
(
int
i
=
0
;
i
<
MAX_DIR_LIGHTS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
MAX_DIR_LIGHTS
;
i
++
)
{
vec3
lightColor
,
lightDir
;
IncidentLight
incidentLight
;
getDirLightDirect
(
directionalLights
[
i
],
lightColor
,
lightDir
);
getDirLightDirect
(
directionalLights
[
i
],
incidentLight
);
vLightFront
+=
BRDF_Lambert
(
lightColor
,
lightDir
,
normal
,
diffuse
);
vLightFront
+=
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
);
#ifdef DOUBLE_SIDED
#ifdef DOUBLE_SIDED
vLightBack
+=
BRDF_Lambert
(
lightColor
,
lightDir
,
-
normal
,
diffuse
);
vLightBack
+=
BRDF_Lambert
(
incidentLight
,
-
normal
,
diffuse
);
#endif
#endif
...
@@ -70,16 +70,16 @@ vec3 diffuse = vec3( 1.0 );
...
@@ -70,16 +70,16 @@ vec3 diffuse = vec3( 1.0 );
for
(
int
i
=
0
;
i
<
MAX_HEMI_LIGHTS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
MAX_HEMI_LIGHTS
;
i
++
)
{
vec3
lightColor
,
lightDir
;
IncidentLight
incidentLight
;
getHemisphereLightIndirect
(
hemisphereLights
[
i
],
normal
,
lightColor
,
lightDir
);
getHemisphereLightIndirect
(
hemisphereLights
[
i
],
normal
,
incidentLight
);
vLightFront
+=
BRDF_Lambert
(
lightColor
,
lightDir
,
normal
,
diffuse
);
vLightFront
+=
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
);
#ifdef DOUBLE_SIDED
#ifdef DOUBLE_SIDED
getHemisphereLightIndirect
(
hemisphereLights
[
i
],
-
normal
,
lightColor
,
lightDir
);
incidentLight
=
getHemisphereLightIndirect
(
hemisphereLights
[
i
],
-
normal
);
vLightBack
+=
BRDF_Lambert
(
lightColor
,
lightDir
,
-
normal
,
diffuse
);
vLightBack
+=
BRDF_Lambert
(
incidentLight
,
-
normal
,
diffuse
);
#endif
#endif
...
...
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
浏览文件 @
d8552f34
...
@@ -17,14 +17,14 @@ vec3 diffuse = diffuseColor.rgb;
...
@@ -17,14 +17,14 @@ vec3 diffuse = diffuseColor.rgb;
for
(
int
i
=
0
;
i
<
MAX_POINT_LIGHTS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
MAX_POINT_LIGHTS
;
i
++
)
{
vec3
lightColor
,
lightDir
;
IncidentLight
incidentLight
;
getPointLightDirect
(
pointLights
[
i
],
-
vViewPosition
,
lightColor
,
lightDir
);
getPointLightDirect
(
pointLights
[
i
],
-
vViewPosition
,
incidentLight
);
totalDirectReflectedDiffuse
+=
totalDirectReflectedDiffuse
+=
BRDF_Lambert
(
lightColor
,
lightDir
,
normal
,
diffuse
);
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
);
totalDirectReflectedSpecular
+=
totalDirectReflectedSpecular
+=
BRDF_BlinnPhong
(
lightColor
,
lightDir
,
normal
,
viewDir
,
specular
,
shininess
);
BRDF_BlinnPhong
(
incidentLight
,
normal
,
viewDir
,
specular
,
shininess
);
}
}
...
@@ -34,14 +34,14 @@ vec3 diffuse = diffuseColor.rgb;
...
@@ -34,14 +34,14 @@ vec3 diffuse = diffuseColor.rgb;
for
(
int
i
=
0
;
i
<
MAX_SPOT_LIGHTS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
MAX_SPOT_LIGHTS
;
i
++
)
{
vec3
lightColor
,
lightDir
;
IncidentLight
incidentLight
;
getSpotLightDirect
(
spotLights
[
i
],
-
vViewPosition
,
lightColor
,
lightDir
);
getSpotLightDirect
(
spotLights
[
i
],
-
vViewPosition
,
incidentLight
);
totalDirectReflectedDiffuse
+=
totalDirectReflectedDiffuse
+=
BRDF_Lambert
(
lightColor
,
lightDir
,
normal
,
diffuse
);
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
);
totalDirectReflectedSpecular
+=
totalDirectReflectedSpecular
+=
BRDF_BlinnPhong
(
lightColor
,
lightDir
,
normal
,
viewDir
,
specular
,
shininess
);
BRDF_BlinnPhong
(
incidentLight
,
normal
,
viewDir
,
specular
,
shininess
);
}
}
...
@@ -51,14 +51,14 @@ vec3 diffuse = diffuseColor.rgb;
...
@@ -51,14 +51,14 @@ vec3 diffuse = diffuseColor.rgb;
for
(
int
i
=
0
;
i
<
MAX_DIR_LIGHTS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
MAX_DIR_LIGHTS
;
i
++
)
{
vec3
lightColor
,
lightDir
;
IncidentLight
incidentLight
;
getDirLightDirect
(
directionalLights
[
i
],
lightColor
,
lightDir
);
getDirLightDirect
(
directionalLights
[
i
],
incidentLight
);
totalDirectReflectedDiffuse
+=
totalDirectReflectedDiffuse
+=
BRDF_Lambert
(
lightColor
,
lightDir
,
normal
,
diffuse
);
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
);
totalDirectReflectedSpecular
+=
totalDirectReflectedSpecular
+=
BRDF_BlinnPhong
(
lightColor
,
lightDir
,
normal
,
viewDir
,
specular
,
shininess
);
BRDF_BlinnPhong
(
incidentLight
,
normal
,
viewDir
,
specular
,
shininess
);
}
}
...
@@ -68,11 +68,11 @@ vec3 diffuse = diffuseColor.rgb;
...
@@ -68,11 +68,11 @@ vec3 diffuse = diffuseColor.rgb;
for
(
int
i
=
0
;
i
<
MAX_HEMI_LIGHTS
;
i
++
)
{
for
(
int
i
=
0
;
i
<
MAX_HEMI_LIGHTS
;
i
++
)
{
vec3
lightColor
,
lightDir
;
IncidentLight
incidentLight
;
getHemisphereLightIndirect
(
hemisphereLights
[
i
],
normal
,
lightColor
,
lightDir
);
getHemisphereLightIndirect
(
hemisphereLights
[
i
],
normal
,
incidentLight
);
totalIndirectReflectedDiffuse
+=
totalIndirectReflectedDiffuse
+=
BRDF_Lambert
(
lightColor
,
lightDir
,
normal
,
diffuse
);
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录