Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
af9fb1d1
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,发现更多精彩内容 >>
提交
af9fb1d1
编写于
8月 28, 2012
作者:
A
alteredq
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added handling of flipSided also to normal map shader.
See #2352
上级
6ae29843
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
7 addition
and
1 deletion
+7
-1
build/three.min.js
build/three.min.js
+1
-1
src/extras/ShaderUtils.js
src/extras/ShaderUtils.js
+6
-0
未找到文件。
build/three.min.js
浏览文件 @
af9fb1d1
...
@@ -510,7 +510,7 @@ vertexShader:"uniform float mRefractionRatio;\nuniform float mFresnelBias;\nunif
...
@@ -510,7 +510,7 @@ vertexShader:"uniform float mRefractionRatio;\nuniform float mFresnelBias;\nunif
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
},
enableDisplacement
:{
type
:
"
i
"
,
value
:
0
},
tDisplacement
:{
type
:
"
t
"
,
value
:
null
},
tDiffuse
:{
type
:
"
t
"
,
value
:
null
},
tCube
:{
type
:
"
t
"
,
value
:
null
},
tNormal
:{
type
:
"
t
"
,
value
:
null
},
tSpecular
:{
type
:
"
t
"
,
value
:
null
},
tAO
:{
type
:
"
t
"
,
value
:
null
},
uNormalScale
:{
type
:
"
f
"
,
value
:
1
},
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
},
enableDisplacement
:{
type
:
"
i
"
,
value
:
0
},
tDisplacement
:{
type
:
"
t
"
,
value
:
null
},
tDiffuse
:{
type
:
"
t
"
,
value
:
null
},
tCube
:{
type
:
"
t
"
,
value
:
null
},
tNormal
:{
type
:
"
t
"
,
value
:
null
},
tSpecular
:{
type
:
"
t
"
,
value
:
null
},
tAO
:{
type
:
"
t
"
,
value
:
null
},
uNormalScale
:{
type
:
"
f
"
,
value
:
1
},
uDisplacementBias
:{
type
:
"
f
"
,
value
:
0
},
uDisplacementScale
:{
type
:
"
f
"
,
value
:
1
},
uDiffuseColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
16777215
)},
uSpecularColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
1118481
)},
uAmbientColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
16777215
)},
uShininess
:{
type
:
"
f
"
,
value
:
30
},
uOpacity
:{
type
:
"
f
"
,
value
:
1
},
useRefract
:{
type
:
"
i
"
,
value
:
0
},
uRefractionRatio
:{
type
:
"
f
"
,
value
:
0.98
},
uReflectivity
:{
type
:
"
f
"
,
value
:
0.5
},
uOffset
:{
type
:
"
v2
"
,
value
:
new
THREE
.
Vector2
(
0
,
0
)},
uRepeat
:{
type
:
"
v2
"
,
value
:
new
THREE
.
Vector2
(
1
,
uDisplacementBias
:{
type
:
"
f
"
,
value
:
0
},
uDisplacementScale
:{
type
:
"
f
"
,
value
:
1
},
uDiffuseColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
16777215
)},
uSpecularColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
1118481
)},
uAmbientColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
16777215
)},
uShininess
:{
type
:
"
f
"
,
value
:
30
},
uOpacity
:{
type
:
"
f
"
,
value
:
1
},
useRefract
:{
type
:
"
i
"
,
value
:
0
},
uRefractionRatio
:{
type
:
"
f
"
,
value
:
0.98
},
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 bool useRefract;
\n
uniform float uRefractionRatio;
\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_HEMI_LIGHTS > 0
\n
uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];
\n
uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];
\n
uniform vec3 hemisphereLightPosition[ MAX_HEMI_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
#if MAX_SPOT_LIGHTS > 0
\n
uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];
\n
uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];
\n
uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];
\n
uniform float spotLightAngle[ MAX_SPOT_LIGHTS ];
\n
uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];
\n
uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];
\n
#endif
\n
#ifdef WRAP_AROUND
\n
uniform vec3 wrapRGB;
\n
#endif
\n
varying vec3 vWorldPosition;
"
,
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 bool useRefract;
\n
uniform float uRefractionRatio;
\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_HEMI_LIGHTS > 0
\n
uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];
\n
uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];
\n
uniform vec3 hemisphereLightPosition[ MAX_HEMI_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
#if MAX_SPOT_LIGHTS > 0
\n
uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];
\n
uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];
\n
uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];
\n
uniform float spotLightAngle[ MAX_SPOT_LIGHTS ];
\n
uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];
\n
uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];
\n
#endif
\n
#ifdef WRAP_AROUND
\n
uniform vec3 wrapRGB;
\n
#endif
\n
varying vec3 vWorldPosition;
"
,
THREE
.
ShaderChunk
.
shadowmap_pars_fragment
,
THREE
.
ShaderChunk
.
fog_pars_fragment
,
"
void main() {
\n
vec3 vViewPosition = cameraPosition - vWorldPosition;
\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
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
\n
vec3 pointVector = lPosition.xyz + vViewPosition.xyz;
\n
float pointDistance = 1.0;
\n
if ( pointLightDistance[ i ] > 0.0 )
\n
pointDistance = 1.0 - min( ( length( pointVector ) / pointLightDistance[ i ] ), 1.0 );
\n
pointVector = normalize( pointVector );
\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
#ifdef PHYSICALLY_BASED_SHADING
\n
float specularNormalization = ( uShininess + 2.0001 ) / 8.0;
\n
vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( pointVector, pointHalfVector ), 5.0 );
\n
pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * pointDistance * specularNormalization;
\n
#else
\n
pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;
\n
#endif
\n
}
\n
#endif
\n
#if MAX_SPOT_LIGHTS > 0
\n
vec3 spotDiffuse = vec3( 0.0 );
\n
vec3 spotSpecular = vec3( 0.0 );
\n
for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {
\n
vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );
\n
vec3 spotVector = lPosition.xyz + vViewPosition.xyz;
\n
float spotDistance = 1.0;
\n
if ( spotLightDistance[ i ] > 0.0 )
\n
spotDistance = 1.0 - min( ( length( spotVector ) / spotLightDistance[ i ] ), 1.0 );
\n
spotVector = normalize( spotVector );
\n
float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );
\n
if ( spotEffect > spotLightAngle[ i ] ) {
\n
spotEffect = pow( spotEffect, spotLightExponent[ i ] );
\n
#ifdef WRAP_AROUND
\n
float spotDiffuseWeightFull = max( dot( normal, spotVector ), 0.0 );
\n
float spotDiffuseWeightHalf = max( 0.5 * dot( normal, spotVector ) + 0.5, 0.0 );
\n
vec3 spotDiffuseWeight = mix( vec3 ( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );
\n
#else
\n
float spotDiffuseWeight = max( dot( normal, spotVector ), 0.0 );
\n
#endif
\n
spotDiffuse += spotDistance * spotLightColor[ i ] * uDiffuseColor * spotDiffuseWeight * spotEffect;
\n
vec3 spotHalfVector = normalize( spotVector + viewPosition );
\n
float spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );
\n
float spotSpecularWeight = specularTex.r * max( pow( spotDotNormalHalf, uShininess ), 0.0 );
\n
#ifdef PHYSICALLY_BASED_SHADING
\n
float specularNormalization = ( uShininess + 2.0001 ) / 8.0;
\n
vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( spotVector, spotHalfVector ), 5.0 );
\n
spotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * spotDistance * specularNormalization * spotEffect;
\n
#else
\n
spotSpecular += spotDistance * spotLightColor[ i ] * uSpecularColor * spotSpecularWeight * spotDiffuseWeight * spotEffect;
\n
#endif
\n
}
\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
#ifdef PHYSICALLY_BASED_SHADING
\n
float specularNormalization = ( uShininess + 2.0001 ) / 8.0;
\n
vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( dirVector, dirHalfVector ), 5.0 );
\n
dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;
\n
#else
\n
dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;
\n
#endif
\n
}
\n
#endif
\n
#if MAX_HEMI_LIGHTS > 0
\n
vec3 hemiDiffuse = vec3( 0.0 );
\n
vec3 hemiSpecular = vec3( 0.0 );
\n
for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {
\n
vec4 lPosition = viewMatrix * vec4( hemisphereLightPosition[ i ], 1.0 );
\n
vec3 lVector = normalize( lPosition.xyz + vViewPosition.xyz );
\n
float dotProduct = dot( normal, lVector );
\n
float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;
\n
hemiDiffuse += uDiffuseColor * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );
\n
float hemiSpecularWeight = 0.0;
\n
vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );
\n
float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;
\n
hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfSky, uShininess ), 0.0 );
\n
vec3 lVectorGround = normalize( -lPosition.xyz + vViewPosition.xyz );
\n
vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );
\n
float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;
\n
hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfGround, uShininess ), 0.0 );
\n
#ifdef PHYSICALLY_BASED_SHADING
\n
float specularNormalization = ( uShininess + 2.0001 ) / 8.0;
\n
vec3 schlickSky = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( lVector, hemiHalfVectorSky ), 5.0 );
\n
vec3 schlickGround = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 5.0 );
\n
hemiSpecular += ( schlickSky + schlickGround ) * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight ) * hemiSpecularWeight * hemiDiffuseWeight * specularNormalization;
\n
#else
\n
hemiSpecular += uSpecularColor * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight ) * hemiSpecularWeight * hemiDiffuseWeight;
\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_HEMI_LIGHTS > 0
\n
totalDiffuse += hemiDiffuse;
\n
totalSpecular += hemiSpecular;
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
totalDiffuse += pointDiffuse;
\n
totalSpecular += pointSpecular;
\n
#endif
\n
#if MAX_SPOT_LIGHTS > 0
\n
totalDiffuse += spotDiffuse;
\n
totalSpecular += spotSpecular;
\n
#endif
\n
#ifdef METAL
\n
gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor + totalSpecular );
\n
#else
\n
gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor ) + totalSpecular;
\n
#endif
\n
if ( enableReflection ) {
\n
vec3 vReflect;
\n
vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );
\n
if ( useRefract ) {
\n
vReflect = refract( cameraToVertex, normal, uRefractionRatio );
\n
} else {
\n
vReflect = reflect( cameraToVertex, normal );
\n
}
\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
vec3 vViewPosition = cameraPosition - vWorldPosition;
\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
#ifdef FLIP_SIDED
\n
finalNormal = -finalNormal;
\n
#endif
\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
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
\n
vec3 pointVector = lPosition.xyz + vViewPosition.xyz;
\n
float pointDistance = 1.0;
\n
if ( pointLightDistance[ i ] > 0.0 )
\n
pointDistance = 1.0 - min( ( length( pointVector ) / pointLightDistance[ i ] ), 1.0 );
\n
pointVector = normalize( pointVector );
\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
#ifdef PHYSICALLY_BASED_SHADING
\n
float specularNormalization = ( uShininess + 2.0001 ) / 8.0;
\n
vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( pointVector, pointHalfVector ), 5.0 );
\n
pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * pointDistance * specularNormalization;
\n
#else
\n
pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;
\n
#endif
\n
}
\n
#endif
\n
#if MAX_SPOT_LIGHTS > 0
\n
vec3 spotDiffuse = vec3( 0.0 );
\n
vec3 spotSpecular = vec3( 0.0 );
\n
for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {
\n
vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );
\n
vec3 spotVector = lPosition.xyz + vViewPosition.xyz;
\n
float spotDistance = 1.0;
\n
if ( spotLightDistance[ i ] > 0.0 )
\n
spotDistance = 1.0 - min( ( length( spotVector ) / spotLightDistance[ i ] ), 1.0 );
\n
spotVector = normalize( spotVector );
\n
float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );
\n
if ( spotEffect > spotLightAngle[ i ] ) {
\n
spotEffect = pow( spotEffect, spotLightExponent[ i ] );
\n
#ifdef WRAP_AROUND
\n
float spotDiffuseWeightFull = max( dot( normal, spotVector ), 0.0 );
\n
float spotDiffuseWeightHalf = max( 0.5 * dot( normal, spotVector ) + 0.5, 0.0 );
\n
vec3 spotDiffuseWeight = mix( vec3 ( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );
\n
#else
\n
float spotDiffuseWeight = max( dot( normal, spotVector ), 0.0 );
\n
#endif
\n
spotDiffuse += spotDistance * spotLightColor[ i ] * uDiffuseColor * spotDiffuseWeight * spotEffect;
\n
vec3 spotHalfVector = normalize( spotVector + viewPosition );
\n
float spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );
\n
float spotSpecularWeight = specularTex.r * max( pow( spotDotNormalHalf, uShininess ), 0.0 );
\n
#ifdef PHYSICALLY_BASED_SHADING
\n
float specularNormalization = ( uShininess + 2.0001 ) / 8.0;
\n
vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( spotVector, spotHalfVector ), 5.0 );
\n
spotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * spotDistance * specularNormalization * spotEffect;
\n
#else
\n
spotSpecular += spotDistance * spotLightColor[ i ] * uSpecularColor * spotSpecularWeight * spotDiffuseWeight * spotEffect;
\n
#endif
\n
}
\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
#ifdef PHYSICALLY_BASED_SHADING
\n
float specularNormalization = ( uShininess + 2.0001 ) / 8.0;
\n
vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( dirVector, dirHalfVector ), 5.0 );
\n
dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;
\n
#else
\n
dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;
\n
#endif
\n
}
\n
#endif
\n
#if MAX_HEMI_LIGHTS > 0
\n
vec3 hemiDiffuse = vec3( 0.0 );
\n
vec3 hemiSpecular = vec3( 0.0 );
\n
for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {
\n
vec4 lPosition = viewMatrix * vec4( hemisphereLightPosition[ i ], 1.0 );
\n
vec3 lVector = normalize( lPosition.xyz + vViewPosition.xyz );
\n
float dotProduct = dot( normal, lVector );
\n
float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;
\n
hemiDiffuse += uDiffuseColor * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );
\n
float hemiSpecularWeight = 0.0;
\n
vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );
\n
float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;
\n
hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfSky, uShininess ), 0.0 );
\n
vec3 lVectorGround = normalize( -lPosition.xyz + vViewPosition.xyz );
\n
vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );
\n
float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;
\n
hemiSpecularWeight += specularTex.r * max( pow( hemiDotNormalHalfGround, uShininess ), 0.0 );
\n
#ifdef PHYSICALLY_BASED_SHADING
\n
float specularNormalization = ( uShininess + 2.0001 ) / 8.0;
\n
vec3 schlickSky = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( lVector, hemiHalfVectorSky ), 5.0 );
\n
vec3 schlickGround = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 5.0 );
\n
hemiSpecular += ( schlickSky + schlickGround ) * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight ) * hemiSpecularWeight * hemiDiffuseWeight * specularNormalization;
\n
#else
\n
hemiSpecular += uSpecularColor * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight ) * hemiSpecularWeight * hemiDiffuseWeight;
\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_HEMI_LIGHTS > 0
\n
totalDiffuse += hemiDiffuse;
\n
totalSpecular += hemiSpecular;
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
totalDiffuse += pointDiffuse;
\n
totalSpecular += pointSpecular;
\n
#endif
\n
#if MAX_SPOT_LIGHTS > 0
\n
totalDiffuse += spotDiffuse;
\n
totalSpecular += spotSpecular;
\n
#endif
\n
#ifdef METAL
\n
gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor + totalSpecular );
\n
#else
\n
gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor ) + totalSpecular;
\n
#endif
\n
if ( enableReflection ) {
\n
vec3 vReflect;
\n
vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );
\n
if ( useRefract ) {
\n
vReflect = refract( cameraToVertex, normal, uRefractionRatio );
\n
} else {
\n
vReflect = reflect( cameraToVertex, normal );
\n
}
\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
uniform bool enableDisplacement;
\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
varying vec3 vWorldPosition;
"
,
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
uniform bool enableDisplacement;
\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
varying vec3 vWorldPosition;
"
,
THREE
.
ShaderChunk
.
skinning_pars_vertex
,
THREE
.
ShaderChunk
.
shadowmap_pars_vertex
,
"
void main() {
"
,
THREE
.
ShaderChunk
.
skinbase_vertex
,
THREE
.
ShaderChunk
.
skinnormal_vertex
,
"
#ifdef USE_SKINNING
\n
vNormal = normalMatrix * skinnedNormal.xyz;
\n
vec4 skinnedTangent = skinMatrix * vec4( tangent.xyz, 0.0 );
\n
vTangent = normalMatrix * skinnedTangent.xyz;
\n
#else
\n
vNormal = normalMatrix * normal;
\n
vTangent = normalMatrix * tangent.xyz;
\n
#endif
\n
vBinormal = cross( vNormal, vTangent ) * tangent.w;
\n
vUv = uv * uRepeat + uOffset;
\n
vec3 displacedPosition;
\n
#ifdef VERTEX_TEXTURES
\n
if ( enableDisplacement ) {
\n
vec3 dv = texture2D( tDisplacement, uv ).xyz;
\n
float df = uDisplacementScale * dv.x + uDisplacementBias;
\n
displacedPosition = position + normalize( normal ) * df;
\n
} else {
\n
#ifdef USE_SKINNING
\n
vec4 skinVertex = vec4( position, 1.0 );
\n
vec4 skinned = boneMatX * skinVertex * skinWeight.x;
\n
skinned
\t
+= boneMatY * skinVertex * skinWeight.y;
\n
displacedPosition = skinned.xyz;
\n
#else
\n
displacedPosition = position;
\n
#endif
\n
}
\n
#else
\n
#ifdef USE_SKINNING
\n
vec4 skinVertex = vec4( position, 1.0 );
\n
vec4 skinned = boneMatX * skinVertex * skinWeight.x;
\n
skinned
\t
+= boneMatY * skinVertex * skinWeight.y;
\n
displacedPosition = skinned.xyz;
\n
#else
\n
displacedPosition = position;
\n
#endif
\n
#endif
\n
vec4 mvPosition = modelViewMatrix * vec4( displacedPosition, 1.0 );
\n
vec4 mPosition = modelMatrix * vec4( displacedPosition, 1.0 );
\n
gl_Position = projectionMatrix * mvPosition;
\n
vWorldPosition = mPosition.xyz;
\n
#ifdef USE_SHADOWMAP
\n
for( int i = 0; i < MAX_SHADOWS; i ++ ) {
\n
vShadowCoord[ i ] = shadowMatrix[ i ] * mPosition;
\n
}
\n
#endif
\n
}
"
].
join
(
"
\n
"
)},
THREE
.
ShaderChunk
.
skinning_pars_vertex
,
THREE
.
ShaderChunk
.
shadowmap_pars_vertex
,
"
void main() {
"
,
THREE
.
ShaderChunk
.
skinbase_vertex
,
THREE
.
ShaderChunk
.
skinnormal_vertex
,
"
#ifdef USE_SKINNING
\n
vNormal = normalMatrix * skinnedNormal.xyz;
\n
vec4 skinnedTangent = skinMatrix * vec4( tangent.xyz, 0.0 );
\n
vTangent = normalMatrix * skinnedTangent.xyz;
\n
#else
\n
vNormal = normalMatrix * normal;
\n
vTangent = normalMatrix * tangent.xyz;
\n
#endif
\n
vBinormal = cross( vNormal, vTangent ) * tangent.w;
\n
vUv = uv * uRepeat + uOffset;
\n
vec3 displacedPosition;
\n
#ifdef VERTEX_TEXTURES
\n
if ( enableDisplacement ) {
\n
vec3 dv = texture2D( tDisplacement, uv ).xyz;
\n
float df = uDisplacementScale * dv.x + uDisplacementBias;
\n
displacedPosition = position + normalize( normal ) * df;
\n
} else {
\n
#ifdef USE_SKINNING
\n
vec4 skinVertex = vec4( position, 1.0 );
\n
vec4 skinned = boneMatX * skinVertex * skinWeight.x;
\n
skinned
\t
+= boneMatY * skinVertex * skinWeight.y;
\n
displacedPosition = skinned.xyz;
\n
#else
\n
displacedPosition = position;
\n
#endif
\n
}
\n
#else
\n
#ifdef USE_SKINNING
\n
vec4 skinVertex = vec4( position, 1.0 );
\n
vec4 skinned = boneMatX * skinVertex * skinWeight.x;
\n
skinned
\t
+= boneMatY * skinVertex * skinWeight.y;
\n
displacedPosition = skinned.xyz;
\n
#else
\n
displacedPosition = position;
\n
#endif
\n
#endif
\n
vec4 mvPosition = modelViewMatrix * vec4( displacedPosition, 1.0 );
\n
vec4 mPosition = modelMatrix * vec4( displacedPosition, 1.0 );
\n
gl_Position = projectionMatrix * mvPosition;
\n
vWorldPosition = mPosition.xyz;
\n
#ifdef USE_SHADOWMAP
\n
for( int i = 0; i < MAX_SHADOWS; i ++ ) {
\n
vShadowCoord[ i ] = shadowMatrix[ i ] * mPosition;
\n
}
\n
#endif
\n
}
"
].
join
(
"
\n
"
)},
cube
:{
uniforms
:{
tCube
:{
type
:
"
t
"
,
value
:
null
},
tFlip
:{
type
:
"
f
"
,
value
:
-
1
}},
vertexShader
:
"
varying vec3 vViewPosition;
\n
void main() {
\n
vec4 mPosition = modelMatrix * 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
}
"
}}});
cube
:{
uniforms
:{
tCube
:{
type
:
"
t
"
,
value
:
null
},
tFlip
:{
type
:
"
f
"
,
value
:
-
1
}},
vertexShader
:
"
varying vec3 vViewPosition;
\n
void main() {
\n
vec4 mPosition = modelMatrix * 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
}
"
}}});
...
...
src/extras/ShaderUtils.js
浏览文件 @
af9fb1d1
...
@@ -275,6 +275,12 @@ THREE.ShaderUtils = {
...
@@ -275,6 +275,12 @@ THREE.ShaderUtils = {
"
mat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );
"
,
"
mat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );
"
,
"
vec3 finalNormal = tsb * normalTex;
"
,
"
vec3 finalNormal = tsb * normalTex;
"
,
"
#ifdef FLIP_SIDED
"
,
"
finalNormal = -finalNormal;
"
,
"
#endif
"
,
"
vec3 normal = normalize( finalNormal );
"
,
"
vec3 normal = normalize( finalNormal );
"
,
"
vec3 viewPosition = normalize( vViewPosition );
"
,
"
vec3 viewPosition = normalize( vViewPosition );
"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录