Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
1aabcb37
T
three.js
项目概览
车家大少爷
/
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,发现更多精彩内容 >>
提交
1aabcb37
编写于
3月 15, 2015
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Examples clean up.
上级
b61ead78
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
48 addition
and
63 deletion
+48
-63
examples/index.html
examples/index.html
+1
-0
examples/js/SkyShader.js
examples/js/SkyShader.js
+16
-23
examples/js/math/Lut.js
examples/js/math/Lut.js
+2
-2
examples/js/postprocessing/AdaptiveToneMappingPass.js
examples/js/postprocessing/AdaptiveToneMappingPass.js
+8
-8
examples/misc_fps.html
examples/misc_fps.html
+6
-5
examples/webgl_interactive_cubes_gpu.html
examples/webgl_interactive_cubes_gpu.html
+1
-0
examples/webgl_shaders_sky.html
examples/webgl_shaders_sky.html
+13
-24
examples/webgl_terrain_dynamic.html
examples/webgl_terrain_dynamic.html
+1
-1
未找到文件。
examples/index.html
浏览文件 @
1aabcb37
...
...
@@ -358,6 +358,7 @@
"
webgl_shadowmap
"
,
"
webgl_shadowmap_performance
"
,
"
webgl_shadowmap_viewer
"
,
"
webgl_shadowmesh
"
,
"
webgl_sprites
"
,
"
webgl_terrain_dynamic
"
,
"
webgl_test_memory
"
,
...
...
examples/js/SkyShader.js
浏览文件 @
1aabcb37
/**
* @author zz85 / https://github.com/zz85
*
* Based on "A Practical Analytic Model for Daylight"
*
* Based on "A Practical Analytic Model for Daylight"
* aka The Preetham Model, the de facto standard analytic skydome model
* http://www.cs.utah.edu/~shirley/papers/sunsky/sunsky.pdf
*
*
* First implemented by Simon Wallner
* http://www.simonwallner.at/projects/atmospheric-scattering
*
*
* Improved by Martin Upitis
* http://blenderartists.org/forum/showthread.php?245954-preethams-sky-impementation-HDR
*
*
* Three.js integration by zz85 http://twitter.com/blurspline
*/
...
...
@@ -30,13 +30,11 @@ THREE.ShaderLib['sky'] = {
vertexShader
:
[
"
varying vec3 vWorldPosition;
"
,
"
varying vec2 vUv;
"
,
"
void main() {
"
,
"
vec4 worldPosition = modelMatrix * vec4( position, 1.0 );
"
,
"
vWorldPosition = worldPosition.xyz;
"
,
"
vUv = uv;
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
...
...
@@ -46,12 +44,9 @@ THREE.ShaderLib['sky'] = {
fragmentShader
:
[
"
uniform sampler2D skySampler;
"
,
"
uniform vec3 sunPosition;
"
,
"
varying vec3 vWorldPosition;
"
,
"
varying vec2 vUv;
"
,
"
vec3 cameraPos = vec3(0., 0., 0.);
"
,
"
// uniform sampler2D sDiffuse;
"
,
...
...
@@ -67,7 +62,6 @@ THREE.ShaderLib['sky'] = {
"
uniform float mieCoefficient;
"
,
"
uniform float mieDirectionalG;
"
,
"
vec3 sunDirection = normalize(sunPosition);
"
,
"
float reileighCoefficient = reileigh;
"
,
...
...
@@ -165,9 +159,9 @@ THREE.ShaderLib['sky'] = {
"
// luminance = 1.0 ;// vWorldPosition.y / 450000. + 0.5; //sunPosition.y / 450000. * 1. + 0.5;
"
,
"
// gl_FragColor = vec4(sunfade, sunfade, sunfade, 1.0);
"
,
"
reileighCoefficient = reileighCoefficient - (1.0* (1.0-sunfade));
"
,
"
float sunE = sunIntensity(dot(sunDirection, up));
"
,
"
// extinction (absorbtion + out scattering)
"
,
...
...
@@ -210,7 +204,7 @@ THREE.ShaderLib['sky'] = {
"
vec2 uv = vec2(phi, theta) / vec2(2.0*pi, pi) + vec2(0.5, 0.0);
"
,
"
// vec3 L0 = texture2D(skySampler, uv).rgb+0.1 * Fex;
"
,
"
vec3 L0 = vec3(0.1) * Fex;
"
,
"
// composition + solar disc
"
,
"
//if (cosTheta > sunAngularDiameterCos)
"
,
"
float sundisk = smoothstep(sunAngularDiameterCos,sunAngularDiameterCos+0.00002,cosTheta);
"
,
...
...
@@ -219,25 +213,25 @@ THREE.ShaderLib['sky'] = {
"
vec3 whiteScale = 1.0/Uncharted2Tonemap(vec3(W));
"
,
"
vec3 texColor = (Lin+L0);
"
,
"
texColor *= 0.04 ;
"
,
"
texColor += vec3(0.0,0.001,0.0025)*0.3;
"
,
"
float g_fMaxLuminance = 1.0;
"
,
"
float fLumScaled = 0.1 / luminance;
"
,
"
float fLumCompressed = (fLumScaled * (1.0 + (fLumScaled / (g_fMaxLuminance * g_fMaxLuminance)))) / (1.0 + fLumScaled);
"
,
"
float ExposureBias = fLumCompressed;
"
,
"
vec3 curr = Uncharted2Tonemap((log2(2.0/pow(luminance,4.0)))*texColor);
"
,
"
vec3 color = curr*whiteScale;
"
,
"
vec3 retColor = pow(color,vec3(1.0/(1.2+(1.2*sunfade))));
"
,
"
gl_FragColor.rgb = retColor;
"
,
"
gl_FragColor.a = 1.0;
"
,
"
}
"
,
...
...
@@ -250,9 +244,9 @@ THREE.Sky = function () {
var
skyShader
=
THREE
.
ShaderLib
[
"
sky
"
];
var
skyUniforms
=
THREE
.
UniformsUtils
.
clone
(
skyShader
.
uniforms
);
var
skyMat
=
new
THREE
.
ShaderMaterial
(
{
fragmentShader
:
skyShader
.
fragmentShader
,
vertexShader
:
skyShader
.
vertexShader
,
var
skyMat
=
new
THREE
.
ShaderMaterial
(
{
fragmentShader
:
skyShader
.
fragmentShader
,
vertexShader
:
skyShader
.
vertexShader
,
uniforms
:
skyUniforms
,
side
:
THREE
.
BackSide
}
);
...
...
@@ -265,5 +259,4 @@ THREE.Sky = function () {
this
.
mesh
=
skyMesh
;
this
.
uniforms
=
skyUniforms
;
};
examples/js/math/Lut.js
浏览文件 @
1aabcb37
...
...
@@ -300,7 +300,7 @@ THREE.Lut.prototype = {
contextTitle
.
fillText
(
this
.
legend
.
labels
.
title
.
toString
()
+
this
.
legend
.
labels
.
um
.
toString
(),
borderThickness
,
this
.
legend
.
labels
.
fontsize
+
borderThickness
);
var
txtTitle
=
new
THREE
.
Texture
(
canvasTitle
);
txtTitle
.
minFilter
=
THREE
.
LinearFilter
;
txtTitle
.
needsUpdate
=
true
;
var
spriteMaterialTitle
=
new
THREE
.
SpriteMaterial
(
{
map
:
txtTitle
,
useScreenCoordinates
:
false
}
);
...
...
@@ -385,7 +385,7 @@ THREE.Lut.prototype = {
contextTick
.
fillText
(
value
.
toString
(),
borderThickness
,
this
.
legend
.
labels
.
fontsize
+
borderThickness
);
var
txtTick
=
new
THREE
.
Texture
(
canvasTick
);
txtTick
.
minFilter
=
THREE
.
LinearFilter
;
txtTick
.
needsUpdate
=
true
;
var
spriteMaterialTick
=
new
THREE
.
SpriteMaterial
(
{
map
:
txtTick
,
useScreenCoordinates
:
false
}
);
...
...
examples/js/postprocessing/AdaptiveToneMappingPass.js
浏览文件 @
1aabcb37
...
...
@@ -16,7 +16,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
this
.
luminanceRT
=
null
;
this
.
previousLuminanceRT
=
null
;
this
.
currentLuminanceRT
=
null
;
if
(
THREE
.
CopyShader
===
undefined
)
console
.
error
(
"
THREE.AdaptiveToneMappingPass relies on THREE.CopyShader
"
);
...
...
@@ -72,15 +72,15 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
"
uniform sampler2D currentLum;
"
,
"
uniform float delta;
"
,
"
uniform float tau;
"
,
"
void main() {
"
,
"
vec4 lastLum = texture2D( lastLum, vUv, MIP_LEVEL_1X1 );
"
,
"
vec4 currentLum = texture2D( currentLum, vUv, MIP_LEVEL_1X1 );
"
,
"
float fLastLum = lastLum.r;
"
,
"
float fCurrentLum = currentLum.r;
"
,
//The adaption seems to work better in extreme lighting differences
//if the input luminance is squared.
"
fCurrentLum *= fCurrentLum;
"
,
...
...
@@ -120,7 +120,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
this
.
camera
=
new
THREE
.
OrthographicCamera
(
-
1
,
1
,
1
,
-
1
,
0
,
1
);
this
.
scene
=
new
THREE
.
Scene
();
this
.
quad
=
new
THREE
.
Mesh
(
new
THREE
.
PlaneGeometry
(
2
,
2
),
null
);
this
.
quad
=
new
THREE
.
Mesh
(
new
THREE
.
Plane
Buffer
Geometry
(
2
,
2
),
null
);
this
.
scene
.
add
(
this
.
quad
);
};
...
...
@@ -160,7 +160,7 @@ THREE.AdaptiveToneMappingPass.prototype = {
this
.
quad
.
material
=
this
.
materialToneMap
;
this
.
materialToneMap
.
uniforms
.
tDiffuse
.
value
=
readBuffer
;
renderer
.
render
(
this
.
scene
,
this
.
camera
,
writeBuffer
,
this
.
clear
);
},
reset
:
function
(
renderer
)
{
...
...
@@ -184,7 +184,7 @@ THREE.AdaptiveToneMappingPass.prototype = {
//We only need mipmapping for the current luminosity because we want a down-sampled version to sample in our adaptive shader
pars
.
minFilter
=
THREE
.
LinearMipMapLinearFilter
;
this
.
currentLuminanceRT
=
new
THREE
.
WebGLRenderTarget
(
this
.
resolution
,
this
.
resolution
,
pars
);
if
(
this
.
adaptive
)
{
this
.
materialToneMap
.
defines
[
"
ADAPTED_LUMINANCE
"
]
=
""
;
this
.
materialToneMap
.
uniforms
.
luminanceMap
.
value
=
this
.
luminanceRT
;
...
...
@@ -261,4 +261,4 @@ THREE.AdaptiveToneMappingPass.prototype = {
}
}
};
\ No newline at end of file
};
examples/misc_fps.html
浏览文件 @
1aabcb37
...
...
@@ -163,7 +163,7 @@
var
actualHeight
=
hits
[
0
].
distance
-
birdsEye
;
// collision: stick to the surface if landing on it
if
(
(
motion
.
velocity
.
y
<=
0
)
&&
(
Math
.
abs
(
actualHeight
)
<
kneeDeep
)
)
{
motion
.
position
.
y
-=
actualHeight
;
motion
.
velocity
.
y
=
0
;
...
...
@@ -185,9 +185,9 @@
// limit the tilt at ±0.4 radians
motion
.
rotation
.
x
=
Math
.
max
(
-
0.4
,
Math
.
min
(
+
0.4
,
motion
.
rotation
.
x
)
);
// wrap horizontal rotation to 0...2π
motion
.
rotation
.
y
+=
tau
;
motion
.
rotation
.
y
%=
tau
;
timeLeft
-=
dt
;
...
...
@@ -233,6 +233,7 @@
var
placeholder
=
new
THREE
.
Object3D
();
var
texture
=
THREE
.
ImageUtils
.
loadTexture
(
textureUrl
);
texture
.
minFilter
=
THREE
.
LinearFilter
;
texture
.
anisotropy
=
textureQuality
;
var
loader
=
new
THREE
.
JSONLoader
();
...
...
@@ -256,7 +257,7 @@
var
camera
=
new
THREE
.
PerspectiveCamera
(
60
,
1
,
0.1
,
9000
);
var
scene
=
new
THREE
.
Scene
();
scene
.
add
(
camera
);
scene
.
add
(
makeSkybox
(
[
...
...
@@ -294,7 +295,7 @@
// call our game loop with the time elapsed since last rendering, in ms
gameLoop
(
timeElapsed
);
renderer
.
render
(
scene
,
camera
);
requestAnimationFrame
(
render
);
};
...
...
examples/webgl_interactive_cubes_gpu.html
浏览文件 @
1aabcb37
...
...
@@ -75,6 +75,7 @@
pickingScene
=
new
THREE
.
Scene
();
pickingTexture
=
new
THREE
.
WebGLRenderTarget
(
window
.
innerWidth
,
window
.
innerHeight
);
pickingTexture
.
minFilter
=
THREE
.
LinearFilter
;
pickingTexture
.
generateMipmaps
=
false
;
scene
.
add
(
new
THREE
.
AmbientLight
(
0x555555
)
);
...
...
examples/webgl_shaders_sky.html
浏览文件 @
1aabcb37
...
...
@@ -20,8 +20,8 @@
}
#info
{
color
:
#
333
;
text-shadow
:
1px
1px
#fff
;
color
:
#
ccc
;
text-shadow
:
1px
1px
rgba
(
0
,
0
,
0
,
0.25
)
;
position
:
absolute
;
top
:
0px
;
width
:
100%
;
padding
:
5px
;
...
...
@@ -29,7 +29,7 @@
}
a
{
color
:
#
333
;
color
:
#
fff
;
}
</style>
...
...
@@ -90,7 +90,7 @@
mieDirectionalG
:
0.8
,
luminance
:
1
,
inclination
:
0.49
,
// elevation / inclination
azimuth
:
0.25
,
// Facing front,
azimuth
:
0.25
,
// Facing front,
sun
:
!
true
}
...
...
@@ -108,8 +108,8 @@
var
phi
=
2
*
Math
.
PI
*
(
effectController
.
azimuth
-
0.5
);
sunSphere
.
position
.
x
=
distance
*
Math
.
cos
(
phi
);
sunSphere
.
position
.
y
=
distance
*
Math
.
sin
(
phi
)
*
Math
.
sin
(
theta
);
sunSphere
.
position
.
z
=
distance
*
Math
.
sin
(
phi
)
*
Math
.
cos
(
theta
);
sunSphere
.
position
.
y
=
distance
*
Math
.
sin
(
phi
)
*
Math
.
sin
(
theta
);
sunSphere
.
position
.
z
=
distance
*
Math
.
sin
(
phi
)
*
Math
.
cos
(
theta
);
sunSphere
.
visible
=
effectController
.
sun
;
...
...
@@ -129,14 +129,14 @@
gui
.
add
(
effectController
,
"
inclination
"
,
0
,
1
,
0.0001
).
onChange
(
guiChanged
);
gui
.
add
(
effectController
,
"
azimuth
"
,
0
,
1
,
0.0001
).
onChange
(
guiChanged
);
gui
.
add
(
effectController
,
"
sun
"
).
onChange
(
guiChanged
);
guiChanged
();
camera
.
lookAt
(
sunSphere
.
position
)
}
...
...
@@ -150,21 +150,10 @@
scene
=
new
THREE
.
Scene
();
var
size
=
500
;
var
geometryLines
=
new
THREE
.
BoxGeometry
(
size
,
size
,
size
);
var
geometryPlane
=
new
THREE
.
PlaneGeometry
(
size
*
10
,
size
*
10
,
1
,
1
);
geometryPlane
.
applyMatrix
(
new
THREE
.
Matrix4
().
makeRotationX
(
-
Math
.
PI
/
2
)
);
var
materialLines
=
new
THREE
.
MeshBasicMaterial
(
{
wireframe
:
true
}
);
meshLines
=
new
THREE
.
Mesh
(
geometryLines
,
materialLines
);
// scene.add( meshLines );
scene
.
add
(
new
THREE
.
Mesh
(
geometryPlane
,
materialLines
)
);
var
helper
=
new
THREE
.
GridHelper
(
5000
,
5000
);
helper
.
color1
.
setHex
(
0xffffff
);
helper
.
color2
.
setHex
(
0xffffff
);
scene
.
add
(
helper
);
initSky
();
...
...
@@ -206,7 +195,7 @@
time
=
Date
.
now
();
requestAnimationFrame
(
animate
);
controls
.
update
();
render
();
...
...
examples/webgl_terrain_dynamic.html
浏览文件 @
1aabcb37
...
...
@@ -606,7 +606,7 @@
var
sceneTmp
=
new
THREE
.
Scene
();
var
meshTmp
=
new
THREE
.
Mesh
(
new
THREE
.
PlaneGeometry
(
SCREEN_WIDTH
,
SCREEN_HEIGHT
),
shaderMaterial
);
var
meshTmp
=
new
THREE
.
Mesh
(
new
THREE
.
Plane
Buffer
Geometry
(
SCREEN_WIDTH
,
SCREEN_HEIGHT
),
shaderMaterial
);
meshTmp
.
position
.
z
=
-
500
;
sceneTmp
.
add
(
meshTmp
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录