Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
7af978c4
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,发现更多精彩内容 >>
提交
7af978c4
编写于
12月 05, 2012
作者:
A
alteredq
浏览文件
操作
浏览文件
下载
差异文件
Merged @MiiBond's shadow map bilinear filtering.
See #2698
上级
9c8c639f
0c899e05
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
447 addition
and
261 deletion
+447
-261
build/three.js
build/three.js
+102
-6
build/three.min.js
build/three.min.js
+153
-151
docs/api/renderers/WebGLRenderer.html
docs/api/renderers/WebGLRenderer.html
+2
-2
examples/webgl_interactive_cubes_gpu.html
examples/webgl_interactive_cubes_gpu.html
+101
-85
examples/webgl_interactive_draggablecubes.html
examples/webgl_interactive_draggablecubes.html
+1
-1
examples/webgl_loader_utf8.html
examples/webgl_loader_utf8.html
+1
-0
examples/webgl_materials_normalmap.html
examples/webgl_materials_normalmap.html
+1
-1
examples/webgl_shading_physical.html
examples/webgl_shading_physical.html
+1
-0
examples/webgl_shadowmap.html
examples/webgl_shadowmap.html
+1
-1
examples/webgl_shadowmap_performance.html
examples/webgl_shadowmap_performance.html
+1
-1
src/Three.js
src/Three.js
+6
-0
src/extras/renderers/plugins/ShadowMapPlugin.js
src/extras/renderers/plugins/ShadowMapPlugin.js
+9
-1
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+16
-4
src/renderers/WebGLShaders.js
src/renderers/WebGLShaders.js
+52
-8
未找到文件。
build/three.js
浏览文件 @
7af978c4
...
...
@@ -91,6 +91,12 @@ THREE.CullFaceFrontBack = 3;
THREE.FrontFaceDirectionCW = 0;
THREE.FrontFaceDirectionCCW = 1;
// SHADOWING TYPES
THREE.BasicShadowMap = 0;
THREE.PCFShadowMap = 1;
THREE.PCFSoftShadowMap = 2;
// MATERIAL CONSTANTS
// side
...
...
@@ -16038,7 +16044,7 @@ THREE.ShaderChunk = {
"shadowCoord.z += shadowBias[ i ];",
"#if
def SHADOWMAP_SOFT
",
"#if
defined( SHADOWMAP_TYPE_PCF )
",
// Percentage-close filtering
// (9 pixel kernel)
...
...
@@ -16108,6 +16114,76 @@ THREE.ShaderChunk = {
"shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );",
"#elif defined( SHADOWMAP_TYPE_PCF_SOFT )",
// Percentage-close filtering
// (9 pixel kernel)
// http://fabiensanglard.net/shadowmappingPCF/
"float shadow = 0.0;",
"float xPixelOffset = 1.0 / shadowMapSize[ i ].x;",
"float yPixelOffset = 1.0 / shadowMapSize[ i ].y;",
"float dx0 = -1.0 * xPixelOffset;",
"float dy0 = -1.0 * yPixelOffset;",
"float dx1 = 1.0 * xPixelOffset;",
"float dy1 = 1.0 * yPixelOffset;",
"mat3 shadowKernel;",
"mat3 depthKernel;",
"depthKernel[0][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );",
"if ( depthKernel[0][0] < shadowCoord.z ) shadowKernel[0][0] = 0.25;",
"else shadowKernel[0][0] = 0.0;",
"depthKernel[0][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );",
"if ( depthKernel[0][1] < shadowCoord.z ) shadowKernel[0][1] = 0.25;",
"else shadowKernel[0][1] = 0.0;",
"depthKernel[0][2] = unpackDepth( texture2D( shadowMap[ i], shadowCoord.xy + vec2( dx0, dy1 ) ) );",
"if ( depthKernel[0][2] < shadowCoord.z ) shadowKernel[0][2] = 0.25;",
"else shadowKernel[0][2] = 0.0;",
"depthKernel[1][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );",
"if ( depthKernel[1][0] < shadowCoord.z ) shadowKernel[1][0] = 0.25;",
"else shadowKernel[1][0] = 0.0;",
"depthKernel[1][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );",
"if ( depthKernel[1][1] < shadowCoord.z ) shadowKernel[1][1] = 0.25;",
"else shadowKernel[1][1] = 0.0;",
"depthKernel[1][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );",
"if ( depthKernel[1][2] < shadowCoord.z ) shadowKernel[1][2] = 0.25;",
"else shadowKernel[1][2] = 0.0;",
"depthKernel[2][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );",
"if ( depthKernel[2][0] < shadowCoord.z ) shadowKernel[2][0] = 0.25;",
"else shadowKernel[2][0] = 0.0;",
"depthKernel[2][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );",
"if ( depthKernel[2][1] < shadowCoord.z ) shadowKernel[2][1] = 0.25;",
"else shadowKernel[2][1] = 0.0;",
"depthKernel[2][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );",
"if ( depthKernel[2][2] < shadowCoord.z ) shadowKernel[2][2] = 0.25;",
"else shadowKernel[2][2] = 0.0;",
"vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[i].xy );",
"shadowKernel[0] = mix( shadowKernel[1], shadowKernel[0], fractionalCoord.x );",
"shadowKernel[1] = mix( shadowKernel[2], shadowKernel[1], fractionalCoord.x );",
"vec4 shadowValues;",
"shadowValues.x = mix( shadowKernel[0][1], shadowKernel[0][0], fractionalCoord.y );",
"shadowValues.y = mix( shadowKernel[0][2], shadowKernel[0][1], fractionalCoord.y );",
"shadowValues.z = mix( shadowKernel[1][1], shadowKernel[1][0], fractionalCoord.y );",
"shadowValues.w = mix( shadowKernel[1][2], shadowKernel[1][1], fractionalCoord.y );",
"shadow = dot( shadowValues, vec4( 1.0 ) );",
"shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );",
"#else",
"vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );",
...
...
@@ -17006,7 +17082,7 @@ THREE.WebGLRenderer = function ( parameters ) {
this.shadowMapEnabled = false;
this.shadowMapAutoUpdate = true;
this.shadowMap
Soft = true
;
this.shadowMap
Type = THREE.PCFShadowMap
;
this.shadowMapCullFace = THREE.CullFaceFront;
this.shadowMapDebug = false;
this.shadowMapCascade = false;
...
...
@@ -21877,7 +21953,7 @@ THREE.WebGLRenderer = function ( parameters ) {
maxShadows: maxShadows,
shadowMapEnabled: this.shadowMapEnabled && object.receiveShadow,
shadowMap
Soft: this.shadowMapSoft
,
shadowMap
Type: this.shadowMapType
,
shadowMapDebug: this.shadowMapDebug,
shadowMapCascade: this.shadowMapCascade,
...
...
@@ -23180,6 +23256,18 @@ THREE.WebGLRenderer = function ( parameters ) {
}
var shadowMapTypeDefine = "SHADOWMAP_TYPE_BASIC";
if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
shadowMapTypeDefine = "SHADOWMAP_TYPE_PCF";
} else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
shadowMapTypeDefine = "SHADOWMAP_TYPE_PCF_SOFT";
}
//console.log( "building new program " );
//
...
...
@@ -23232,7 +23320,7 @@ THREE.WebGLRenderer = function ( parameters ) {
parameters.flipSided ? "#define FLIP_SIDED" : "",
parameters.shadowMapEnabled ? "#define USE_SHADOWMAP" : "",
parameters.shadowMap
Soft ? "#define SHADOWMAP_SOFT"
: "",
parameters.shadowMap
Enabled ? "#define " + shadowMapTypeDefine
: "",
parameters.shadowMapDebug ? "#define SHADOWMAP_DEBUG" : "",
parameters.shadowMapCascade ? "#define SHADOWMAP_CASCADE" : "",
...
...
@@ -23331,7 +23419,7 @@ THREE.WebGLRenderer = function ( parameters ) {
parameters.flipSided ? "#define FLIP_SIDED" : "",
parameters.shadowMapEnabled ? "#define USE_SHADOWMAP" : "",
parameters.shadowMap
Soft ? "#define SHADOWMAP_SOFT"
: "",
parameters.shadowMap
Enabled ? "#define " + shadowMapTypeDefine
: "",
parameters.shadowMapDebug ? "#define SHADOWMAP_DEBUG" : "",
parameters.shadowMapCascade ? "#define SHADOWMAP_CASCADE" : "",
...
...
@@ -35691,7 +35779,15 @@ THREE.ShadowMapPlugin = function ( ) {
if ( ! light.shadowMap ) {
var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat };
var shadowFilter = THREE.LinearFilter;
if ( _renderer.shadowMapType === THREE.PCFSoftShadowMap ) {
shadowFilter = THREE.NearestFilter;
}
var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
light.shadowMap = new THREE.WebGLRenderTarget( light.shadowMapWidth, light.shadowMapHeight, pars );
light.shadowMapSize = new THREE.Vector2( light.shadowMapWidth, light.shadowMapHeight );
...
...
build/three.min.js
浏览文件 @
7af978c4
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
docs/api/renderers/WebGLRenderer.html
浏览文件 @
7af978c4
...
...
@@ -110,9 +110,9 @@
<div>
Default is true. TODO
</div>
<h3>
.[page:
Boolean shadowMapSoft
]
</h3>
<h3>
.[page:
Integer shadowMapType
]
</h3>
<div>
Default is
true
. TODO
</div>
<div>
Default is
THREE.PCFShadowMap
. TODO
</div>
<h3>
.[page:Boolean shadowMapCullFrontFaces]
</h3>
...
...
examples/webgl_interactive_cubes_gpu.html
浏览文件 @
7af978c4
...
...
@@ -50,14 +50,14 @@
var
highlightBox
;
var
mouse
=
new
THREE
.
Vector2
();
var
offset
=
new
THREE
.
Vector3
(
10
,
10
,
10
);
var
offset
=
new
THREE
.
Vector3
(
10
,
10
,
10
);
init
();
animate
();
function
init
()
{
container
=
document
.
getElementById
(
"
container
"
);
container
=
document
.
getElementById
(
"
container
"
);
camera
=
new
THREE
.
PerspectiveCamera
(
70
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
10000
);
camera
.
position
.
z
=
1000
;
...
...
@@ -72,126 +72,128 @@
controls
.
dynamicDampingFactor
=
0.3
;
scene
=
new
THREE
.
Scene
();
pickingScene
=
new
THREE
.
Scene
();
pickingTexture
=
new
THREE
.
WebGLRenderTarget
(
window
.
innerWidth
,
window
.
innerHeight
);
pickingTexture
=
new
THREE
.
WebGLRenderTarget
(
window
.
innerWidth
,
window
.
innerHeight
);
pickingTexture
.
generateMipmaps
=
false
;
scene
.
add
(
new
THREE
.
AmbientLight
(
0x555555
)
);
var
light
=
new
THREE
.
SpotLight
(
0xffffff
,
1.5
);
light
.
position
.
set
(
0
,
500
,
2000
);
light
.
castShadow
=
true
;
scene
.
add
(
light
)
;
light
.
shadowCameraNear
=
200
;
light
.
shadowCameraFar
=
camera
.
far
;
light
.
shadowCameraFov
=
50
;
var
geometry
=
new
THREE
.
Geometry
(),
pickingGeometry
=
new
THREE
.
Geometry
(),
pickingMaterial
=
new
THREE
.
MeshBasicMaterial
(
{
vertexColors
:
THREE
.
VertexColors
}
),
defaultMaterial
=
new
THREE
.
MeshLambertMaterial
({
color
:
0xffffff
,
shading
:
THREE
.
FlatShading
,
vertexColors
:
THREE
.
VertexColors
}
);
light
.
shadowBias
=
-
0.00022
;
light
.
shadowDarkness
=
0.5
;
function
applyVertexColors
(
g
,
c
)
{
light
.
shadowMapWidth
=
1024
;
light
.
shadowMapHeight
=
1024
;
g
.
faces
.
forEach
(
function
(
f
)
{
scene
.
add
(
light
);
var
n
=
(
f
instanceof
THREE
.
Face3
)
?
3
:
4
;
for
(
var
j
=
0
;
j
<
n
;
j
++
)
{
f
.
vertexColors
[
j
]
=
c
;
var
geometry
=
new
THREE
.
Geometry
(),
pickingGeometry
=
new
THREE
.
Geometry
(),
pickingMaterial
=
new
THREE
.
MeshBasicMaterial
({
vertexColors
:
THREE
.
VertexColors
}),
defaultMaterial
=
new
THREE
.
MeshLambertMaterial
({
color
:
0xffffff
,
shading
:
THREE
.
FlatShading
,
vertexColors
:
THREE
.
VertexColors
});
function
applyVertexColors
(
g
,
c
)
{
g
.
faces
.
forEach
(
function
(
f
){
var
n
=
(
f
instanceof
THREE
.
Face3
)
?
3
:
4
;
for
(
var
j
=
0
;
j
<
n
;
j
++
){
f
.
vertexColors
[
j
]
=
c
;
}
});
}
);
}
for
(
var
i
=
0
;
i
<
5000
;
i
++
)
{
var
position
=
new
THREE
.
Vector3
();
position
.
x
=
Math
.
random
()
*
10000
-
5000
;
position
.
y
=
Math
.
random
()
*
6000
-
3000
;
position
.
z
=
Math
.
random
()
*
8000
-
4000
;
var
rotation
=
new
THREE
.
Vector3
();
rotation
.
x
=
(
Math
.
random
()
*
2
*
Math
.
PI
);
rotation
.
y
=
(
Math
.
random
()
*
2
*
Math
.
PI
);
rotation
.
z
=
(
Math
.
random
()
*
2
*
Math
.
PI
);
rotation
.
x
=
(
Math
.
random
()
*
2
*
Math
.
PI
);
rotation
.
y
=
(
Math
.
random
()
*
2
*
Math
.
PI
);
rotation
.
z
=
(
Math
.
random
()
*
2
*
Math
.
PI
);
var
scale
=
new
THREE
.
Vector3
();
scale
.
x
=
Math
.
random
()
*
200
+
100
;
scale
.
y
=
Math
.
random
()
*
200
+
100
;
scale
.
z
=
Math
.
random
()
*
200
+
100
;
//give the geom's vertices a random color, to be displayed
var
geom
=
new
THREE
.
CubeGeometry
(
1
,
1
,
1
);
var
color
=
new
THREE
.
Color
(
Math
.
random
()
*
0xffffff
);
applyVertexColors
(
geom
,
color
);
var
cube
=
new
THREE
.
Mesh
(
geom
);
cube
.
position
.
copy
(
position
);
cube
.
rotation
.
copy
(
rotation
);
cube
.
scale
.
copy
(
scale
);
THREE
.
GeometryUtils
.
merge
(
geometry
,
cube
);
// give the geom's vertices a random color, to be displayed
var
geom
=
new
THREE
.
CubeGeometry
(
1
,
1
,
1
);
var
color
=
new
THREE
.
Color
(
Math
.
random
()
*
0xffffff
);
applyVertexColors
(
geom
,
color
);
var
cube
=
new
THREE
.
Mesh
(
geom
);
cube
.
position
.
copy
(
position
);
cube
.
rotation
.
copy
(
rotation
);
cube
.
scale
.
copy
(
scale
);
THREE
.
GeometryUtils
.
merge
(
geometry
,
cube
);
//give the pickingGeom's vertices a color corresponding to the "id"
var
pickingGeom
=
new
THREE
.
CubeGeometry
(
1
,
1
,
1
);
var
pickingColor
=
new
THREE
.
Color
(
i
);
applyVertexColors
(
pickingGeom
,
pickingColor
);
var
pickingCube
=
new
THREE
.
Mesh
(
pickingGeom
);
pickingCube
.
position
.
copy
(
position
);
pickingCube
.
rotation
.
copy
(
rotation
);
pickingCube
.
scale
.
copy
(
scale
);
THREE
.
GeometryUtils
.
merge
(
pickingGeometry
,
pickingCube
);
pickingData
[
i
]
=
{
var
pickingGeom
=
new
THREE
.
CubeGeometry
(
1
,
1
,
1
);
var
pickingColor
=
new
THREE
.
Color
(
i
);
applyVertexColors
(
pickingGeom
,
pickingColor
);
var
pickingCube
=
new
THREE
.
Mesh
(
pickingGeom
);
pickingCube
.
position
.
copy
(
position
);
pickingCube
.
rotation
.
copy
(
rotation
);
pickingCube
.
scale
.
copy
(
scale
);
THREE
.
GeometryUtils
.
merge
(
pickingGeometry
,
pickingCube
);
pickingData
[
i
]
=
{
position
:
position
,
rotation
:
rotation
,
scale
:
scale
};
}
var
drawnObject
=
new
THREE
.
Mesh
(
geometry
,
defaultMaterial
);
//drawnObject.castShadow = true;
//drawnObject.receiveShadow = true;
scene
.
add
(
drawnObject
);
pickingScene
.
add
(
new
THREE
.
Mesh
(
pickingGeometry
,
pickingMaterial
));
highlightBox
=
new
THREE
.
Mesh
(
new
THREE
.
CubeGeometry
(
1
,
1
,
1
),
new
THREE
.
MeshLambertMaterial
({
color
:
0xffff00
}));
scene
.
add
(
highlightBox
);
var
drawnObject
=
new
THREE
.
Mesh
(
geometry
,
defaultMaterial
);
scene
.
add
(
drawnObject
);
pickingScene
.
add
(
new
THREE
.
Mesh
(
pickingGeometry
,
pickingMaterial
)
);
highlightBox
=
new
THREE
.
Mesh
(
new
THREE
.
CubeGeometry
(
1
,
1
,
1
),
new
THREE
.
MeshLambertMaterial
(
{
color
:
0xffff00
}
)
);
scene
.
add
(
highlightBox
);
projector
=
new
THREE
.
Projector
();
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
,
clearColor
:
0xffffff
}
);
renderer
.
sortObjects
=
false
;
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
shadowMapEnabled
=
true
;
renderer
.
shadowMapSoft
=
true
;
container
.
appendChild
(
renderer
.
domElement
);
stats
=
new
Stats
();
stats
.
domElement
.
style
.
position
=
'
absolute
'
;
stats
.
domElement
.
style
.
top
=
'
0px
'
;
container
.
appendChild
(
stats
.
domElement
);
renderer
.
domElement
.
addEventListener
(
'
mousemove
'
,
onMouseMove
);
renderer
.
domElement
.
addEventListener
(
'
mousemove
'
,
onMouseMove
);
}
//
function
onMouseMove
(
e
)
{
function
onMouseMove
(
e
)
{
mouse
.
x
=
e
.
clientX
;
mouse
.
y
=
e
.
clientY
;
}
function
animate
()
{
requestAnimationFrame
(
animate
);
...
...
@@ -202,30 +204,44 @@
}
function
pick
()
{
//render the picking scene off-screen
renderer
.
render
(
pickingScene
,
camera
,
pickingTexture
);
var
gl
=
self
.
renderer
.
getContext
();
renderer
.
render
(
pickingScene
,
camera
,
pickingTexture
);
var
pixelBuffer
=
new
Uint8Array
(
4
);
//read the pixel under the mouse from the texture
gl
.
readPixels
(
mouse
.
x
,
pickingTexture
.
height
-
mouse
.
y
,
1
,
1
,
gl
.
RGBA
,
gl
.
UNSIGNED_BYTE
,
pixelBuffer
);
var
pixelBuffer
=
new
Uint8Array
(
4
);
gl
.
readPixels
(
mouse
.
x
,
pickingTexture
.
height
-
mouse
.
y
,
1
,
1
,
gl
.
RGBA
,
gl
.
UNSIGNED_BYTE
,
pixelBuffer
);
//interpret the pixel as an ID
var
id
=
(
pixelBuffer
[
0
]
<<
16
)
|
(
pixelBuffer
[
1
]
<<
8
)
|
(
pixelBuffer
[
2
]);
var
data
=
pickingData
[
id
];
if
(
data
){
var
id
=
(
pixelBuffer
[
0
]
<<
16
)
|
(
pixelBuffer
[
1
]
<<
8
)
|
(
pixelBuffer
[
2
]
);
var
data
=
pickingData
[
id
];
if
(
data
)
{
//move our highlightBox so that it surrounds the picked object
if
(
data
.
position
&&
data
.
rotation
&&
data
.
scale
){
highlightBox
.
position
.
copy
(
data
.
position
);
highlightBox
.
rotation
.
copy
(
data
.
rotation
);
highlightBox
.
scale
.
copy
(
data
.
scale
).
addSelf
(
offset
);
if
(
data
.
position
&&
data
.
rotation
&&
data
.
scale
){
highlightBox
.
position
.
copy
(
data
.
position
);
highlightBox
.
rotation
.
copy
(
data
.
rotation
);
highlightBox
.
scale
.
copy
(
data
.
scale
).
addSelf
(
offset
);
highlightBox
.
visible
=
true
;
}
}
else
{
highlightBox
.
visible
=
false
;
}
}
function
render
()
{
controls
.
update
();
...
...
examples/webgl_interactive_draggablecubes.html
浏览文件 @
7af978c4
...
...
@@ -111,7 +111,7 @@
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
shadowMapEnabled
=
true
;
renderer
.
shadowMap
Soft
=
true
;
renderer
.
shadowMap
Type
=
THREE
.
PCFShadowMap
;
container
.
appendChild
(
renderer
.
domElement
);
...
...
examples/webgl_loader_utf8.html
浏览文件 @
7af978c4
...
...
@@ -128,6 +128,7 @@
renderer
.
physicallyBasedShading
=
true
;
renderer
.
shadowMapEnabled
=
true
;
renderer
.
shadowMapType
=
THREE
.
PCFShadowMap
;
// STATS
...
...
examples/webgl_materials_normalmap.html
浏览文件 @
7af978c4
...
...
@@ -212,7 +212,7 @@
//
renderer
.
shadowMapEnabled
=
true
;
renderer
.
shadowMap
Soft
=
true
;
renderer
.
shadowMap
Type
=
THREE
.
PCFShadowMap
;
//
...
...
examples/webgl_shading_physical.html
浏览文件 @
7af978c4
...
...
@@ -359,6 +359,7 @@
renderer
.
shadowMapAutoUpdate
=
false
;
renderer
.
shadowMapEnabled
=
true
;
renderer
.
shadowMapType
=
THREE
.
PCFSoftShadowMap
;
//
...
...
examples/webgl_shadowmap.html
浏览文件 @
7af978c4
...
...
@@ -141,7 +141,7 @@
//
renderer
.
shadowMapEnabled
=
true
;
renderer
.
shadowMap
Soft
=
true
;
renderer
.
shadowMap
Type
=
THREE
.
PCFShadowMap
;
// STATS
...
...
examples/webgl_shadowmap_performance.html
浏览文件 @
7af978c4
...
...
@@ -141,7 +141,7 @@
//
renderer
.
shadowMapEnabled
=
true
;
renderer
.
shadowMap
Soft
=
true
;
renderer
.
shadowMap
Type
=
THREE
.
PCFSoftShadowMap
;
// STATS
...
...
src/Three.js
浏览文件 @
7af978c4
...
...
@@ -91,6 +91,12 @@ THREE.CullFaceFrontBack = 3;
THREE
.
FrontFaceDirectionCW
=
0
;
THREE
.
FrontFaceDirectionCCW
=
1
;
// SHADOWING TYPES
THREE
.
BasicShadowMap
=
0
;
THREE
.
PCFShadowMap
=
1
;
THREE
.
PCFSoftShadowMap
=
2
;
// MATERIAL CONSTANTS
// side
...
...
src/extras/renderers/plugins/ShadowMapPlugin.js
浏览文件 @
7af978c4
...
...
@@ -139,7 +139,15 @@ THREE.ShadowMapPlugin = function ( ) {
if
(
!
light
.
shadowMap
)
{
var
pars
=
{
minFilter
:
THREE
.
NearestFilter
,
magFilter
:
THREE
.
NearestFilter
,
format
:
THREE
.
RGBAFormat
};
var
shadowFilter
=
THREE
.
LinearFilter
;
if
(
_renderer
.
shadowMapType
===
THREE
.
PCFSoftShadowMap
)
{
shadowFilter
=
THREE
.
NearestFilter
;
}
var
pars
=
{
minFilter
:
shadowFilter
,
magFilter
:
shadowFilter
,
format
:
THREE
.
RGBAFormat
};
light
.
shadowMap
=
new
THREE
.
WebGLRenderTarget
(
light
.
shadowMapWidth
,
light
.
shadowMapHeight
,
pars
);
light
.
shadowMapSize
=
new
THREE
.
Vector2
(
light
.
shadowMapWidth
,
light
.
shadowMapHeight
);
...
...
src/renderers/WebGLRenderer.js
浏览文件 @
7af978c4
...
...
@@ -53,7 +53,7 @@ THREE.WebGLRenderer = function ( parameters ) {
this
.
shadowMapEnabled
=
false
;
this
.
shadowMapAutoUpdate
=
true
;
this
.
shadowMap
Soft
=
true
;
this
.
shadowMap
Type
=
THREE
.
PCFShadowMap
;
this
.
shadowMapCullFace
=
THREE
.
CullFaceFront
;
this
.
shadowMapDebug
=
false
;
this
.
shadowMapCascade
=
false
;
...
...
@@ -4924,7 +4924,7 @@ THREE.WebGLRenderer = function ( parameters ) {
maxShadows
:
maxShadows
,
shadowMapEnabled
:
this
.
shadowMapEnabled
&&
object
.
receiveShadow
,
shadowMap
Soft
:
this
.
shadowMapSoft
,
shadowMap
Type
:
this
.
shadowMapType
,
shadowMapDebug
:
this
.
shadowMapDebug
,
shadowMapCascade
:
this
.
shadowMapCascade
,
...
...
@@ -6227,6 +6227,18 @@ THREE.WebGLRenderer = function ( parameters ) {
}
var
shadowMapTypeDefine
=
"
SHADOWMAP_TYPE_BASIC
"
;
if
(
parameters
.
shadowMapType
===
THREE
.
PCFShadowMap
)
{
shadowMapTypeDefine
=
"
SHADOWMAP_TYPE_PCF
"
;
}
else
if
(
parameters
.
shadowMapType
===
THREE
.
PCFSoftShadowMap
)
{
shadowMapTypeDefine
=
"
SHADOWMAP_TYPE_PCF_SOFT
"
;
}
//console.log( "building new program " );
//
...
...
@@ -6279,7 +6291,7 @@ THREE.WebGLRenderer = function ( parameters ) {
parameters
.
flipSided
?
"
#define FLIP_SIDED
"
:
""
,
parameters
.
shadowMapEnabled
?
"
#define USE_SHADOWMAP
"
:
""
,
parameters
.
shadowMap
Soft
?
"
#define SHADOWMAP_SOFT
"
:
""
,
parameters
.
shadowMap
Enabled
?
"
#define
"
+
shadowMapTypeDefine
:
""
,
parameters
.
shadowMapDebug
?
"
#define SHADOWMAP_DEBUG
"
:
""
,
parameters
.
shadowMapCascade
?
"
#define SHADOWMAP_CASCADE
"
:
""
,
...
...
@@ -6378,7 +6390,7 @@ THREE.WebGLRenderer = function ( parameters ) {
parameters
.
flipSided
?
"
#define FLIP_SIDED
"
:
""
,
parameters
.
shadowMapEnabled
?
"
#define USE_SHADOWMAP
"
:
""
,
parameters
.
shadowMap
Soft
?
"
#define SHADOWMAP_SOFT
"
:
""
,
parameters
.
shadowMap
Enabled
?
"
#define
"
+
shadowMapTypeDefine
:
""
,
parameters
.
shadowMapDebug
?
"
#define SHADOWMAP_DEBUG
"
:
""
,
parameters
.
shadowMapCascade
?
"
#define SHADOWMAP_CASCADE
"
:
""
,
...
...
src/renderers/WebGLShaders.js
浏览文件 @
7af978c4
...
...
@@ -1547,7 +1547,7 @@ THREE.ShaderChunk = {
"
shadowCoord.z += shadowBias[ i ];
"
,
"
#if
def SHADOWMAP_SOFT
"
,
"
#if
defined( SHADOWMAP_TYPE_PCF )
"
,
// Percentage-close filtering
// (9 pixel kernel)
...
...
@@ -1583,6 +1583,51 @@ THREE.ShaderChunk = {
"
float xPixelOffset = 1.0 / shadowMapSize[ i ].x;
"
,
"
float yPixelOffset = 1.0 / shadowMapSize[ i ].y;
"
,
"
float dx0 = -1.25 * xPixelOffset;
"
,
"
float dy0 = -1.25 * yPixelOffset;
"
,
"
float dx1 = 1.25 * xPixelOffset;
"
,
"
float dy1 = 1.25 * yPixelOffset;
"
,
"
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );
"
,
"
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
"
,
"
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );
"
,
"
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
"
,
"
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );
"
,
"
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
"
,
"
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );
"
,
"
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
"
,
"
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );
"
,
"
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
"
,
"
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );
"
,
"
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
"
,
"
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );
"
,
"
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
"
,
"
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );
"
,
"
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
"
,
"
fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );
"
,
"
if ( fDepth < shadowCoord.z ) shadow += shadowDelta;
"
,
"
shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );
"
,
"
#elif defined( SHADOWMAP_TYPE_PCF_SOFT )
"
,
// Percentage-close filtering
// (9 pixel kernel)
// http://fabiensanglard.net/shadowmappingPCF/
"
float shadow = 0.0;
"
,
"
float xPixelOffset = 1.0 / shadowMapSize[ i ].x;
"
,
"
float yPixelOffset = 1.0 / shadowMapSize[ i ].y;
"
,
"
float dx0 = -1.0 * xPixelOffset;
"
,
"
float dy0 = -1.0 * yPixelOffset;
"
,
"
float dx1 = 1.0 * xPixelOffset;
"
,
...
...
@@ -1627,19 +1672,18 @@ THREE.ShaderChunk = {
"
if ( depthKernel[2][2] < shadowCoord.z ) shadowKernel[2][2] = 0.25;
"
,
"
else shadowKernel[2][2] = 0.0;
"
,
"
vec2 fractionalCoord = 1.0 - fract(shadowCoord.xy * shadowMapSize[i].xy );
"
,
"
vec2 fractionalCoord = 1.0 - fract(
shadowCoord.xy * shadowMapSize[i].xy );
"
,
"
shadowKernel[0] = mix( shadowKernel[1], shadowKernel[0], fractionalCoord.x );
"
,
"
shadowKernel[1] = mix( shadowKernel[2], shadowKernel[1], fractionalCoord.x );
"
,
"
vec4 shadowValues;
"
,
"
shadowValues.x = mix(shadowKernel[0][1], shadowKernel[0][0], fractionalCoord.y );
"
,
"
shadowValues.y = mix(shadowKernel[0][2], shadowKernel[0][1], fractionalCoord.y );
"
,
"
shadowValues.z = mix(shadowKernel[1][1], shadowKernel[1][0], fractionalCoord.y );
"
,
"
shadowValues.w = mix(shadowKernel[1][2], shadowKernel[1][1], fractionalCoord.y );
"
,
"
shadowValues.x = mix(
shadowKernel[0][1], shadowKernel[0][0], fractionalCoord.y );
"
,
"
shadowValues.y = mix(
shadowKernel[0][2], shadowKernel[0][1], fractionalCoord.y );
"
,
"
shadowValues.z = mix(
shadowKernel[1][1], shadowKernel[1][0], fractionalCoord.y );
"
,
"
shadowValues.w = mix(
shadowKernel[1][2], shadowKernel[1][1], fractionalCoord.y );
"
,
"
shadow = dot(
shadowValues, vec4(1.0)
);
"
,
"
shadow = dot(
shadowValues, vec4( 1.0 )
);
"
,
"
shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );
"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录