-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support object-space normal maps #14239
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,6 +220,13 @@ <h3>[property:Texture normalMap]</h3> | |
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider consolidating multiple document entries by moving the property to |
||
<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. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider nuking, would be serialized with the texture, there are possibly materials that extend Consider not making the super class aware of the sub classes. |
||
data.normalScale = this.normalScale.toArray(); | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider nuking, and moving to If not, consider adding documentation for this class. |
||
this.normalScale.copy( source.normalScale ); | ||
|
||
this.displacementMap = source.displacementMap; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider nuking, and moving to |
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider nuking, and moving to |
||
this.normalScale.copy( source.normalScale ); | ||
|
||
this.displacementMap = source.displacementMap; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider decoupling from
|
||
displacementMap: !! material.displacementMap, | ||
roughnessMap: !! material.roughnessMap, | ||
metalnessMap: !! material.metalnessMap, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider consolidating multiple document entries by moving the property to
Texture
. If not, add the documentation forMeshNormalMaterial
.