Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
47e1c58d
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,发现更多精彩内容 >>
提交
47e1c58d
编写于
9月 06, 2015
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7110 from tschw/SkinTangents
Skin shader example update.
上级
02348e1f
01609aec
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
62 addition
and
59 deletion
+62
-59
examples/js/ShaderSkin.js
examples/js/ShaderSkin.js
+47
-54
examples/webgl_materials_skin.html
examples/webgl_materials_skin.html
+15
-5
未找到文件。
examples/js/ShaderSkin.js
浏览文件 @
47e1c58d
...
...
@@ -167,7 +167,7 @@ THREE.ShaderSkin = {
"
diffuseColor = diffuseColor * colDiffuse;
"
,
"
vec3 normal = normalize( vNormal );
"
,
"
vec3 view
Posi
tion = normalize( vViewPosition );
"
,
"
vec3 view
erDirec
tion = normalize( vViewPosition );
"
,
"
float specularStrength;
"
,
...
...
@@ -207,10 +207,10 @@ THREE.ShaderSkin = {
"
float pointDiffuseWeightHalf = max( 0.5 * dot( normal, lVector ) + 0.5, 0.0 );
"
,
"
vec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), uWrapRGB );
"
,
"
float pointSpecularWeight = KS_Skin_Specular( normal, lVector, view
Posi
tion, uRoughness, uSpecularBrightness );
"
,
"
float pointSpecularWeight = KS_Skin_Specular( normal, lVector, view
erDirec
tion, uRoughness, uSpecularBrightness );
"
,
"
totalDiffuseLight +=
attenuation * pointLightColor[ i ] * pointDiffuseWeight
;
"
,
"
totalSpecularLight +=
attenuation * specular * pointLightColor[ i ] * pointSpecularWeight * specularStrength
;
"
,
"
totalDiffuseLight +=
pointLightColor[ i ] * ( pointDiffuseWeight * attenuation )
;
"
,
"
totalSpecularLight +=
pointLightColor[ i ] * specular * ( pointSpecularWeight * specularStrength * attenuation )
;
"
,
"
}
"
,
...
...
@@ -228,10 +228,10 @@ THREE.ShaderSkin = {
"
float dirDiffuseWeightHalf = max( 0.5 * dot( normal, dirVector ) + 0.5, 0.0 );
"
,
"
vec3 dirDiffuseWeight = mix( vec3 ( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), uWrapRGB );
"
,
"
float dirSpecularWeight = KS_Skin_Specular( normal, dirVector, view
Posi
tion, uRoughness, uSpecularBrightness );
"
,
"
float dirSpecularWeight = KS_Skin_Specular( normal, dirVector, view
erDirec
tion, uRoughness, uSpecularBrightness );
"
,
"
totalDiffuseLight += directionalLightColor[ i ] * dirDiffuseWeight;
"
,
"
totalSpecularLight +=
specular * directionalLightColor[ i ] * dirSpecularWeight * specularStrength
;
"
,
"
totalSpecularLight +=
directionalLightColor[ i ] * ( dirSpecularWeight * specularStrength )
;
"
,
"
}
"
,
...
...
@@ -253,14 +253,16 @@ THREE.ShaderSkin = {
// specular (sky light)
"
float hemiSpecularWeight = 0.0;
"
,
"
hemiSpecularWeight += KS_Skin_Specular( normal, lVector, view
Posi
tion, uRoughness, uSpecularBrightness );
"
,
"
hemiSpecularWeight += KS_Skin_Specular( normal, lVector, view
erDirec
tion, uRoughness, uSpecularBrightness );
"
,
// specular (ground light)
"
vec3 lVectorGround = -lVector;
"
,
"
hemiSpecularWeight += KS_Skin_Specular( normal, lVectorGround, view
Posi
tion, uRoughness, uSpecularBrightness );
"
,
"
hemiSpecularWeight += KS_Skin_Specular( normal, lVectorGround, view
erDirec
tion, uRoughness, uSpecularBrightness );
"
,
"
totalSpecularLight += specular * mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight ) * hemiSpecularWeight * specularStrength;
"
,
"
vec3 hemiSpecularColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );
"
,
"
totalSpecularLight += hemiSpecularColor * specular * ( hemiSpecularWeight * specularStrength );
"
,
"
}
"
,
...
...
@@ -355,7 +357,9 @@ THREE.ShaderSkin = {
"
opacity
"
:
{
type
:
"
f
"
,
value
:
1
},
"
uRoughness
"
:
{
type
:
"
f
"
,
value
:
0.15
},
"
uSpecularBrightness
"
:
{
type
:
"
f
"
,
value
:
0.75
}
"
uSpecularBrightness
"
:
{
type
:
"
f
"
,
value
:
0.75
},
"
uPixelSize
"
:
{
type
:
"
f
"
,
value
:
0.01
}
}
...
...
@@ -383,9 +387,8 @@ THREE.ShaderSkin = {
"
uniform sampler2D tBeckmann;
"
,
"
uniform float uNormalScale;
"
,
"
uniform float uPixelSize;
"
,
"
varying vec3 vTangent;
"
,
"
varying vec3 vBinormal;
"
,
"
varying vec3 vNormal;
"
,
"
varying vec2 vUv;
"
,
...
...
@@ -453,20 +456,30 @@ THREE.ShaderSkin = {
"
vec4 mSpecular = vec4( specular, opacity );
"
,
"
vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;
"
,
"
normalTex.xy *= uNormalScale;
"
,
"
normalTex = normalize( normalTex );
"
,
"
vec4 colDiffuse = texture2D( tDiffuse, vUv );
"
,
"
colDiffuse *= colDiffuse;
"
,
"
diffuseColor *= colDiffuse;
"
,
"
mat3 tsb = mat3( vTangent, vBinormal, vNormal );
"
,
// normal mapping
"
vec2 uz = vec2( vUv.x, vViewPosition.z );
"
,
"
vec2 uzDx = dFdx( uz ), uzDy = dFdy( uz );
"
,
"
vec2 tangent2D = normalize( vec2( uzDx.x, uzDy.x ) );
"
,
"
vec2 zVec2D = vec2( uzDx.y, uzDy.y );
"
,
"
vec3 tangent = vec3( tangent2D * uPixelSize, dot( tangent2D, zVec2D ) );
"
,
"
vec3 binormal = normalize( cross( vNormal, tangent ) );
"
,
"
tangent = cross( binormal, vNormal );
"
,
"
mat3 tsb = mat3( tangent, binormal, vNormal );
"
,
"
vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;
"
,
"
normalTex.xy *= uNormalScale;
"
,
"
normalTex = normalize( normalTex );
"
,
"
vec3 finalNormal = tsb * normalTex;
"
,
"
vec3 normal = normalize( finalNormal );
"
,
"
vec3 view
Posi
tion = normalize( vViewPosition );
"
,
"
vec3 view
erDirec
tion = normalize( vViewPosition );
"
,
// point lights
...
...
@@ -478,14 +491,19 @@ THREE.ShaderSkin = {
"
for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
"
,
"
vec3 pointVector = normalize( vPointLight[ i ].xyz );
"
,
"
float
pointDistance
= vPointLight[ i ].w;
"
,
"
float
attenuation
= vPointLight[ i ].w;
"
,
"
float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );
"
,
"
totalDiffuseLight += pointDistance * pointLightColor[ i ] * pointDiffuseWeight;
"
,
"
totalDiffuseLight += pointLightColor[ i ] * ( pointDiffuseWeight * attenuation );
"
,
"
if ( passID == 1 ) {
"
,
"
float pointSpecularWeight = KS_Skin_Specular( normal, pointVector, viewerDirection, uRoughness, uSpecularBrightness );
"
,
"
if ( passID == 1 )
"
,
"
totalSpecularLight += pointDistance * mSpecular.xyz * pointLightColor[ i ] * KS_Skin_Specular( normal, pointVector, viewPosition, uRoughness, uSpecularBrightness );
"
,
"
totalSpecularLight += pointLightColor[ i ] * mSpecular.xyz * ( pointSpecularWeight * attenuation );
"
,
"
}
"
,
"
}
"
,
...
...
@@ -503,8 +521,13 @@ THREE.ShaderSkin = {
"
totalDiffuseLight += directionalLightColor[ i ] * dirDiffuseWeight;
"
,
"
if ( passID == 1 )
"
,
"
totalSpecularLight += mSpecular.xyz * directionalLightColor[ i ] * KS_Skin_Specular( normal, dirVector, viewPosition, uRoughness, uSpecularBrightness );
"
,
"
if ( passID == 1 ) {
"
,
"
float dirSpecularWeight = KS_Skin_Specular( normal, dirVector, viewerDirection, uRoughness, uSpecularBrightness );
"
,
"
totalSpecularLight += directionalLightColor[ i ] * mSpecular.xyz * dirSpecularWeight;
"
,
"
}
"
,
"
}
"
,
...
...
@@ -572,8 +595,6 @@ THREE.ShaderSkin = {
vertexShader
:
[
"
attribute vec4 tangent;
"
,
"
#ifdef VERTEX_TEXTURES
"
,
"
uniform sampler2D tDisplacement;
"
,
...
...
@@ -582,8 +603,6 @@ THREE.ShaderSkin = {
"
#endif
"
,
"
varying vec3 vTangent;
"
,
"
varying vec3 vBinormal;
"
,
"
varying vec3 vNormal;
"
,
"
varying vec2 vUv;
"
,
...
...
@@ -611,13 +630,6 @@ THREE.ShaderSkin = {
"
vNormal = normalize( normalMatrix * normal );
"
,
// tangent and binormal vectors
"
vTangent = normalize( normalMatrix * tangent.xyz );
"
,
"
vBinormal = cross( vNormal, vTangent ) * tangent.w;
"
,
"
vBinormal = normalize( vBinormal );
"
,
"
vUv = uv;
"
,
// point lights
...
...
@@ -659,18 +671,6 @@ THREE.ShaderSkin = {
vertexShaderUV
:
[
"
attribute vec4 tangent;
"
,
"
#ifdef VERTEX_TEXTURES
"
,
"
uniform sampler2D tDisplacement;
"
,
"
uniform float uDisplacementScale;
"
,
"
uniform float uDisplacementBias;
"
,
"
#endif
"
,
"
varying vec3 vTangent;
"
,
"
varying vec3 vBinormal;
"
,
"
varying vec3 vNormal;
"
,
"
varying vec2 vUv;
"
,
...
...
@@ -698,13 +698,6 @@ THREE.ShaderSkin = {
"
vNormal = normalize( normalMatrix * normal );
"
,
// tangent and binormal vectors
"
vTangent = normalize( normalMatrix * tangent.xyz );
"
,
"
vBinormal = cross( vNormal, vTangent ) * tangent.w;
"
,
"
vBinormal = normalize( vBinormal );
"
,
"
vUv = uv;
"
,
// point lights
...
...
examples/webgl_materials_skin.html
浏览文件 @
47e1c58d
...
...
@@ -87,6 +87,8 @@
var
windowHalfX
=
window
.
innerWidth
/
2
;
var
windowHalfY
=
window
.
innerHeight
/
2
;
var
pixelSizeUniform
=
{
type
:
'
f
'
,
value
:
0.001
};
var
firstPass
=
true
;
init
();
...
...
@@ -134,14 +136,18 @@
uniformsUV
[
"
uRoughness
"
].
value
=
0.185
;
uniformsUV
[
"
uSpecularBrightness
"
].
value
=
0.8
;
var
uniforms
=
THREE
.
UniformsUtils
.
clone
(
uniformsUV
);
uniforms
[
"
tDiffuse
"
].
value
=
uniformsUV
[
"
tDiffuse
"
].
value
;
uniforms
[
"
tNormal
"
].
value
=
uniformsUV
[
"
tNormal
"
].
value
;
uniforms
[
"
passID
"
].
value
=
1
;
var
parameters
=
{
fragmentShader
:
shader
.
fragmentShader
,
vertexShader
:
shader
.
vertexShader
,
uniforms
:
uniforms
,
lights
:
true
};
var
parametersUV
=
{
fragmentShader
:
shader
.
fragmentShader
,
vertexShader
:
shader
.
vertexShaderUV
,
uniforms
:
uniformsUV
,
lights
:
true
};
// let those refer to the same object for central control
uniformsUV
[
"
pixelSize
"
]
=
pixelSizeUniform
;
uniforms
[
"
pixelSize
"
]
=
pixelSizeUniform
;
var
parameters
=
{
fragmentShader
:
shader
.
fragmentShader
,
vertexShader
:
shader
.
vertexShader
,
uniforms
:
uniforms
,
lights
:
true
,
derivatives
:
true
};
var
parametersUV
=
{
fragmentShader
:
shader
.
fragmentShader
,
vertexShader
:
shader
.
vertexShaderUV
,
uniforms
:
uniformsUV
,
lights
:
true
,
derivatives
:
true
};
material
=
new
THREE
.
ShaderMaterial
(
parameters
);
var
materialUV
=
new
THREE
.
ShaderMaterial
(
parametersUV
);
...
...
@@ -156,9 +162,10 @@
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
false
}
);
renderer
.
setClearColor
(
0x050505
);
renderer
.
setPixelRatio
(
window
.
devicePixelRatio
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
autoClear
=
false
;
onWindowResize
();
// sets size
container
.
appendChild
(
renderer
.
domElement
);
// STATS
...
...
@@ -267,14 +274,17 @@
camera
.
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
camera
.
updateProjectionMatrix
();
var
projection00
=
camera
.
projectionMatrix
.
elements
[
0
];
// == 1 / windowHalfX, in view space, assuming near == 1
pixelSizeUniform
.
value
=
1
/
(
projection00
*
windowHalfX
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
}
function
createScene
(
geometry
,
scale
,
material
)
{
geometry
.
computeTangents
();
mesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
mesh
.
position
.
y
=
-
50
;
mesh
.
scale
.
set
(
scale
,
scale
,
scale
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录