Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
a3b2a184
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,发现更多精彩内容 >>
提交
a3b2a184
编写于
11月 25, 2016
作者:
T
Takahiro
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update WebGLDeferredRenderer
上级
916a10c8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
102 addition
and
11 deletion
+102
-11
examples/js/renderers/WebGLDeferredRenderer.js
examples/js/renderers/WebGLDeferredRenderer.js
+37
-9
examples/webgldeferred_animation.html
examples/webgldeferred_animation.html
+65
-2
未找到文件。
examples/js/renderers/WebGLDeferredRenderer.js
浏览文件 @
a3b2a184
...
...
@@ -1270,7 +1270,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
*
* 1') g-buffer normal + depth pass + shininess
*
*
R
: normal
*
RG
: normal
* B: shininess
* A: depth
*/
...
...
@@ -1571,6 +1571,33 @@ THREE.DeferredShaderChunk = {
].
join
(
"
\n
"
),
// Refer to http://aras-p.info/texts/CompactNormalStorage.html
packNormal
:
[
"
vec2 normal_to_vec2( vec3 normal ) {
"
,
"
return normal.xy / sqrt( normal.z * 8.0 + 8.0 ) + 0.5;
"
,
"
}
"
].
join
(
"
\n
"
),
unpackVector2
:
[
"
vec3 vec2_to_normal( vec2 data ) {
"
,
"
vec2 fenc = data * 4.0 - 2.0;
"
,
"
float f = dot( fenc, fenc );
"
,
"
float g = sqrt( 1.0 - f / 4.0 );
"
,
"
vec3 normal;
"
,
"
normal.xy = fenc * g;
"
,
"
normal.z = 1.0 - f / 2.0;
"
,
"
return normal;
"
,
"
}
"
].
join
(
"
\n
"
),
computeTextureCoord
:
[
"
vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );
"
...
...
@@ -1596,11 +1623,10 @@ THREE.DeferredShaderChunk = {
].
join
(
"
\n
"
),
// TODO: optimize normal packing. reference http://aras-p.info/texts/CompactNormalStorage.html
packNormalDepthShininess
:
[
"
vec4 packedNormalDepthShininess;
"
,
"
packedNormalDepthShininess.x
= vec3_to_float( normal * 0.5 + 0.5
);
"
,
"
packedNormalDepthShininess.x
y = normal_to_vec2( normal
);
"
,
"
packedNormalDepthShininess.z = shininess;
"
,
"
packedNormalDepthShininess.w = position.z / position.w;
"
...
...
@@ -1613,10 +1639,9 @@ THREE.DeferredShaderChunk = {
"
if ( depth == 0.0 ) discard;
"
,
"
vec3 normal =
float_to_vec3( normalDepthMap.x ) * 2.0 - 1.0
;
"
,
"
vec3 normal =
vec2_to_normal( normalDepthMap.xy )
;
"
,
"
float shininess = normalDepthMap.z;
"
].
join
(
"
\n
"
),
packColor
:
[
...
...
@@ -1991,7 +2016,7 @@ THREE.ShaderDeferred = {
"
vec3 lightVector = normalize( lightPositionVS.xyz - vertexPositionVS.xyz );
"
,
"
float rho = dot( lightDirectionVS, lightVector );
"
,
"
float rhoMax = cos( lightAngle
* 0.5
);
"
,
"
float rhoMax = cos( lightAngle );
"
,
"
if ( rho <= rhoMax ) discard;
"
,
...
...
@@ -2135,7 +2160,7 @@ THREE.ShaderDeferred = {
"
uniform float shininess;
"
,
THREE
.
DeferredShaderChunk
[
"
pack
Vector3
"
],
THREE
.
DeferredShaderChunk
[
"
pack
Normal
"
],
"
void main() {
"
,
...
...
@@ -2196,6 +2221,7 @@ THREE.ShaderDeferred = {
"
uniform mat4 matProjInverse;
"
,
THREE
.
DeferredShaderChunk
[
"
unpackFloat
"
],
THREE
.
DeferredShaderChunk
[
"
unpackVector2
"
],
"
void main() {
"
,
...
...
@@ -2270,6 +2296,7 @@ THREE.ShaderDeferred = {
"
uniform mat4 matProjInverse;
"
,
THREE
.
DeferredShaderChunk
[
"
unpackFloat
"
],
THREE
.
DeferredShaderChunk
[
"
unpackVector2
"
],
"
void main() {
"
,
...
...
@@ -2280,7 +2307,7 @@ THREE.ShaderDeferred = {
"
vec3 lightVector = normalize( lightPositionVS.xyz - vertexPositionVS.xyz );
"
,
"
float rho = dot( lightDirectionVS, lightVector );
"
,
"
float rhoMax = cos( lightAngle
* 0.5
);
"
,
"
float rhoMax = cos( lightAngle );
"
,
"
if ( rho <= rhoMax ) discard;
"
,
...
...
@@ -2360,6 +2387,7 @@ THREE.ShaderDeferred = {
"
uniform mat4 matProjInverse;
"
,
THREE
.
DeferredShaderChunk
[
"
unpackFloat
"
],
THREE
.
DeferredShaderChunk
[
"
unpackVector2
"
],
"
void main() {
"
,
...
...
@@ -2458,7 +2486,7 @@ THREE.ShaderDeferred = {
"
vec3 diffuseFinal = diffuseColor.rgb * light.rgb;
"
,
"
vec3 emissiveFinal = emissiveColor;
"
,
"
vec3 specularFinal = specularColor * light.rgb *
( light.a / ( 0.2126 * light.r + 0.7152 * light.g + 0.0722 * light.b + 0.00001 ) )
;
"
,
"
vec3 specularFinal = specularColor * light.rgb *
light.a
;
"
,
"
gl_FragColor = vec4( diffuseFinal + emissiveFinal + specularFinal, 1.0 );
"
,
...
...
examples/webgldeferred_animation.html
浏览文件 @
a3b2a184
...
...
@@ -36,6 +36,7 @@
<body>
<div
id=
"container"
></div>
<script
src=
"js/libs/dat.gui.min.js"
></script>
<script
src=
"js/libs/stats.min.js"
></script>
<script
src=
"../build/three.js"
></script>
<script
src=
"js/Detector.js"
></script>
...
...
@@ -65,6 +66,7 @@
var
numLights
=
40
;
var
lights
=
[];
var
transparentObjects
=
[];
var
ready
=
false
;
...
...
@@ -93,6 +95,7 @@
initKnight
();
initRoom
();
initLights
();
initGui
();
document
.
addEventListener
(
'
mousemove
'
,
onDocumentMouseMove
,
false
);
window
.
addEventListener
(
'
resize
'
,
onWindowResize
,
false
);
...
...
@@ -210,18 +213,78 @@
mesh
=
new
THREE
.
Mesh
(
geometry
,
transparentMaterial
);
mesh
.
position
.
z
=
size
/
2
;
mesh
.
scale
.
multiplyScalar
(
0.33
);
//room.add( mesh );
mesh
.
visible
=
false
;
transparentObjects
.
push
(
mesh
);
room
.
add
(
mesh
);
// back2, to check if transparency works
mesh
=
new
THREE
.
Mesh
(
geometry
,
transparentMaterial
);
mesh
.
position
.
z
=
-
size
/
4
;
mesh
.
scale
.
multiplyScalar
(
0.75
);
//room.add( mesh );
mesh
.
visible
=
false
;
transparentObjects
.
push
(
mesh
);
room
.
add
(
mesh
);
scene
.
add
(
room
);
}
function
initGui
()
{
var
gui
=
new
dat
.
GUI
(
{
width
:
280
}
);
var
api
=
{
'
mode
'
:
0
,
'
transparent_objects
'
:
false
};
var
folder
=
gui
.
addFolder
(
'
menu
'
);
folder
.
add
(
api
,
'
mode
'
,
{
'
classic
'
:
0
,
'
light pre-pass
'
:
1
,
'
forward
'
:
2
}
).
onChange
(
function
()
{
switch
(
parseInt
(
api
.
mode
)
)
{
case
0
:
renderer
.
forwardRendering
=
false
;
renderer
.
enableLightPrePass
(
false
);
break
;
case
1
:
renderer
.
forwardRendering
=
false
;
renderer
.
enableLightPrePass
(
true
);
break
;
case
2
:
renderer
.
forwardRendering
=
true
;
break
;
default
:
break
;
}
}
);
folder
.
add
(
api
,
'
transparent_objects
'
).
onChange
(
function
()
{
for
(
var
i
=
0
,
il
=
transparentObjects
.
length
;
i
<
il
;
i
++
)
{
transparentObjects
[
i
].
visible
=
api
[
'
transparent_objects
'
];
}
}
);
folder
.
open
();
}
function
onDocumentMouseMove
(
event
)
{
mouseX
=
(
event
.
clientX
-
windowHalfX
)
/
10.0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录