Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
e5f809a6
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,体验更适合开发者的 AI 搜索 >>
提交
e5f809a6
编写于
6月 08, 2018
作者:
W
WestLangley
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support object-space normal maps
上级
e2b49c01
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
88 addition
and
27 deletion
+88
-27
docs/api/materials/MeshPhongMaterial.html
docs/api/materials/MeshPhongMaterial.html
+7
-0
docs/api/materials/MeshStandardMaterial.html
docs/api/materials/MeshStandardMaterial.html
+7
-0
src/constants.js
src/constants.js
+2
-0
src/materials/Material.js
src/materials/Material.js
+2
-1
src/materials/MeshNormalMaterial.js
src/materials/MeshNormalMaterial.js
+4
-0
src/materials/MeshPhongMaterial.js
src/materials/MeshPhongMaterial.js
+4
-1
src/materials/MeshStandardMaterial.js
src/materials/MeshStandardMaterial.js
+4
-0
src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl
src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl
+23
-1
src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
...enderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
+26
-18
src/renderers/shaders/ShaderLib/normal_frag.glsl
src/renderers/shaders/ShaderLib/normal_frag.glsl
+1
-1
src/renderers/shaders/ShaderLib/normal_vert.glsl
src/renderers/shaders/ShaderLib/normal_vert.glsl
+2
-2
src/renderers/webgl/WebGLProgram.js
src/renderers/webgl/WebGLProgram.js
+3
-1
src/renderers/webgl/WebGLPrograms.js
src/renderers/webgl/WebGLPrograms.js
+3
-2
未找到文件。
docs/api/materials/MeshPhongMaterial.html
浏览文件 @
e5f809a6
...
...
@@ -178,6 +178,13 @@
the way the color is lit. Normal maps do not change the actual shape of the surface, only the lighting.
</p>
<h3>
[property:Integer normalMapType]
</h3>
<p>
The type of normal map.
<br
/><br
/>
Options are [page:constant THREE.TangentSpaceNormalMap] (default), and [page:constant THREE.ObjectSpaceNormalMap].
</p>
<h3>
[property:Vector2 normalScale]
</h3>
<p>
How much the normal map affects the material. Typical ranges are 0-1.
...
...
docs/api/materials/MeshStandardMaterial.html
浏览文件 @
e5f809a6
...
...
@@ -220,6 +220,13 @@
the way the color is lit. Normal maps do not change the actual shape of the surface, only the lighting.
</p>
<h3>
[property:Integer normalMapType]
</h3>
<p>
The type of normal map.
<br
/><br
/>
Options are [page:constant THREE.TangentSpaceNormalMap] (default), and [page:constant THREE.ObjectSpaceNormalMap].
</p>
<h3>
[property:Vector2 normalScale]
</h3>
<p>
How much the normal map affects the material. Typical ranges are 0-1.
...
...
src/constants.js
浏览文件 @
e5f809a6
...
...
@@ -137,3 +137,5 @@ export var RGBM16Encoding = 3005;
export
var
RGBDEncoding
=
3006
;
export
var
BasicDepthPacking
=
3200
;
export
var
RGBADepthPacking
=
3201
;
export
var
TangentSpaceNormalMap
=
0
;
export
var
ObjectSpaceNormalMap
=
1
;
src/materials/Material.js
浏览文件 @
e5f809a6
import
{
EventDispatcher
}
from
'
../core/EventDispatcher.js
'
;
import
{
NoColors
,
FrontSide
,
FlatShading
,
NormalBlending
,
LessEqualDepth
,
AddEquation
,
OneMinusSrcAlphaFactor
,
SrcAlphaFactor
}
from
'
../constants.js
'
;
import
{
NoColors
,
FrontSide
,
FlatShading
,
NormalBlending
,
LessEqualDepth
,
AddEquation
,
OneMinusSrcAlphaFactor
,
SrcAlphaFactor
,
TangentSpaceNormalMap
}
from
'
../constants.js
'
;
import
{
_Math
}
from
'
../math/Math.js
'
;
/**
...
...
@@ -194,6 +194,7 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
if
(
this
.
normalMap
&&
this
.
normalMap
.
isTexture
)
{
data
.
normalMap
=
this
.
normalMap
.
toJSON
(
meta
).
uuid
;
if
(
this
.
normalMapType
!==
TangentSpaceNormalMap
)
data
.
normalMapType
=
this
.
normalMapType
;
data
.
normalScale
=
this
.
normalScale
.
toArray
();
}
...
...
src/materials/MeshNormalMaterial.js
浏览文件 @
e5f809a6
import
{
TangentSpaceNormalMap
}
from
'
../constants.js
'
;
import
{
Material
}
from
'
./Material.js
'
;
import
{
Vector2
}
from
'
../math/Vector2.js
'
;
...
...
@@ -12,6 +13,7 @@ import { Vector2 } from '../math/Vector2.js';
* bumpScale: <float>,
*
* normalMap: new THREE.Texture( <Image> ),
* normalMapType: THREE.TangentSpaceNormalMap,
* normalScale: <Vector2>,
*
* displacementMap: new THREE.Texture( <Image> ),
...
...
@@ -37,6 +39,7 @@ function MeshNormalMaterial( parameters ) {
this
.
bumpScale
=
1
;
this
.
normalMap
=
null
;
this
.
normalMapType
=
TangentSpaceNormalMap
;
this
.
normalScale
=
new
Vector2
(
1
,
1
);
this
.
displacementMap
=
null
;
...
...
@@ -70,6 +73,7 @@ MeshNormalMaterial.prototype.copy = function ( source ) {
this
.
bumpScale
=
source
.
bumpScale
;
this
.
normalMap
=
source
.
normalMap
;
this
.
normalMapType
=
source
.
normalMapType
;
this
.
normalScale
.
copy
(
source
.
normalScale
);
this
.
displacementMap
=
source
.
displacementMap
;
...
...
src/materials/MeshPhongMaterial.js
浏览文件 @
e5f809a6
import
{
MultiplyOperation
,
TangentSpaceNormalMap
}
from
'
../constants.js
'
;
import
{
Material
}
from
'
./Material.js
'
;
import
{
MultiplyOperation
}
from
'
../constants.js
'
;
import
{
Vector2
}
from
'
../math/Vector2.js
'
;
import
{
Color
}
from
'
../math/Color.js
'
;
...
...
@@ -29,6 +29,7 @@ import { Color } from '../math/Color.js';
* bumpScale: <float>,
*
* normalMap: new THREE.Texture( <Image> ),
* normalMapType: THREE.TangentSpaceNormalMap,
* normalScale: <Vector2>,
*
* displacementMap: new THREE.Texture( <Image> ),
...
...
@@ -79,6 +80,7 @@ function MeshPhongMaterial( parameters ) {
this
.
bumpScale
=
1
;
this
.
normalMap
=
null
;
this
.
normalMapType
=
TangentSpaceNormalMap
;
this
.
normalScale
=
new
Vector2
(
1
,
1
);
this
.
displacementMap
=
null
;
...
...
@@ -136,6 +138,7 @@ MeshPhongMaterial.prototype.copy = function ( source ) {
this
.
bumpScale
=
source
.
bumpScale
;
this
.
normalMap
=
source
.
normalMap
;
this
.
normalMapType
=
source
.
normalMapType
;
this
.
normalScale
.
copy
(
source
.
normalScale
);
this
.
displacementMap
=
source
.
displacementMap
;
...
...
src/materials/MeshStandardMaterial.js
浏览文件 @
e5f809a6
import
{
TangentSpaceNormalMap
}
from
'
../constants.js
'
;
import
{
Material
}
from
'
./Material.js
'
;
import
{
Vector2
}
from
'
../math/Vector2.js
'
;
import
{
Color
}
from
'
../math/Color.js
'
;
...
...
@@ -27,6 +28,7 @@ import { Color } from '../math/Color.js';
* bumpScale: <float>,
*
* normalMap: new THREE.Texture( <Image> ),
* normalMapType: THREE.TangentSpaceNormalMap,
* normalScale: <Vector2>,
*
* displacementMap: new THREE.Texture( <Image> ),
...
...
@@ -81,6 +83,7 @@ function MeshStandardMaterial( parameters ) {
this
.
bumpScale
=
1
;
this
.
normalMap
=
null
;
this
.
normalMapType
=
TangentSpaceNormalMap
;
this
.
normalScale
=
new
Vector2
(
1
,
1
);
this
.
displacementMap
=
null
;
...
...
@@ -142,6 +145,7 @@ MeshStandardMaterial.prototype.copy = function ( source ) {
this
.
bumpScale
=
source
.
bumpScale
;
this
.
normalMap
=
source
.
normalMap
;
this
.
normalMapType
=
source
.
normalMapType
;
this
.
normalScale
.
copy
(
source
.
normalScale
);
this
.
displacementMap
=
source
.
displacementMap
;
...
...
src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl
浏览文件 @
e5f809a6
#ifdef USE_NORMALMAP
normal
=
perturbNormal2Arb
(
-
vViewPosition
,
normal
);
#ifdef OBJECTSPACE_NORMALMAP
normal
=
texture2D
(
normalMap
,
vUv
).
xyz
*
2
.
0
-
1
.
0
;
// overrides both flatShading and attribute normals
#ifdef FLIP_SIDED
normal
=
-
normal
;
#endif
#ifdef DOUBLE_SIDED
normal
=
normal
*
(
float
(
gl_FrontFacing
)
*
2
.
0
-
1
.
0
);
#endif
normal
=
normalize
(
normalMatrix
*
normal
);
#else // tangent-space normal map
normal
=
perturbNormal2Arb
(
-
vViewPosition
,
normal
);
#endif
#elif defined( USE_BUMPMAP )
...
...
src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
浏览文件 @
e5f809a6
...
...
@@ -3,32 +3,40 @@
uniform
sampler2D
normalMap
;
uniform
vec2
normalScale
;
// Per-Pixel Tangent Space Normal Mapping
// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
#ifdef OBJECTSPACE_NORMALMAP
vec3
perturbNormal2Arb
(
vec3
eye_pos
,
vec3
surf_norm
)
{
uniform
mat3
normalMatrix
;
// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
#else
vec3
q0
=
vec3
(
dFdx
(
eye_pos
.
x
),
dFdx
(
eye_pos
.
y
),
dFdx
(
eye_pos
.
z
)
);
vec3
q1
=
vec3
(
dFdy
(
eye_pos
.
x
),
dFdy
(
eye_pos
.
y
),
dFdy
(
eye_pos
.
z
)
);
vec2
st0
=
dFdx
(
vUv
.
st
);
vec2
st1
=
dFdy
(
vUv
.
st
);
// Per-Pixel Tangent Space Normal Mapping
// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
float
scale
=
sign
(
st1
.
t
*
st0
.
s
-
st0
.
t
*
st1
.
s
);
// we do not care about the magnitude
vec3
perturbNormal2Arb
(
vec3
eye_pos
,
vec3
surf_norm
)
{
vec3
S
=
normalize
(
(
q0
*
st1
.
t
-
q1
*
st0
.
t
)
*
scale
);
vec3
T
=
normalize
(
(
-
q0
*
st1
.
s
+
q1
*
st0
.
s
)
*
scale
);
vec3
N
=
normalize
(
surf_norm
);
mat3
tsn
=
mat3
(
S
,
T
,
N
);
// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
vec3
mapN
=
texture2D
(
normalMap
,
vUv
).
xyz
*
2
.
0
-
1
.
0
;
vec3
q0
=
vec3
(
dFdx
(
eye_pos
.
x
),
dFdx
(
eye_pos
.
y
),
dFdx
(
eye_pos
.
z
)
);
vec3
q1
=
vec3
(
dFdy
(
eye_pos
.
x
),
dFdy
(
eye_pos
.
y
),
dFdy
(
eye_pos
.
z
)
);
vec2
st0
=
dFdx
(
vUv
.
st
);
vec2
st1
=
dFdy
(
vUv
.
st
);
mapN
.
xy
*=
normalScale
;
mapN
.
xy
*=
(
float
(
gl_FrontFacing
)
*
2
.
0
-
1
.
0
);
float
scale
=
sign
(
st1
.
t
*
st0
.
s
-
st0
.
t
*
st1
.
s
);
// we do not care about the magnitude
return
normalize
(
tsn
*
mapN
);
vec3
S
=
normalize
(
(
q0
*
st1
.
t
-
q1
*
st0
.
t
)
*
scale
);
vec3
T
=
normalize
(
(
-
q0
*
st1
.
s
+
q1
*
st0
.
s
)
*
scale
);
vec3
N
=
normalize
(
surf_norm
);
mat3
tsn
=
mat3
(
S
,
T
,
N
);
}
vec3
mapN
=
texture2D
(
normalMap
,
vUv
).
xyz
*
2
.
0
-
1
.
0
;
mapN
.
xy
*=
normalScale
;
mapN
.
xy
*=
(
float
(
gl_FrontFacing
)
*
2
.
0
-
1
.
0
);
return
normalize
(
tsn
*
mapN
);
}
#endif
#endif
src/renderers/shaders/ShaderLib/normal_frag.glsl
浏览文件 @
e5f809a6
...
...
@@ -2,7 +2,7 @@
uniform
float
opacity
;
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) ||
defined( USE_NORMALMAP
)
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) ||
( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP )
)
varying
vec3
vViewPosition
;
...
...
src/renderers/shaders/ShaderLib/normal_vert.glsl
浏览文件 @
e5f809a6
#define NORMAL
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) ||
defined( USE_NORMALMAP
)
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) ||
( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP )
)
varying
vec3
vViewPosition
;
...
...
@@ -41,7 +41,7 @@ void main() {
#include <project_vertex>
#include <logdepthbuf_vertex>
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) ||
defined( USE_NORMALMAP
)
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) ||
( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP )
)
vViewPosition
=
-
mvPosition
.
xyz
;
...
...
src/renderers/webgl/WebGLProgram.js
浏览文件 @
e5f809a6
...
...
@@ -84,7 +84,7 @@ function generateExtensions( extensions, parameters, rendererExtensions ) {
extensions
=
extensions
||
{};
var
chunks
=
[
(
extensions
.
derivatives
||
parameters
.
envMapCubeUV
||
parameters
.
bumpMap
||
parameters
.
normalMap
||
parameters
.
flatShading
)
?
'
#extension GL_OES_standard_derivatives : enable
'
:
''
,
(
extensions
.
derivatives
||
parameters
.
envMapCubeUV
||
parameters
.
bumpMap
||
(
parameters
.
normalMap
&&
!
parameters
.
objectSpaceNormalMap
)
||
parameters
.
flatShading
)
?
'
#extension GL_OES_standard_derivatives : enable
'
:
''
,
(
extensions
.
fragDepth
||
parameters
.
logarithmicDepthBuffer
)
&&
rendererExtensions
.
get
(
'
EXT_frag_depth
'
)
?
'
#extension GL_EXT_frag_depth : enable
'
:
''
,
(
extensions
.
drawBuffers
)
&&
rendererExtensions
.
get
(
'
WEBGL_draw_buffers
'
)
?
'
#extension GL_EXT_draw_buffers : require
'
:
''
,
(
extensions
.
shaderTextureLOD
||
parameters
.
envMap
)
&&
rendererExtensions
.
get
(
'
EXT_shader_texture_lod
'
)
?
'
#extension GL_EXT_shader_texture_lod : enable
'
:
''
...
...
@@ -349,6 +349,7 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters
parameters
.
emissiveMap
?
'
#define USE_EMISSIVEMAP
'
:
''
,
parameters
.
bumpMap
?
'
#define USE_BUMPMAP
'
:
''
,
parameters
.
normalMap
?
'
#define USE_NORMALMAP
'
:
''
,
(
parameters
.
normalMap
&&
parameters
.
objectSpaceNormalMap
)
?
'
#define OBJECTSPACE_NORMALMAP
'
:
''
,
parameters
.
displacementMap
&&
parameters
.
supportsVertexTextures
?
'
#define USE_DISPLACEMENTMAP
'
:
''
,
parameters
.
specularMap
?
'
#define USE_SPECULARMAP
'
:
''
,
parameters
.
roughnessMap
?
'
#define USE_ROUGHNESSMAP
'
:
''
,
...
...
@@ -455,6 +456,7 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters
parameters
.
emissiveMap
?
'
#define USE_EMISSIVEMAP
'
:
''
,
parameters
.
bumpMap
?
'
#define USE_BUMPMAP
'
:
''
,
parameters
.
normalMap
?
'
#define USE_NORMALMAP
'
:
''
,
(
parameters
.
normalMap
&&
parameters
.
objectSpaceNormalMap
)
?
'
#define OBJECTSPACE_NORMALMAP
'
:
''
,
parameters
.
specularMap
?
'
#define USE_SPECULARMAP
'
:
''
,
parameters
.
roughnessMap
?
'
#define USE_ROUGHNESSMAP
'
:
''
,
parameters
.
metalnessMap
?
'
#define USE_METALNESSMAP
'
:
''
,
...
...
src/renderers/webgl/WebGLPrograms.js
浏览文件 @
e5f809a6
...
...
@@ -2,7 +2,7 @@
* @author mrdoob / http://mrdoob.com/
*/
import
{
BackSide
,
DoubleSide
,
CubeUVRefractionMapping
,
CubeUVReflectionMapping
,
GammaEncoding
,
LinearEncoding
}
from
'
../../constants.js
'
;
import
{
BackSide
,
DoubleSide
,
CubeUVRefractionMapping
,
CubeUVReflectionMapping
,
GammaEncoding
,
LinearEncoding
,
ObjectSpaceNormalMap
}
from
'
../../constants.js
'
;
import
{
WebGLProgram
}
from
'
./WebGLProgram.js
'
;
function
WebGLPrograms
(
renderer
,
extensions
,
capabilities
)
{
...
...
@@ -27,7 +27,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
var
parameterNames
=
[
"
precision
"
,
"
supportsVertexTextures
"
,
"
map
"
,
"
mapEncoding
"
,
"
envMap
"
,
"
envMapMode
"
,
"
envMapEncoding
"
,
"
lightMap
"
,
"
aoMap
"
,
"
emissiveMap
"
,
"
emissiveMapEncoding
"
,
"
bumpMap
"
,
"
normalMap
"
,
"
displacementMap
"
,
"
specularMap
"
,
"
lightMap
"
,
"
aoMap
"
,
"
emissiveMap
"
,
"
emissiveMapEncoding
"
,
"
bumpMap
"
,
"
normalMap
"
,
"
objectSpaceNormalMap
"
,
"
displacementMap
"
,
"
specularMap
"
,
"
roughnessMap
"
,
"
metalnessMap
"
,
"
gradientMap
"
,
"
alphaMap
"
,
"
combine
"
,
"
vertexColors
"
,
"
fog
"
,
"
useFog
"
,
"
fogExp
"
,
"
flatShading
"
,
"
sizeAttenuation
"
,
"
logarithmicDepthBuffer
"
,
"
skinning
"
,
...
...
@@ -148,6 +148,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
emissiveMapEncoding
:
getTextureEncodingFromMap
(
material
.
emissiveMap
,
renderer
.
gammaInput
),
bumpMap
:
!!
material
.
bumpMap
,
normalMap
:
!!
material
.
normalMap
,
objectSpaceNormalMap
:
material
.
normalMapType
===
ObjectSpaceNormalMap
,
displacementMap
:
!!
material
.
displacementMap
,
roughnessMap
:
!!
material
.
roughnessMap
,
metalnessMap
:
!!
material
.
metalnessMap
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录