Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
13ccc02a
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,发现更多精彩内容 >>
提交
13ccc02a
编写于
3月 09, 2011
作者:
A
alteredq
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactored shader and uniform snippets out of WebGLRenderer into WebGLShaders.
上级
d6db37ef
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
943 addition
and
886 deletion
+943
-886
build/Three.js
build/Three.js
+21
-21
build/custom/ThreeWebGL.js
build/custom/ThreeWebGL.js
+21
-20
examples/misc_ubiquity_test.html
examples/misc_ubiquity_test.html
+4
-1
examples/webgl_geometry_hierarchy.html
examples/webgl_geometry_hierarchy.html
+4
-1
examples/webgl_geometry_hierarchy2.html
examples/webgl_geometry_hierarchy2.html
+4
-1
examples/webgl_performance.html
examples/webgl_performance.html
+4
-1
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+0
-835
src/renderers/WebGLShaders.js
src/renderers/WebGLShaders.js
+840
-0
utils/build.py
utils/build.py
+2
-0
utils/exporters/max/ThreeJSExporter.ms
utils/exporters/max/ThreeJSExporter.ms
+43
-6
未找到文件。
build/Three.js
浏览文件 @
13ccc02a
此差异已折叠。
点击以展开。
build/custom/ThreeWebGL.js
浏览文件 @
13ccc02a
此差异已折叠。
点击以展开。
examples/misc_ubiquity_test.html
浏览文件 @
13ccc02a
...
...
@@ -33,6 +33,7 @@
<script
type=
"text/javascript"
src=
"../src/core/Face4.js"
></script>
<script
type=
"text/javascript"
src=
"../src/core/UV.js"
></script>
<script
type=
"text/javascript"
src=
"../src/core/Geometry.js"
></script>
<script
type=
"text/javascript"
src=
"../src/core/Spline.js"
></script>
<script
type=
"text/javascript"
src=
"../src/animation/AnimationHandler.js"
></script>
<script
type=
"text/javascript"
src=
"../src/animation/Animation.js"
></script>
<script
type=
"text/javascript"
src=
"../src/cameras/Camera.js"
></script>
...
...
@@ -65,6 +66,7 @@
<script
type=
"text/javascript"
src=
"../src/objects/SkinnedMesh.js"
></script>
<script
type=
"text/javascript"
src=
"../src/objects/Ribbon.js"
></script>
<script
type=
"text/javascript"
src=
"../src/objects/Sound.js"
></script>
<script
type=
"text/javascript"
src=
"../src/objects/LOD.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/scenes/FogExp2.js"
></script>
...
...
@@ -72,6 +74,7 @@
<script
type=
"text/javascript"
src=
"../src/renderers/DOMRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/CanvasRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/SVGRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/WebGLShaders.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/WebGLRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/SoundRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/renderables/RenderableObject.js"
></script>
...
...
@@ -91,7 +94,7 @@
<script
type=
"text/javascript"
src=
"../src/extras/primitives/LathedObject.js"
></script>
<script
type=
"text/javascript"
src=
"../src/extras/objects/MarchingCubes.js"
></script>
<script
type=
"text/javascript"
src=
"../src/extras/io/Loader.js"
></script>
<script
type=
"text/javascript"
src=
"obj/Qrcode.js"
></script>
<script
type=
"text/javascript"
src=
"js/RequestAnimationFrame.js"
></script>
...
...
examples/webgl_geometry_hierarchy.html
浏览文件 @
13ccc02a
...
...
@@ -33,6 +33,7 @@
<script
type=
"text/javascript"
src=
"../src/core/Face4.js"
></script>
<script
type=
"text/javascript"
src=
"../src/core/UV.js"
></script>
<script
type=
"text/javascript"
src=
"../src/core/Geometry.js"
></script>
<script
type=
"text/javascript"
src=
"../src/core/Spline.js"
></script>
<script
type=
"text/javascript"
src=
"../src/animation/AnimationHandler.js"
></script>
<script
type=
"text/javascript"
src=
"../src/animation/Animation.js"
></script>
<script
type=
"text/javascript"
src=
"../src/cameras/Camera.js"
></script>
...
...
@@ -65,6 +66,7 @@
<script
type=
"text/javascript"
src=
"../src/objects/SkinnedMesh.js"
></script>
<script
type=
"text/javascript"
src=
"../src/objects/Ribbon.js"
></script>
<script
type=
"text/javascript"
src=
"../src/objects/Sound.js"
></script>
<script
type=
"text/javascript"
src=
"../src/objects/LOD.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/scenes/FogExp2.js"
></script>
...
...
@@ -72,6 +74,7 @@
<script
type=
"text/javascript"
src=
"../src/renderers/DOMRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/CanvasRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/SVGRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/WebGLShaders.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/WebGLRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/SoundRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/renderables/RenderableObject.js"
></script>
...
...
@@ -91,7 +94,7 @@
<script
type=
"text/javascript"
src=
"../src/extras/primitives/LathedObject.js"
></script>
<script
type=
"text/javascript"
src=
"../src/extras/objects/MarchingCubes.js"
></script>
<script
type=
"text/javascript"
src=
"../src/extras/io/Loader.js"
></script>
<script
type=
"text/javascript"
src=
"js/RequestAnimationFrame.js"
></script>
<script
type=
"text/javascript"
src=
"js/Stats.js"
></script>
...
...
examples/webgl_geometry_hierarchy2.html
浏览文件 @
13ccc02a
...
...
@@ -33,6 +33,7 @@
<script
type=
"text/javascript"
src=
"../src/core/Face4.js"
></script>
<script
type=
"text/javascript"
src=
"../src/core/UV.js"
></script>
<script
type=
"text/javascript"
src=
"../src/core/Geometry.js"
></script>
<script
type=
"text/javascript"
src=
"../src/core/Spline.js"
></script>
<script
type=
"text/javascript"
src=
"../src/animation/AnimationHandler.js"
></script>
<script
type=
"text/javascript"
src=
"../src/animation/Animation.js"
></script>
<script
type=
"text/javascript"
src=
"../src/cameras/Camera.js"
></script>
...
...
@@ -65,6 +66,7 @@
<script
type=
"text/javascript"
src=
"../src/objects/SkinnedMesh.js"
></script>
<script
type=
"text/javascript"
src=
"../src/objects/Ribbon.js"
></script>
<script
type=
"text/javascript"
src=
"../src/objects/Sound.js"
></script>
<script
type=
"text/javascript"
src=
"../src/objects/LOD.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/scenes/FogExp2.js"
></script>
...
...
@@ -72,6 +74,7 @@
<script
type=
"text/javascript"
src=
"../src/renderers/DOMRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/CanvasRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/SVGRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/WebGLShaders.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/WebGLRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/SoundRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/renderables/RenderableObject.js"
></script>
...
...
@@ -91,7 +94,7 @@
<script
type=
"text/javascript"
src=
"../src/extras/primitives/LathedObject.js"
></script>
<script
type=
"text/javascript"
src=
"../src/extras/objects/MarchingCubes.js"
></script>
<script
type=
"text/javascript"
src=
"../src/extras/io/Loader.js"
></script>
<script
type=
"text/javascript"
src=
"js/RequestAnimationFrame.js"
></script>
<script
type=
"text/javascript"
src=
"js/Stats.js"
></script>
...
...
examples/webgl_performance.html
浏览文件 @
13ccc02a
...
...
@@ -33,6 +33,7 @@
<script
type=
"text/javascript"
src=
"../src/core/Face4.js"
></script>
<script
type=
"text/javascript"
src=
"../src/core/UV.js"
></script>
<script
type=
"text/javascript"
src=
"../src/core/Geometry.js"
></script>
<script
type=
"text/javascript"
src=
"../src/core/Spline.js"
></script>
<script
type=
"text/javascript"
src=
"../src/animation/AnimationHandler.js"
></script>
<script
type=
"text/javascript"
src=
"../src/animation/Animation.js"
></script>
<script
type=
"text/javascript"
src=
"../src/cameras/Camera.js"
></script>
...
...
@@ -65,6 +66,7 @@
<script
type=
"text/javascript"
src=
"../src/objects/SkinnedMesh.js"
></script>
<script
type=
"text/javascript"
src=
"../src/objects/Ribbon.js"
></script>
<script
type=
"text/javascript"
src=
"../src/objects/Sound.js"
></script>
<script
type=
"text/javascript"
src=
"../src/objects/LOD.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/scenes/FogExp2.js"
></script>
...
...
@@ -72,6 +74,7 @@
<script
type=
"text/javascript"
src=
"../src/renderers/DOMRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/CanvasRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/SVGRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/WebGLShaders.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/WebGLRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/SoundRenderer.js"
></script>
<script
type=
"text/javascript"
src=
"../src/renderers/renderables/RenderableObject.js"
></script>
...
...
@@ -91,7 +94,7 @@
<script
type=
"text/javascript"
src=
"../src/extras/primitives/LathedObject.js"
></script>
<script
type=
"text/javascript"
src=
"../src/extras/objects/MarchingCubes.js"
></script>
<script
type=
"text/javascript"
src=
"../src/extras/io/Loader.js"
></script>
<script
type=
"text/javascript"
src=
"js/RequestAnimationFrame.js"
></script>
<script
type=
"text/javascript"
src=
"js/Stats.js"
></script>
...
...
src/renderers/WebGLRenderer.js
浏览文件 @
13ccc02a
...
...
@@ -3187,838 +3187,3 @@ THREE.WebGLRenderer = function ( parameters ) {
*/
};
THREE
.
Snippets
=
{
// FOG
fog_pars_fragment
:
[
"
#ifdef USE_FOG
"
,
"
uniform vec3 fogColor;
"
,
"
#ifdef FOG_EXP2
"
,
"
uniform float fogDensity;
"
,
"
#else
"
,
"
uniform float fogNear;
"
,
"
uniform float fogFar;
"
,
"
#endif
"
,
"
#endif
"
].
join
(
"
\n
"
),
fog_fragment
:
[
"
#ifdef USE_FOG
"
,
"
float depth = gl_FragCoord.z / gl_FragCoord.w;
"
,
"
#ifdef FOG_EXP2
"
,
"
const float LOG2 = 1.442695;
"
,
"
float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );
"
,
"
fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );
"
,
"
#else
"
,
"
float fogFactor = smoothstep( fogNear, fogFar, depth );
"
,
"
#endif
"
,
"
gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );
"
,
"
#endif
"
].
join
(
"
\n
"
),
// ENVIRONMENT MAP
envmap_pars_fragment
:
[
"
#ifdef USE_ENVMAP
"
,
"
varying vec3 vReflect;
"
,
"
uniform float reflectivity;
"
,
"
uniform samplerCube envMap;
"
,
"
uniform int combine;
"
,
"
#endif
"
].
join
(
"
\n
"
),
envmap_fragment
:
[
"
#ifdef USE_ENVMAP
"
,
"
vec4 cubeColor = textureCube( envMap, vec3( -vReflect.x, vReflect.yz ) );
"
,
"
if ( combine == 1 ) {
"
,
//"gl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );",
"
gl_FragColor = vec4( mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity ), opacity );
"
,
"
} else {
"
,
"
gl_FragColor = gl_FragColor * cubeColor;
"
,
"
}
"
,
"
#endif
"
].
join
(
"
\n
"
),
envmap_pars_vertex
:
[
"
#ifdef USE_ENVMAP
"
,
"
varying vec3 vReflect;
"
,
"
uniform float refractionRatio;
"
,
"
uniform bool useRefract;
"
,
"
#endif
"
].
join
(
"
\n
"
),
envmap_vertex
:
[
"
#ifdef USE_ENVMAP
"
,
"
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
"
,
"
vec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;
"
,
"
if ( useRefract ) {
"
,
"
vReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refractionRatio );
"
,
"
} else {
"
,
"
vReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );
"
,
"
}
"
,
"
#endif
"
].
join
(
"
\n
"
),
// COLOR MAP (particles)
map_particle_pars_fragment
:
[
"
#ifdef USE_MAP
"
,
"
uniform sampler2D map;
"
,
"
#endif
"
].
join
(
"
\n
"
),
map_particle_fragment
:
[
"
#ifdef USE_MAP
"
,
"
gl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );
"
,
"
#endif
"
].
join
(
"
\n
"
),
// COLOR MAP (triangles)
map_pars_fragment
:
[
"
#ifdef USE_MAP
"
,
"
varying vec2 vUv;
"
,
"
uniform sampler2D map;
"
,
"
#endif
"
].
join
(
"
\n
"
),
map_pars_vertex
:
[
"
#ifdef USE_MAP
"
,
"
varying vec2 vUv;
"
,
"
#endif
"
].
join
(
"
\n
"
),
map_fragment
:
[
"
#ifdef USE_MAP
"
,
"
gl_FragColor = gl_FragColor * texture2D( map, vUv );
"
,
"
#endif
"
].
join
(
"
\n
"
),
map_vertex
:
[
"
#ifdef USE_MAP
"
,
"
vUv = uv;
"
,
"
#endif
"
].
join
(
"
\n
"
),
// LIGHT MAP
lightmap_pars_fragment
:
[
"
#ifdef USE_LIGHTMAP
"
,
"
varying vec2 vUv2;
"
,
"
uniform sampler2D lightMap;
"
,
"
#endif
"
].
join
(
"
\n
"
),
lightmap_pars_vertex
:
[
"
#ifdef USE_LIGHTMAP
"
,
"
varying vec2 vUv2;
"
,
"
#endif
"
].
join
(
"
\n
"
),
lightmap_fragment
:
[
"
#ifdef USE_LIGHTMAP
"
,
"
gl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );
"
,
"
#endif
"
].
join
(
"
\n
"
),
lightmap_vertex
:
[
"
#ifdef USE_LIGHTMAP
"
,
"
vUv2 = uv2;
"
,
"
#endif
"
].
join
(
"
\n
"
),
lights_pars_vertex
:
[
"
uniform bool enableLighting;
"
,
"
uniform vec3 ambientLightColor;
"
,
"
#if MAX_DIR_LIGHTS > 0
"
,
"
uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];
"
,
"
uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
"
,
"
#endif
"
,
"
#if MAX_POINT_LIGHTS > 0
"
,
"
uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];
"
,
"
uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];
"
,
"
#ifdef PHONG
"
,
"
varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];
"
,
"
#endif
"
,
"
#endif
"
].
join
(
"
\n
"
),
// LIGHTS
lights_vertex
:
[
"
if ( !enableLighting ) {
"
,
"
vLightWeighting = vec3( 1.0 );
"
,
"
} else {
"
,
"
vLightWeighting = ambientLightColor;
"
,
"
#if MAX_DIR_LIGHTS > 0
"
,
"
for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {
"
,
"
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
"
,
"
float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );
"
,
"
vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;
"
,
"
}
"
,
"
#endif
"
,
"
#if MAX_POINT_LIGHTS > 0
"
,
"
for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {
"
,
"
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
"
,
"
vec3 pointLightVector = normalize( lPosition.xyz - mvPosition.xyz );
"
,
"
float pointLightWeighting = max( dot( transformedNormal, pointLightVector ), 0.0 );
"
,
"
vLightWeighting += pointLightColor[ i ] * pointLightWeighting;
"
,
"
#ifdef PHONG
"
,
"
vPointLightVector[ i ] = pointLightVector;
"
,
"
#endif
"
,
"
}
"
,
"
#endif
"
,
"
}
"
].
join
(
"
\n
"
),
lights_pars_fragment
:
[
"
#if MAX_DIR_LIGHTS > 0
"
,
"
uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
"
,
"
#endif
"
,
"
#if MAX_POINT_LIGHTS > 0
"
,
"
varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];
"
,
"
#endif
"
,
"
varying vec3 vViewPosition;
"
,
"
varying vec3 vNormal;
"
].
join
(
"
\n
"
),
lights_fragment
:
[
"
vec3 normal = normalize( vNormal );
"
,
"
vec3 viewPosition = normalize( vViewPosition );
"
,
"
vec4 mColor = vec4( diffuse, opacity );
"
,
"
vec4 mSpecular = vec4( specular, opacity );
"
,
"
#if MAX_POINT_LIGHTS > 0
"
,
"
vec4 pointDiffuse = vec4( 0.0 );
"
,
"
vec4 pointSpecular = vec4( 0.0 );
"
,
"
for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {
"
,
"
vec3 pointVector = normalize( vPointLightVector[ i ] );
"
,
"
vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );
"
,
"
float pointDotNormalHalf = dot( normal, pointHalfVector );
"
,
"
float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );
"
,
"
float pointSpecularWeight = 0.0;
"
,
"
if ( pointDotNormalHalf >= 0.0 )
"
,
"
pointSpecularWeight = pow( pointDotNormalHalf, shininess );
"
,
"
pointDiffuse += mColor * pointDiffuseWeight;
"
,
"
pointSpecular += mSpecular * pointSpecularWeight;
"
,
"
}
"
,
"
#endif
"
,
"
#if MAX_DIR_LIGHTS > 0
"
,
"
vec4 dirDiffuse = vec4( 0.0 );
"
,
"
vec4 dirSpecular = vec4( 0.0 );
"
,
"
for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {
"
,
"
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
"
,
"
vec3 dirVector = normalize( lDirection.xyz );
"
,
"
vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );
"
,
"
float dirDotNormalHalf = dot( normal, dirHalfVector );
"
,
"
float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );
"
,
"
float dirSpecularWeight = 0.0;
"
,
"
if ( dirDotNormalHalf >= 0.0 )
"
,
"
dirSpecularWeight = pow( dirDotNormalHalf, shininess );
"
,
"
dirDiffuse += mColor * dirDiffuseWeight;
"
,
"
dirSpecular += mSpecular * dirSpecularWeight;
"
,
"
}
"
,
"
#endif
"
,
"
vec4 totalLight = vec4( ambient, opacity );
"
,
"
#if MAX_DIR_LIGHTS > 0
"
,
"
totalLight += dirDiffuse + dirSpecular;
"
,
"
#endif
"
,
"
#if MAX_POINT_LIGHTS > 0
"
,
"
totalLight += pointDiffuse + pointSpecular;
"
,
"
#endif
"
,
"
gl_FragColor = gl_FragColor * totalLight;
"
].
join
(
"
\n
"
),
// VERTEX COLORS
color_pars_fragment
:
[
"
#ifdef USE_COLOR
"
,
"
varying vec3 vColor;
"
,
"
#endif
"
].
join
(
"
\n
"
),
color_fragment
:
[
"
#ifdef USE_COLOR
"
,
"
gl_FragColor = gl_FragColor * vec4( vColor, opacity );
"
,
"
#endif
"
].
join
(
"
\n
"
),
color_pars_vertex
:
[
"
#ifdef USE_COLOR
"
,
"
varying vec3 vColor;
"
,
"
#endif
"
].
join
(
"
\n
"
),
color_vertex
:
[
"
#ifdef USE_COLOR
"
,
"
vColor = color;
"
,
"
#endif
"
].
join
(
"
\n
"
),
// skinning
skinning_pars_vertex
:
[
"
#ifdef USE_SKINNING
"
,
"
uniform mat4 boneGlobalMatrices[ MAX_BONES ];
"
,
"
#endif
"
].
join
(
"
\n
"
),
skinning_vertex
:
[
"
#ifdef USE_SKINNING
"
,
"
gl_Position = ( boneGlobalMatrices[ int( skinIndex.x ) ] * skinVertexA ) * skinWeight.x;
"
,
"
gl_Position += ( boneGlobalMatrices[ int( skinIndex.y ) ] * skinVertexB ) * skinWeight.y;
"
,
// this doesn't work, no idea why
//"gl_Position = projectionMatrix * cameraInverseMatrix * objectMatrix * gl_Position;",
"
gl_Position = projectionMatrix * viewMatrix * objectMatrix * gl_Position;
"
,
"
#else
"
,
"
gl_Position = projectionMatrix * mvPosition;
"
,
"
#endif
"
].
join
(
"
\n
"
)
};
THREE
.
UniformsLib
=
{
common
:
{
"
diffuse
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0xeeeeee
)
},
"
opacity
"
:
{
type
:
"
f
"
,
value
:
1.0
},
"
map
"
:
{
type
:
"
t
"
,
value
:
0
,
texture
:
null
},
"
lightMap
"
:
{
type
:
"
t
"
,
value
:
2
,
texture
:
null
},
"
envMap
"
:
{
type
:
"
t
"
,
value
:
1
,
texture
:
null
},
"
useRefract
"
:
{
type
:
"
i
"
,
value
:
0
},
"
reflectivity
"
:
{
type
:
"
f
"
,
value
:
1.0
},
"
refractionRatio
"
:
{
type
:
"
f
"
,
value
:
0.98
},
"
combine
"
:
{
type
:
"
i
"
,
value
:
0
},
"
fogDensity
"
:
{
type
:
"
f
"
,
value
:
0.00025
},
"
fogNear
"
:
{
type
:
"
f
"
,
value
:
1
},
"
fogFar
"
:
{
type
:
"
f
"
,
value
:
2000
},
"
fogColor
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0xffffff
)
}
},
lights
:
{
"
enableLighting
"
:
{
type
:
"
i
"
,
value
:
1
},
"
ambientLightColor
"
:
{
type
:
"
fv
"
,
value
:
[]
},
"
directionalLightDirection
"
:
{
type
:
"
fv
"
,
value
:
[]
},
"
directionalLightColor
"
:
{
type
:
"
fv
"
,
value
:
[]
},
"
pointLightPosition
"
:
{
type
:
"
fv
"
,
value
:
[]
},
"
pointLightColor
"
:
{
type
:
"
fv
"
,
value
:
[]
}
},
particle
:
{
"
psColor
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0xeeeeee
)
},
"
opacity
"
:
{
type
:
"
f
"
,
value
:
1.0
},
"
size
"
:
{
type
:
"
f
"
,
value
:
1.0
},
"
scale
"
:
{
type
:
"
f
"
,
value
:
1.0
},
"
map
"
:
{
type
:
"
t
"
,
value
:
0
,
texture
:
null
},
"
fogDensity
"
:
{
type
:
"
f
"
,
value
:
0.00025
},
"
fogNear
"
:
{
type
:
"
f
"
,
value
:
1
},
"
fogFar
"
:
{
type
:
"
f
"
,
value
:
2000
},
"
fogColor
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0xffffff
)
}
}
};
THREE
.
ShaderLib
=
{
'
depth
'
:
{
uniforms
:
{
"
mNear
"
:
{
type
:
"
f
"
,
value
:
1.0
},
"
mFar
"
:
{
type
:
"
f
"
,
value
:
2000.0
},
"
opacity
"
:
{
type
:
"
f
"
,
value
:
1.0
}
},
fragmentShader
:
[
"
uniform float mNear;
"
,
"
uniform float mFar;
"
,
"
uniform float opacity;
"
,
"
void main() {
"
,
"
float depth = gl_FragCoord.z / gl_FragCoord.w;
"
,
"
float color = 1.0 - smoothstep( mNear, mFar, depth );
"
,
"
gl_FragColor = vec4( vec3( color ), opacity );
"
,
"
}
"
].
join
(
"
\n
"
),
vertexShader
:
[
"
void main() {
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
}
"
].
join
(
"
\n
"
)
},
'
normal
'
:
{
uniforms
:
{
"
opacity
"
:
{
type
:
"
f
"
,
value
:
1.0
}
},
fragmentShader
:
[
"
uniform float opacity;
"
,
"
varying vec3 vNormal;
"
,
"
void main() {
"
,
"
gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );
"
,
"
}
"
].
join
(
"
\n
"
),
vertexShader
:
[
"
varying vec3 vNormal;
"
,
"
void main() {
"
,
"
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
"
,
"
vNormal = normalize( normalMatrix * normal );
"
,
"
gl_Position = projectionMatrix * mvPosition;
"
,
"
}
"
].
join
(
"
\n
"
)
},
'
basic
'
:
{
uniforms
:
THREE
.
UniformsLib
[
"
common
"
],
fragmentShader
:
[
"
uniform vec3 diffuse;
"
,
"
uniform float opacity;
"
,
THREE
.
Snippets
[
"
color_pars_fragment
"
],
THREE
.
Snippets
[
"
map_pars_fragment
"
],
THREE
.
Snippets
[
"
lightmap_pars_fragment
"
],
THREE
.
Snippets
[
"
envmap_pars_fragment
"
],
THREE
.
Snippets
[
"
fog_pars_fragment
"
],
"
void main() {
"
,
"
gl_FragColor = vec4( diffuse, opacity );
"
,
THREE
.
Snippets
[
"
map_fragment
"
],
THREE
.
Snippets
[
"
lightmap_fragment
"
],
THREE
.
Snippets
[
"
color_fragment
"
],
THREE
.
Snippets
[
"
envmap_fragment
"
],
THREE
.
Snippets
[
"
fog_fragment
"
],
"
}
"
].
join
(
"
\n
"
),
vertexShader
:
[
THREE
.
Snippets
[
"
map_pars_vertex
"
],
THREE
.
Snippets
[
"
lightmap_pars_vertex
"
],
THREE
.
Snippets
[
"
envmap_pars_vertex
"
],
THREE
.
Snippets
[
"
color_pars_vertex
"
],
THREE
.
Snippets
[
"
skinning_pars_vertex
"
],
"
void main() {
"
,
"
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
"
,
THREE
.
Snippets
[
"
map_vertex
"
],
THREE
.
Snippets
[
"
lightmap_vertex
"
],
THREE
.
Snippets
[
"
envmap_vertex
"
],
THREE
.
Snippets
[
"
color_vertex
"
],
THREE
.
Snippets
[
"
skinning_vertex
"
],
"
}
"
].
join
(
"
\n
"
)
},
'
lambert
'
:
{
uniforms
:
Uniforms
.
merge
(
[
THREE
.
UniformsLib
[
"
common
"
],
THREE
.
UniformsLib
[
"
lights
"
]
]
),
fragmentShader
:
[
"
uniform vec3 diffuse;
"
,
"
uniform float opacity;
"
,
"
varying vec3 vLightWeighting;
"
,
THREE
.
Snippets
[
"
color_pars_fragment
"
],
THREE
.
Snippets
[
"
map_pars_fragment
"
],
THREE
.
Snippets
[
"
lightmap_pars_fragment
"
],
THREE
.
Snippets
[
"
envmap_pars_fragment
"
],
THREE
.
Snippets
[
"
fog_pars_fragment
"
],
"
void main() {
"
,
"
gl_FragColor = vec4( diffuse, opacity );
"
,
"
gl_FragColor = gl_FragColor * vec4( vLightWeighting, 1.0 );
"
,
THREE
.
Snippets
[
"
map_fragment
"
],
THREE
.
Snippets
[
"
lightmap_fragment
"
],
THREE
.
Snippets
[
"
color_fragment
"
],
THREE
.
Snippets
[
"
envmap_fragment
"
],
THREE
.
Snippets
[
"
fog_fragment
"
],
"
}
"
].
join
(
"
\n
"
),
vertexShader
:
[
"
varying vec3 vLightWeighting;
"
,
THREE
.
Snippets
[
"
map_pars_vertex
"
],
THREE
.
Snippets
[
"
lightmap_pars_vertex
"
],
THREE
.
Snippets
[
"
envmap_pars_vertex
"
],
THREE
.
Snippets
[
"
lights_pars_vertex
"
],
THREE
.
Snippets
[
"
color_pars_vertex
"
],
THREE
.
Snippets
[
"
skinning_pars_vertex
"
],
"
void main() {
"
,
"
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
"
,
THREE
.
Snippets
[
"
map_vertex
"
],
THREE
.
Snippets
[
"
lightmap_vertex
"
],
THREE
.
Snippets
[
"
envmap_vertex
"
],
THREE
.
Snippets
[
"
color_vertex
"
],
"
vec3 transformedNormal = normalize( normalMatrix * normal );
"
,
THREE
.
Snippets
[
"
lights_vertex
"
],
THREE
.
Snippets
[
"
skinning_vertex
"
],
"
}
"
].
join
(
"
\n
"
)
},
'
phong
'
:
{
uniforms
:
Uniforms
.
merge
(
[
THREE
.
UniformsLib
[
"
common
"
],
THREE
.
UniformsLib
[
"
lights
"
],
{
"
ambient
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0x050505
)
},
"
specular
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0x111111
)
},
"
shininess
"
:
{
type
:
"
f
"
,
value
:
30
}
}
]
),
fragmentShader
:
[
"
uniform vec3 diffuse;
"
,
"
uniform float opacity;
"
,
"
uniform vec3 ambient;
"
,
"
uniform vec3 specular;
"
,
"
uniform float shininess;
"
,
"
varying vec3 vLightWeighting;
"
,
THREE
.
Snippets
[
"
color_pars_fragment
"
],
THREE
.
Snippets
[
"
map_pars_fragment
"
],
THREE
.
Snippets
[
"
lightmap_pars_fragment
"
],
THREE
.
Snippets
[
"
envmap_pars_fragment
"
],
THREE
.
Snippets
[
"
fog_pars_fragment
"
],
THREE
.
Snippets
[
"
lights_pars_fragment
"
],
"
void main() {
"
,
"
gl_FragColor = vec4( vLightWeighting, 1.0 );
"
,
THREE
.
Snippets
[
"
lights_fragment
"
],
THREE
.
Snippets
[
"
map_fragment
"
],
THREE
.
Snippets
[
"
lightmap_fragment
"
],
THREE
.
Snippets
[
"
color_fragment
"
],
THREE
.
Snippets
[
"
envmap_fragment
"
],
THREE
.
Snippets
[
"
fog_fragment
"
],
"
}
"
].
join
(
"
\n
"
),
vertexShader
:
[
"
#define PHONG
"
,
"
varying vec3 vLightWeighting;
"
,
"
varying vec3 vViewPosition;
"
,
"
varying vec3 vNormal;
"
,
THREE
.
Snippets
[
"
map_pars_vertex
"
],
THREE
.
Snippets
[
"
lightmap_pars_vertex
"
],
THREE
.
Snippets
[
"
envmap_pars_vertex
"
],
THREE
.
Snippets
[
"
lights_pars_vertex
"
],
THREE
.
Snippets
[
"
color_pars_vertex
"
],
THREE
.
Snippets
[
"
skinning_pars_vertex
"
],
"
void main() {
"
,
"
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
"
,
THREE
.
Snippets
[
"
map_vertex
"
],
THREE
.
Snippets
[
"
lightmap_vertex
"
],
THREE
.
Snippets
[
"
envmap_vertex
"
],
THREE
.
Snippets
[
"
color_vertex
"
],
"
#ifndef USE_ENVMAP
"
,
"
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
"
,
"
#endif
"
,
"
vViewPosition = cameraPosition - mPosition.xyz;
"
,
"
vec3 transformedNormal = normalize( normalMatrix * normal );
"
,
"
vNormal = transformedNormal;
"
,
THREE
.
Snippets
[
"
lights_vertex
"
],
THREE
.
Snippets
[
"
skinning_vertex
"
],
"
}
"
].
join
(
"
\n
"
)
},
'
particle_basic
'
:
{
uniforms
:
THREE
.
UniformsLib
[
"
particle
"
],
fragmentShader
:
[
"
uniform vec3 psColor;
"
,
"
uniform float opacity;
"
,
THREE
.
Snippets
[
"
color_pars_fragment
"
],
THREE
.
Snippets
[
"
map_particle_pars_fragment
"
],
THREE
.
Snippets
[
"
fog_pars_fragment
"
],
"
void main() {
"
,
"
gl_FragColor = vec4( psColor, opacity );
"
,
THREE
.
Snippets
[
"
map_particle_fragment
"
],
THREE
.
Snippets
[
"
color_fragment
"
],
THREE
.
Snippets
[
"
fog_fragment
"
],
"
}
"
].
join
(
"
\n
"
),
vertexShader
:
[
"
uniform float size;
"
,
"
uniform float scale;
"
,
THREE
.
Snippets
[
"
color_pars_vertex
"
],
"
void main() {
"
,
THREE
.
Snippets
[
"
color_vertex
"
],
"
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
"
,
"
#ifdef USE_SIZEATTENUATION
"
,
"
gl_PointSize = size * ( scale / length( mvPosition.xyz ) );
"
,
"
#else
"
,
"
gl_PointSize = size;
"
,
"
#endif
"
,
"
gl_Position = projectionMatrix * mvPosition;
"
,
"
}
"
].
join
(
"
\n
"
)
}
};
src/renderers/WebGLShaders.js
0 → 100644
浏览文件 @
13ccc02a
/**
* @author alteredq / http://alteredqualia.com/
* @author mrdoob / http://mrdoob.com/
* @author mikael emtinger / http://gomo.se/
*/
THREE
.
ShaderChunk
=
{
// FOG
fog_pars_fragment
:
[
"
#ifdef USE_FOG
"
,
"
uniform vec3 fogColor;
"
,
"
#ifdef FOG_EXP2
"
,
"
uniform float fogDensity;
"
,
"
#else
"
,
"
uniform float fogNear;
"
,
"
uniform float fogFar;
"
,
"
#endif
"
,
"
#endif
"
].
join
(
"
\n
"
),
fog_fragment
:
[
"
#ifdef USE_FOG
"
,
"
float depth = gl_FragCoord.z / gl_FragCoord.w;
"
,
"
#ifdef FOG_EXP2
"
,
"
const float LOG2 = 1.442695;
"
,
"
float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );
"
,
"
fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );
"
,
"
#else
"
,
"
float fogFactor = smoothstep( fogNear, fogFar, depth );
"
,
"
#endif
"
,
"
gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );
"
,
"
#endif
"
].
join
(
"
\n
"
),
// ENVIRONMENT MAP
envmap_pars_fragment
:
[
"
#ifdef USE_ENVMAP
"
,
"
varying vec3 vReflect;
"
,
"
uniform float reflectivity;
"
,
"
uniform samplerCube envMap;
"
,
"
uniform int combine;
"
,
"
#endif
"
].
join
(
"
\n
"
),
envmap_fragment
:
[
"
#ifdef USE_ENVMAP
"
,
"
vec4 cubeColor = textureCube( envMap, vec3( -vReflect.x, vReflect.yz ) );
"
,
"
if ( combine == 1 ) {
"
,
//"gl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );",
"
gl_FragColor = vec4( mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity ), opacity );
"
,
"
} else {
"
,
"
gl_FragColor = gl_FragColor * cubeColor;
"
,
"
}
"
,
"
#endif
"
].
join
(
"
\n
"
),
envmap_pars_vertex
:
[
"
#ifdef USE_ENVMAP
"
,
"
varying vec3 vReflect;
"
,
"
uniform float refractionRatio;
"
,
"
uniform bool useRefract;
"
,
"
#endif
"
].
join
(
"
\n
"
),
envmap_vertex
:
[
"
#ifdef USE_ENVMAP
"
,
"
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
"
,
"
vec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;
"
,
"
if ( useRefract ) {
"
,
"
vReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refractionRatio );
"
,
"
} else {
"
,
"
vReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );
"
,
"
}
"
,
"
#endif
"
].
join
(
"
\n
"
),
// COLOR MAP (particles)
map_particle_pars_fragment
:
[
"
#ifdef USE_MAP
"
,
"
uniform sampler2D map;
"
,
"
#endif
"
].
join
(
"
\n
"
),
map_particle_fragment
:
[
"
#ifdef USE_MAP
"
,
"
gl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );
"
,
"
#endif
"
].
join
(
"
\n
"
),
// COLOR MAP (triangles)
map_pars_fragment
:
[
"
#ifdef USE_MAP
"
,
"
varying vec2 vUv;
"
,
"
uniform sampler2D map;
"
,
"
#endif
"
].
join
(
"
\n
"
),
map_pars_vertex
:
[
"
#ifdef USE_MAP
"
,
"
varying vec2 vUv;
"
,
"
#endif
"
].
join
(
"
\n
"
),
map_fragment
:
[
"
#ifdef USE_MAP
"
,
"
gl_FragColor = gl_FragColor * texture2D( map, vUv );
"
,
"
#endif
"
].
join
(
"
\n
"
),
map_vertex
:
[
"
#ifdef USE_MAP
"
,
"
vUv = uv;
"
,
"
#endif
"
].
join
(
"
\n
"
),
// LIGHT MAP
lightmap_pars_fragment
:
[
"
#ifdef USE_LIGHTMAP
"
,
"
varying vec2 vUv2;
"
,
"
uniform sampler2D lightMap;
"
,
"
#endif
"
].
join
(
"
\n
"
),
lightmap_pars_vertex
:
[
"
#ifdef USE_LIGHTMAP
"
,
"
varying vec2 vUv2;
"
,
"
#endif
"
].
join
(
"
\n
"
),
lightmap_fragment
:
[
"
#ifdef USE_LIGHTMAP
"
,
"
gl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );
"
,
"
#endif
"
].
join
(
"
\n
"
),
lightmap_vertex
:
[
"
#ifdef USE_LIGHTMAP
"
,
"
vUv2 = uv2;
"
,
"
#endif
"
].
join
(
"
\n
"
),
lights_pars_vertex
:
[
"
uniform bool enableLighting;
"
,
"
uniform vec3 ambientLightColor;
"
,
"
#if MAX_DIR_LIGHTS > 0
"
,
"
uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];
"
,
"
uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
"
,
"
#endif
"
,
"
#if MAX_POINT_LIGHTS > 0
"
,
"
uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];
"
,
"
uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];
"
,
"
#ifdef PHONG
"
,
"
varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];
"
,
"
#endif
"
,
"
#endif
"
].
join
(
"
\n
"
),
// LIGHTS
lights_vertex
:
[
"
if ( !enableLighting ) {
"
,
"
vLightWeighting = vec3( 1.0 );
"
,
"
} else {
"
,
"
vLightWeighting = ambientLightColor;
"
,
"
#if MAX_DIR_LIGHTS > 0
"
,
"
for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {
"
,
"
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
"
,
"
float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );
"
,
"
vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;
"
,
"
}
"
,
"
#endif
"
,
"
#if MAX_POINT_LIGHTS > 0
"
,
"
for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {
"
,
"
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
"
,
"
vec3 pointLightVector = normalize( lPosition.xyz - mvPosition.xyz );
"
,
"
float pointLightWeighting = max( dot( transformedNormal, pointLightVector ), 0.0 );
"
,
"
vLightWeighting += pointLightColor[ i ] * pointLightWeighting;
"
,
"
#ifdef PHONG
"
,
"
vPointLightVector[ i ] = pointLightVector;
"
,
"
#endif
"
,
"
}
"
,
"
#endif
"
,
"
}
"
].
join
(
"
\n
"
),
lights_pars_fragment
:
[
"
#if MAX_DIR_LIGHTS > 0
"
,
"
uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
"
,
"
#endif
"
,
"
#if MAX_POINT_LIGHTS > 0
"
,
"
varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];
"
,
"
#endif
"
,
"
varying vec3 vViewPosition;
"
,
"
varying vec3 vNormal;
"
].
join
(
"
\n
"
),
lights_fragment
:
[
"
vec3 normal = normalize( vNormal );
"
,
"
vec3 viewPosition = normalize( vViewPosition );
"
,
"
vec4 mColor = vec4( diffuse, opacity );
"
,
"
vec4 mSpecular = vec4( specular, opacity );
"
,
"
#if MAX_POINT_LIGHTS > 0
"
,
"
vec4 pointDiffuse = vec4( 0.0 );
"
,
"
vec4 pointSpecular = vec4( 0.0 );
"
,
"
for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {
"
,
"
vec3 pointVector = normalize( vPointLightVector[ i ] );
"
,
"
vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );
"
,
"
float pointDotNormalHalf = dot( normal, pointHalfVector );
"
,
"
float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );
"
,
"
float pointSpecularWeight = 0.0;
"
,
"
if ( pointDotNormalHalf >= 0.0 )
"
,
"
pointSpecularWeight = pow( pointDotNormalHalf, shininess );
"
,
"
pointDiffuse += mColor * pointDiffuseWeight;
"
,
"
pointSpecular += mSpecular * pointSpecularWeight;
"
,
"
}
"
,
"
#endif
"
,
"
#if MAX_DIR_LIGHTS > 0
"
,
"
vec4 dirDiffuse = vec4( 0.0 );
"
,
"
vec4 dirSpecular = vec4( 0.0 );
"
,
"
for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {
"
,
"
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
"
,
"
vec3 dirVector = normalize( lDirection.xyz );
"
,
"
vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );
"
,
"
float dirDotNormalHalf = dot( normal, dirHalfVector );
"
,
"
float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );
"
,
"
float dirSpecularWeight = 0.0;
"
,
"
if ( dirDotNormalHalf >= 0.0 )
"
,
"
dirSpecularWeight = pow( dirDotNormalHalf, shininess );
"
,
"
dirDiffuse += mColor * dirDiffuseWeight;
"
,
"
dirSpecular += mSpecular * dirSpecularWeight;
"
,
"
}
"
,
"
#endif
"
,
"
vec4 totalLight = vec4( ambient, opacity );
"
,
"
#if MAX_DIR_LIGHTS > 0
"
,
"
totalLight += dirDiffuse + dirSpecular;
"
,
"
#endif
"
,
"
#if MAX_POINT_LIGHTS > 0
"
,
"
totalLight += pointDiffuse + pointSpecular;
"
,
"
#endif
"
,
"
gl_FragColor = gl_FragColor * totalLight;
"
].
join
(
"
\n
"
),
// VERTEX COLORS
color_pars_fragment
:
[
"
#ifdef USE_COLOR
"
,
"
varying vec3 vColor;
"
,
"
#endif
"
].
join
(
"
\n
"
),
color_fragment
:
[
"
#ifdef USE_COLOR
"
,
"
gl_FragColor = gl_FragColor * vec4( vColor, opacity );
"
,
"
#endif
"
].
join
(
"
\n
"
),
color_pars_vertex
:
[
"
#ifdef USE_COLOR
"
,
"
varying vec3 vColor;
"
,
"
#endif
"
].
join
(
"
\n
"
),
color_vertex
:
[
"
#ifdef USE_COLOR
"
,
"
vColor = color;
"
,
"
#endif
"
].
join
(
"
\n
"
),
// skinning
skinning_pars_vertex
:
[
"
#ifdef USE_SKINNING
"
,
"
uniform mat4 boneGlobalMatrices[ MAX_BONES ];
"
,
"
#endif
"
].
join
(
"
\n
"
),
skinning_vertex
:
[
"
#ifdef USE_SKINNING
"
,
"
gl_Position = ( boneGlobalMatrices[ int( skinIndex.x ) ] * skinVertexA ) * skinWeight.x;
"
,
"
gl_Position += ( boneGlobalMatrices[ int( skinIndex.y ) ] * skinVertexB ) * skinWeight.y;
"
,
// this doesn't work, no idea why
//"gl_Position = projectionMatrix * cameraInverseMatrix * objectMatrix * gl_Position;",
"
gl_Position = projectionMatrix * viewMatrix * objectMatrix * gl_Position;
"
,
"
#else
"
,
"
gl_Position = projectionMatrix * mvPosition;
"
,
"
#endif
"
].
join
(
"
\n
"
)
};
THREE
.
UniformsLib
=
{
common
:
{
"
diffuse
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0xeeeeee
)
},
"
opacity
"
:
{
type
:
"
f
"
,
value
:
1.0
},
"
map
"
:
{
type
:
"
t
"
,
value
:
0
,
texture
:
null
},
"
lightMap
"
:
{
type
:
"
t
"
,
value
:
2
,
texture
:
null
},
"
envMap
"
:
{
type
:
"
t
"
,
value
:
1
,
texture
:
null
},
"
useRefract
"
:
{
type
:
"
i
"
,
value
:
0
},
"
reflectivity
"
:
{
type
:
"
f
"
,
value
:
1.0
},
"
refractionRatio
"
:
{
type
:
"
f
"
,
value
:
0.98
},
"
combine
"
:
{
type
:
"
i
"
,
value
:
0
},
"
fogDensity
"
:
{
type
:
"
f
"
,
value
:
0.00025
},
"
fogNear
"
:
{
type
:
"
f
"
,
value
:
1
},
"
fogFar
"
:
{
type
:
"
f
"
,
value
:
2000
},
"
fogColor
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0xffffff
)
}
},
lights
:
{
"
enableLighting
"
:
{
type
:
"
i
"
,
value
:
1
},
"
ambientLightColor
"
:
{
type
:
"
fv
"
,
value
:
[]
},
"
directionalLightDirection
"
:
{
type
:
"
fv
"
,
value
:
[]
},
"
directionalLightColor
"
:
{
type
:
"
fv
"
,
value
:
[]
},
"
pointLightPosition
"
:
{
type
:
"
fv
"
,
value
:
[]
},
"
pointLightColor
"
:
{
type
:
"
fv
"
,
value
:
[]
}
},
particle
:
{
"
psColor
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0xeeeeee
)
},
"
opacity
"
:
{
type
:
"
f
"
,
value
:
1.0
},
"
size
"
:
{
type
:
"
f
"
,
value
:
1.0
},
"
scale
"
:
{
type
:
"
f
"
,
value
:
1.0
},
"
map
"
:
{
type
:
"
t
"
,
value
:
0
,
texture
:
null
},
"
fogDensity
"
:
{
type
:
"
f
"
,
value
:
0.00025
},
"
fogNear
"
:
{
type
:
"
f
"
,
value
:
1
},
"
fogFar
"
:
{
type
:
"
f
"
,
value
:
2000
},
"
fogColor
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0xffffff
)
}
}
};
THREE
.
ShaderLib
=
{
'
depth
'
:
{
uniforms
:
{
"
mNear
"
:
{
type
:
"
f
"
,
value
:
1.0
},
"
mFar
"
:
{
type
:
"
f
"
,
value
:
2000.0
},
"
opacity
"
:
{
type
:
"
f
"
,
value
:
1.0
}
},
fragmentShader
:
[
"
uniform float mNear;
"
,
"
uniform float mFar;
"
,
"
uniform float opacity;
"
,
"
void main() {
"
,
"
float depth = gl_FragCoord.z / gl_FragCoord.w;
"
,
"
float color = 1.0 - smoothstep( mNear, mFar, depth );
"
,
"
gl_FragColor = vec4( vec3( color ), opacity );
"
,
"
}
"
].
join
(
"
\n
"
),
vertexShader
:
[
"
void main() {
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
}
"
].
join
(
"
\n
"
)
},
'
normal
'
:
{
uniforms
:
{
"
opacity
"
:
{
type
:
"
f
"
,
value
:
1.0
}
},
fragmentShader
:
[
"
uniform float opacity;
"
,
"
varying vec3 vNormal;
"
,
"
void main() {
"
,
"
gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );
"
,
"
}
"
].
join
(
"
\n
"
),
vertexShader
:
[
"
varying vec3 vNormal;
"
,
"
void main() {
"
,
"
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
"
,
"
vNormal = normalize( normalMatrix * normal );
"
,
"
gl_Position = projectionMatrix * mvPosition;
"
,
"
}
"
].
join
(
"
\n
"
)
},
'
basic
'
:
{
uniforms
:
THREE
.
UniformsLib
[
"
common
"
],
fragmentShader
:
[
"
uniform vec3 diffuse;
"
,
"
uniform float opacity;
"
,
THREE
.
ShaderChunk
[
"
color_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
map_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
lightmap_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
envmap_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
fog_pars_fragment
"
],
"
void main() {
"
,
"
gl_FragColor = vec4( diffuse, opacity );
"
,
THREE
.
ShaderChunk
[
"
map_fragment
"
],
THREE
.
ShaderChunk
[
"
lightmap_fragment
"
],
THREE
.
ShaderChunk
[
"
color_fragment
"
],
THREE
.
ShaderChunk
[
"
envmap_fragment
"
],
THREE
.
ShaderChunk
[
"
fog_fragment
"
],
"
}
"
].
join
(
"
\n
"
),
vertexShader
:
[
THREE
.
ShaderChunk
[
"
map_pars_vertex
"
],
THREE
.
ShaderChunk
[
"
lightmap_pars_vertex
"
],
THREE
.
ShaderChunk
[
"
envmap_pars_vertex
"
],
THREE
.
ShaderChunk
[
"
color_pars_vertex
"
],
THREE
.
ShaderChunk
[
"
skinning_pars_vertex
"
],
"
void main() {
"
,
"
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
"
,
THREE
.
ShaderChunk
[
"
map_vertex
"
],
THREE
.
ShaderChunk
[
"
lightmap_vertex
"
],
THREE
.
ShaderChunk
[
"
envmap_vertex
"
],
THREE
.
ShaderChunk
[
"
color_vertex
"
],
THREE
.
ShaderChunk
[
"
skinning_vertex
"
],
"
}
"
].
join
(
"
\n
"
)
},
'
lambert
'
:
{
uniforms
:
Uniforms
.
merge
(
[
THREE
.
UniformsLib
[
"
common
"
],
THREE
.
UniformsLib
[
"
lights
"
]
]
),
fragmentShader
:
[
"
uniform vec3 diffuse;
"
,
"
uniform float opacity;
"
,
"
varying vec3 vLightWeighting;
"
,
THREE
.
ShaderChunk
[
"
color_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
map_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
lightmap_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
envmap_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
fog_pars_fragment
"
],
"
void main() {
"
,
"
gl_FragColor = vec4( diffuse, opacity );
"
,
"
gl_FragColor = gl_FragColor * vec4( vLightWeighting, 1.0 );
"
,
THREE
.
ShaderChunk
[
"
map_fragment
"
],
THREE
.
ShaderChunk
[
"
lightmap_fragment
"
],
THREE
.
ShaderChunk
[
"
color_fragment
"
],
THREE
.
ShaderChunk
[
"
envmap_fragment
"
],
THREE
.
ShaderChunk
[
"
fog_fragment
"
],
"
}
"
].
join
(
"
\n
"
),
vertexShader
:
[
"
varying vec3 vLightWeighting;
"
,
THREE
.
ShaderChunk
[
"
map_pars_vertex
"
],
THREE
.
ShaderChunk
[
"
lightmap_pars_vertex
"
],
THREE
.
ShaderChunk
[
"
envmap_pars_vertex
"
],
THREE
.
ShaderChunk
[
"
lights_pars_vertex
"
],
THREE
.
ShaderChunk
[
"
color_pars_vertex
"
],
THREE
.
ShaderChunk
[
"
skinning_pars_vertex
"
],
"
void main() {
"
,
"
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
"
,
THREE
.
ShaderChunk
[
"
map_vertex
"
],
THREE
.
ShaderChunk
[
"
lightmap_vertex
"
],
THREE
.
ShaderChunk
[
"
envmap_vertex
"
],
THREE
.
ShaderChunk
[
"
color_vertex
"
],
"
vec3 transformedNormal = normalize( normalMatrix * normal );
"
,
THREE
.
ShaderChunk
[
"
lights_vertex
"
],
THREE
.
ShaderChunk
[
"
skinning_vertex
"
],
"
}
"
].
join
(
"
\n
"
)
},
'
phong
'
:
{
uniforms
:
Uniforms
.
merge
(
[
THREE
.
UniformsLib
[
"
common
"
],
THREE
.
UniformsLib
[
"
lights
"
],
{
"
ambient
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0x050505
)
},
"
specular
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0x111111
)
},
"
shininess
"
:
{
type
:
"
f
"
,
value
:
30
}
}
]
),
fragmentShader
:
[
"
uniform vec3 diffuse;
"
,
"
uniform float opacity;
"
,
"
uniform vec3 ambient;
"
,
"
uniform vec3 specular;
"
,
"
uniform float shininess;
"
,
"
varying vec3 vLightWeighting;
"
,
THREE
.
ShaderChunk
[
"
color_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
map_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
lightmap_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
envmap_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
fog_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
lights_pars_fragment
"
],
"
void main() {
"
,
"
gl_FragColor = vec4( vLightWeighting, 1.0 );
"
,
THREE
.
ShaderChunk
[
"
lights_fragment
"
],
THREE
.
ShaderChunk
[
"
map_fragment
"
],
THREE
.
ShaderChunk
[
"
lightmap_fragment
"
],
THREE
.
ShaderChunk
[
"
color_fragment
"
],
THREE
.
ShaderChunk
[
"
envmap_fragment
"
],
THREE
.
ShaderChunk
[
"
fog_fragment
"
],
"
}
"
].
join
(
"
\n
"
),
vertexShader
:
[
"
#define PHONG
"
,
"
varying vec3 vLightWeighting;
"
,
"
varying vec3 vViewPosition;
"
,
"
varying vec3 vNormal;
"
,
THREE
.
ShaderChunk
[
"
map_pars_vertex
"
],
THREE
.
ShaderChunk
[
"
lightmap_pars_vertex
"
],
THREE
.
ShaderChunk
[
"
envmap_pars_vertex
"
],
THREE
.
ShaderChunk
[
"
lights_pars_vertex
"
],
THREE
.
ShaderChunk
[
"
color_pars_vertex
"
],
THREE
.
ShaderChunk
[
"
skinning_pars_vertex
"
],
"
void main() {
"
,
"
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
"
,
THREE
.
ShaderChunk
[
"
map_vertex
"
],
THREE
.
ShaderChunk
[
"
lightmap_vertex
"
],
THREE
.
ShaderChunk
[
"
envmap_vertex
"
],
THREE
.
ShaderChunk
[
"
color_vertex
"
],
"
#ifndef USE_ENVMAP
"
,
"
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
"
,
"
#endif
"
,
"
vViewPosition = cameraPosition - mPosition.xyz;
"
,
"
vec3 transformedNormal = normalize( normalMatrix * normal );
"
,
"
vNormal = transformedNormal;
"
,
THREE
.
ShaderChunk
[
"
lights_vertex
"
],
THREE
.
ShaderChunk
[
"
skinning_vertex
"
],
"
}
"
].
join
(
"
\n
"
)
},
'
particle_basic
'
:
{
uniforms
:
THREE
.
UniformsLib
[
"
particle
"
],
fragmentShader
:
[
"
uniform vec3 psColor;
"
,
"
uniform float opacity;
"
,
THREE
.
ShaderChunk
[
"
color_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
map_particle_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
fog_pars_fragment
"
],
"
void main() {
"
,
"
gl_FragColor = vec4( psColor, opacity );
"
,
THREE
.
ShaderChunk
[
"
map_particle_fragment
"
],
THREE
.
ShaderChunk
[
"
color_fragment
"
],
THREE
.
ShaderChunk
[
"
fog_fragment
"
],
"
}
"
].
join
(
"
\n
"
),
vertexShader
:
[
"
uniform float size;
"
,
"
uniform float scale;
"
,
THREE
.
ShaderChunk
[
"
color_pars_vertex
"
],
"
void main() {
"
,
THREE
.
ShaderChunk
[
"
color_vertex
"
],
"
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
"
,
"
#ifdef USE_SIZEATTENUATION
"
,
"
gl_PointSize = size * ( scale / length( mvPosition.xyz ) );
"
,
"
#else
"
,
"
gl_PointSize = size;
"
,
"
#endif
"
,
"
gl_Position = projectionMatrix * mvPosition;
"
,
"
}
"
].
join
(
"
\n
"
)
}
};
utils/build.py
浏览文件 @
13ccc02a
...
...
@@ -69,6 +69,7 @@ COMMON_FILES = [
'renderers/DOMRenderer.js'
,
'renderers/CanvasRenderer.js'
,
'renderers/SVGRenderer.js'
,
'renderers/WebGLShaders.js'
,
'renderers/WebGLRenderer.js'
,
'renderers/SoundRenderer.js'
,
'renderers/renderables/RenderableObject.js'
,
...
...
@@ -267,6 +268,7 @@ WEBGL_FILES = [
'scenes/Fog.js'
,
'scenes/FogExp2.js'
,
'renderers/SoundRenderer.js'
,
'renderers/WebGLShaders.js'
,
'renderers/WebGLRenderer.js'
,
]
...
...
utils/exporters/max/ThreeJSExporter.ms
浏览文件 @
13ccc02a
...
...
@@ -408,7 +408,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
-------------------------------------------------------------------------------------
-- Export materials
function ExportMaterials zmaterials =
function ExportMaterials zmaterials
hasDummyMaterial
=
(
Format "'materials': [\n" to:ostream
...
...
@@ -448,10 +448,22 @@ rollout ThreeJSExporter "ThreeJSExporter"
Format "}" to:ostream
if
i < totalMaterials
then Format "," to:ostream
if
( i < totalMaterials or hasDummyMaterial )
then Format "," to:ostream
Format "\n\n" to:ostream
)
if hasDummyMaterial then
(
Format "{\n" to:ostream
Format "'DbgIndex' : %,\n" totalMaterials to:ostream
Format "'DbgName' : '%',\n" "dummy" to:ostream
Format "}" to:ostream
)
Format "],\n\n" to:ostream
...
...
@@ -554,12 +566,16 @@ rollout ThreeJSExporter "ThreeJSExporter"
useMultiMaterial = false
materialIDList = #()
if ( classof objMaterial ) == StandardMaterial then
materialClass = classof objMaterial
if materialClass == StandardMaterial then
(
fm = findItem allMaterials objMaterial
)
else
else
if materialClass == MultiMaterial then
(
useMultiMaterial = true
...
...
@@ -572,11 +588,21 @@ rollout ThreeJSExporter "ThreeJSExporter"
mMergedIndex = findItem allMaterials subMaterial
if mMergedIndex > 0 then
(
materialIDList[mID] = mMergedIndex
)
)
)
else
(
-- undefined material
fm = 0
)
for i = 1 to n do
...
...
@@ -592,8 +618,10 @@ rollout ThreeJSExporter "ThreeJSExporter"
if useMultiMaterial then
(
mID = GetFaceMatID objMesh i
fm = materialIDList[mID]
)
if hasUVs then
...
...
@@ -608,7 +636,9 @@ rollout ThreeJSExporter "ThreeJSExporter"
)
else
(
fuv = false
)
append zface fv
...
...
@@ -632,9 +662,12 @@ rollout ThreeJSExporter "ThreeJSExporter"
if materialClass == StandardMaterial then
(
if ( findItem whereto objMaterial ) == 0 then
(
append whereto objMaterial
)
)
...
...
@@ -652,7 +685,9 @@ rollout ThreeJSExporter "ThreeJSExporter"
if ( findItem whereto subMaterial ) == 0 then
(
append whereto subMaterial
)
)
...
...
@@ -728,6 +763,8 @@ rollout ThreeJSExporter "ThreeJSExporter"
mergedFaces = #()
mergedMaterials = #()
hasDummyMaterial = true
for obj in selection do
(
...
...
@@ -800,7 +837,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
-- Dump all materials in the scene
ExportMaterials mergedMaterials
ExportMaterials mergedMaterials
hasDummyMaterial
-- Dump merged data from all selected geometries
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录