Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
599a3dff
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,发现更多精彩内容 >>
提交
599a3dff
编写于
4月 11, 2018
作者:
M
Mugen87
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
OutlinePass: Enable renderToScreen
上级
c36f35d9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
92 addition
and
82 deletion
+92
-82
examples/js/postprocessing/OutlinePass.js
examples/js/postprocessing/OutlinePass.js
+92
-82
未找到文件。
examples/js/postprocessing/OutlinePass.js
浏览文件 @
599a3dff
...
...
@@ -243,106 +243,116 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype
render
:
function
(
renderer
,
writeBuffer
,
readBuffer
,
delta
,
maskActive
)
{
if
(
this
.
selectedObjects
.
length
===
0
)
return
;
if
(
this
.
selectedObjects
.
length
>
0
)
{
this
.
oldClearColor
.
copy
(
renderer
.
getClearColor
()
);
this
.
oldClearAlpha
=
renderer
.
getClearAlpha
();
var
oldAutoClear
=
renderer
.
autoClear
;
this
.
oldClearColor
.
copy
(
renderer
.
getClearColor
()
);
this
.
oldClearAlpha
=
renderer
.
getClearAlpha
();
var
oldAutoClear
=
renderer
.
autoClear
;
renderer
.
autoClear
=
false
;
renderer
.
autoClear
=
false
;
if
(
maskActive
)
renderer
.
context
.
disable
(
renderer
.
context
.
STENCIL_TEST
);
if
(
maskActive
)
renderer
.
context
.
disable
(
renderer
.
context
.
STENCIL_TEST
);
renderer
.
setClearColor
(
0xffffff
,
1
);
renderer
.
setClearColor
(
0xffffff
,
1
);
// Make selected objects invisible
this
.
changeVisibilityOfSelectedObjects
(
false
);
// Make selected objects invisible
this
.
changeVisibilityOfSelectedObjects
(
false
);
var
currentBackground
=
this
.
renderScene
.
background
;
this
.
renderScene
.
background
=
null
;
var
currentBackground
=
this
.
renderScene
.
background
;
this
.
renderScene
.
background
=
null
;
// 1. Draw Non Selected objects in the depth buffer
this
.
renderScene
.
overrideMaterial
=
this
.
depthMaterial
;
renderer
.
render
(
this
.
renderScene
,
this
.
renderCamera
,
this
.
renderTargetDepthBuffer
,
true
);
// 1. Draw Non Selected objects in the depth buffer
this
.
renderScene
.
overrideMaterial
=
this
.
depthMaterial
;
renderer
.
render
(
this
.
renderScene
,
this
.
renderCamera
,
this
.
renderTargetDepthBuffer
,
true
);
// Make selected objects visible
this
.
changeVisibilityOfSelectedObjects
(
true
);
// Make selected objects visible
this
.
changeVisibilityOfSelectedObjects
(
true
);
// Update Texture Matrix for Depth compare
this
.
updateTextureMatrix
();
// Update Texture Matrix for Depth compare
this
.
updateTextureMatrix
();
// Make non selected objects invisible, and draw only the selected objects, by comparing the depth buffer of non selected objects
this
.
changeVisibilityOfNonSelectedObjects
(
false
);
this
.
renderScene
.
overrideMaterial
=
this
.
prepareMaskMaterial
;
this
.
prepareMaskMaterial
.
uniforms
[
"
cameraNearFar
"
].
value
=
new
THREE
.
Vector2
(
this
.
renderCamera
.
near
,
this
.
renderCamera
.
far
);
this
.
prepareMaskMaterial
.
uniforms
[
"
depthTexture
"
].
value
=
this
.
renderTargetDepthBuffer
.
texture
;
this
.
prepareMaskMaterial
.
uniforms
[
"
textureMatrix
"
].
value
=
this
.
textureMatrix
;
renderer
.
render
(
this
.
renderScene
,
this
.
renderCamera
,
this
.
renderTargetMaskBuffer
,
true
);
this
.
renderScene
.
overrideMaterial
=
null
;
this
.
changeVisibilityOfNonSelectedObjects
(
true
);
// Make non selected objects invisible, and draw only the selected objects, by comparing the depth buffer of non selected objects
this
.
changeVisibilityOfNonSelectedObjects
(
false
);
this
.
renderScene
.
overrideMaterial
=
this
.
prepareMaskMaterial
;
this
.
prepareMaskMaterial
.
uniforms
[
"
cameraNearFar
"
].
value
=
new
THREE
.
Vector2
(
this
.
renderCamera
.
near
,
this
.
renderCamera
.
far
);
this
.
prepareMaskMaterial
.
uniforms
[
"
depthTexture
"
].
value
=
this
.
renderTargetDepthBuffer
.
texture
;
this
.
prepareMaskMaterial
.
uniforms
[
"
textureMatrix
"
].
value
=
this
.
textureMatrix
;
renderer
.
render
(
this
.
renderScene
,
this
.
renderCamera
,
this
.
renderTargetMaskBuffer
,
true
);
this
.
renderScene
.
overrideMaterial
=
null
;
this
.
changeVisibilityOfNonSelectedObjects
(
true
);
this
.
renderScene
.
background
=
currentBackground
;
this
.
renderScene
.
background
=
currentBackground
;
// 2. Downsample to Half resolution
this
.
quad
.
material
=
this
.
materialCopy
;
this
.
copyUniforms
[
"
tDiffuse
"
].
value
=
this
.
renderTargetMaskBuffer
.
texture
;
renderer
.
render
(
this
.
scene
,
this
.
camera
,
this
.
renderTargetMaskDownSampleBuffer
,
true
);
// 2. Downsample to Half resolution
this
.
quad
.
material
=
this
.
materialCopy
;
this
.
copyUniforms
[
"
tDiffuse
"
].
value
=
this
.
renderTargetMaskBuffer
.
texture
;
renderer
.
render
(
this
.
scene
,
this
.
camera
,
this
.
renderTargetMaskDownSampleBuffer
,
true
);
this
.
tempPulseColor1
.
copy
(
this
.
visibleEdgeColor
);
this
.
tempPulseColor2
.
copy
(
this
.
hiddenEdgeColor
);
this
.
tempPulseColor1
.
copy
(
this
.
visibleEdgeColor
);
this
.
tempPulseColor2
.
copy
(
this
.
hiddenEdgeColor
);
if
(
this
.
pulsePeriod
>
0
)
{
if
(
this
.
pulsePeriod
>
0
)
{
var
scalar
=
(
1
+
0.25
)
/
2
+
Math
.
cos
(
performance
.
now
()
*
0.01
/
this
.
pulsePeriod
)
*
(
1.0
-
0.25
)
/
2
;
this
.
tempPulseColor1
.
multiplyScalar
(
scalar
);
this
.
tempPulseColor2
.
multiplyScalar
(
scalar
);
var
scalar
=
(
1
+
0.25
)
/
2
+
Math
.
cos
(
performance
.
now
()
*
0.01
/
this
.
pulsePeriod
)
*
(
1.0
-
0.25
)
/
2
;
this
.
tempPulseColor1
.
multiplyScalar
(
scalar
);
this
.
tempPulseColor2
.
multiplyScalar
(
scalar
);
}
// 3. Apply Edge Detection Pass
this
.
quad
.
material
=
this
.
edgeDetectionMaterial
;
this
.
edgeDetectionMaterial
.
uniforms
[
"
maskTexture
"
].
value
=
this
.
renderTargetMaskDownSampleBuffer
.
texture
;
this
.
edgeDetectionMaterial
.
uniforms
[
"
texSize
"
].
value
=
new
THREE
.
Vector2
(
this
.
renderTargetMaskDownSampleBuffer
.
width
,
this
.
renderTargetMaskDownSampleBuffer
.
height
);
this
.
edgeDetectionMaterial
.
uniforms
[
"
visibleEdgeColor
"
].
value
=
this
.
tempPulseColor1
;
this
.
edgeDetectionMaterial
.
uniforms
[
"
hiddenEdgeColor
"
].
value
=
this
.
tempPulseColor2
;
renderer
.
render
(
this
.
scene
,
this
.
camera
,
this
.
renderTargetEdgeBuffer1
,
true
);
// 4. Apply Blur on Half res
this
.
quad
.
material
=
this
.
separableBlurMaterial1
;
this
.
separableBlurMaterial1
.
uniforms
[
"
colorTexture
"
].
value
=
this
.
renderTargetEdgeBuffer1
.
texture
;
this
.
separableBlurMaterial1
.
uniforms
[
"
direction
"
].
value
=
THREE
.
OutlinePass
.
BlurDirectionX
;
this
.
separableBlurMaterial1
.
uniforms
[
"
kernelRadius
"
].
value
=
this
.
edgeThickness
;
renderer
.
render
(
this
.
scene
,
this
.
camera
,
this
.
renderTargetBlurBuffer1
,
true
);
this
.
separableBlurMaterial1
.
uniforms
[
"
colorTexture
"
].
value
=
this
.
renderTargetBlurBuffer1
.
texture
;
this
.
separableBlurMaterial1
.
uniforms
[
"
direction
"
].
value
=
THREE
.
OutlinePass
.
BlurDirectionY
;
renderer
.
render
(
this
.
scene
,
this
.
camera
,
this
.
renderTargetEdgeBuffer1
,
true
);
// Apply Blur on quarter res
this
.
quad
.
material
=
this
.
separableBlurMaterial2
;
this
.
separableBlurMaterial2
.
uniforms
[
"
colorTexture
"
].
value
=
this
.
renderTargetEdgeBuffer1
.
texture
;
this
.
separableBlurMaterial2
.
uniforms
[
"
direction
"
].
value
=
THREE
.
OutlinePass
.
BlurDirectionX
;
renderer
.
render
(
this
.
scene
,
this
.
camera
,
this
.
renderTargetBlurBuffer2
,
true
);
this
.
separableBlurMaterial2
.
uniforms
[
"
colorTexture
"
].
value
=
this
.
renderTargetBlurBuffer2
.
texture
;
this
.
separableBlurMaterial2
.
uniforms
[
"
direction
"
].
value
=
THREE
.
OutlinePass
.
BlurDirectionY
;
renderer
.
render
(
this
.
scene
,
this
.
camera
,
this
.
renderTargetEdgeBuffer2
,
true
);
// Blend it additively over the input texture
this
.
quad
.
material
=
this
.
overlayMaterial
;
this
.
overlayMaterial
.
uniforms
[
"
maskTexture
"
].
value
=
this
.
renderTargetMaskBuffer
.
texture
;
this
.
overlayMaterial
.
uniforms
[
"
edgeTexture1
"
].
value
=
this
.
renderTargetEdgeBuffer1
.
texture
;
this
.
overlayMaterial
.
uniforms
[
"
edgeTexture2
"
].
value
=
this
.
renderTargetEdgeBuffer2
.
texture
;
this
.
overlayMaterial
.
uniforms
[
"
patternTexture
"
].
value
=
this
.
patternTexture
;
this
.
overlayMaterial
.
uniforms
[
"
edgeStrength
"
].
value
=
this
.
edgeStrength
;
this
.
overlayMaterial
.
uniforms
[
"
edgeGlow
"
].
value
=
this
.
edgeGlow
;
this
.
overlayMaterial
.
uniforms
[
"
usePatternTexture
"
].
value
=
this
.
usePatternTexture
;
if
(
maskActive
)
renderer
.
context
.
enable
(
renderer
.
context
.
STENCIL_TEST
);
renderer
.
render
(
this
.
scene
,
this
.
camera
,
readBuffer
,
false
);
renderer
.
setClearColor
(
this
.
oldClearColor
,
this
.
oldClearAlpha
);
renderer
.
autoClear
=
oldAutoClear
;
}
// 3. Apply Edge Detection Pass
this
.
quad
.
material
=
this
.
edgeDetectionMaterial
;
this
.
edgeDetectionMaterial
.
uniforms
[
"
maskTexture
"
].
value
=
this
.
renderTargetMaskDownSampleBuffer
.
texture
;
this
.
edgeDetectionMaterial
.
uniforms
[
"
texSize
"
].
value
=
new
THREE
.
Vector2
(
this
.
renderTargetMaskDownSampleBuffer
.
width
,
this
.
renderTargetMaskDownSampleBuffer
.
height
);
this
.
edgeDetectionMaterial
.
uniforms
[
"
visibleEdgeColor
"
].
value
=
this
.
tempPulseColor1
;
this
.
edgeDetectionMaterial
.
uniforms
[
"
hiddenEdgeColor
"
].
value
=
this
.
tempPulseColor2
;
renderer
.
render
(
this
.
scene
,
this
.
camera
,
this
.
renderTargetEdgeBuffer1
,
true
);
// 4. Apply Blur on Half res
this
.
quad
.
material
=
this
.
separableBlurMaterial1
;
this
.
separableBlurMaterial1
.
uniforms
[
"
colorTexture
"
].
value
=
this
.
renderTargetEdgeBuffer1
.
texture
;
this
.
separableBlurMaterial1
.
uniforms
[
"
direction
"
].
value
=
THREE
.
OutlinePass
.
BlurDirectionX
;
this
.
separableBlurMaterial1
.
uniforms
[
"
kernelRadius
"
].
value
=
this
.
edgeThickness
;
renderer
.
render
(
this
.
scene
,
this
.
camera
,
this
.
renderTargetBlurBuffer1
,
true
);
this
.
separableBlurMaterial1
.
uniforms
[
"
colorTexture
"
].
value
=
this
.
renderTargetBlurBuffer1
.
texture
;
this
.
separableBlurMaterial1
.
uniforms
[
"
direction
"
].
value
=
THREE
.
OutlinePass
.
BlurDirectionY
;
renderer
.
render
(
this
.
scene
,
this
.
camera
,
this
.
renderTargetEdgeBuffer1
,
true
);
// Apply Blur on quarter res
this
.
quad
.
material
=
this
.
separableBlurMaterial2
;
this
.
separableBlurMaterial2
.
uniforms
[
"
colorTexture
"
].
value
=
this
.
renderTargetEdgeBuffer1
.
texture
;
this
.
separableBlurMaterial2
.
uniforms
[
"
direction
"
].
value
=
THREE
.
OutlinePass
.
BlurDirectionX
;
renderer
.
render
(
this
.
scene
,
this
.
camera
,
this
.
renderTargetBlurBuffer2
,
true
);
this
.
separableBlurMaterial2
.
uniforms
[
"
colorTexture
"
].
value
=
this
.
renderTargetBlurBuffer2
.
texture
;
this
.
separableBlurMaterial2
.
uniforms
[
"
direction
"
].
value
=
THREE
.
OutlinePass
.
BlurDirectionY
;
renderer
.
render
(
this
.
scene
,
this
.
camera
,
this
.
renderTargetEdgeBuffer2
,
true
);
// Blend it additively over the input texture
this
.
quad
.
material
=
this
.
overlayMaterial
;
this
.
overlayMaterial
.
uniforms
[
"
maskTexture
"
].
value
=
this
.
renderTargetMaskBuffer
.
texture
;
this
.
overlayMaterial
.
uniforms
[
"
edgeTexture1
"
].
value
=
this
.
renderTargetEdgeBuffer1
.
texture
;
this
.
overlayMaterial
.
uniforms
[
"
edgeTexture2
"
].
value
=
this
.
renderTargetEdgeBuffer2
.
texture
;
this
.
overlayMaterial
.
uniforms
[
"
patternTexture
"
].
value
=
this
.
patternTexture
;
this
.
overlayMaterial
.
uniforms
[
"
edgeStrength
"
].
value
=
this
.
edgeStrength
;
this
.
overlayMaterial
.
uniforms
[
"
edgeGlow
"
].
value
=
this
.
edgeGlow
;
this
.
overlayMaterial
.
uniforms
[
"
usePatternTexture
"
].
value
=
this
.
usePatternTexture
;
if
(
maskActive
)
renderer
.
context
.
enable
(
renderer
.
context
.
STENCIL_TEST
);
renderer
.
render
(
this
.
scene
,
this
.
camera
,
readBuffer
,
false
);
renderer
.
setClearColor
(
this
.
oldClearColor
,
this
.
oldClearAlpha
);
renderer
.
autoClear
=
oldAutoClear
;
if
(
this
.
renderToScreen
)
{
this
.
quad
.
material
=
this
.
materialCopy
;
this
.
copyUniforms
[
"
tDiffuse
"
].
value
=
readBuffer
.
texture
;
renderer
.
render
(
this
.
scene
,
this
.
camera
);
}
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录