Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
b7c78635
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 搜索 >>
提交
b7c78635
编写于
12月 21, 2010
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added Fog to WebGLRenderer2.
上级
c39eca33
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
44 addition
and
2 deletion
+44
-2
examples/webglrenderer2_sandbox.html
examples/webglrenderer2_sandbox.html
+2
-0
src/renderers/WebGLRenderer2.js
src/renderers/WebGLRenderer2.js
+41
-2
src/scenes/Fog.js
src/scenes/Fog.js
+1
-0
未找到文件。
examples/webglrenderer2_sandbox.html
浏览文件 @
b7c78635
...
...
@@ -83,6 +83,7 @@
<script
type=
"text/javascript"
src=
"../src/materials/mappings/SphericalRefractionMapping.js"
></script>
<script
type=
"text/javascript"
src=
"../src/materials/mappings/UVMapping.js"
></script>
<script
type=
"text/javascript"
src=
"../src/scenes/Scene.js"
></script>
<script
type=
"text/javascript"
src=
"../src/scenes/Fog.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/Projector.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/DOMRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/CanvasRenderer.js"
></script>
...
...
@@ -130,6 +131,7 @@
camera
.
position
.
z
=
3200
;
scene
=
new
THREE
.
Scene
();
scene
.
fog
=
new
THREE
.
Fog
(
0xffffff
,
0.00025
);
var
geometry
=
new
Sphere
(
100
,
32
,
16
);
...
...
src/renderers/WebGLRenderer2.js
浏览文件 @
b7c78635
/**
* @author mrdoob / http://mrdoob.com/
*
* Based on code by:
* @author alteredq / http://alteredqualia.com/
* @author supereggbert / http://www.paulbrunt.co.uk/
*/
THREE
.
WebGLRenderer2
=
function
()
{
...
...
@@ -134,11 +138,28 @@ THREE.WebGLRenderer2 = function () {
if
(
program
!=
_currentProgram
)
{
_gl
.
useProgram
(
program
);
_currentProgram
=
program
;
_gl
.
useProgram
(
program
);
// scene
if
(
scene
.
fog
)
{
_gl
.
uniform1i
(
program
.
uniforms
.
fog
,
1
);
_gl
.
uniform1f
(
program
.
uniforms
.
fogDensity
,
scene
.
fog
.
density
);
_gl
.
uniform3f
(
program
.
uniforms
.
fogColor
,
scene
.
fog
.
color
.
r
,
scene
.
fog
.
color
.
g
,
scene
.
fog
.
color
.
b
);
}
else
{
_gl
.
uniform1i
(
program
.
uniforms
.
fog
,
0
);
}
}
// materials
if
(
material
instanceof
THREE
.
MeshBasicMaterial
||
material
instanceof
THREE
.
MeshLambertMaterial
||
material
instanceof
THREE
.
MeshPhongMaterial
)
{
...
...
@@ -462,6 +483,10 @@ THREE.WebGLRenderer2 = function () {
fs
+=
'
gl_FragColor = vec4( mColor.xyz, mOpacity );
\n
'
;
identifiers
.
push
(
'
mColor
'
,
'
mOpacity
'
);
// uvmap
if
(
material
.
map
)
{
pvs
+=
'
varying vec2 vUv;
\n
'
,
...
...
@@ -481,7 +506,21 @@ THREE.WebGLRenderer2 = function () {
}
identifiers
.
push
(
'
mColor
'
,
'
mOpacity
'
);
// fog
pfs
+=
'
uniform bool fog;
\n
'
;
pfs
+=
'
uniform vec3 fogColor;
\n
'
;
pfs
+=
'
uniform float fogDensity;
\n
'
;
fs
+=
'
if ( fog ) {
\n
'
;
fs
+=
'
const float LOG2 = 1.442695;
\n
'
;
fs
+=
'
float z = gl_FragCoord.z / gl_FragCoord.w;
\n
'
;
fs
+=
'
float fogFactor = exp2( - fogDensity * fogDensity * z * z * LOG2 );
\n
'
;
fs
+=
'
fogFactor = clamp( fogFactor, 0.0, 1.0 );
\n
'
;
fs
+=
'
gl_FragColor = mix( vec4( fogColor, 1.0 ), gl_FragColor, fogFactor );
\n
'
,
fs
+=
'
}
\n
'
;
identifiers
.
push
(
'
fog
'
,
'
fogColor
'
,
'
fogDensity
'
);
vs
+=
'
}
'
;
fs
+=
'
}
'
;
...
...
src/scenes/Fog.js
浏览文件 @
b7c78635
/**
* @author mr.doob / http://mrdoob.com/
* @author alteredq / http://alteredqualia.com/
*/
THREE
.
Fog
=
function
(
hex
,
density
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录