Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
fktz008
three.js
提交
71fafdf2
T
three.js
项目概览
fktz008
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
71fafdf2
编写于
1月 01, 2012
作者:
A
alteredq
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Some cleanup and normalization fixes in shaders.
上级
2e22acbf
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
19 addition
and
29 deletion
+19
-29
build/Three.js
build/Three.js
+4
-4
build/custom/ThreeExtras.js
build/custom/ThreeExtras.js
+1
-1
build/custom/ThreeWebGL.js
build/custom/ThreeWebGL.js
+3
-3
examples/js/ShaderTerrain.js
examples/js/ShaderTerrain.js
+1
-3
src/extras/ShaderUtils.js
src/extras/ShaderUtils.js
+2
-4
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+2
-2
src/renderers/WebGLShaders.js
src/renderers/WebGLShaders.js
+6
-12
未找到文件。
build/Three.js
浏览文件 @
71fafdf2
此差异已折叠。
点击以展开。
build/custom/ThreeExtras.js
浏览文件 @
71fafdf2
...
...
@@ -25,7 +25,7 @@ if(THREE.WebGLRenderer)THREE.ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRat
vertexShader
:
"
uniform float mRefractionRatio;
\n
uniform float mFresnelBias;
\n
uniform float mFresnelScale;
\n
uniform float mFresnelPower;
\n
varying vec3 vReflect;
\n
varying vec3 vRefract[3];
\n
varying float vReflectionFactor;
\n
void main() {
\n
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
\n
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
\n
vec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );
\n
vec3 I = mPosition.xyz - cameraPosition;
\n
vReflect = reflect( I, nWorld );
\n
vRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );
\n
vRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );
\n
vRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );
\n
vReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );
\n
gl_Position = projectionMatrix * mvPosition;
\n
}
"
},
normal
:{
uniforms
:
THREE
.
UniformsUtils
.
merge
([
THREE
.
UniformsLib
.
fog
,
THREE
.
UniformsLib
.
lights
,
THREE
.
UniformsLib
.
shadowmap
,{
enableAO
:{
type
:
"
i
"
,
value
:
0
},
enableDiffuse
:{
type
:
"
i
"
,
value
:
0
},
enableSpecular
:{
type
:
"
i
"
,
value
:
0
},
enableReflection
:{
type
:
"
i
"
,
value
:
0
},
tDiffuse
:{
type
:
"
t
"
,
value
:
0
,
texture
:
null
},
tCube
:{
type
:
"
t
"
,
value
:
1
,
texture
:
null
},
tNormal
:{
type
:
"
t
"
,
value
:
2
,
texture
:
null
},
tSpecular
:{
type
:
"
t
"
,
value
:
3
,
texture
:
null
},
tAO
:{
type
:
"
t
"
,
value
:
4
,
texture
:
null
},
tDisplacement
:{
type
:
"
t
"
,
value
:
5
,
texture
:
null
},
uNormalScale
:{
type
:
"
f
"
,
value
:
1
},
uDisplacementBias
:{
type
:
"
f
"
,
value
:
0
},
uDisplacementScale
:{
type
:
"
f
"
,
value
:
1
},
uDiffuseColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
15658734
)},
uSpecularColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
1118481
)},
uAmbientColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
328965
)},
uShininess
:{
type
:
"
f
"
,
value
:
30
},
uOpacity
:{
type
:
"
f
"
,
value
:
1
},
uReflectivity
:{
type
:
"
f
"
,
value
:
0.5
},
uOffset
:{
type
:
"
v2
"
,
value
:
new
THREE
.
Vector2
(
0
,
0
)},
uRepeat
:{
type
:
"
v2
"
,
value
:
new
THREE
.
Vector2
(
1
,
1
)},
wrapRGB
:{
type
:
"
v3
"
,
value
:
new
THREE
.
Vector3
(
1
,
1
,
1
)}}]),
fragmentShader
:[
"
uniform vec3 uAmbientColor;
\n
uniform vec3 uDiffuseColor;
\n
uniform vec3 uSpecularColor;
\n
uniform float uShininess;
\n
uniform float uOpacity;
\n
uniform bool enableDiffuse;
\n
uniform bool enableSpecular;
\n
uniform bool enableAO;
\n
uniform bool enableReflection;
\n
uniform sampler2D tDiffuse;
\n
uniform sampler2D tNormal;
\n
uniform sampler2D tSpecular;
\n
uniform sampler2D tAO;
\n
uniform samplerCube tCube;
\n
uniform float uNormalScale;
\n
uniform float uReflectivity;
\n
varying vec3 vTangent;
\n
varying vec3 vBinormal;
\n
varying vec3 vNormal;
\n
varying vec2 vUv;
\n
uniform vec3 ambientLightColor;
\n
#if MAX_DIR_LIGHTS > 0
\n
uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];
\n
uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];
\n
varying vec4 vPointLight[ MAX_POINT_LIGHTS ];
\n
#endif
\n
#ifdef WRAP_AROUND
\n
uniform vec3 wrapRGB;
\n
#endif
\n
varying vec3 vViewPosition;
"
,
THREE
.
ShaderChunk
.
shadowmap_pars_fragment
,
THREE
.
ShaderChunk
.
fog_pars_fragment
,
"
void main() {
\n
gl_FragColor = vec4( vec3( 1.0 ), uOpacity );
\n
vec3 specularTex = vec3( 1.0 );
\n
vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;
\n
normalTex.xy *= uNormalScale;
\n
normalTex = normalize( normalTex );
\n
if( enableDiffuse ) {
\n
#ifdef GAMMA_INPUT
\n
vec4 texelColor = texture2D( tDiffuse, vUv );
\n
texelColor.xyz *= texelColor.xyz;
\n
gl_FragColor = gl_FragColor * texelColor;
\n
#else
\n
gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );
\n
#endif
\n
}
\n
if( enableAO ) {
\n
#ifdef GAMMA_INPUT
\n
vec4 aoColor = texture2D( tAO, vUv );
\n
aoColor.xyz *= aoColor.xyz;
\n
gl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;
\n
#else
\n
gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;
\n
#endif
\n
}
\n
if( enableSpecular )
\n
specularTex = texture2D( tSpecular, vUv ).xyz;
\n
mat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );
\n
vec3 finalNormal = tsb * normalTex;
\n
vec3 normal = normalize( finalNormal );
\n
vec3 viewPosition = normalize( vViewPosition );
\n
#if MAX_POINT_LIGHTS > 0
\n
vec3 pointDiffuse = vec3( 0.0 );
\n
vec3 pointSpecular = vec3( 0.0 );
\n
for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
\n
vec3 pointVector = normalize( vPointLight[ i ].xyz );
\n
float pointDistance = vPointLight[ i ].w;
\n
#ifdef WRAP_AROUND
\n
float pointDiffuseWeightFull = max( dot( normal, pointVector ), 0.0 );
\n
float pointDiffuseWeightHalf = max( 0.5 * dot( normal, pointVector ) + 0.5, 0.0 );
\n
vec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );
\n
#else
\n
float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );
\n
#endif
\n
pointDiffuse += pointDistance * pointLightColor[ i ] * uDiffuseColor * pointDiffuseWeight;
\n
vec3 pointHalfVector = normalize(
vPointLight[ i ].xyz + viewPosition );
\n
float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );
\n
float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, uShininess ), 0.0 );
\n
pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;
\n
}
\n
#endif
\n
#if MAX_DIR_LIGHTS > 0
\n
vec3 dirDiffuse = vec3( 0.0 );
\n
vec3 dirSpecular = vec3( 0.0 );
\n
for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {
\n
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
\n
vec3 dirVector = normalize( lDirection.xyz );
\n
#ifdef WRAP_AROUND
\n
float directionalLightWeightingFull = max( dot( normal, dirVector ), 0.0 );
\n
float directionalLightWeightingHalf = max( 0.5 * dot( normal, dirVector ) + 0.5, 0.0 );
\n
vec3 dirDiffuseWeight = mix( vec3( directionalLightWeightingFull ), vec3( directionalLightWeightingHalf ), wrapRGB );
\n
#else
\n
float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );
\n
#endif
\n
dirDiffuse += directionalLightColor[ i ] * uDiffuseColor * dirDiffuseWeight;
\n
vec3 dirHalfVector = normalize( lDirection.xyz
+ viewPosition );
\n
float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );
\n
float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, uShininess ), 0.0 );
\n
dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;
\n
}
\n
#endif
\n
vec3 totalDiffuse = vec3( 0.0 );
\n
vec3 totalSpecular = vec3( 0.0 );
\n
#if MAX_DIR_LIGHTS > 0
\n
totalDiffuse += dirDiffuse;
\n
totalSpecular += dirSpecular;
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
totalDiffuse += pointDiffuse;
\n
totalSpecular += pointSpecular;
\n
#endif
\n
gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor) + totalSpecular;
\n
if ( enableReflection ) {
\n
vec3 wPos = cameraPosition - vViewPosition;
\n
vec3 vReflect = reflect( normalize( wPos ), normal );
\n
vec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );
\n
#ifdef GAMMA_INPUT
\n
cubeColor.xyz *= cubeColor.xyz;
\n
#endif
\n
gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * uReflectivity );
\n
}
"
,
THREE
.
ShaderChunk
.
shadowmap_pars_fragment
,
THREE
.
ShaderChunk
.
fog_pars_fragment
,
"
void main() {
\n
gl_FragColor = vec4( vec3( 1.0 ), uOpacity );
\n
vec3 specularTex = vec3( 1.0 );
\n
vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;
\n
normalTex.xy *= uNormalScale;
\n
normalTex = normalize( normalTex );
\n
if( enableDiffuse ) {
\n
#ifdef GAMMA_INPUT
\n
vec4 texelColor = texture2D( tDiffuse, vUv );
\n
texelColor.xyz *= texelColor.xyz;
\n
gl_FragColor = gl_FragColor * texelColor;
\n
#else
\n
gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );
\n
#endif
\n
}
\n
if( enableAO ) {
\n
#ifdef GAMMA_INPUT
\n
vec4 aoColor = texture2D( tAO, vUv );
\n
aoColor.xyz *= aoColor.xyz;
\n
gl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;
\n
#else
\n
gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;
\n
#endif
\n
}
\n
if( enableSpecular )
\n
specularTex = texture2D( tSpecular, vUv ).xyz;
\n
mat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );
\n
vec3 finalNormal = tsb * normalTex;
\n
vec3 normal = normalize( finalNormal );
\n
vec3 viewPosition = normalize( vViewPosition );
\n
#if MAX_POINT_LIGHTS > 0
\n
vec3 pointDiffuse = vec3( 0.0 );
\n
vec3 pointSpecular = vec3( 0.0 );
\n
for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
\n
vec3 pointVector = normalize( vPointLight[ i ].xyz );
\n
float pointDistance = vPointLight[ i ].w;
\n
#ifdef WRAP_AROUND
\n
float pointDiffuseWeightFull = max( dot( normal, pointVector ), 0.0 );
\n
float pointDiffuseWeightHalf = max( 0.5 * dot( normal, pointVector ) + 0.5, 0.0 );
\n
vec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );
\n
#else
\n
float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );
\n
#endif
\n
pointDiffuse += pointDistance * pointLightColor[ i ] * uDiffuseColor * pointDiffuseWeight;
\n
vec3 pointHalfVector = normalize(
pointVector + viewPosition );
\n
float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );
\n
float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, uShininess ), 0.0 );
\n
pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;
\n
}
\n
#endif
\n
#if MAX_DIR_LIGHTS > 0
\n
vec3 dirDiffuse = vec3( 0.0 );
\n
vec3 dirSpecular = vec3( 0.0 );
\n
for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {
\n
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
\n
vec3 dirVector = normalize( lDirection.xyz );
\n
#ifdef WRAP_AROUND
\n
float directionalLightWeightingFull = max( dot( normal, dirVector ), 0.0 );
\n
float directionalLightWeightingHalf = max( 0.5 * dot( normal, dirVector ) + 0.5, 0.0 );
\n
vec3 dirDiffuseWeight = mix( vec3( directionalLightWeightingFull ), vec3( directionalLightWeightingHalf ), wrapRGB );
\n
#else
\n
float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );
\n
#endif
\n
dirDiffuse += directionalLightColor[ i ] * uDiffuseColor * dirDiffuseWeight;
\n
vec3 dirHalfVector = normalize( dirVector
+ viewPosition );
\n
float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );
\n
float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, uShininess ), 0.0 );
\n
dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;
\n
}
\n
#endif
\n
vec3 totalDiffuse = vec3( 0.0 );
\n
vec3 totalSpecular = vec3( 0.0 );
\n
#if MAX_DIR_LIGHTS > 0
\n
totalDiffuse += dirDiffuse;
\n
totalSpecular += dirSpecular;
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
totalDiffuse += pointDiffuse;
\n
totalSpecular += pointSpecular;
\n
#endif
\n
gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor) + totalSpecular;
\n
if ( enableReflection ) {
\n
vec3 wPos = cameraPosition - vViewPosition;
\n
vec3 vReflect = reflect( normalize( wPos ), normal );
\n
vec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );
\n
#ifdef GAMMA_INPUT
\n
cubeColor.xyz *= cubeColor.xyz;
\n
#endif
\n
gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * uReflectivity );
\n
}
"
,
THREE
.
ShaderChunk
.
shadowmap_fragment
,
THREE
.
ShaderChunk
.
linear_to_gamma_fragment
,
THREE
.
ShaderChunk
.
fog_fragment
,
"
}
"
].
join
(
"
\n
"
),
vertexShader
:[
"
attribute vec4 tangent;
\n
uniform vec2 uOffset;
\n
uniform vec2 uRepeat;
\n
#ifdef VERTEX_TEXTURES
\n
uniform sampler2D tDisplacement;
\n
uniform float uDisplacementScale;
\n
uniform float uDisplacementBias;
\n
#endif
\n
varying vec3 vTangent;
\n
varying vec3 vBinormal;
\n
varying vec3 vNormal;
\n
varying vec2 vUv;
\n
#if MAX_POINT_LIGHTS > 0
\n
uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];
\n
uniform float pointLightDistance[ MAX_POINT_LIGHTS ];
\n
varying vec4 vPointLight[ MAX_POINT_LIGHTS ];
\n
#endif
\n
varying vec3 vViewPosition;
"
,
THREE
.
ShaderChunk
.
shadowmap_pars_vertex
,
"
void main() {
\n
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
\n
vViewPosition = -mvPosition.xyz;
\n
vNormal = normalMatrix * normal;
\n
vTangent = normalMatrix * tangent.xyz;
\n
vBinormal = cross( vNormal, vTangent ) * tangent.w;
\n
vUv = uv * uRepeat + uOffset;
\n
#if MAX_POINT_LIGHTS > 0
\n
for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {
\n
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
\n
vec3 lVector = lPosition.xyz - mvPosition.xyz;
\n
float lDistance = 1.0;
\n
if ( pointLightDistance[ i ] > 0.0 )
\n
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
\n
lVector = normalize( lVector );
\n
vPointLight[ i ] = vec4( lVector, lDistance );
\n
}
\n
#endif
\n
#ifdef VERTEX_TEXTURES
\n
vec3 dv = texture2D( tDisplacement, uv ).xyz;
\n
float df = uDisplacementScale * dv.x + uDisplacementBias;
\n
vec4 displacedPosition = vec4( normalize( vNormal.xyz ) * df, 0.0 ) + mvPosition;
\n
gl_Position = projectionMatrix * displacedPosition;
\n
#else
\n
gl_Position = projectionMatrix * mvPosition;
\n
#endif
"
,
THREE
.
ShaderChunk
.
shadowmap_vertex
,
"
}
"
].
join
(
"
\n
"
)},
cube
:{
uniforms
:{
tCube
:{
type
:
"
t
"
,
value
:
1
,
texture
:
null
},
tFlip
:{
type
:
"
f
"
,
value
:
-
1
}},
vertexShader
:
"
varying vec3 vViewPosition;
\n
void main() {
\n
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
\n
vViewPosition = cameraPosition - mPosition.xyz;
\n
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
\n
}
"
,
fragmentShader
:
"
uniform samplerCube tCube;
\n
uniform float tFlip;
\n
varying vec3 vViewPosition;
\n
void main() {
\n
vec3 wPos = cameraPosition - vViewPosition;
\n
gl_FragColor = textureCube( tCube, vec3( tFlip * wPos.x, wPos.yz ) );
\n
}
"
}}};
...
...
build/custom/ThreeWebGL.js
浏览文件 @
71fafdf2
...
...
@@ -141,10 +141,10 @@ THREE.ShaderChunk={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#i
envmap_fragment
:
"
#ifdef USE_ENVMAP
\n
vec4 cubeColor = textureCube( envMap, vec3( flipEnvMap * vReflect.x, vReflect.yz ) );
\n
#ifdef GAMMA_INPUT
\n
cubeColor.xyz *= cubeColor.xyz;
\n
#endif
\n
if ( combine == 1 ) {
\n
gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity );
\n
} else {
\n
gl_FragColor.xyz = gl_FragColor.xyz * cubeColor.xyz;
\n
}
\n
#endif
"
,
envmap_pars_vertex
:
"
#ifdef USE_ENVMAP
\n
varying vec3 vReflect;
\n
uniform float refractionRatio;
\n
uniform bool useRefract;
\n
#endif
"
,
envmap_vertex
:
"
#ifdef USE_ENVMAP
\n
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
\n
vec3 nWorld = mat3( objectMatrix[ 0 ].xyz, objectMatrix[ 1 ].xyz, objectMatrix[ 2 ].xyz ) * normal;
\n
if ( useRefract ) {
\n
vReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refractionRatio );
\n
} else {
\n
vReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );
\n
}
\n
#endif
"
,
map_particle_pars_fragment
:
"
#ifdef USE_MAP
\n
uniform sampler2D map;
\n
#endif
"
,
map_particle_fragment
:
"
#ifdef USE_MAP
\n
gl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );
\n
#endif
"
,
map_pars_vertex
:
"
#ifdef USE_MAP
\n
varying vec2 vUv;
\n
uniform vec4 offsetRepeat;
\n
#endif
"
,
map_pars_fragment
:
"
#ifdef USE_MAP
\n
varying vec2 vUv;
\n
uniform sampler2D map;
\n
#endif
"
,
map_vertex
:
"
#ifdef USE_MAP
\n
vUv = uv * offsetRepeat.zw + offsetRepeat.xy;
\n
#endif
"
,
map_fragment
:
"
#ifdef USE_MAP
\n
#ifdef GAMMA_INPUT
\n
vec4 texelColor = texture2D( map, vUv );
\n
texelColor.xyz *= texelColor.xyz;
\n
gl_FragColor = gl_FragColor * texelColor;
\n
#else
\n
gl_FragColor = gl_FragColor * texture2D( map, vUv );
\n
#endif
\n
#endif
"
,
lightmap_pars_fragment
:
"
#ifdef USE_LIGHTMAP
\n
varying vec2 vUv2;
\n
uniform sampler2D lightMap;
\n
#endif
"
,
lightmap_pars_vertex
:
"
#ifdef USE_LIGHTMAP
\n
varying vec2 vUv2;
\n
#endif
"
,
lightmap_fragment
:
"
#ifdef USE_LIGHTMAP
\n
gl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );
\n
#endif
"
,
lightmap_vertex
:
"
#ifdef USE_LIGHTMAP
\n
vUv2 = uv2;
\n
#endif
"
,
lights_lambert_pars_vertex
:
"
uniform vec3 ambient;
\n
uniform vec3 diffuse;
\n
uniform vec3 ambientLightColor;
\n
#if MAX_DIR_LIGHTS > 0
\n
uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];
\n
uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];
\n
uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];
\n
uniform float pointLightDistance[ MAX_POINT_LIGHTS ];
\n
#endif
\n
#ifdef WRAP_AROUND
\n
uniform vec3 wrapRGB;
\n
#endif
"
,
lights_lambert_vertex
:
"
vLightWeighting = vec3( 0.0 );
\n
#if MAX_DIR_LIGHTS > 0
\n
for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
\n
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
\n
#ifdef WRAP_AROUND
\n
float directionalLightWeightingFull = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );
\n
float directionalLightWeightingHalf = max( 0.5 * dot( transformedNormal, normalize( lDirection.xyz ) ) + 0.5, 0.0 );
\n
vec3 directionalLightWeighting = mix( vec3( directionalLightWeightingFull ), vec3( directionalLightWeightingHalf ), wrapRGB );
\n
#else
\n
float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz )
), 0.0 );
\n
#endif
\n
vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;
\n
}
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
\n
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
\n
vec3 lVector = lPosition.xyz - mvPosition.xyz;
\n
float lDistance = 1.0;
\n
if ( pointLightDistance[ i ] > 0.0 )
\n
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
\n
lVector = normalize( lVector );
\n
#ifdef WRAP_AROUND
\n
float pointLightWeightingFull = max( dot( transformedNormal, lVector ), 0.0 );
\n
float pointLightWeightingHalf = max( 0.5 * dot( transformedNormal, lVector ) + 0.5, 0.0 );
\n
vec3 pointLightWeighting = mix( vec3 ( pointLightWeightingFull ), vec3( pointLightWeightingHalf ), wrapRGB );
\n
#else
\n
float pointLightWeighting = max( dot( transformedNormal, lVector ), 0.0 );
\n
#endif
\n
vLightWeighting += pointLightColor[ i ] * pointLightWeighting * lDistance;
\n
}
\n
#endif
\n
vLightWeighting = vLightWeighting * diffuse + ambient * ambientLightColor;
"
,
lights_phong_pars_vertex
:
"
#if MAX_POINT_LIGHTS > 0
\n
#ifndef PHONG_PER_PIXEL
\n
uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];
\n
uniform float pointLightDistance[ MAX_POINT_LIGHTS ];
\n
varying vec4 vPointLight[ MAX_POINT_LIGHTS ];
\n
#endif
\n
#endif
"
,
lights_phong_vertex
:
"
#if MAX_POINT_LIGHTS > 0
\n
#ifndef PHONG_PER_PIXEL
\n
for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
\n
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
\n
vec3 lVector = lPosition.xyz - mvPosition.xyz;
\n
float lDistance = 1.0;
\n
if ( pointLightDistance[ i ] > 0.0 )
\n
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
\n
lVector = normalize( lVector );
\n
vPointLight[ i ] = vec4( lVector, lDistance );
\n
}
\n
#endif
\n
#endif
"
,
lights_lambert_vertex
:
"
vLightWeighting = vec3( 0.0 );
\n
#if MAX_DIR_LIGHTS > 0
\n
for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
\n
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
\n
vec3 dirVector = normalize( lDirection.xyz );
\n
#ifdef WRAP_AROUND
\n
float directionalLightWeightingFull = max( dot( transformedNormal, dirVector ), 0.0 );
\n
float directionalLightWeightingHalf = max( 0.5 * dot( transformedNormal, dirVector ) + 0.5, 0.0 );
\n
vec3 directionalLightWeighting = mix( vec3( directionalLightWeightingFull ), vec3( directionalLightWeightingHalf ), wrapRGB );
\n
#else
\n
float directionalLightWeighting = max( dot( transformedNormal, dirVector
), 0.0 );
\n
#endif
\n
vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;
\n
}
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
\n
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
\n
vec3 lVector = lPosition.xyz - mvPosition.xyz;
\n
float lDistance = 1.0;
\n
if ( pointLightDistance[ i ] > 0.0 )
\n
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
\n
lVector = normalize( lVector );
\n
#ifdef WRAP_AROUND
\n
float pointLightWeightingFull = max( dot( transformedNormal, lVector ), 0.0 );
\n
float pointLightWeightingHalf = max( 0.5 * dot( transformedNormal, lVector ) + 0.5, 0.0 );
\n
vec3 pointLightWeighting = mix( vec3 ( pointLightWeightingFull ), vec3( pointLightWeightingHalf ), wrapRGB );
\n
#else
\n
float pointLightWeighting = max( dot( transformedNormal, lVector ), 0.0 );
\n
#endif
\n
vLightWeighting += pointLightColor[ i ] * pointLightWeighting * lDistance;
\n
}
\n
#endif
\n
vLightWeighting = vLightWeighting * diffuse + ambient * ambientLightColor;
"
,
lights_phong_pars_vertex
:
"
#if MAX_POINT_LIGHTS > 0
\n
#ifndef PHONG_PER_PIXEL
\n
uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];
\n
uniform float pointLightDistance[ MAX_POINT_LIGHTS ];
\n
varying vec4 vPointLight[ MAX_POINT_LIGHTS ];
\n
#endif
\n
#endif
"
,
lights_phong_vertex
:
"
#if MAX_POINT_LIGHTS > 0
\n
#ifndef PHONG_PER_PIXEL
\n
for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
\n
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
\n
vec3 lVector = lPosition.xyz - mvPosition.xyz;
\n
float lDistance = 1.0;
\n
if ( pointLightDistance[ i ] > 0.0 )
\n
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
\n
vPointLight[ i ] = vec4( lVector, lDistance );
\n
}
\n
#endif
\n
#endif
"
,
lights_phong_pars_fragment
:
"
uniform vec3 ambientLightColor;
\n
#if MAX_DIR_LIGHTS > 0
\n
uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];
\n
uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];
\n
#ifdef PHONG_PER_PIXEL
\n
uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];
\n
uniform float pointLightDistance[ MAX_POINT_LIGHTS ];
\n
#else
\n
varying vec4 vPointLight[ MAX_POINT_LIGHTS ];
\n
#endif
\n
#endif
\n
#ifdef WRAP_AROUND
\n
uniform vec3 wrapRGB;
\n
#endif
\n
varying vec3 vViewPosition;
\n
varying vec3 vNormal;
"
,
lights_phong_fragment
:
"
vec3 normal = normalize( vNormal );
\n
vec3 viewPosition = normalize( vViewPosition );
\n
#if MAX_POINT_LIGHTS > 0
\n
vec3 pointDiffuse = vec3( 0.0 );
\n
vec3 pointSpecular = vec3( 0.0 );
\n
for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
\n
#ifdef PHONG_PER_PIXEL
\n
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
\n
vec3 lVector = lPosition.xyz + vViewPosition.xyz;
\n
float lDistance = 1.0;
\n
if ( pointLightDistance[ i ] > 0.0 )
\n
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
\n
lVector = normalize( lVector );
\n
#else
\n
vec3 lVector = normalize( vPointLight[ i ].xyz );
\n
float lDistance = vPointLight[ i ].w;
\n
#endif
\n
#ifdef WRAP_AROUND
\n
float pointDiffuseWeightFull = max( dot( normal, lVector ), 0.0 );
\n
float pointDiffuseWeightHalf = max( 0.5 * dot( normal, lVector ) + 0.5, 0.0 );
\n
vec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );
\n
#else
\n
float pointDiffuseWeight = max( dot( normal, lVector ), 0.0 );
\n
#endif
\n
pointDiffuse += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;
\n
vec3 pointHalfVector = normalize( lVector + viewPosition );
\n
float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );
\n
float pointSpecularWeight = max( pow( pointDotNormalHalf, shininess ), 0.0 );
\n
#ifdef PHYSICALLY_BASED_SHADING
\n
vec3 schlick = specular + vec3( 1.0 - specular ) * pow( dot( lVector, pointHalfVector ), 5.0 );
\n
pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance;
\n
#else
\n
pointSpecular += specular * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance;
\n
#endif
\n
}
\n
#endif
\n
#if MAX_DIR_LIGHTS > 0
\n
vec3 dirDiffuse = vec3( 0.0 );
\n
vec3 dirSpecular = vec3( 0.0 );
\n
for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
\n
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
\n
vec3 dirVector = normalize( lDirection.xyz );
\n
#ifdef WRAP_AROUND
\n
float dirDiffuseWeightFull = max( dot( normal, dirVector ), 0.0 );
\n
float dirDiffuseWeightHalf = max( 0.5 * dot( normal, dirVector ) + 0.5, 0.0 );
\n
vec3 dirDiffuseWeight = mix( vec3( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), wrapRGB );
\n
#else
\n
float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );
\n
#endif
\n
dirDiffuse += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;
\n
vec3 dirHalfVector = normalize(
lDirection.xyz
+ viewPosition );
\n
float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );
\n
float dirSpecularWeight = max( pow( dirDotNormalHalf, shininess ), 0.0 );
\n
#ifdef PHYSICALLY_BASED_SHADING
\n
vec3 schlick = specular + vec3( 1.0 - specular ) * pow( dot( dirVector, dirHalfVector ), 5.0 );
\n
dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight;
\n
#else
\n
dirSpecular += specular * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight;
\n
#endif
\n
}
\n
#endif
\n
vec3 totalDiffuse = vec3( 0.0 );
\n
vec3 totalSpecular = vec3( 0.0 );
\n
#if MAX_DIR_LIGHTS > 0
\n
totalDiffuse += dirDiffuse;
\n
totalSpecular += dirSpecular;
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
totalDiffuse += pointDiffuse;
\n
totalSpecular += pointSpecular;
\n
#endif
\n
#ifdef METAL
\n
gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * ambient + totalSpecular );
\n
#else
\n
gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * ambient ) + totalSpecular;
\n
#endif
"
,
lights_phong_fragment
:
"
vec3 normal = normalize( vNormal );
\n
vec3 viewPosition = normalize( vViewPosition );
\n
#if MAX_POINT_LIGHTS > 0
\n
vec3 pointDiffuse = vec3( 0.0 );
\n
vec3 pointSpecular = vec3( 0.0 );
\n
for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
\n
#ifdef PHONG_PER_PIXEL
\n
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
\n
vec3 lVector = lPosition.xyz + vViewPosition.xyz;
\n
float lDistance = 1.0;
\n
if ( pointLightDistance[ i ] > 0.0 )
\n
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
\n
lVector = normalize( lVector );
\n
#else
\n
vec3 lVector = normalize( vPointLight[ i ].xyz );
\n
float lDistance = vPointLight[ i ].w;
\n
#endif
\n
#ifdef WRAP_AROUND
\n
float pointDiffuseWeightFull = max( dot( normal, lVector ), 0.0 );
\n
float pointDiffuseWeightHalf = max( 0.5 * dot( normal, lVector ) + 0.5, 0.0 );
\n
vec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );
\n
#else
\n
float pointDiffuseWeight = max( dot( normal, lVector ), 0.0 );
\n
#endif
\n
pointDiffuse += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;
\n
vec3 pointHalfVector = normalize( lVector + viewPosition );
\n
float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );
\n
float pointSpecularWeight = max( pow( pointDotNormalHalf, shininess ), 0.0 );
\n
#ifdef PHYSICALLY_BASED_SHADING
\n
vec3 schlick = specular + vec3( 1.0 - specular ) * pow( dot( lVector, pointHalfVector ), 5.0 );
\n
pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance;
\n
#else
\n
pointSpecular += specular * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance;
\n
#endif
\n
}
\n
#endif
\n
#if MAX_DIR_LIGHTS > 0
\n
vec3 dirDiffuse = vec3( 0.0 );
\n
vec3 dirSpecular = vec3( 0.0 );
\n
for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
\n
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
\n
vec3 dirVector = normalize( lDirection.xyz );
\n
#ifdef WRAP_AROUND
\n
float dirDiffuseWeightFull = max( dot( normal, dirVector ), 0.0 );
\n
float dirDiffuseWeightHalf = max( 0.5 * dot( normal, dirVector ) + 0.5, 0.0 );
\n
vec3 dirDiffuseWeight = mix( vec3( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), wrapRGB );
\n
#else
\n
float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );
\n
#endif
\n
dirDiffuse += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;
\n
vec3 dirHalfVector = normalize(
dirVector
+ viewPosition );
\n
float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );
\n
float dirSpecularWeight = max( pow( dirDotNormalHalf, shininess ), 0.0 );
\n
#ifdef PHYSICALLY_BASED_SHADING
\n
vec3 schlick = specular + vec3( 1.0 - specular ) * pow( dot( dirVector, dirHalfVector ), 5.0 );
\n
dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight;
\n
#else
\n
dirSpecular += specular * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight;
\n
#endif
\n
}
\n
#endif
\n
vec3 totalDiffuse = vec3( 0.0 );
\n
vec3 totalSpecular = vec3( 0.0 );
\n
#if MAX_DIR_LIGHTS > 0
\n
totalDiffuse += dirDiffuse;
\n
totalSpecular += dirSpecular;
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
totalDiffuse += pointDiffuse;
\n
totalSpecular += pointSpecular;
\n
#endif
\n
#ifdef METAL
\n
gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * ambient + totalSpecular );
\n
#else
\n
gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * ambient ) + totalSpecular;
\n
#endif
"
,
color_pars_fragment
:
"
#ifdef USE_COLOR
\n
varying vec3 vColor;
\n
#endif
"
,
color_fragment
:
"
#ifdef USE_COLOR
\n
gl_FragColor = gl_FragColor * vec4( vColor, opacity );
\n
#endif
"
,
color_pars_vertex
:
"
#ifdef USE_COLOR
\n
varying vec3 vColor;
\n
#endif
"
,
color_vertex
:
"
#ifdef USE_COLOR
\n
#ifdef GAMMA_INPUT
\n
vColor = color * color;
\n
#else
\n
vColor = color;
\n
#endif
\n
#endif
"
,
skinning_pars_vertex
:
"
#ifdef USE_SKINNING
\n
uniform mat4 boneGlobalMatrices[ MAX_BONES ];
\n
#endif
"
,
skinning_vertex
:
"
#ifdef USE_SKINNING
\n
gl_Position = ( boneGlobalMatrices[ int( skinIndex.x ) ] * skinVertexA ) * skinWeight.x;
\n
gl_Position += ( boneGlobalMatrices[ int( skinIndex.y ) ] * skinVertexB ) * skinWeight.y;
\n
gl_Position = projectionMatrix * viewMatrix * objectMatrix * gl_Position;
\n
#endif
"
,
morphtarget_pars_vertex
:
"
#ifdef USE_MORPHTARGETS
\n
uniform float morphTargetInfluences[ 8 ];
\n
#endif
"
,
morphtarget_vertex
:
"
#ifdef USE_MORPHTARGETS
\n
vec3 morphed = vec3( 0.0, 0.0, 0.0 );
\n
morphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];
\n
morphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];
\n
morphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];
\n
morphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];
\n
morphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];
\n
morphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];
\n
morphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];
\n
morphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];
\n
morphed += position;
\n
gl_Position = projectionMatrix * modelViewMatrix * vec4( morphed, 1.0 );
\n
#endif
"
,
default_vertex
:
"
#ifndef USE_MORPHTARGETS
\n
#ifndef USE_SKINNING
\n
gl_Position = projectionMatrix * mvPosition;
\n
#endif
\n
#endif
"
,
shadowmap_pars_fragment
:
"
#ifdef USE_SHADOWMAP
\n
uniform sampler2D shadowMap[ MAX_SHADOWS ];
\n
uniform float shadowDarkness;
\n
uniform float shadowBias;
\n
varying vec4 vShadowCoord[ MAX_SHADOWS ];
\n
float unpackDepth( const in vec4 rgba_depth ) {
\n
const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );
\n
float depth = dot( rgba_depth, bit_shift );
\n
return depth;
\n
}
\n
#endif
"
,
...
...
examples/js/ShaderTerrain.js
浏览文件 @
71fafdf2
...
...
@@ -157,11 +157,9 @@ THREE.ShaderTerrain = {
"
for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
"
,
"
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
"
,
"
vec3 lVector = lPosition.xyz + vViewPosition.xyz;
"
,
"
float lDistance = 1.0;
"
,
"
if ( pointLightDistance[ i ] > 0.0 )
"
,
"
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
"
,
...
...
@@ -194,7 +192,7 @@ THREE.ShaderTerrain = {
"
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
"
,
"
vec3 dirVector = normalize( lDirection.xyz );
"
,
"
vec3 dirHalfVector = normalize(
lDirection.xyz
+ viewPosition );
"
,
"
vec3 dirHalfVector = normalize(
dirVector
+ viewPosition );
"
,
"
float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );
"
,
"
float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );
"
,
...
...
src/extras/ShaderUtils.js
浏览文件 @
71fafdf2
...
...
@@ -275,7 +275,7 @@ THREE.ShaderUtils = {
// specular
"
vec3 pointHalfVector = normalize(
vPointLight[ i ].xyz
+ viewPosition );
"
,
"
vec3 pointHalfVector = normalize(
pointVector
+ viewPosition );
"
,
"
float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );
"
,
"
float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, uShininess ), 0.0 );
"
,
...
...
@@ -316,7 +316,7 @@ THREE.ShaderUtils = {
// specular
"
vec3 dirHalfVector = normalize(
lDirection.xyz
+ viewPosition );
"
,
"
vec3 dirHalfVector = normalize(
dirVector
+ viewPosition );
"
,
"
float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );
"
,
"
float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, uShininess ), 0.0 );
"
,
...
...
@@ -426,11 +426,9 @@ THREE.ShaderUtils = {
"
for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {
"
,
"
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
"
,
"
vec3 lVector = lPosition.xyz - mvPosition.xyz;
"
,
"
float lDistance = 1.0;
"
,
"
if ( pointLightDistance[ i ] > 0.0 )
"
,
"
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
"
,
...
...
src/renderers/WebGLRenderer.js
浏览文件 @
71fafdf2
...
...
@@ -5239,7 +5239,7 @@ THREE.WebGLRenderer = function ( parameters ) {
var
i
,
l
,
id
;
for
(
i
=
0
,
l
=
identifiers
.
length
;
i
<
l
;
i
++
)
{
for
(
i
=
0
,
l
=
identifiers
.
length
;
i
<
l
;
i
++
)
{
id
=
identifiers
[
i
];
program
.
uniforms
[
id
]
=
_gl
.
getUniformLocation
(
program
,
id
);
...
...
@@ -5252,7 +5252,7 @@ THREE.WebGLRenderer = function ( parameters ) {
var
i
,
l
,
id
;
for
(
i
=
0
,
l
=
identifiers
.
length
;
i
<
l
;
i
++
)
{
for
(
i
=
0
,
l
=
identifiers
.
length
;
i
<
l
;
i
++
)
{
id
=
identifiers
[
i
];
program
.
attributes
[
id
]
=
_gl
.
getAttribLocation
(
program
,
id
);
...
...
src/renderers/WebGLShaders.js
浏览文件 @
71fafdf2
...
...
@@ -292,17 +292,18 @@ THREE.ShaderChunk = {
"
for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {
"
,
"
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
"
,
"
vec3 dirVector = normalize( lDirection.xyz );
"
,
"
#ifdef WRAP_AROUND
"
,
"
float directionalLightWeightingFull = max( dot( transformedNormal,
normalize( lDirection.xyz )
), 0.0 );
"
,
"
float directionalLightWeightingHalf = max( 0.5 * dot( transformedNormal,
normalize( lDirection.xyz )
) + 0.5, 0.0 );
"
,
"
float directionalLightWeightingFull = max( dot( transformedNormal,
dirVector
), 0.0 );
"
,
"
float directionalLightWeightingHalf = max( 0.5 * dot( transformedNormal,
dirVector
) + 0.5, 0.0 );
"
,
"
vec3 directionalLightWeighting = mix( vec3( directionalLightWeightingFull ), vec3( directionalLightWeightingHalf ), wrapRGB );
"
,
"
#else
"
,
"
float directionalLightWeighting = max( dot( transformedNormal,
normalize( lDirection.xyz )
), 0.0 );
"
,
"
float directionalLightWeighting = max( dot( transformedNormal,
dirVector
), 0.0 );
"
,
"
#endif
"
,
...
...
@@ -317,11 +318,9 @@ THREE.ShaderChunk = {
"
for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
"
,
"
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
"
,
"
vec3 lVector = lPosition.xyz - mvPosition.xyz;
"
,
"
float lDistance = 1.0;
"
,
"
if ( pointLightDistance[ i ] > 0.0 )
"
,
"
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
"
,
...
...
@@ -340,7 +339,6 @@ THREE.ShaderChunk = {
"
#endif
"
,
"
vLightWeighting += pointLightColor[ i ] * pointLightWeighting * lDistance;
"
,
"
}
"
,
...
...
@@ -377,16 +375,12 @@ THREE.ShaderChunk = {
"
for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
"
,
"
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
"
,
"
vec3 lVector = lPosition.xyz - mvPosition.xyz;
"
,
"
float lDistance = 1.0;
"
,
"
if ( pointLightDistance[ i ] > 0.0 )
"
,
"
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
"
,
"
lVector = normalize( lVector );
"
,
"
vPointLight[ i ] = vec4( lVector, lDistance );
"
,
"
}
"
,
...
...
@@ -451,8 +445,8 @@ THREE.ShaderChunk = {
"
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
"
,
"
vec3 lVector = lPosition.xyz + vViewPosition.xyz;
"
,
"
float lDistance = 1.0;
"
,
"
float lDistance = 1.0;
"
,
"
if ( pointLightDistance[ i ] > 0.0 )
"
,
"
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
"
,
...
...
@@ -532,7 +526,7 @@ THREE.ShaderChunk = {
// specular
"
vec3 dirHalfVector = normalize(
lDirection.xyz
+ viewPosition );
"
,
"
vec3 dirHalfVector = normalize(
dirVector
+ viewPosition );
"
,
"
float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );
"
,
"
float dirSpecularWeight = max( pow( dirDotNormalHalf, shininess ), 0.0 );
"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录