Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
abc1cb85
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,发现更多精彩内容 >>
未验证
提交
abc1cb85
编写于
5月 07, 2020
作者:
M
Mr.doob
提交者:
GitHub
5月 07, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19304 from taphos/materials-helper
WebGLMaterials helper
上级
31caca74
9c27aceb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
696 addition
and
659 deletion
+696
-659
src/renderers/WebGLRenderer.js
src/renderers/WebGLRenderer.js
+5
-659
src/renderers/webgl/WebGLMaterials.d.ts
src/renderers/webgl/WebGLMaterials.d.ts
+13
-0
src/renderers/webgl/WebGLMaterials.js
src/renderers/webgl/WebGLMaterials.js
+678
-0
未找到文件。
src/renderers/WebGLRenderer.js
浏览文件 @
abc1cb85
...
...
@@ -13,7 +13,6 @@ import {
UnsignedByteType
,
LinearEncoding
,
NoToneMapping
,
BackSide
}
from
'
../constants.js
'
;
import
{
MathUtils
}
from
'
../math/MathUtils.js
'
;
import
{
DataTexture
}
from
'
../textures/DataTexture.js
'
;
...
...
@@ -46,6 +45,7 @@ import { WebGLTextures } from './webgl/WebGLTextures.js';
import
{
WebGLUniforms
}
from
'
./webgl/WebGLUniforms.js
'
;
import
{
WebGLUtils
}
from
'
./webgl/WebGLUtils.js
'
;
import
{
WebXRManager
}
from
'
./webxr/WebXRManager.js
'
;
import
{
WebGLMaterials
}
from
"
./webgl/WebGLMaterials.js
"
;
function
WebGLRenderer
(
parameters
)
{
...
...
@@ -242,7 +242,7 @@ function WebGLRenderer( parameters ) {
var
extensions
,
capabilities
,
state
,
info
;
var
properties
,
textures
,
attributes
,
geometries
,
objects
;
var
programCache
,
renderLists
,
renderStates
;
var
programCache
,
materials
,
renderLists
,
renderStates
;
var
background
,
morphtargets
,
bufferRenderer
,
indexedBufferRenderer
;
...
...
@@ -282,6 +282,7 @@ function WebGLRenderer( parameters ) {
objects
=
new
WebGLObjects
(
_gl
,
geometries
,
attributes
,
info
);
morphtargets
=
new
WebGLMorphtargets
(
_gl
);
programCache
=
new
WebGLPrograms
(
_this
,
extensions
,
capabilities
);
materials
=
new
WebGLMaterials
(
properties
);
renderLists
=
new
WebGLRenderLists
();
renderStates
=
new
WebGLRenderStates
();
...
...
@@ -1860,87 +1861,11 @@ function WebGLRenderer( parameters ) {
if
(
fog
&&
material
.
fog
)
{
refreshUniformsFog
(
m_uniforms
,
fog
);
materials
.
refreshUniformsFog
(
m_uniforms
,
fog
);
}
if
(
material
.
isMeshBasicMaterial
)
{
refreshUniformsCommon
(
m_uniforms
,
material
);
}
else
if
(
material
.
isMeshLambertMaterial
)
{
refreshUniformsCommon
(
m_uniforms
,
material
);
refreshUniformsLambert
(
m_uniforms
,
material
);
}
else
if
(
material
.
isMeshToonMaterial
)
{
refreshUniformsCommon
(
m_uniforms
,
material
);
refreshUniformsToon
(
m_uniforms
,
material
);
}
else
if
(
material
.
isMeshPhongMaterial
)
{
refreshUniformsCommon
(
m_uniforms
,
material
);
refreshUniformsPhong
(
m_uniforms
,
material
);
}
else
if
(
material
.
isMeshStandardMaterial
)
{
refreshUniformsCommon
(
m_uniforms
,
material
,
environment
);
if
(
material
.
isMeshPhysicalMaterial
)
{
refreshUniformsPhysical
(
m_uniforms
,
material
,
environment
);
}
else
{
refreshUniformsStandard
(
m_uniforms
,
material
,
environment
);
}
}
else
if
(
material
.
isMeshMatcapMaterial
)
{
refreshUniformsCommon
(
m_uniforms
,
material
);
refreshUniformsMatcap
(
m_uniforms
,
material
);
}
else
if
(
material
.
isMeshDepthMaterial
)
{
refreshUniformsCommon
(
m_uniforms
,
material
);
refreshUniformsDepth
(
m_uniforms
,
material
);
}
else
if
(
material
.
isMeshDistanceMaterial
)
{
refreshUniformsCommon
(
m_uniforms
,
material
);
refreshUniformsDistance
(
m_uniforms
,
material
);
}
else
if
(
material
.
isMeshNormalMaterial
)
{
refreshUniformsCommon
(
m_uniforms
,
material
);
refreshUniformsNormal
(
m_uniforms
,
material
);
}
else
if
(
material
.
isLineBasicMaterial
)
{
refreshUniformsLine
(
m_uniforms
,
material
);
if
(
material
.
isLineDashedMaterial
)
{
refreshUniformsDash
(
m_uniforms
,
material
);
}
}
else
if
(
material
.
isPointsMaterial
)
{
refreshUniformsPoints
(
m_uniforms
,
material
);
}
else
if
(
material
.
isSpriteMaterial
)
{
refreshUniformsSprites
(
m_uniforms
,
material
);
}
else
if
(
material
.
isShadowMaterial
)
{
m_uniforms
.
color
.
value
.
copy
(
material
.
color
);
m_uniforms
.
opacity
.
value
=
material
.
opacity
;
}
materials
.
refreshUniforms
(
m_uniforms
,
material
,
environment
,
_pixelRatio
,
_height
);
// RectAreaLight Texture
// TODO (mrdoob): Find a nicer implementation
...
...
@@ -1950,12 +1875,6 @@ function WebGLRenderer( parameters ) {
WebGLUniforms
.
upload
(
_gl
,
materialProperties
.
uniformsList
,
m_uniforms
,
textures
);
if
(
material
.
isShaderMaterial
)
{
material
.
uniformsNeedUpdate
=
false
;
// #15581
}
}
if
(
material
.
isShaderMaterial
&&
material
.
uniformsNeedUpdate
===
true
)
{
...
...
@@ -1981,579 +1900,6 @@ function WebGLRenderer( parameters ) {
}
// Uniforms (refresh uniforms objects)
function
refreshUniformsCommon
(
uniforms
,
material
,
environment
)
{
uniforms
.
opacity
.
value
=
material
.
opacity
;
if
(
material
.
color
)
{
uniforms
.
diffuse
.
value
.
copy
(
material
.
color
);
}
if
(
material
.
emissive
)
{
uniforms
.
emissive
.
value
.
copy
(
material
.
emissive
).
multiplyScalar
(
material
.
emissiveIntensity
);
}
if
(
material
.
map
)
{
uniforms
.
map
.
value
=
material
.
map
;
}
if
(
material
.
alphaMap
)
{
uniforms
.
alphaMap
.
value
=
material
.
alphaMap
;
}
if
(
material
.
specularMap
)
{
uniforms
.
specularMap
.
value
=
material
.
specularMap
;
}
var
envMap
=
material
.
envMap
||
environment
;
if
(
envMap
)
{
uniforms
.
envMap
.
value
=
envMap
;
uniforms
.
flipEnvMap
.
value
=
envMap
.
isCubeTexture
?
-
1
:
1
;
uniforms
.
reflectivity
.
value
=
material
.
reflectivity
;
uniforms
.
refractionRatio
.
value
=
material
.
refractionRatio
;
uniforms
.
maxMipLevel
.
value
=
properties
.
get
(
envMap
).
__maxMipLevel
;
}
if
(
material
.
lightMap
)
{
uniforms
.
lightMap
.
value
=
material
.
lightMap
;
uniforms
.
lightMapIntensity
.
value
=
material
.
lightMapIntensity
;
}
if
(
material
.
aoMap
)
{
uniforms
.
aoMap
.
value
=
material
.
aoMap
;
uniforms
.
aoMapIntensity
.
value
=
material
.
aoMapIntensity
;
}
// uv repeat and offset setting priorities
// 1. color map
// 2. specular map
// 3. normal map
// 4. bump map
// 5. alpha map
// 6. emissive map
var
uvScaleMap
;
if
(
material
.
map
)
{
uvScaleMap
=
material
.
map
;
}
else
if
(
material
.
specularMap
)
{
uvScaleMap
=
material
.
specularMap
;
}
else
if
(
material
.
displacementMap
)
{
uvScaleMap
=
material
.
displacementMap
;
}
else
if
(
material
.
normalMap
)
{
uvScaleMap
=
material
.
normalMap
;
}
else
if
(
material
.
bumpMap
)
{
uvScaleMap
=
material
.
bumpMap
;
}
else
if
(
material
.
roughnessMap
)
{
uvScaleMap
=
material
.
roughnessMap
;
}
else
if
(
material
.
metalnessMap
)
{
uvScaleMap
=
material
.
metalnessMap
;
}
else
if
(
material
.
alphaMap
)
{
uvScaleMap
=
material
.
alphaMap
;
}
else
if
(
material
.
emissiveMap
)
{
uvScaleMap
=
material
.
emissiveMap
;
}
if
(
uvScaleMap
!==
undefined
)
{
// backwards compatibility
if
(
uvScaleMap
.
isWebGLRenderTarget
)
{
uvScaleMap
=
uvScaleMap
.
texture
;
}
if
(
uvScaleMap
.
matrixAutoUpdate
===
true
)
{
uvScaleMap
.
updateMatrix
();
}
uniforms
.
uvTransform
.
value
.
copy
(
uvScaleMap
.
matrix
);
}
// uv repeat and offset setting priorities for uv2
// 1. ao map
// 2. light map
var
uv2ScaleMap
;
if
(
material
.
aoMap
)
{
uv2ScaleMap
=
material
.
aoMap
;
}
else
if
(
material
.
lightMap
)
{
uv2ScaleMap
=
material
.
lightMap
;
}
if
(
uv2ScaleMap
!==
undefined
)
{
// backwards compatibility
if
(
uv2ScaleMap
.
isWebGLRenderTarget
)
{
uv2ScaleMap
=
uv2ScaleMap
.
texture
;
}
if
(
uv2ScaleMap
.
matrixAutoUpdate
===
true
)
{
uv2ScaleMap
.
updateMatrix
();
}
uniforms
.
uv2Transform
.
value
.
copy
(
uv2ScaleMap
.
matrix
);
}
}
function
refreshUniformsLine
(
uniforms
,
material
)
{
uniforms
.
diffuse
.
value
.
copy
(
material
.
color
);
uniforms
.
opacity
.
value
=
material
.
opacity
;
}
function
refreshUniformsDash
(
uniforms
,
material
)
{
uniforms
.
dashSize
.
value
=
material
.
dashSize
;
uniforms
.
totalSize
.
value
=
material
.
dashSize
+
material
.
gapSize
;
uniforms
.
scale
.
value
=
material
.
scale
;
}
function
refreshUniformsPoints
(
uniforms
,
material
)
{
uniforms
.
diffuse
.
value
.
copy
(
material
.
color
);
uniforms
.
opacity
.
value
=
material
.
opacity
;
uniforms
.
size
.
value
=
material
.
size
*
_pixelRatio
;
uniforms
.
scale
.
value
=
_height
*
0.5
;
if
(
material
.
map
)
{
uniforms
.
map
.
value
=
material
.
map
;
}
if
(
material
.
alphaMap
)
{
uniforms
.
alphaMap
.
value
=
material
.
alphaMap
;
}
// uv repeat and offset setting priorities
// 1. color map
// 2. alpha map
var
uvScaleMap
;
if
(
material
.
map
)
{
uvScaleMap
=
material
.
map
;
}
else
if
(
material
.
alphaMap
)
{
uvScaleMap
=
material
.
alphaMap
;
}
if
(
uvScaleMap
!==
undefined
)
{
if
(
uvScaleMap
.
matrixAutoUpdate
===
true
)
{
uvScaleMap
.
updateMatrix
();
}
uniforms
.
uvTransform
.
value
.
copy
(
uvScaleMap
.
matrix
);
}
}
function
refreshUniformsSprites
(
uniforms
,
material
)
{
uniforms
.
diffuse
.
value
.
copy
(
material
.
color
);
uniforms
.
opacity
.
value
=
material
.
opacity
;
uniforms
.
rotation
.
value
=
material
.
rotation
;
if
(
material
.
map
)
{
uniforms
.
map
.
value
=
material
.
map
;
}
if
(
material
.
alphaMap
)
{
uniforms
.
alphaMap
.
value
=
material
.
alphaMap
;
}
// uv repeat and offset setting priorities
// 1. color map
// 2. alpha map
var
uvScaleMap
;
if
(
material
.
map
)
{
uvScaleMap
=
material
.
map
;
}
else
if
(
material
.
alphaMap
)
{
uvScaleMap
=
material
.
alphaMap
;
}
if
(
uvScaleMap
!==
undefined
)
{
if
(
uvScaleMap
.
matrixAutoUpdate
===
true
)
{
uvScaleMap
.
updateMatrix
();
}
uniforms
.
uvTransform
.
value
.
copy
(
uvScaleMap
.
matrix
);
}
}
function
refreshUniformsFog
(
uniforms
,
fog
)
{
uniforms
.
fogColor
.
value
.
copy
(
fog
.
color
);
if
(
fog
.
isFog
)
{
uniforms
.
fogNear
.
value
=
fog
.
near
;
uniforms
.
fogFar
.
value
=
fog
.
far
;
}
else
if
(
fog
.
isFogExp2
)
{
uniforms
.
fogDensity
.
value
=
fog
.
density
;
}
}
function
refreshUniformsLambert
(
uniforms
,
material
)
{
if
(
material
.
emissiveMap
)
{
uniforms
.
emissiveMap
.
value
=
material
.
emissiveMap
;
}
}
function
refreshUniformsPhong
(
uniforms
,
material
)
{
uniforms
.
specular
.
value
.
copy
(
material
.
specular
);
uniforms
.
shininess
.
value
=
Math
.
max
(
material
.
shininess
,
1
e
-
4
);
// to prevent pow( 0.0, 0.0 )
if
(
material
.
emissiveMap
)
{
uniforms
.
emissiveMap
.
value
=
material
.
emissiveMap
;
}
if
(
material
.
bumpMap
)
{
uniforms
.
bumpMap
.
value
=
material
.
bumpMap
;
uniforms
.
bumpScale
.
value
=
material
.
bumpScale
;
if
(
material
.
side
===
BackSide
)
uniforms
.
bumpScale
.
value
*=
-
1
;
}
if
(
material
.
normalMap
)
{
uniforms
.
normalMap
.
value
=
material
.
normalMap
;
uniforms
.
normalScale
.
value
.
copy
(
material
.
normalScale
);
if
(
material
.
side
===
BackSide
)
uniforms
.
normalScale
.
value
.
negate
();
}
if
(
material
.
displacementMap
)
{
uniforms
.
displacementMap
.
value
=
material
.
displacementMap
;
uniforms
.
displacementScale
.
value
=
material
.
displacementScale
;
uniforms
.
displacementBias
.
value
=
material
.
displacementBias
;
}
}
function
refreshUniformsToon
(
uniforms
,
material
)
{
uniforms
.
specular
.
value
.
copy
(
material
.
specular
);
uniforms
.
shininess
.
value
=
Math
.
max
(
material
.
shininess
,
1
e
-
4
);
// to prevent pow( 0.0, 0.0 )
if
(
material
.
gradientMap
)
{
uniforms
.
gradientMap
.
value
=
material
.
gradientMap
;
}
if
(
material
.
emissiveMap
)
{
uniforms
.
emissiveMap
.
value
=
material
.
emissiveMap
;
}
if
(
material
.
bumpMap
)
{
uniforms
.
bumpMap
.
value
=
material
.
bumpMap
;
uniforms
.
bumpScale
.
value
=
material
.
bumpScale
;
if
(
material
.
side
===
BackSide
)
uniforms
.
bumpScale
.
value
*=
-
1
;
}
if
(
material
.
normalMap
)
{
uniforms
.
normalMap
.
value
=
material
.
normalMap
;
uniforms
.
normalScale
.
value
.
copy
(
material
.
normalScale
);
if
(
material
.
side
===
BackSide
)
uniforms
.
normalScale
.
value
.
negate
();
}
if
(
material
.
displacementMap
)
{
uniforms
.
displacementMap
.
value
=
material
.
displacementMap
;
uniforms
.
displacementScale
.
value
=
material
.
displacementScale
;
uniforms
.
displacementBias
.
value
=
material
.
displacementBias
;
}
}
function
refreshUniformsStandard
(
uniforms
,
material
,
environment
)
{
uniforms
.
roughness
.
value
=
material
.
roughness
;
uniforms
.
metalness
.
value
=
material
.
metalness
;
if
(
material
.
roughnessMap
)
{
uniforms
.
roughnessMap
.
value
=
material
.
roughnessMap
;
}
if
(
material
.
metalnessMap
)
{
uniforms
.
metalnessMap
.
value
=
material
.
metalnessMap
;
}
if
(
material
.
emissiveMap
)
{
uniforms
.
emissiveMap
.
value
=
material
.
emissiveMap
;
}
if
(
material
.
bumpMap
)
{
uniforms
.
bumpMap
.
value
=
material
.
bumpMap
;
uniforms
.
bumpScale
.
value
=
material
.
bumpScale
;
if
(
material
.
side
===
BackSide
)
uniforms
.
bumpScale
.
value
*=
-
1
;
}
if
(
material
.
normalMap
)
{
uniforms
.
normalMap
.
value
=
material
.
normalMap
;
uniforms
.
normalScale
.
value
.
copy
(
material
.
normalScale
);
if
(
material
.
side
===
BackSide
)
uniforms
.
normalScale
.
value
.
negate
();
}
if
(
material
.
displacementMap
)
{
uniforms
.
displacementMap
.
value
=
material
.
displacementMap
;
uniforms
.
displacementScale
.
value
=
material
.
displacementScale
;
uniforms
.
displacementBias
.
value
=
material
.
displacementBias
;
}
if
(
material
.
envMap
||
environment
)
{
//uniforms.envMap.value = material.envMap; // part of uniforms common
uniforms
.
envMapIntensity
.
value
=
material
.
envMapIntensity
;
}
}
function
refreshUniformsPhysical
(
uniforms
,
material
,
environment
)
{
refreshUniformsStandard
(
uniforms
,
material
,
environment
);
uniforms
.
reflectivity
.
value
=
material
.
reflectivity
;
// also part of uniforms common
uniforms
.
clearcoat
.
value
=
material
.
clearcoat
;
uniforms
.
clearcoatRoughness
.
value
=
material
.
clearcoatRoughness
;
if
(
material
.
sheen
)
uniforms
.
sheen
.
value
.
copy
(
material
.
sheen
);
if
(
material
.
clearcoatMap
)
{
uniforms
.
clearcoatMap
.
value
=
material
.
clearcoatMap
;
}
if
(
material
.
clearcoatRoughnessMap
)
{
uniforms
.
clearcoatRoughnessMap
.
value
=
material
.
clearcoatRoughnessMap
;
}
if
(
material
.
clearcoatNormalMap
)
{
uniforms
.
clearcoatNormalScale
.
value
.
copy
(
material
.
clearcoatNormalScale
);
uniforms
.
clearcoatNormalMap
.
value
=
material
.
clearcoatNormalMap
;
if
(
material
.
side
===
BackSide
)
{
uniforms
.
clearcoatNormalScale
.
value
.
negate
();
}
}
uniforms
.
transparency
.
value
=
material
.
transparency
;
}
function
refreshUniformsMatcap
(
uniforms
,
material
)
{
if
(
material
.
matcap
)
{
uniforms
.
matcap
.
value
=
material
.
matcap
;
}
if
(
material
.
bumpMap
)
{
uniforms
.
bumpMap
.
value
=
material
.
bumpMap
;
uniforms
.
bumpScale
.
value
=
material
.
bumpScale
;
if
(
material
.
side
===
BackSide
)
uniforms
.
bumpScale
.
value
*=
-
1
;
}
if
(
material
.
normalMap
)
{
uniforms
.
normalMap
.
value
=
material
.
normalMap
;
uniforms
.
normalScale
.
value
.
copy
(
material
.
normalScale
);
if
(
material
.
side
===
BackSide
)
uniforms
.
normalScale
.
value
.
negate
();
}
if
(
material
.
displacementMap
)
{
uniforms
.
displacementMap
.
value
=
material
.
displacementMap
;
uniforms
.
displacementScale
.
value
=
material
.
displacementScale
;
uniforms
.
displacementBias
.
value
=
material
.
displacementBias
;
}
}
function
refreshUniformsDepth
(
uniforms
,
material
)
{
if
(
material
.
displacementMap
)
{
uniforms
.
displacementMap
.
value
=
material
.
displacementMap
;
uniforms
.
displacementScale
.
value
=
material
.
displacementScale
;
uniforms
.
displacementBias
.
value
=
material
.
displacementBias
;
}
}
function
refreshUniformsDistance
(
uniforms
,
material
)
{
if
(
material
.
displacementMap
)
{
uniforms
.
displacementMap
.
value
=
material
.
displacementMap
;
uniforms
.
displacementScale
.
value
=
material
.
displacementScale
;
uniforms
.
displacementBias
.
value
=
material
.
displacementBias
;
}
uniforms
.
referencePosition
.
value
.
copy
(
material
.
referencePosition
);
uniforms
.
nearDistance
.
value
=
material
.
nearDistance
;
uniforms
.
farDistance
.
value
=
material
.
farDistance
;
}
function
refreshUniformsNormal
(
uniforms
,
material
)
{
if
(
material
.
bumpMap
)
{
uniforms
.
bumpMap
.
value
=
material
.
bumpMap
;
uniforms
.
bumpScale
.
value
=
material
.
bumpScale
;
if
(
material
.
side
===
BackSide
)
uniforms
.
bumpScale
.
value
*=
-
1
;
}
if
(
material
.
normalMap
)
{
uniforms
.
normalMap
.
value
=
material
.
normalMap
;
uniforms
.
normalScale
.
value
.
copy
(
material
.
normalScale
);
if
(
material
.
side
===
BackSide
)
uniforms
.
normalScale
.
value
.
negate
();
}
if
(
material
.
displacementMap
)
{
uniforms
.
displacementMap
.
value
=
material
.
displacementMap
;
uniforms
.
displacementScale
.
value
=
material
.
displacementScale
;
uniforms
.
displacementBias
.
value
=
material
.
displacementBias
;
}
}
// If uniforms are marked as clean, they don't need to be loaded to the GPU.
function
markUniformsLightsNeedsUpdate
(
uniforms
,
value
)
{
...
...
src/renderers/webgl/WebGLMaterials.d.ts
0 → 100644
浏览文件 @
abc1cb85
import
{
Material
}
from
"
../../materials/Material
"
;
import
{
Texture
}
from
"
../../textures/Texture
"
;
import
{
IFog
}
from
"
../../scenes/Fog
"
;
import
{
WebGLProperties
}
from
"
./WebGLProperties
"
;
export
class
WebGLMaterials
{
constructor
(
properties
:
WebGLProperties
);
refreshUniforms
(
uniforms
:
object
,
material
:
Material
,
environment
:
Texture
,
pixelRatio
:
number
,
height
:
number
);
refreshUniformsFog
(
uniforms
:
object
,
fog
:
IFog
);
}
src/renderers/webgl/WebGLMaterials.js
0 → 100644
浏览文件 @
abc1cb85
import
{
BackSide
}
from
"
../../constants.js
"
;
/**
* @author mrdoob / http://mrdoob.com/
*
* This is a helper which deals with webgl specific logic of builtin materials
* i.e. uniforms refresh before material is being rendered
*/
function
WebGLMaterials
(
properties
)
{
function
refreshUniforms
(
uniforms
,
material
,
environment
,
pixelRatio
,
height
)
{
if
(
material
.
isMeshBasicMaterial
)
{
refreshUniformsCommon
(
uniforms
,
material
);
}
else
if
(
material
.
isMeshLambertMaterial
)
{
refreshUniformsCommon
(
uniforms
,
material
);
refreshUniformsLambert
(
uniforms
,
material
);
}
else
if
(
material
.
isMeshToonMaterial
)
{
refreshUniformsCommon
(
uniforms
,
material
);
refreshUniformsToon
(
uniforms
,
material
);
}
else
if
(
material
.
isMeshPhongMaterial
)
{
refreshUniformsCommon
(
uniforms
,
material
);
refreshUniformsPhong
(
uniforms
,
material
);
}
else
if
(
material
.
isMeshStandardMaterial
)
{
refreshUniformsCommon
(
uniforms
,
material
,
environment
);
if
(
material
.
isMeshPhysicalMaterial
)
{
refreshUniformsPhysical
(
uniforms
,
material
,
environment
);
}
else
{
refreshUniformsStandard
(
uniforms
,
material
,
environment
);
}
}
else
if
(
material
.
isMeshMatcapMaterial
)
{
refreshUniformsCommon
(
uniforms
,
material
);
refreshUniformsMatcap
(
uniforms
,
material
);
}
else
if
(
material
.
isMeshDepthMaterial
)
{
refreshUniformsCommon
(
uniforms
,
material
);
refreshUniformsDepth
(
uniforms
,
material
);
}
else
if
(
material
.
isMeshDistanceMaterial
)
{
refreshUniformsCommon
(
uniforms
,
material
);
refreshUniformsDistance
(
uniforms
,
material
);
}
else
if
(
material
.
isMeshNormalMaterial
)
{
refreshUniformsCommon
(
uniforms
,
material
);
refreshUniformsNormal
(
uniforms
,
material
);
}
else
if
(
material
.
isLineBasicMaterial
)
{
refreshUniformsLine
(
uniforms
,
material
);
if
(
material
.
isLineDashedMaterial
)
{
refreshUniformsDash
(
uniforms
,
material
);
}
}
else
if
(
material
.
isPointsMaterial
)
{
refreshUniformsPoints
(
uniforms
,
material
,
pixelRatio
,
height
);
}
else
if
(
material
.
isSpriteMaterial
)
{
refreshUniformsSprites
(
uniforms
,
material
);
}
else
if
(
material
.
isShadowMaterial
)
{
uniforms
.
color
.
value
.
copy
(
material
.
color
);
uniforms
.
opacity
.
value
=
material
.
opacity
;
}
if
(
material
.
isShaderMaterial
)
{
material
.
uniformsNeedUpdate
=
false
;
// #15581
}
}
function
refreshUniformsCommon
(
uniforms
,
material
,
environment
)
{
uniforms
.
opacity
.
value
=
material
.
opacity
;
if
(
material
.
color
)
{
uniforms
.
diffuse
.
value
.
copy
(
material
.
color
);
}
if
(
material
.
emissive
)
{
uniforms
.
emissive
.
value
.
copy
(
material
.
emissive
).
multiplyScalar
(
material
.
emissiveIntensity
);
}
if
(
material
.
map
)
{
uniforms
.
map
.
value
=
material
.
map
;
}
if
(
material
.
alphaMap
)
{
uniforms
.
alphaMap
.
value
=
material
.
alphaMap
;
}
if
(
material
.
specularMap
)
{
uniforms
.
specularMap
.
value
=
material
.
specularMap
;
}
var
envMap
=
material
.
envMap
||
environment
;
if
(
envMap
)
{
uniforms
.
envMap
.
value
=
envMap
;
uniforms
.
flipEnvMap
.
value
=
envMap
.
isCubeTexture
?
-
1
:
1
;
uniforms
.
reflectivity
.
value
=
material
.
reflectivity
;
uniforms
.
refractionRatio
.
value
=
material
.
refractionRatio
;
uniforms
.
maxMipLevel
.
value
=
properties
.
get
(
envMap
).
__maxMipLevel
;
}
if
(
material
.
lightMap
)
{
uniforms
.
lightMap
.
value
=
material
.
lightMap
;
uniforms
.
lightMapIntensity
.
value
=
material
.
lightMapIntensity
;
}
if
(
material
.
aoMap
)
{
uniforms
.
aoMap
.
value
=
material
.
aoMap
;
uniforms
.
aoMapIntensity
.
value
=
material
.
aoMapIntensity
;
}
// uv repeat and offset setting priorities
// 1. color map
// 2. specular map
// 3. normal map
// 4. bump map
// 5. alpha map
// 6. emissive map
var
uvScaleMap
;
if
(
material
.
map
)
{
uvScaleMap
=
material
.
map
;
}
else
if
(
material
.
specularMap
)
{
uvScaleMap
=
material
.
specularMap
;
}
else
if
(
material
.
displacementMap
)
{
uvScaleMap
=
material
.
displacementMap
;
}
else
if
(
material
.
normalMap
)
{
uvScaleMap
=
material
.
normalMap
;
}
else
if
(
material
.
bumpMap
)
{
uvScaleMap
=
material
.
bumpMap
;
}
else
if
(
material
.
roughnessMap
)
{
uvScaleMap
=
material
.
roughnessMap
;
}
else
if
(
material
.
metalnessMap
)
{
uvScaleMap
=
material
.
metalnessMap
;
}
else
if
(
material
.
alphaMap
)
{
uvScaleMap
=
material
.
alphaMap
;
}
else
if
(
material
.
emissiveMap
)
{
uvScaleMap
=
material
.
emissiveMap
;
}
if
(
uvScaleMap
!==
undefined
)
{
// backwards compatibility
if
(
uvScaleMap
.
isWebGLRenderTarget
)
{
uvScaleMap
=
uvScaleMap
.
texture
;
}
if
(
uvScaleMap
.
matrixAutoUpdate
===
true
)
{
uvScaleMap
.
updateMatrix
();
}
uniforms
.
uvTransform
.
value
.
copy
(
uvScaleMap
.
matrix
);
}
// uv repeat and offset setting priorities for uv2
// 1. ao map
// 2. light map
var
uv2ScaleMap
;
if
(
material
.
aoMap
)
{
uv2ScaleMap
=
material
.
aoMap
;
}
else
if
(
material
.
lightMap
)
{
uv2ScaleMap
=
material
.
lightMap
;
}
if
(
uv2ScaleMap
!==
undefined
)
{
// backwards compatibility
if
(
uv2ScaleMap
.
isWebGLRenderTarget
)
{
uv2ScaleMap
=
uv2ScaleMap
.
texture
;
}
if
(
uv2ScaleMap
.
matrixAutoUpdate
===
true
)
{
uv2ScaleMap
.
updateMatrix
();
}
uniforms
.
uv2Transform
.
value
.
copy
(
uv2ScaleMap
.
matrix
);
}
}
function
refreshUniformsLine
(
uniforms
,
material
)
{
uniforms
.
diffuse
.
value
.
copy
(
material
.
color
);
uniforms
.
opacity
.
value
=
material
.
opacity
;
}
function
refreshUniformsDash
(
uniforms
,
material
)
{
uniforms
.
dashSize
.
value
=
material
.
dashSize
;
uniforms
.
totalSize
.
value
=
material
.
dashSize
+
material
.
gapSize
;
uniforms
.
scale
.
value
=
material
.
scale
;
}
function
refreshUniformsPoints
(
uniforms
,
material
,
pixelRatio
,
height
)
{
uniforms
.
diffuse
.
value
.
copy
(
material
.
color
);
uniforms
.
opacity
.
value
=
material
.
opacity
;
uniforms
.
size
.
value
=
material
.
size
*
pixelRatio
;
uniforms
.
scale
.
value
=
height
*
0.5
;
if
(
material
.
map
)
{
uniforms
.
map
.
value
=
material
.
map
;
}
if
(
material
.
alphaMap
)
{
uniforms
.
alphaMap
.
value
=
material
.
alphaMap
;
}
// uv repeat and offset setting priorities
// 1. color map
// 2. alpha map
var
uvScaleMap
;
if
(
material
.
map
)
{
uvScaleMap
=
material
.
map
;
}
else
if
(
material
.
alphaMap
)
{
uvScaleMap
=
material
.
alphaMap
;
}
if
(
uvScaleMap
!==
undefined
)
{
if
(
uvScaleMap
.
matrixAutoUpdate
===
true
)
{
uvScaleMap
.
updateMatrix
();
}
uniforms
.
uvTransform
.
value
.
copy
(
uvScaleMap
.
matrix
);
}
}
function
refreshUniformsSprites
(
uniforms
,
material
)
{
uniforms
.
diffuse
.
value
.
copy
(
material
.
color
);
uniforms
.
opacity
.
value
=
material
.
opacity
;
uniforms
.
rotation
.
value
=
material
.
rotation
;
if
(
material
.
map
)
{
uniforms
.
map
.
value
=
material
.
map
;
}
if
(
material
.
alphaMap
)
{
uniforms
.
alphaMap
.
value
=
material
.
alphaMap
;
}
// uv repeat and offset setting priorities
// 1. color map
// 2. alpha map
var
uvScaleMap
;
if
(
material
.
map
)
{
uvScaleMap
=
material
.
map
;
}
else
if
(
material
.
alphaMap
)
{
uvScaleMap
=
material
.
alphaMap
;
}
if
(
uvScaleMap
!==
undefined
)
{
if
(
uvScaleMap
.
matrixAutoUpdate
===
true
)
{
uvScaleMap
.
updateMatrix
();
}
uniforms
.
uvTransform
.
value
.
copy
(
uvScaleMap
.
matrix
);
}
}
function
refreshUniformsFog
(
uniforms
,
fog
)
{
uniforms
.
fogColor
.
value
.
copy
(
fog
.
color
);
if
(
fog
.
isFog
)
{
uniforms
.
fogNear
.
value
=
fog
.
near
;
uniforms
.
fogFar
.
value
=
fog
.
far
;
}
else
if
(
fog
.
isFogExp2
)
{
uniforms
.
fogDensity
.
value
=
fog
.
density
;
}
}
function
refreshUniformsLambert
(
uniforms
,
material
)
{
if
(
material
.
emissiveMap
)
{
uniforms
.
emissiveMap
.
value
=
material
.
emissiveMap
;
}
}
function
refreshUniformsPhong
(
uniforms
,
material
)
{
uniforms
.
specular
.
value
.
copy
(
material
.
specular
);
uniforms
.
shininess
.
value
=
Math
.
max
(
material
.
shininess
,
1
e
-
4
);
// to prevent pow( 0.0, 0.0 )
if
(
material
.
emissiveMap
)
{
uniforms
.
emissiveMap
.
value
=
material
.
emissiveMap
;
}
if
(
material
.
bumpMap
)
{
uniforms
.
bumpMap
.
value
=
material
.
bumpMap
;
uniforms
.
bumpScale
.
value
=
material
.
bumpScale
;
if
(
material
.
side
===
BackSide
)
uniforms
.
bumpScale
.
value
*=
-
1
;
}
if
(
material
.
normalMap
)
{
uniforms
.
normalMap
.
value
=
material
.
normalMap
;
uniforms
.
normalScale
.
value
.
copy
(
material
.
normalScale
);
if
(
material
.
side
===
BackSide
)
uniforms
.
normalScale
.
value
.
negate
();
}
if
(
material
.
displacementMap
)
{
uniforms
.
displacementMap
.
value
=
material
.
displacementMap
;
uniforms
.
displacementScale
.
value
=
material
.
displacementScale
;
uniforms
.
displacementBias
.
value
=
material
.
displacementBias
;
}
}
function
refreshUniformsToon
(
uniforms
,
material
)
{
uniforms
.
specular
.
value
.
copy
(
material
.
specular
);
uniforms
.
shininess
.
value
=
Math
.
max
(
material
.
shininess
,
1
e
-
4
);
// to prevent pow( 0.0, 0.0 )
if
(
material
.
gradientMap
)
{
uniforms
.
gradientMap
.
value
=
material
.
gradientMap
;
}
if
(
material
.
emissiveMap
)
{
uniforms
.
emissiveMap
.
value
=
material
.
emissiveMap
;
}
if
(
material
.
bumpMap
)
{
uniforms
.
bumpMap
.
value
=
material
.
bumpMap
;
uniforms
.
bumpScale
.
value
=
material
.
bumpScale
;
if
(
material
.
side
===
BackSide
)
uniforms
.
bumpScale
.
value
*=
-
1
;
}
if
(
material
.
normalMap
)
{
uniforms
.
normalMap
.
value
=
material
.
normalMap
;
uniforms
.
normalScale
.
value
.
copy
(
material
.
normalScale
);
if
(
material
.
side
===
BackSide
)
uniforms
.
normalScale
.
value
.
negate
();
}
if
(
material
.
displacementMap
)
{
uniforms
.
displacementMap
.
value
=
material
.
displacementMap
;
uniforms
.
displacementScale
.
value
=
material
.
displacementScale
;
uniforms
.
displacementBias
.
value
=
material
.
displacementBias
;
}
}
function
refreshUniformsStandard
(
uniforms
,
material
,
environment
)
{
uniforms
.
roughness
.
value
=
material
.
roughness
;
uniforms
.
metalness
.
value
=
material
.
metalness
;
if
(
material
.
roughnessMap
)
{
uniforms
.
roughnessMap
.
value
=
material
.
roughnessMap
;
}
if
(
material
.
metalnessMap
)
{
uniforms
.
metalnessMap
.
value
=
material
.
metalnessMap
;
}
if
(
material
.
emissiveMap
)
{
uniforms
.
emissiveMap
.
value
=
material
.
emissiveMap
;
}
if
(
material
.
bumpMap
)
{
uniforms
.
bumpMap
.
value
=
material
.
bumpMap
;
uniforms
.
bumpScale
.
value
=
material
.
bumpScale
;
if
(
material
.
side
===
BackSide
)
uniforms
.
bumpScale
.
value
*=
-
1
;
}
if
(
material
.
normalMap
)
{
uniforms
.
normalMap
.
value
=
material
.
normalMap
;
uniforms
.
normalScale
.
value
.
copy
(
material
.
normalScale
);
if
(
material
.
side
===
BackSide
)
uniforms
.
normalScale
.
value
.
negate
();
}
if
(
material
.
displacementMap
)
{
uniforms
.
displacementMap
.
value
=
material
.
displacementMap
;
uniforms
.
displacementScale
.
value
=
material
.
displacementScale
;
uniforms
.
displacementBias
.
value
=
material
.
displacementBias
;
}
if
(
material
.
envMap
||
environment
)
{
//uniforms.envMap.value = material.envMap; // part of uniforms common
uniforms
.
envMapIntensity
.
value
=
material
.
envMapIntensity
;
}
}
function
refreshUniformsPhysical
(
uniforms
,
material
,
environment
)
{
refreshUniformsStandard
(
uniforms
,
material
,
environment
);
uniforms
.
reflectivity
.
value
=
material
.
reflectivity
;
// also part of uniforms common
uniforms
.
clearcoat
.
value
=
material
.
clearcoat
;
uniforms
.
clearcoatRoughness
.
value
=
material
.
clearcoatRoughness
;
if
(
material
.
sheen
)
uniforms
.
sheen
.
value
.
copy
(
material
.
sheen
);
if
(
material
.
clearcoatMap
)
{
uniforms
.
clearcoatMap
.
value
=
material
.
clearcoatMap
;
}
if
(
material
.
clearcoatRoughnessMap
)
{
uniforms
.
clearcoatRoughnessMap
.
value
=
material
.
clearcoatRoughnessMap
;
}
if
(
material
.
clearcoatNormalMap
)
{
uniforms
.
clearcoatNormalScale
.
value
.
copy
(
material
.
clearcoatNormalScale
);
uniforms
.
clearcoatNormalMap
.
value
=
material
.
clearcoatNormalMap
;
if
(
material
.
side
===
BackSide
)
{
uniforms
.
clearcoatNormalScale
.
value
.
negate
();
}
}
uniforms
.
transparency
.
value
=
material
.
transparency
;
}
function
refreshUniformsMatcap
(
uniforms
,
material
)
{
if
(
material
.
matcap
)
{
uniforms
.
matcap
.
value
=
material
.
matcap
;
}
if
(
material
.
bumpMap
)
{
uniforms
.
bumpMap
.
value
=
material
.
bumpMap
;
uniforms
.
bumpScale
.
value
=
material
.
bumpScale
;
if
(
material
.
side
===
BackSide
)
uniforms
.
bumpScale
.
value
*=
-
1
;
}
if
(
material
.
normalMap
)
{
uniforms
.
normalMap
.
value
=
material
.
normalMap
;
uniforms
.
normalScale
.
value
.
copy
(
material
.
normalScale
);
if
(
material
.
side
===
BackSide
)
uniforms
.
normalScale
.
value
.
negate
();
}
if
(
material
.
displacementMap
)
{
uniforms
.
displacementMap
.
value
=
material
.
displacementMap
;
uniforms
.
displacementScale
.
value
=
material
.
displacementScale
;
uniforms
.
displacementBias
.
value
=
material
.
displacementBias
;
}
}
function
refreshUniformsDepth
(
uniforms
,
material
)
{
if
(
material
.
displacementMap
)
{
uniforms
.
displacementMap
.
value
=
material
.
displacementMap
;
uniforms
.
displacementScale
.
value
=
material
.
displacementScale
;
uniforms
.
displacementBias
.
value
=
material
.
displacementBias
;
}
}
function
refreshUniformsDistance
(
uniforms
,
material
)
{
if
(
material
.
displacementMap
)
{
uniforms
.
displacementMap
.
value
=
material
.
displacementMap
;
uniforms
.
displacementScale
.
value
=
material
.
displacementScale
;
uniforms
.
displacementBias
.
value
=
material
.
displacementBias
;
}
uniforms
.
referencePosition
.
value
.
copy
(
material
.
referencePosition
);
uniforms
.
nearDistance
.
value
=
material
.
nearDistance
;
uniforms
.
farDistance
.
value
=
material
.
farDistance
;
}
function
refreshUniformsNormal
(
uniforms
,
material
)
{
if
(
material
.
bumpMap
)
{
uniforms
.
bumpMap
.
value
=
material
.
bumpMap
;
uniforms
.
bumpScale
.
value
=
material
.
bumpScale
;
if
(
material
.
side
===
BackSide
)
uniforms
.
bumpScale
.
value
*=
-
1
;
}
if
(
material
.
normalMap
)
{
uniforms
.
normalMap
.
value
=
material
.
normalMap
;
uniforms
.
normalScale
.
value
.
copy
(
material
.
normalScale
);
if
(
material
.
side
===
BackSide
)
uniforms
.
normalScale
.
value
.
negate
();
}
if
(
material
.
displacementMap
)
{
uniforms
.
displacementMap
.
value
=
material
.
displacementMap
;
uniforms
.
displacementScale
.
value
=
material
.
displacementScale
;
uniforms
.
displacementBias
.
value
=
material
.
displacementBias
;
}
}
return
{
refreshUniforms
:
refreshUniforms
,
refreshUniformsFog
:
refreshUniformsFog
};
}
export
{
WebGLMaterials
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录