Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
02f81a26
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,发现更多精彩内容 >>
提交
02f81a26
编写于
12月 20, 2010
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merging with alteredq's branch.
上级
17c1349d
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
696 addition
and
642 deletion
+696
-642
build/Three.js
build/Three.js
+180
-179
build/ThreeDebug.js
build/ThreeDebug.js
+181
-180
build/ThreeExtras.js
build/ThreeExtras.js
+225
-224
examples/materials_gl.html
examples/materials_gl.html
+1
-4
src/materials/MeshDepthMaterial.js
src/materials/MeshDepthMaterial.js
+7
-0
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+102
-55
未找到文件。
build/Three.js
浏览文件 @
02f81a26
此差异已折叠。
点击以展开。
build/ThreeDebug.js
浏览文件 @
02f81a26
此差异已折叠。
点击以展开。
build/ThreeExtras.js
浏览文件 @
02f81a26
此差异已折叠。
点击以展开。
examples/materials_gl.html
浏览文件 @
02f81a26
...
...
@@ -17,10 +17,7 @@
<pre
id=
"log"
></pre>
<script
type=
"text/javascript"
src=
"../build/Three.js"
></script>
<script
type=
"text/javascript"
src=
"../src/extras/primitives/Sphere.js"
></script>
<script
type=
"text/javascript"
src=
"../src/extras/primitives/Plane.js"
></script>
<script
type=
"text/javascript"
src=
"../build/ThreeExtras.js"
></script>
<script
type=
"text/javascript"
src=
"js/Stats.js"
></script>
...
...
src/materials/MeshDepthMaterial.js
浏览文件 @
02f81a26
...
...
@@ -13,9 +13,16 @@ THREE.MeshDepthMaterial = function ( parameters ) {
this
.
near
=
1
;
this
.
far
=
1000
;
this
.
opacity
=
1
;
this
.
shading
=
THREE
.
SmoothShading
;
this
.
blending
=
THREE
.
NormalBlending
;
this
.
wireframe
=
false
;
this
.
wireframe_linewidth
=
1
;
this
.
wireframe_linecap
=
'
round
'
;
this
.
wireframe_linejoin
=
'
round
'
;
if
(
parameters
)
{
if
(
parameters
.
near
!==
undefined
)
this
.
near
=
parameters
.
near
;
...
...
src/renderers/WebGLRenderer.js
浏览文件 @
02f81a26
...
...
@@ -31,7 +31,7 @@ THREE.WebGLRenderer = function ( scene ) {
// ubershader material constants
BASIC
=
0
,
LAMBERT
=
1
,
PHONG
=
2
,
DEPTH
=
3
,
NORMAL
=
4
,
BASIC
=
0
,
LAMBERT
=
1
,
PHONG
=
2
,
// heuristics to create shader parameters according to lights in the scene
// (not to blow over maxLights budget)
...
...
@@ -359,6 +359,14 @@ THREE.WebGLRenderer = function ( scene ) {
};
function
setMaterialShaders
(
material
,
shaders
)
{
material
.
fragment_shader
=
shaders
.
fragment_shader
;
material
.
vertex_shader
=
shaders
.
vertex_shader
;
material
.
uniforms
=
shaders
.
uniforms
;
};
this
.
renderBuffer
=
function
(
camera
,
lights
,
material
,
geometryChunk
)
{
var
mColor
,
mOpacity
,
mReflectivity
,
...
...
@@ -369,10 +377,25 @@ THREE.WebGLRenderer = function ( scene ) {
program
,
u
,
identifiers
,
attributes
;
if
(
material
instanceof
THREE
.
MeshShaderMaterial
)
{
if
(
material
instanceof
THREE
.
MeshShaderMaterial
||
material
instanceof
THREE
.
MeshDepthMaterial
||
material
instanceof
THREE
.
MeshNormalMaterial
)
{
if
(
!
material
.
program
)
{
if
(
material
instanceof
THREE
.
MeshDepthMaterial
)
{
setMaterialShaders
(
material
,
ShaderLib
[
'
depth
'
]
);
material
.
uniforms
.
mNear
.
value
=
material
.
near
;
material
.
uniforms
.
mFar
.
value
=
material
.
far
;
}
else
if
(
material
instanceof
THREE
.
MeshNormalMaterial
)
{
setMaterialShaders
(
material
,
ShaderLib
[
'
normal
'
]
);
}
material
.
program
=
buildProgram
(
material
.
fragment_shader
,
material
.
vertex_shader
);
identifiers
=
[
'
viewMatrix
'
,
'
modelViewMatrix
'
,
'
projectionMatrix
'
,
'
normalMatrix
'
,
'
objectMatrix
'
,
'
cameraPosition
'
];
...
...
@@ -381,6 +404,7 @@ THREE.WebGLRenderer = function ( scene ) {
identifiers
.
push
(
u
);
}
cacheUniformLocations
(
material
.
program
,
identifiers
);
cacheAttributeLocations
(
material
.
program
,
[
"
position
"
,
"
normal
"
,
"
uv
"
,
"
tangent
"
]
);
...
...
@@ -410,7 +434,9 @@ THREE.WebGLRenderer = function ( scene ) {
this
.
loadCamera
(
program
,
camera
);
this
.
loadMatrices
(
program
);
if
(
material
instanceof
THREE
.
MeshShaderMaterial
)
{
if
(
material
instanceof
THREE
.
MeshShaderMaterial
||
material
instanceof
THREE
.
MeshDepthMaterial
||
material
instanceof
THREE
.
MeshNormalMaterial
)
{
mWireframe
=
material
.
wireframe
;
mLineWidth
=
material
.
wireframe_linewidth
;
...
...
@@ -452,31 +478,7 @@ THREE.WebGLRenderer = function ( scene ) {
}
if
(
material
instanceof
THREE
.
MeshNormalMaterial
)
{
mOpacity
=
material
.
opacity
;
mBlending
=
material
.
blending
;
_gl
.
uniform1f
(
program
.
uniforms
.
mOpacity
,
mOpacity
);
_gl
.
uniform1i
(
program
.
uniforms
.
material
,
NORMAL
);
}
else
if
(
material
instanceof
THREE
.
MeshDepthMaterial
)
{
mOpacity
=
material
.
opacity
;
mWireframe
=
material
.
wireframe
;
mLineWidth
=
material
.
wireframe_linewidth
;
_gl
.
uniform1f
(
program
.
uniforms
.
mOpacity
,
mOpacity
);
_gl
.
uniform1f
(
program
.
uniforms
.
m2Near
,
material
.
__2near
);
_gl
.
uniform1f
(
program
.
uniforms
.
mFarPlusNear
,
material
.
__farPlusNear
);
_gl
.
uniform1f
(
program
.
uniforms
.
mFarMinusNear
,
material
.
__farMinusNear
);
_gl
.
uniform1i
(
program
.
uniforms
.
material
,
DEPTH
);
}
else
if
(
material
instanceof
THREE
.
MeshPhongMaterial
)
{
if
(
material
instanceof
THREE
.
MeshPhongMaterial
)
{
mAmbient
=
material
.
ambient
;
mSpecular
=
material
.
specular
;
...
...
@@ -924,7 +926,7 @@ THREE.WebGLRenderer = function ( scene ) {
maxDirLights
?
"
#define MAX_DIR_LIGHTS
"
+
maxDirLights
:
""
,
maxPointLights
?
"
#define MAX_POINT_LIGHTS
"
+
maxPointLights
:
""
,
"
uniform int material;
"
,
// 0 - Basic, 1 - Lambert, 2 - Phong
, 3 - Depth, 4 - Normal
"
uniform int material;
"
,
// 0 - Basic, 1 - Lambert, 2 - Phong
"
uniform bool enableMap;
"
,
"
uniform bool enableCubeMap;
"
,
...
...
@@ -941,10 +943,6 @@ THREE.WebGLRenderer = function ( scene ) {
"
uniform vec4 mSpecular;
"
,
"
uniform float mShininess;
"
,
"
uniform float m2Near;
"
,
"
uniform float mFarPlusNear;
"
,
"
uniform float mFarMinusNear;
"
,
"
uniform int pointLightNumber;
"
,
"
uniform int directionalLightNumber;
"
,
...
...
@@ -985,28 +983,10 @@ THREE.WebGLRenderer = function ( scene ) {
"
}
"
,
// Normals
"
if ( material == 4 ) {
"
,
"
gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, mOpacity );
"
,
// Depth
"
} else if ( material == 3 ) {
"
,
// this breaks shader validation in Chrome 9.0.576.0 dev
// and also latest continuous build Chromium 9.0.583.0 (66089)
// (curiously it works in Chrome 9.0.576.0 canary build and Firefox 4b7)
//"float w = 1.0 - ( m2Near / ( mFarPlusNear - gl_FragCoord.z * mFarMinusNear ) );",
"
float w = 0.5;
"
,
"
gl_FragColor = vec4( w, w, w, mOpacity );
"
,
// Blinn-Phong
// based on o3d example
"
} else
if ( material == 2 ) {
"
,
"
if ( material == 2 ) {
"
,
"
vec3 normal = normalize( vNormal );
"
,
"
vec3 viewPosition = normalize( vViewPosition );
"
,
...
...
@@ -1420,15 +1400,13 @@ THREE.WebGLRenderer = function ( scene ) {
// matrices
// lights
// material properties (Basic / Lambert / Blinn-Phong shader)
// material properties (Depth)
cacheUniformLocations
(
program
,
[
'
viewMatrix
'
,
'
modelViewMatrix
'
,
'
projectionMatrix
'
,
'
normalMatrix
'
,
'
objectMatrix
'
,
'
cameraPosition
'
,
'
enableLighting
'
,
'
ambientLightColor
'
,
'
material
'
,
'
mColor
'
,
'
mAmbient
'
,
'
mSpecular
'
,
'
mShininess
'
,
'
mOpacity
'
,
'
enableMap
'
,
'
tMap
'
,
'
enableCubeMap
'
,
'
tCube
'
,
'
mixEnvMap
'
,
'
mReflectivity
'
,
'
mRefractionRatio
'
,
'
useRefract
'
,
'
m2Near
'
,
'
mFarPlusNear
'
,
'
mFarMinusNear
'
'
mRefractionRatio
'
,
'
useRefract
'
]
);
...
...
@@ -1629,5 +1607,74 @@ THREE.WebGLRenderer = function ( scene ) {
return str;
}
*/
var
ShaderLib
=
{
'
depth
'
:
{
uniforms
:
{
"
mNear
"
:
{
type
:
"
f
"
,
value
:
1.0
},
"
mFar
"
:
{
type
:
"
f
"
,
value
:
2000.0
}
},
fragment_shader
:
[
"
uniform float mNear;
"
,
"
uniform float mFar;
"
,
"
void main() {
"
,
"
float depth = gl_FragCoord.z / gl_FragCoord.w;
"
,
"
float color = 1.0 - smoothstep( mNear, mFar, depth );
"
,
"
gl_FragColor = vec4( vec3( color ), 1.0 );
"
,
"
}
"
].
join
(
"
\n
"
),
vertex_shader
:
[
"
void main() {
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
}
"
].
join
(
"
\n
"
)
},
'
normal
'
:
{
uniforms
:
{
},
fragment_shader
:
[
"
varying vec3 vNormal;
"
,
"
void main() {
"
,
"
gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, 1.0 );
"
,
"
}
"
].
join
(
"
\n
"
),
vertex_shader
:
[
"
varying vec3 vNormal;
"
,
"
void main() {
"
,
"
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
"
,
"
vNormal = normalize( normalMatrix * normal );
"
,
"
gl_Position = projectionMatrix * mvPosition;
"
,
"
}
"
].
join
(
"
\n
"
)
}
};
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录