Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
926f1be2
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,发现更多精彩内容 >>
提交
926f1be2
编写于
3月 24, 2011
作者:
M
Mikael Emtinger
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Initial add of lens flare
上级
66f657d8
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
204 addition
and
118 deletion
+204
-118
src/lights/LensFlare.js
src/lights/LensFlare.js
+53
-0
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+151
-118
未找到文件。
src/lights/LensFlare.js
0 → 100644
浏览文件 @
926f1be2
/**
* @author Mikael Emtinger
*/
THREE
.
LensFlare
=
function
(
material
,
size
)
{
THREE
.
Object3D
.
call
(
this
);
this
.
positionScreen
=
new
THREE
.
Vector3
();
this
.
lensFlares
=
[];
this
.
customUpdateCallback
=
undefined
;
this
.
addLensFlare
(
material
,
size
,
0
);
};
THREE
.
LensFlare
.
prototype
=
new
THREE
.
Object3D
();
THREE
.
LensFlare
.
prototype
.
constructor
=
THREE
.
LensFlare
;
THREE
.
LensFlare
.
prototype
.
supr
=
THREE
.
Object3D
.
prototype
;
/*
* Add: adds another flare
*/
THREE
.
LensFlare
.
prototype
.
add
=
function
(
material
,
size
,
distance
)
{
distance
=
Math
.
min
(
distance
,
Math
.
max
(
0
,
distance
));
lensFlares
.
push
(
{
material
:
material
,
size
:
size
,
distance
:
distance
,
position
:
new
THREE
.
Vector3
()
}
);
}
/*
* Update lens flares update positions on all flares based on the screen position
* Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
*/
THREE
.
LensFlare
.
updateLensFlares
=
function
()
{
// todo: update lens halo positions here
}
src/renderers/WebGLRenderer.js
浏览文件 @
926f1be2
...
...
@@ -2524,17 +2524,61 @@ THREE.WebGLRenderer = function ( parameters ) {
}
// render flares
if
(
scene
.
__webglLensFlares
.
length
)
{
renderLensFlares
(
scene
,
renderTarget
);
}
//////////////////////// stencil shadows begin //////////////////////
// method: we're rendering the world in light, then the shadow
// volumes into the stencil and last a big darkening
// quad over the whole thing. This is NOT how you're
// supposed to do stencil shadows but is much faster
//
// render stencil shadows
if
(
scene
.
__webglShadowVolumes
.
length
&&
scene
.
lights
.
length
)
{
renderStencilShadows
(
scene
);
}
// Generate mipmap if we're using any kind of mipmap filtering
if
(
renderTarget
&&
renderTarget
.
minFilter
!==
THREE
.
NearestFilter
&&
renderTarget
.
minFilter
!==
THREE
.
LinearFilter
)
{
updateRenderTargetMipmap
(
renderTarget
);
}
};
/*
* Render lens flares
* Method: renders 9 0xff00ff-colored points scattered over the light source area,
* reads these back and calculates occlusion.
* Then LensFlare.updateLensFlares() is called to re-position and
* update transparency of flares. Then they are rendered.
*
*/
function
renderLensFlares
()
{
}
/*
* Stencil Shadows
* method: we're rendering the world in light, then the shadow
* volumes into the stencil and last a big darkening
* quad over the whole thing. This is not how "you're
* supposed to" do stencil shadows but is much faster
*
*/
function
renderStencilShadows
(
scene
)
{
// setup stencil
_gl
.
enable
(
_gl
.
POLYGON_OFFSET_FILL
);
...
...
@@ -2548,19 +2592,17 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl
.
stencilOpSeparate
(
_gl
.
FRONT
,
_gl
.
KEEP
,
_gl
.
DECR
,
_gl
.
KEEP
);
// loop through all directional lights
var
l
,
ll
=
scene
.
lights
.
length
;
var
p
;
var
light
,
geometryGroup
;
var
light
,
lights
=
scene
.
lights
,
geometryGroup
;
var
dirLight
=
[];
var
program
;
var
p_uniforms
;
var
m_uniforms
;
var
attributes
;
ol
=
scene
.
__webglShadowVolumes
.
length
;
var
o
,
ol
=
scene
.
__webglShadowVolumes
.
length
;
for
(
l
=
0
;
l
<
ll
;
l
++
)
{
...
...
@@ -2575,14 +2617,14 @@ THREE.WebGLRenderer = function ( parameters ) {
// render all volumes
for
(
o
=
0
;
o
<
ol
;
o
++
)
{
for
(
o
=
0
;
o
<
ol
;
o
++
)
{
object
=
scene
.
__webglShadowVolumes
[
o
].
object
;
geometryGroup
=
scene
.
__webglShadowVolumes
[
o
].
buffer
;
material
=
object
.
materials
[
0
];
if
(
!
material
.
program
)
_this
.
initMaterial
(
material
,
lights
,
fog
,
object
);
if
(
!
material
.
program
)
_this
.
initMaterial
(
material
,
lights
,
undefined
,
object
);
program
=
material
.
program
,
p_uniforms
=
program
.
uniforms
,
...
...
@@ -2602,10 +2644,7 @@ THREE.WebGLRenderer = function ( parameters ) {
object
.
matrixWorld
.
flattenToArray
(
object
.
_objectMatrixArray
);
//object._modelViewMatrix.multiplyToArray( camera.matrixWorldInverse, object.matrixWorld, object._modelViewMatrixArray );
_gl
.
uniformMatrix4fv
(
p_uniforms
.
objectMatrix
,
false
,
object
.
_objectMatrixArray
);
//_gl.uniformMatrix4fv( p_uniforms.modelViewMatrix, false, object._modelViewMatrixArray );
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryGroup
.
__webGLVertexBuffer
);
...
...
@@ -2628,8 +2667,7 @@ THREE.WebGLRenderer = function ( parameters ) {
}
// draw darkening polygon
// setup color+stencil
_gl
.
disable
(
_gl
.
POLYGON_OFFSET_FILL
);
_gl
.
colorMask
(
true
,
true
,
true
,
true
);
...
...
@@ -2637,10 +2675,8 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl
.
stencilOp
(
_gl
.
KEEP
,
_gl
.
KEEP
,
_gl
.
KEEP
);
_gl
.
disable
(
_gl
.
DEPTH_TEST
);
_gl
.
enable
(
_gl
.
BLEND
);
_gl
.
blendFunc
(
_gl
.
ONE
,
_gl
.
ONE_MINUS_SRC_ALPHA
);
_gl
.
blendEquation
(
_gl
.
FUNC_ADD
);
// draw darkening polygon
_oldBlending
=
""
;
_oldProgram
=
_shadow
.
program
;
...
...
@@ -2652,6 +2688,10 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl
.
vertexAttribPointer
(
_shadow
.
vertexLocation
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
_gl
.
enableVertexAttribArray
(
_shadow
.
vertexLocation
);
_gl
.
enable
(
_gl
.
BLEND
);
_gl
.
blendFunc
(
_gl
.
ONE
,
_gl
.
ONE_MINUS_SRC_ALPHA
);
_gl
.
blendEquation
(
_gl
.
FUNC_ADD
);
_gl
.
bindBuffer
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
_shadow
.
elementBuffer
);
_gl
.
drawElements
(
_gl
.
TRIANGLES
,
6
,
_gl
.
UNSIGNED_SHORT
,
0
);
...
...
@@ -2665,19 +2705,6 @@ THREE.WebGLRenderer = function ( parameters ) {
}
//////////////////////// stencil shadows end //////////////////////
// Generate mipmap if we're using any kind of mipmap filtering
if
(
renderTarget
&&
renderTarget
.
minFilter
!==
THREE
.
NearestFilter
&&
renderTarget
.
minFilter
!==
THREE
.
LinearFilter
)
{
updateRenderTargetMipmap
(
renderTarget
);
}
};
function
setupMatrices
(
object
,
camera
)
{
object
.
_modelViewMatrix
.
multiplyToArray
(
camera
.
matrixWorldInverse
,
object
.
matrixWorld
,
object
.
_modelViewMatrixArray
);
...
...
@@ -2692,6 +2719,7 @@ THREE.WebGLRenderer = function ( parameters ) {
scene
.
__webglObjects
=
[];
scene
.
__webglObjectsImmediate
=
[];
scene
.
__webglShadowVolumes
=
[];
scene
.
__webglLensFlares
=
[];
}
while
(
scene
.
__objectsAdded
.
length
)
{
...
...
@@ -2722,6 +2750,11 @@ THREE.WebGLRenderer = function ( parameters ) {
}
for
(
var
o
=
0
,
ol
=
scene
.
__webglLensFlares
.
length
;
o
<
ol
;
o
++
)
{
updateObject
(
scene
.
__webglLensFlares
[
o
].
object
,
scene
);
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录