Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
ea903ed0
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,体验更适合开发者的 AI 搜索 >>
提交
ea903ed0
编写于
10月 11, 2015
作者:
B
Ben Houston
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
introducing the GeometricContext struct, broken hemisphere lights.
上级
b1017293
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
67 addition
and
54 deletion
+67
-54
examples/webgl_animation_skinning_morph.html
examples/webgl_animation_skinning_morph.html
+2
-0
examples/webgl_lights_pointlights.html
examples/webgl_lights_pointlights.html
+1
-1
examples/webgl_morphnormals.html
examples/webgl_morphnormals.html
+1
-1
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+5
-4
src/renderers/shaders/ShaderChunk/common.glsl
src/renderers/shaders/ShaderChunk/common.glsl
+25
-19
src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
+16
-14
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
+17
-15
未找到文件。
examples/webgl_animation_skinning_morph.html
浏览文件 @
ea903ed0
...
...
@@ -158,6 +158,8 @@
var
loader
=
new
THREE
.
JSONLoader
();
loader
.
load
(
"
models/skinned/knight.js
"
,
function
(
geometry
,
materials
)
{
console
.
log
(
'
materials
'
,
materials
);
createScene
(
geometry
,
materials
,
0
,
FLOOR
,
-
300
,
60
)
}
);
...
...
examples/webgl_lights_pointlights.html
浏览文件 @
ea903ed0
...
...
@@ -72,7 +72,7 @@
var
callback
=
function
(
geometry
)
{
object
=
new
THREE
.
Mesh
(
geometry
,
new
THREE
.
MeshPhongMaterial
(
{
color
:
0x555555
,
specular
:
0x
ffffff
,
shininess
:
50
}
)
);
object
=
new
THREE
.
Mesh
(
geometry
,
new
THREE
.
MeshPhongMaterial
(
{
color
:
0x555555
,
specular
:
0x
111111
,
shininess
:
50
}
)
);
object
.
scale
.
x
=
object
.
scale
.
y
=
object
.
scale
.
z
=
0.80
;
scene
.
add
(
object
);
...
...
examples/webgl_morphnormals.html
浏览文件 @
ea903ed0
...
...
@@ -114,7 +114,7 @@
geometry
.
computeVertexNormals
();
geometry
.
computeMorphNormals
();
var
material
=
new
THREE
.
MeshPhongMaterial
(
{
color
:
0xffffff
,
specular
:
0x
ffffff
,
shininess
:
20
,
morphTargets
:
true
,
morphNormals
:
true
,
vertexColors
:
THREE
.
FaceColors
,
shading
:
THREE
.
SmoothShading
}
);
var
material
=
new
THREE
.
MeshPhongMaterial
(
{
color
:
0xffffff
,
specular
:
0x
111111
,
shininess
:
20
,
morphTargets
:
true
,
morphNormals
:
true
,
vertexColors
:
THREE
.
FaceColors
,
shading
:
THREE
.
SmoothShading
}
);
var
mesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
mesh
.
scale
.
set
(
1.5
,
1.5
,
1.5
);
...
...
src/renderers/WebGLRenderer.js
浏览文件 @
ea903ed0
...
...
@@ -2518,7 +2518,7 @@ THREE.WebGLRenderer = function ( parameters ) {
if
(
!
light
.
__webglUniforms
)
{
light
.
__webglUniforms
=
{
posi
tion
:
new
THREE
.
Vector3
(),
direc
tion
:
new
THREE
.
Vector3
(),
skyColor
:
new
THREE
.
Color
(),
groundColor
:
new
THREE
.
Color
()
}
...
...
@@ -2532,10 +2532,11 @@ THREE.WebGLRenderer = function ( parameters ) {
continue
;
}
lightUniforms
.
position
.
setFromMatrixPosition
(
light
.
matrixWorld
);
lightUniforms
.
position
.
transformDirection
(
viewMatrix
);
lightUniforms
.
direction
.
setFromMatrixPosition
(
light
.
matrixWorld
);
lightUniforms
.
direction
.
transformDirection
(
viewMatrix
);
lightUniforms
.
direction
.
normalize
();
lightUniforms
.
skyColor
.
copy
(
light
.
color
).
multiplyScalar
(
intensity
);
lightUniforms
.
skyColor
.
copy
(
light
.
color
).
multiplyScalar
(
intensity
);
lightUniforms
.
groundColor
.
copy
(
light
.
groundColor
).
multiplyScalar
(
intensity
);
}
...
...
src/renderers/shaders/ShaderChunk/common.glsl
浏览文件 @
ea903ed0
...
...
@@ -102,18 +102,24 @@ struct ReflectedLight {
vec3
diffuse
;
};
void
BRDF_Lambert
(
const
in
IncidentLight
incidentLight
,
const
in
vec3
normal
,
const
in
vec3
diffuseColor
,
inout
ReflectedLight
reflectedLight
)
{
struct
GeometricContext
{
vec3
position
;
vec3
normal
;
vec3
viewDir
;
};
void
BRDF_Lambert
(
const
in
IncidentLight
incidentLight
,
const
in
GeometricContext
geometryContext
,
const
in
vec3
diffuseColor
,
inout
ReflectedLight
reflectedLight
)
{
reflectedLight
.
diffuse
+=
incidentLight
.
color
*
diffuseColor
*
(
saturate
(
dot
(
normal
,
incidentLight
.
direction
)
)
*
RECIPROCAL_PI
);
reflectedLight
.
diffuse
+=
incidentLight
.
color
*
diffuseColor
*
(
saturate
(
dot
(
geometryContext
.
normal
,
incidentLight
.
direction
)
)
*
RECIPROCAL_PI
);
}
void
BRDF_OrenNayar
(
const
in
IncidentLight
incidentLight
,
const
in
vec3
normal
,
const
in
vec3
viewDir
,
const
in
vec3
diffuse
,
const
in
float
roughness
,
inout
ReflectedLight
reflectedLight
)
{
void
BRDF_OrenNayar
(
const
in
IncidentLight
incidentLight
,
const
in
GeometricContext
geometryContext
,
const
in
vec3
diffuse
,
const
in
float
roughness
,
inout
ReflectedLight
reflectedLight
)
{
vec3
halfDir
=
normalize
(
incidentLight
.
direction
+
viewDir
);
float
dotVH
=
saturate
(
dot
(
viewDir
,
halfDir
)
);
float
dotNV
=
saturate
(
dot
(
normal
,
viewDir
)
);
float
dotNL
=
saturate
(
dot
(
normal
,
incidentLight
.
direction
)
);
vec3
halfDir
=
normalize
(
incidentLight
.
direction
+
geometryContext
.
viewDir
);
float
dotVH
=
saturate
(
dot
(
geometryContext
.
viewDir
,
halfDir
)
);
float
dotNV
=
saturate
(
dot
(
geometryContext
.
normal
,
geometryContext
.
viewDir
)
);
float
dotNL
=
saturate
(
dot
(
geometryContext
.
normal
,
incidentLight
.
direction
)
);
float
m2
=
roughness
*
roughness
;
float
termA
=
1
.
0
-
0
.
5
*
m2
/
(
m2
+
0
.
33
);
...
...
@@ -153,10 +159,10 @@ float D_BlinnPhong( const in float shininess, const in float dotNH ) {
}
void
BRDF_BlinnPhong
(
const
in
IncidentLight
incidentLight
,
const
in
vec3
normal
,
const
in
vec3
viewDir
,
const
in
vec3
specularColor
,
const
in
float
shininess
,
inout
ReflectedLight
reflectedLight
)
{
void
BRDF_BlinnPhong
(
const
in
IncidentLight
incidentLight
,
const
in
GeometricContext
geometryContext
,
const
in
vec3
specularColor
,
const
in
float
shininess
,
inout
ReflectedLight
reflectedLight
)
{
vec3
halfDir
=
normalize
(
incidentLight
.
direction
+
viewDir
);
float
dotNH
=
saturate
(
dot
(
normal
,
halfDir
)
);
vec3
halfDir
=
normalize
(
incidentLight
.
direction
+
geometryContext
.
viewDir
);
float
dotNH
=
saturate
(
dot
(
geometryContext
.
normal
,
halfDir
)
);
float
dotLH
=
saturate
(
dot
(
incidentLight
.
direction
,
halfDir
)
);
vec3
F
=
F_Schlick
(
specularColor
,
dotLH
);
...
...
@@ -176,7 +182,7 @@ void BRDF_BlinnPhong( const in IncidentLight incidentLight, const in vec3 normal
uniform
DirectionalLight
directionalLights
[
MAX_DIR_LIGHTS
];
void
getDirIncidentLight
(
const
in
DirectionalLight
directionalLight
,
out
IncidentLight
incidentLight
)
{
void
getDirIncidentLight
(
const
in
DirectionalLight
directionalLight
,
const
in
GeometricContext
geometryContext
,
out
IncidentLight
incidentLight
)
{
incidentLight
.
color
=
directionalLight
.
color
;
incidentLight
.
direction
=
directionalLight
.
direction
;
...
...
@@ -196,11 +202,11 @@ void BRDF_BlinnPhong( const in IncidentLight incidentLight, const in vec3 normal
uniform
PointLight
pointLights
[
MAX_POINT_LIGHTS
];
void
getPointIncidentLight
(
const
in
PointLight
pointLight
,
const
in
vec3
position
,
out
IncidentLight
incidentLight
)
{
void
getPointIncidentLight
(
const
in
PointLight
pointLight
,
const
in
GeometricContext
geometryContext
,
out
IncidentLight
incidentLight
)
{
vec3
lightPosition
=
pointLight
.
position
;
vec3
lVector
=
lightPosition
-
position
;
vec3
lVector
=
lightPosition
-
geometryContext
.
position
;
incidentLight
.
direction
=
normalize
(
lVector
);
incidentLight
.
color
=
pointLight
.
color
;
...
...
@@ -224,11 +230,11 @@ void BRDF_BlinnPhong( const in IncidentLight incidentLight, const in vec3 normal
uniform
SpotLight
spotLights
[
MAX_SPOT_LIGHTS
];
void
getSpotIncidentLight
(
const
in
SpotLight
spotLight
,
const
in
vec3
position
,
out
IncidentLight
incidentLight
)
{
void
getSpotIncidentLight
(
const
in
SpotLight
spotLight
,
const
in
GeometricContext
geometryContext
,
out
IncidentLight
incidentLight
)
{
vec3
lightPosition
=
spotLight
.
position
;
vec3
lVector
=
lightPosition
-
position
;
vec3
lVector
=
lightPosition
-
geometryContext
.
position
;
incidentLight
.
direction
=
normalize
(
lVector
);
float
spotEffect
=
dot
(
spotLight
.
direction
,
incidentLight
.
direction
);
...
...
@@ -250,17 +256,17 @@ void BRDF_BlinnPhong( const in IncidentLight incidentLight, const in vec3 normal
vec3
groundColor
;
};
layout
(
packed
)
uniform
HemisphereLight
hemisphereLights
[
MAX_HEMI_LIGHTS
];
uniform
HemisphereLight
hemisphereLights
[
MAX_HEMI_LIGHTS
];
void
getHemisphereIncidentLight
(
const
in
HemisphereLight
hemiLight
,
const
in
vec3
normal
,
out
IncidentLight
incidentLight
)
{
void
getHemisphereIncidentLight
(
const
in
HemisphereLight
hemiLight
,
const
in
GeometricContext
geometryContext
,
out
IncidentLight
incidentLight
)
{
float
dotNL
=
dot
(
normal
,
hemiLight
.
direction
);
float
dotNL
=
dot
(
geometryContext
.
normal
,
hemiLight
.
direction
);
float
hemiDiffuseWeight
=
0
.
5
*
dotNL
+
0
.
5
;
incidentLight
.
color
=
mix
(
hemiLight
.
groundColor
,
hemiLight
.
skyColor
,
hemiDiffuseWeight
);
incidentLight
.
direction
=
normal
;
incidentLight
.
direction
=
geometryContext
.
normal
;
}
...
...
src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
浏览文件 @
ea903ed0
vec3
viewDir
=
normalize
(
-
mvPosition
.
xyz
);
vec3
normal
=
normalize
(
transformedNormal
);
vec3
backNormal
=
-
normal
;
vec3
diffuse
=
vec3
(
1
.
0
);
...
...
@@ -7,18 +7,20 @@ IncidentLight incidentLight;
ReflectedLight
frontReflectedLight
=
ReflectedLight
(
vec3
(
0
.
0
),
vec3
(
0
.
0
)
);
ReflectedLight
backReflectedLight
=
ReflectedLight
(
vec3
(
0
.
0
),
vec3
(
0
.
0
)
);
GeometricContext
geometricContext
=
GeometricContext
(
mvPosition
.
xyz
,
normal
,
viewDir
);
GeometricContext
backGeometricContext
=
GeometricContext
(
mvPosition
.
xyz
,
-
normal
,
viewDir
);
#if MAX_POINT_LIGHTS > 0
for
(
int
i
=
0
;
i
<
MAX_POINT_LIGHTS
;
i
++
)
{
getPointIncidentLight
(
pointLights
[
i
],
mvPosition
.
xyz
,
incidentLight
);
getPointIncidentLight
(
pointLights
[
i
],
geometricContext
,
incidentLight
);
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
,
frontReflectedLight
);
BRDF_Lambert
(
incidentLight
,
geometricContext
,
diffuse
,
frontReflectedLight
);
#ifdef DOUBLE_SIDED
BRDF_Lambert
(
incidentLight
,
back
Normal
,
diffuse
,
backReflectedLight
);
BRDF_Lambert
(
incidentLight
,
back
GeometricContext
,
diffuse
,
backReflectedLight
);
#endif
...
...
@@ -30,13 +32,13 @@ ReflectedLight backReflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ) );
for
(
int
i
=
0
;
i
<
MAX_SPOT_LIGHTS
;
i
++
)
{
getSpotIncidentLight
(
spotLights
[
i
],
mvPosition
.
xyz
,
incidentLight
);
getSpotIncidentLight
(
spotLights
[
i
],
geometricContext
,
incidentLight
);
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
,
frontReflectedLight
);
BRDF_Lambert
(
incidentLight
,
geometricContext
,
diffuse
,
frontReflectedLight
);
#ifdef DOUBLE_SIDED
BRDF_Lambert
(
incidentLight
,
back
Normal
,
diffuse
,
backReflectedLight
);
BRDF_Lambert
(
incidentLight
,
back
GeometricContext
,
diffuse
,
backReflectedLight
);
#endif
...
...
@@ -48,13 +50,13 @@ ReflectedLight backReflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ) );
for
(
int
i
=
0
;
i
<
MAX_DIR_LIGHTS
;
i
++
)
{
getDirIncidentLight
(
directionalLights
[
i
],
incidentLight
);
getDirIncidentLight
(
directionalLights
[
i
],
geometricContext
,
incidentLight
);
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
,
frontReflectedLight
);
BRDF_Lambert
(
incidentLight
,
geometricContext
,
diffuse
,
frontReflectedLight
);
#ifdef DOUBLE_SIDED
BRDF_Lambert
(
incidentLight
,
back
Normal
,
diffuse
,
backReflectedLight
);
BRDF_Lambert
(
incidentLight
,
back
GeometricContext
,
diffuse
,
backReflectedLight
);
#endif
...
...
@@ -66,15 +68,15 @@ ReflectedLight backReflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ) );
for
(
int
i
=
0
;
i
<
MAX_HEMI_LIGHTS
;
i
++
)
{
getHemisphereLightIndirect
(
hemisphereLights
[
i
],
normal
,
incidentLight
);
getHemisphereLightIndirect
(
hemisphereLights
[
i
],
geometricContext
,
,
incidentLight
);
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
,
frontReflectedLight
);
BRDF_Lambert
(
incidentLight
,
geometricContext
,
,
diffuse
,
frontReflectedLight
);
#ifdef DOUBLE_SIDED
getHemisphereIncidentLight
(
hemisphereLights
[
i
],
back
Normal
,
incidentLight
);
getHemisphereIncidentLight
(
hemisphereLights
[
i
],
back
GeometricContext
,
incidentLight
);
BRDF_Lambert
(
incidentLight
,
back
Normal
,
diffuse
,
backReflectedLight
);
BRDF_Lambert
(
incidentLight
,
back
GeometricContext
,
diffuse
,
backReflectedLight
);
#endif
...
...
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
浏览文件 @
ea903ed0
...
...
@@ -24,16 +24,18 @@ IncidentLight incidentLight;
ReflectedLight
directReflectedLight
=
ReflectedLight
(
vec3
(
0
.
0
),
vec3
(
0
.
0
)
);
ReflectedLight
indirectReflectedLight
=
ReflectedLight
(
vec3
(
0
.
0
),
vec3
(
0
.
0
)
);
GeometricContext
geometricContext
=
GeometricContext
(
-
vViewPosition
,
normal
,
viewDir
);
#if MAX_POINT_LIGHTS > 0
for
(
int
i
=
0
;
i
<
MAX_POINT_LIGHTS
;
i
++
)
{
getPointIncidentLight
(
pointLights
[
i
],
-
vViewPosition
,
incidentLight
);
getPointIncidentLight
(
pointLights
[
i
],
geometricContext
,
incidentLight
);
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
,
directReflectedLight
);
//BRDF_OrenNayar( incidentLight,
normal, viewDir
, diffuse, 0.5, directReflectedLight );
BRDF_Lambert
(
incidentLight
,
geometricContext
,
diffuse
,
directReflectedLight
);
//BRDF_OrenNayar( incidentLight,
geometricContext
, diffuse, 0.5, directReflectedLight );
BRDF_BlinnPhong
(
incidentLight
,
normal
,
viewDir
,
specular
,
shininess
,
directReflectedLight
);
BRDF_BlinnPhong
(
incidentLight
,
geometricContext
,
specular
,
shininess
,
directReflectedLight
);
}
...
...
@@ -43,12 +45,12 @@ ReflectedLight indirectReflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 )
for
(
int
i
=
0
;
i
<
MAX_SPOT_LIGHTS
;
i
++
)
{
getSpotIncidentLight
(
spotLights
[
i
],
-
vViewPosition
,
incidentLight
);
getSpotIncidentLight
(
spotLights
[
i
],
geometricContext
,
incidentLight
);
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
,
directReflectedLight
);
//BRDF_OrenNayar( incidentLight,
normal, viewDir
, diffuse, 0.5, directReflectedLight );
BRDF_Lambert
(
incidentLight
,
geometricContext
,
diffuse
,
directReflectedLight
);
//BRDF_OrenNayar( incidentLight,
geometricContext
, diffuse, 0.5, directReflectedLight );
BRDF_BlinnPhong
(
incidentLight
,
normal
,
viewDir
,
specular
,
shininess
,
directReflectedLight
);
BRDF_BlinnPhong
(
incidentLight
,
geometricContext
,
specular
,
shininess
,
directReflectedLight
);
}
...
...
@@ -58,12 +60,12 @@ ReflectedLight indirectReflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 )
for
(
int
i
=
0
;
i
<
MAX_DIR_LIGHTS
;
i
++
)
{
getDirIncidentLight
(
directionalLights
[
i
],
incidentLight
);
getDirIncidentLight
(
directionalLights
[
i
],
geometricContext
,
incidentLight
);
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
,
directReflectedLight
);
//BRDF_OrenNayar( incidentLight,
normal, viewDir
, diffuse, 0.5, directReflectedLight );
BRDF_Lambert
(
incidentLight
,
geometricContext
,
diffuse
,
directReflectedLight
);
//BRDF_OrenNayar( incidentLight,
geometricContext
, diffuse, 0.5, directReflectedLight );
BRDF_BlinnPhong
(
incidentLight
,
normal
,
viewDir
,
specular
,
shininess
,
directReflectedLight
);
BRDF_BlinnPhong
(
incidentLight
,
geometricContext
,
specular
,
shininess
,
directReflectedLight
);
}
...
...
@@ -73,10 +75,10 @@ ReflectedLight indirectReflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 )
for
(
int
i
=
0
;
i
<
MAX_HEMI_LIGHTS
;
i
++
)
{
getHemisphereIncidentLight
(
hemisphereLights
[
i
],
normal
,
incidentLight
);
getHemisphereIncidentLight
(
hemisphereLights
[
i
],
geometricContext
,
incidentLight
);
BRDF_Lambert
(
incidentLight
,
normal
,
diffuse
,
indirectReflectedLight
);
//BRDF_OrenNayar( incidentLight,
normal, viewDir
, diffuse, 0.5, indirectReflectedLight );
BRDF_Lambert
(
incidentLight
,
geometricContext
,
diffuse
,
indirectReflectedLight
);
//BRDF_OrenNayar( incidentLight,
geometricContext
, diffuse, 0.5, indirectReflectedLight );
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录