Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
ef2243bd
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,发现更多精彩内容 >>
提交
ef2243bd
编写于
12月 03, 2010
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge remote branch 'alteredq/master'
上级
5573f954
9b80eab8
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
435 addition
and
401 deletion
+435
-401
build/Three.js
build/Three.js
+102
-101
build/ThreeDebug.js
build/ThreeDebug.js
+103
-102
build/ThreeExtras.js
build/ThreeExtras.js
+128
-127
examples/materials_shaders_fresnel.html
examples/materials_shaders_fresnel.html
+2
-3
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+100
-68
未找到文件。
build/Three.js
浏览文件 @
ef2243bd
此差异已折叠。
点击以展开。
build/ThreeDebug.js
浏览文件 @
ef2243bd
此差异已折叠。
点击以展开。
build/ThreeExtras.js
浏览文件 @
ef2243bd
此差异已折叠。
点击以展开。
examples/materials_shaders_fresnel.html
浏览文件 @
ef2243bd
...
...
@@ -36,14 +36,14 @@
<div
id=
"info"
><a
href=
"http://github.com/mrdoob/three.js"
target=
"_blank"
>
three.js
</a>
- webgl cube Fresnel shader demo. texture by
<a
href=
"http://www.humus.name/index.php?page=Textures"
target=
"_blank"
>
Humus
</a>
</div>
<script
type=
"text/javascript"
src=
"../build/ThreeExtras.js"
></script>
<script
type=
"text/javascript"
src=
"js/Stats.js"
></script>
<!--
<script type="text/javascript" src="js/Stats.js"></script>
-->
<script
type=
"text/javascript"
>
var
statsEnabled
=
fals
e
;
var
statsEnabled
=
tru
e
;
var
container
,
stats
;
...
...
@@ -79,7 +79,6 @@
sceneCube
=
new
THREE
.
Scene
();
var
geometry
=
new
Sphere
(
100
,
32
,
16
);
geometry
.
sortFacesByMaterial
();
var
path
=
"
textures/cube/Park2/
"
;
var
format
=
'
.jpg
'
;
...
...
src/renderers/WebGLRenderer.js
浏览文件 @
ef2243bd
...
...
@@ -20,7 +20,7 @@ THREE.WebGLRenderer = function ( scene ) {
// See http://code.google.com/p/chromium/issues/detail?id=63491
var
_canvas
=
document
.
createElement
(
'
canvas
'
),
_gl
,
_
program
,
_old
Program
,
_
oldProgram
,
_uber
Program
,
_modelViewMatrix
=
new
THREE
.
Matrix4
(),
_normalMatrix
,
_viewMatrixArray
=
new
Float32Array
(
16
),
...
...
@@ -42,7 +42,9 @@ THREE.WebGLRenderer = function ( scene ) {
this
.
autoClear
=
true
;
initGL
();
initUbershader
(
maxLightCount
.
directional
,
maxLightCount
.
point
);
_uberProgram
=
initUbershader
(
maxLightCount
.
directional
,
maxLightCount
.
point
);
_oldProgram
=
_uberProgram
;
//alert( dumpObject( getGLParams() ) );
...
...
@@ -60,17 +62,17 @@ THREE.WebGLRenderer = function ( scene ) {
};
this
.
setupLights
=
function
(
program
,
scene
)
{
this
.
setupLights
=
function
(
program
,
lights
)
{
var
l
,
ll
,
light
,
r
,
g
,
b
,
ambientLights
=
[],
pointLights
=
[],
directionalLights
=
[],
colors
=
[],
positions
=
[];
_gl
.
uniform1i
(
program
.
uniforms
.
enableLighting
,
scene
.
lights
.
length
);
_gl
.
uniform1i
(
program
.
uniforms
.
enableLighting
,
lights
.
length
);
for
(
l
=
0
,
ll
=
scene
.
lights
.
length
;
l
<
ll
;
l
++
)
{
for
(
l
=
0
,
ll
=
lights
.
length
;
l
<
ll
;
l
++
)
{
light
=
scene
.
lights
[
l
];
light
=
lights
[
l
];
if
(
light
instanceof
THREE
.
AmbientLight
)
{
...
...
@@ -300,10 +302,14 @@ THREE.WebGLRenderer = function ( scene ) {
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryChunk
.
__webGLNormalBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
new
Float32Array
(
normalArray
),
_gl
.
STATIC_DRAW
);
geometryChunk
.
__webGLUVBuffer
=
_gl
.
createBuffer
();
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryChunk
.
__webGLUVBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
new
Float32Array
(
uvArray
),
_gl
.
STATIC_DRAW
);
if
(
uvArray
.
length
>
0
)
{
geometryChunk
.
__webGLUVBuffer
=
_gl
.
createBuffer
();
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryChunk
.
__webGLUVBuffer
);
_gl
.
bufferData
(
_gl
.
ARRAY_BUFFER
,
new
Float32Array
(
uvArray
),
_gl
.
STATIC_DRAW
);
}
geometryChunk
.
__webGLFaceBuffer
=
_gl
.
createBuffer
();
_gl
.
bindBuffer
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
geometryChunk
.
__webGLFaceBuffer
);
_gl
.
bufferData
(
_gl
.
ELEMENT_ARRAY_BUFFER
,
new
Uint16Array
(
faceArray
),
_gl
.
STATIC_DRAW
);
...
...
@@ -317,14 +323,14 @@ THREE.WebGLRenderer = function ( scene ) {
};
this
.
renderBuffer
=
function
(
camera
,
material
,
geometryChunk
)
{
this
.
renderBuffer
=
function
(
camera
,
lights
,
material
,
geometryChunk
)
{
var
mColor
,
mOpacity
,
mReflectivity
,
mWireframe
,
mLineWidth
,
mBlending
,
mAmbient
,
mSpecular
,
mShininess
,
mMap
,
envMap
,
mixEnvMap
,
mRefractionRatio
,
useRefract
,
program
,
u
,
identifiers
;
program
,
u
,
identifiers
,
attributes
;
if
(
material
instanceof
THREE
.
MeshShaderMaterial
)
{
...
...
@@ -334,9 +340,13 @@ THREE.WebGLRenderer = function ( scene ) {
material
.
program
=
buildProgram
(
material
.
fragment_shader
,
material
.
vertex_shader
);
identifiers
=
[
'
viewMatrix
'
,
'
modelViewMatrix
'
,
'
projectionMatrix
'
,
'
normalMatrix
'
,
'
objectMatrix
'
,
'
cameraPosition
'
];
for
(
u
in
material
.
uniforms
)
identifiers
.
push
(
u
);
for
(
u
in
material
.
uniforms
)
{
identifiers
.
push
(
u
);
}
cacheUniformLocations
(
material
.
program
,
identifiers
);
cacheAttributeLocations
(
material
.
program
);
cacheAttributeLocations
(
material
.
program
,
[
"
position
"
,
"
normal
"
,
"
uv
"
]
);
}
...
...
@@ -344,7 +354,7 @@ THREE.WebGLRenderer = function ( scene ) {
}
else
{
program
=
_
p
rogram
;
program
=
_
uberP
rogram
;
}
...
...
@@ -354,17 +364,27 @@ THREE.WebGLRenderer = function ( scene ) {
_oldProgram
=
program
;
}
if
(
program
==
_uberProgram
)
{
this
.
setupLights
(
program
,
lights
);
}
this
.
loadCamera
(
program
,
camera
);
this
.
loadMatrices
(
program
);
if
(
material
instanceof
THREE
.
MeshShaderMaterial
)
{
mWireframe
=
material
.
wireframe
;
mLineWidth
=
material
.
wireframe_linewidth
;
setUniforms
(
program
,
material
.
uniforms
);
this
.
loadCamera
(
program
,
camera
);
this
.
loadMatrices
(
program
);
}
else
if
(
material
instanceof
THREE
.
MeshPhongMaterial
||
}
if
(
material
instanceof
THREE
.
MeshPhongMaterial
||
material
instanceof
THREE
.
MeshLambertMaterial
||
material
instanceof
THREE
.
MeshBasicMaterial
)
{
...
...
@@ -473,28 +493,34 @@ THREE.WebGLRenderer = function ( scene ) {
}
attributes
=
program
.
attributes
;
// vertices
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryChunk
.
__webGLVertexBuffer
);
_gl
.
vertexAttribPointer
(
program
.
position
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
_gl
.
vertexAttribPointer
(
attributes
.
position
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
// normals
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryChunk
.
__webGLNormalBuffer
);
_gl
.
vertexAttribPointer
(
program
.
normal
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
_gl
.
vertexAttribPointer
(
attributes
.
normal
,
3
,
_gl
.
FLOAT
,
false
,
0
,
0
);
// uvs
if
(
mMap
)
{
if
(
attributes
.
uv
>=
0
)
{
if
(
geometryChunk
.
__webGLUVBuffer
)
{
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryChunk
.
__webGLUVBuffer
);
_gl
.
bindBuffer
(
_gl
.
ARRAY_BUFFER
,
geometryChunk
.
__webGLUVBuffer
);
_gl
.
enableVertexAttribArray
(
program
.
uv
);
_gl
.
vertexAttribPointer
(
program
.
uv
,
2
,
_gl
.
FLOAT
,
false
,
0
,
0
);
_gl
.
enableVertexAttribArray
(
attributes
.
uv
);
_gl
.
vertexAttribPointer
(
attributes
.
uv
,
2
,
_gl
.
FLOAT
,
false
,
0
,
0
);
}
else
{
}
else
{
_gl
.
disableVertexAttribArray
(
program
.
uv
);
_gl
.
disableVertexAttribArray
(
attributes
.
uv
);
}
}
...
...
@@ -517,7 +543,7 @@ THREE.WebGLRenderer = function ( scene ) {
};
this
.
renderPass
=
function
(
camera
,
object
,
geometryChunk
,
blending
,
transparent
)
{
this
.
renderPass
=
function
(
camera
,
lights
,
object
,
geometryChunk
,
blending
,
transparent
)
{
var
i
,
l
,
m
,
ml
,
material
,
meshMaterial
;
...
...
@@ -533,7 +559,7 @@ THREE.WebGLRenderer = function ( scene ) {
if
(
material
&&
material
.
blending
==
blending
&&
(
material
.
opacity
<
1.0
==
transparent
)
)
{
this
.
setBlending
(
material
.
blending
);
this
.
renderBuffer
(
camera
,
material
,
geometryChunk
);
this
.
renderBuffer
(
camera
,
lights
,
material
,
geometryChunk
);
}
...
...
@@ -545,7 +571,7 @@ THREE.WebGLRenderer = function ( scene ) {
if
(
material
&&
material
.
blending
==
blending
&&
(
material
.
opacity
<
1.0
==
transparent
)
)
{
this
.
setBlending
(
material
.
blending
);
this
.
renderBuffer
(
camera
,
material
,
geometryChunk
);
this
.
renderBuffer
(
camera
,
lights
,
material
,
geometryChunk
);
}
...
...
@@ -557,7 +583,8 @@ THREE.WebGLRenderer = function ( scene ) {
this
.
render
=
function
(
scene
,
camera
)
{
var
o
,
ol
,
webGLObject
,
object
,
buffer
;
var
o
,
ol
,
webGLObject
,
object
,
buffer
,
lights
=
scene
.
lights
;
this
.
initWebGLObjects
(
scene
);
...
...
@@ -568,10 +595,7 @@ THREE.WebGLRenderer = function ( scene ) {
}
camera
.
autoUpdateMatrix
&&
camera
.
updateMatrix
();
this
.
loadCamera
(
_program
,
camera
);
this
.
setupLights
(
_program
,
scene
);
// opaque pass
for
(
o
=
0
,
ol
=
scene
.
__webGLObjects
.
length
;
o
<
ol
;
o
++
)
{
...
...
@@ -584,8 +608,7 @@ THREE.WebGLRenderer = function ( scene ) {
if
(
object
.
visible
)
{
this
.
setupMatrices
(
object
,
camera
);
this
.
loadMatrices
(
_program
);
this
.
renderPass
(
camera
,
object
,
buffer
,
THREE
.
NormalBlending
,
false
);
this
.
renderPass
(
camera
,
lights
,
object
,
buffer
,
THREE
.
NormalBlending
,
false
);
}
...
...
@@ -603,21 +626,20 @@ THREE.WebGLRenderer = function ( scene ) {
if
(
object
.
visible
)
{
this
.
setupMatrices
(
object
,
camera
);
this
.
loadMatrices
(
_program
);
// opaque blended materials
this
.
renderPass
(
camera
,
object
,
buffer
,
THREE
.
AdditiveBlending
,
false
);
this
.
renderPass
(
camera
,
object
,
buffer
,
THREE
.
SubtractiveBlending
,
false
);
this
.
renderPass
(
camera
,
lights
,
object
,
buffer
,
THREE
.
AdditiveBlending
,
false
);
this
.
renderPass
(
camera
,
lights
,
object
,
buffer
,
THREE
.
SubtractiveBlending
,
false
);
// transparent blended materials
this
.
renderPass
(
camera
,
object
,
buffer
,
THREE
.
AdditiveBlending
,
true
);
this
.
renderPass
(
camera
,
object
,
buffer
,
THREE
.
SubtractiveBlending
,
true
);
this
.
renderPass
(
camera
,
lights
,
object
,
buffer
,
THREE
.
AdditiveBlending
,
true
);
this
.
renderPass
(
camera
,
lights
,
object
,
buffer
,
THREE
.
SubtractiveBlending
,
true
);
// transparent normal materials
this
.
renderPass
(
camera
,
object
,
buffer
,
THREE
.
NormalBlending
,
true
);
this
.
renderPass
(
camera
,
lights
,
object
,
buffer
,
THREE
.
NormalBlending
,
true
);
}
...
...
@@ -1188,6 +1210,7 @@ THREE.WebGLRenderer = function ( scene ) {
}
program
.
uniforms
=
{};
program
.
attributes
=
{};
return
program
;
...
...
@@ -1301,44 +1324,51 @@ THREE.WebGLRenderer = function ( scene ) {
for
(
i
=
0
,
l
=
identifiers
.
length
;
i
<
l
;
i
++
)
{
id
=
identifiers
[
i
];
program
.
uniforms
[
id
]
=
_gl
.
getUniformLocation
(
program
,
id
);
id
=
identifiers
[
i
];
program
.
uniforms
[
id
]
=
_gl
.
getUniformLocation
(
program
,
id
);
}
};
function
cacheAttributeLocations
(
program
)
{
program
.
position
=
_gl
.
getAttribLocation
(
program
,
"
position
"
);
_gl
.
enableVertexAttribArray
(
program
.
position
);
program
.
normal
=
_gl
.
getAttribLocation
(
program
,
"
normal
"
);
_gl
.
enableVertexAttribArray
(
program
.
normal
);
program
.
uv
=
_gl
.
getAttribLocation
(
program
,
"
uv
"
);
_gl
.
enableVertexAttribArray
(
program
.
uv
);
function
cacheAttributeLocations
(
program
,
identifiers
)
{
var
i
,
l
,
id
;
for
(
i
=
0
,
l
=
identifiers
.
length
;
i
<
l
;
i
++
)
{
id
=
identifiers
[
i
];
program
.
attributes
[
id
]
=
_gl
.
getAttribLocation
(
program
,
id
);
if
(
program
.
attributes
[
id
]
>=
0
)
{
_gl
.
enableVertexAttribArray
(
program
.
attributes
[
id
]
);
}
}
};
function
initUbershader
(
maxDirLights
,
maxPointLights
)
{
var
vertex_shader
=
generateVertexShader
(
maxDirLights
,
maxPointLights
),
fragment_shader
=
generateFragmentShader
(
maxDirLights
,
maxPointLights
);
fragment_shader
=
generateFragmentShader
(
maxDirLights
,
maxPointLights
),
program
;
//log ( vertex_shader );
//log ( fragment_shader );
_
program
=
buildProgram
(
fragment_shader
,
vertex_shader
);
program
=
buildProgram
(
fragment_shader
,
vertex_shader
);
_gl
.
useProgram
(
_
program
);
_gl
.
useProgram
(
program
);
// matrices
// lights
// material properties (Basic / Lambert / Blinn-Phong shader)
// material properties (Depth)
cacheUniformLocations
(
_
program
,
[
'
viewMatrix
'
,
'
modelViewMatrix
'
,
'
projectionMatrix
'
,
'
normalMatrix
'
,
'
objectMatrix
'
,
'
cameraPosition
'
,
cacheUniformLocations
(
program
,
[
'
viewMatrix
'
,
'
modelViewMatrix
'
,
'
projectionMatrix
'
,
'
normalMatrix
'
,
'
objectMatrix
'
,
'
cameraPosition
'
,
'
enableLighting
'
,
'
ambientLightColor
'
,
'
material
'
,
'
mColor
'
,
'
mAmbient
'
,
'
mSpecular
'
,
'
mShininess
'
,
'
mOpacity
'
,
'
enableMap
'
,
'
tMap
'
,
...
...
@@ -1350,34 +1380,36 @@ THREE.WebGLRenderer = function ( scene ) {
if
(
maxDirLights
)
{
cacheUniformLocations
(
_
program
,
[
'
directionalLightNumber
'
,
'
directionalLightColor
'
,
'
directionalLightDirection
'
]
);
cacheUniformLocations
(
program
,
[
'
directionalLightNumber
'
,
'
directionalLightColor
'
,
'
directionalLightDirection
'
]
);
}
if
(
maxPointLights
)
{
cacheUniformLocations
(
_
program
,
[
'
pointLightNumber
'
,
'
pointLightColor
'
,
'
pointLightPosition
'
]
);
cacheUniformLocations
(
program
,
[
'
pointLightNumber
'
,
'
pointLightColor
'
,
'
pointLightPosition
'
]
);
}
// texture (diffuse map)
_gl
.
uniform1i
(
_
program
.
uniforms
.
enableMap
,
0
);
_gl
.
uniform1i
(
_
program
.
uniforms
.
tMap
,
0
);
_gl
.
uniform1i
(
program
.
uniforms
.
enableMap
,
0
);
_gl
.
uniform1i
(
program
.
uniforms
.
tMap
,
0
);
// cube texture
_gl
.
uniform1i
(
_
program
.
uniforms
.
enableCubeMap
,
0
);
_gl
.
uniform1i
(
_
program
.
uniforms
.
tCube
,
1
);
// it's important to use non-zero texture unit, otherwise it doesn't work
_gl
.
uniform1i
(
_
program
.
uniforms
.
mixEnvMap
,
0
);
_gl
.
uniform1i
(
program
.
uniforms
.
enableCubeMap
,
0
);
_gl
.
uniform1i
(
program
.
uniforms
.
tCube
,
1
);
// it's important to use non-zero texture unit, otherwise it doesn't work
_gl
.
uniform1i
(
program
.
uniforms
.
mixEnvMap
,
0
);
// refraction
_gl
.
uniform1i
(
_
program
.
uniforms
.
useRefract
,
0
);
_gl
.
uniform1i
(
program
.
uniforms
.
useRefract
,
0
);
//
vertex
arrays
//
attribute
arrays
cacheAttributeLocations
(
_program
);
cacheAttributeLocations
(
program
,
[
"
position
"
,
"
normal
"
,
"
uv
"
]
);
return
program
;
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录