提交 db230978 编写于 作者: W WestLangley

MeshPhongMaterial: Added support for Emissive Maps

上级 71008527
......@@ -27,6 +27,7 @@
map — Set texture map. Default is null <br />
lightMap — Set light map. Default is null.<br />
aoMap — Set ao map. Default is null.<br />
emissiveMap — Set emissive map. Default is null.<br />
specularMap — Set specular map. Default is null.<br />
alphaMap — Set alpha map. Default is null.<br />
envMap — Set env map. Default is null.<br />
......@@ -76,13 +77,16 @@
</div>
<h3>[property:Texture map]</h3>
<div>Set color texture map. Default is null.</div>
<div>Set color texture map. Default is null. The texture map color is modulated by the diffuse color.</div>
<h3>[property:Texture lightMap]</h3>
<div>Set light map. Default is null.</div>
<div>Set light map. Default is null. The lightMap requires a second set of UVs.</div>
<h3>[property:Texture aoMap]</h3>
<div>Set ambient occlusion map. Default is null.</div>
<div>Set ambient occlusion map. Default is null. The aoMap requires a second set of UVs.</div>
<h3>[property:Texture emissiveMap]</h3>
<div>Set emisssive (glow) map. Default is null. The emissive map color is modulated by the emissive color. If you have an emissive map, be sure to set the emissive color to something other than black.</div>
<h3>[property:Texture bumpMap]</h3>
<div>
......
......@@ -17,6 +17,8 @@
* aoMap: new THREE.Texture( <Image> ),
* aoMapIntensity: <float>
*
* emissiveMap: new THREE.Texture( <Image> ),
*
* bumpMap: new THREE.Texture( <Image> ),
* bumpScale: <float>,
*
......@@ -71,6 +73,8 @@ THREE.MeshPhongMaterial = function ( parameters ) {
this.aoMap = null;
this.aoMapIntensity = 1.0;
this.emissiveMap = null;
this.bumpMap = null;
this.bumpScale = 1;
......@@ -129,6 +133,8 @@ THREE.MeshPhongMaterial.prototype.clone = function () {
material.aoMap = this.aoMap;
material.aoMapIntensity = this.aoMapIntensity;
material.emissiveMap = this.emissiveMap;
material.bumpMap = this.bumpMap;
material.bumpScale = this.bumpScale;
......
......@@ -1834,6 +1834,7 @@ THREE.WebGLRenderer = function ( parameters ) {
envMapMode: material.envMap && material.envMap.mapping,
lightMap: !! material.lightMap,
aoMap: !! material.aoMap,
emissiveMap: !! material.emissiveMap,
bumpMap: !! material.bumpMap,
normalMap: !! material.normalMap,
specularMap: !! material.specularMap,
......@@ -2336,6 +2337,7 @@ THREE.WebGLRenderer = function ( parameters ) {
// 3. normal map
// 4. bump map
// 5. alpha map
// 6. emissive map
var uvScaleMap;
......@@ -2359,6 +2361,10 @@ THREE.WebGLRenderer = function ( parameters ) {
uvScaleMap = material.alphaMap;
} else if ( material.emissiveMap ) {
uvScaleMap = material.emissiveMap;
}
if ( uvScaleMap !== undefined ) {
......@@ -2443,6 +2449,8 @@ THREE.WebGLRenderer = function ( parameters ) {
uniforms.aoMap.value = material.aoMap;
uniforms.aoMapIntensity.value = material.aoMapIntensity;
uniforms.emissiveMap.value = material.emissiveMap;
}
function refreshUniformsLambert ( uniforms, material ) {
......
#ifdef USE_EMISSIVEMAP
vec4 emissiveColor = texture2D( emissiveMap, vUv );
emissiveColor.rgb = inputToLinear( emissiveColor.rgb );
totalEmissiveLight *= emissiveColor.rgb;
#endif
#ifdef USE_EMISSIVEMAP
uniform sampler2D emissiveMap;
#endif
......@@ -156,10 +156,10 @@ vec3 totalSpecularLight = vec3( 0.0 );
#ifdef METAL
outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) * specular + totalSpecularLight + emissive;
outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) * specular + totalSpecularLight + totalEmissiveLight;
#else
outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) + totalSpecularLight + emissive;
outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) + totalSpecularLight + totalEmissiveLight;
#endif
......@@ -6,4 +6,4 @@
diffuseColor *= texelColor;
#endif
\ No newline at end of file
#endif
#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP )
#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP )
varying vec2 vUv;
......
#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP )
#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP )
varying vec2 vUv;
uniform vec4 offsetRepeat;
......
#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP )
#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP )
vUv = uv * offsetRepeat.zw + offsetRepeat.xy;
......
......@@ -101,7 +101,7 @@ THREE.ShaderLib = {
THREE.ShaderChunk[ "fog_fragment" ],
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
"}"
......@@ -212,9 +212,6 @@ THREE.ShaderLib = {
" #ifdef DOUBLE_SIDED",
//"float isFront = float( gl_FrontFacing );",
//"gl_FragColor.xyz *= isFront * vLightFront + ( 1.0 - isFront ) * vLightBack;",
" if ( gl_FrontFacing )",
" outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
" else",
......@@ -233,7 +230,7 @@ THREE.ShaderLib = {
THREE.ShaderChunk[ "fog_fragment" ],
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
"}"
......@@ -248,6 +245,7 @@ THREE.ShaderLib = {
THREE.UniformsLib[ "common" ],
THREE.UniformsLib[ "aomap" ],
THREE.UniformsLib[ "lightmap" ],
THREE.UniformsLib[ "emissivemap" ],
THREE.UniformsLib[ "bump" ],
THREE.UniformsLib[ "normalmap" ],
THREE.UniformsLib[ "fog" ],
......@@ -307,7 +305,7 @@ THREE.ShaderLib = {
THREE.ShaderChunk[ "default_vertex" ],
THREE.ShaderChunk[ "logdepthbuf_vertex" ],
" vViewPosition = -mvPosition.xyz;",
" vViewPosition = - mvPosition.xyz;",
THREE.ShaderChunk[ "worldpos_vertex" ],
THREE.ShaderChunk[ "envmap_vertex" ],
......@@ -336,6 +334,7 @@ THREE.ShaderLib = {
THREE.ShaderChunk[ "alphamap_pars_fragment" ],
THREE.ShaderChunk[ "aomap_pars_fragment" ],
THREE.ShaderChunk[ "lightmap_pars_fragment" ],
THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
THREE.ShaderChunk[ "envmap_pars_fragment" ],
THREE.ShaderChunk[ "fog_pars_fragment" ],
THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
......@@ -347,9 +346,10 @@ THREE.ShaderLib = {
"void main() {",
" vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
" vec3 outgoingLight = vec3( 0.0 );",
" vec4 diffuseColor = vec4( diffuse, opacity );",
" vec3 totalAmbientLight = ambientLightColor;",
" vec3 totalEmissiveLight = emissive;",
THREE.ShaderChunk[ "logdepthbuf_fragment" ],
THREE.ShaderChunk[ "map_fragment" ],
......@@ -359,6 +359,7 @@ THREE.ShaderLib = {
THREE.ShaderChunk[ "specularmap_fragment" ],
THREE.ShaderChunk[ "lightmap_fragment" ],
THREE.ShaderChunk[ "aomap_fragment" ],
THREE.ShaderChunk[ "emissivemap_fragment" ],
THREE.ShaderChunk[ "lights_phong_fragment" ],
......@@ -369,7 +370,7 @@ THREE.ShaderLib = {
THREE.ShaderChunk[ "fog_fragment" ],
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
"}"
......@@ -432,7 +433,7 @@ THREE.ShaderLib = {
"void main() {",
" vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
" vec3 outgoingLight = vec3( 0.0 );",
" vec4 diffuseColor = vec4( psColor, opacity );",
THREE.ShaderChunk[ "logdepthbuf_fragment" ],
......@@ -445,7 +446,7 @@ THREE.ShaderLib = {
THREE.ShaderChunk[ "shadowmap_fragment" ],
THREE.ShaderChunk[ "fog_fragment" ],
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
"}"
......@@ -517,7 +518,7 @@ THREE.ShaderLib = {
" }",
" vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
" vec3 outgoingLight = vec3( 0.0 );",
" vec4 diffuseColor = vec4( diffuse, opacity );",
THREE.ShaderChunk[ "logdepthbuf_fragment" ],
......@@ -527,7 +528,7 @@ THREE.ShaderLib = {
THREE.ShaderChunk[ "fog_fragment" ],
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
" gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
"}"
......@@ -585,7 +586,7 @@ THREE.ShaderLib = {
" #endif",
" float color = 1.0 - smoothstep( mNear, mFar, depth );",
" gl_FragColor = vec4( vec3( color ), opacity );", // TODO, this should be pre-multiplied to allow for bright highlights on very transparent objects
" gl_FragColor = vec4( vec3( color ), opacity );",
"}"
......
......@@ -36,6 +36,12 @@ THREE.UniformsLib = {
},
emissivemap: {
"emissiveMap" : { type: "t", value: null },
},
bump: {
"bumpMap" : { type: "t", value: null },
......
......@@ -213,6 +213,7 @@ THREE.WebGLProgram = ( function () {
parameters.envMap ? '#define ' + envMapModeDefine : '',
parameters.lightMap ? '#define USE_LIGHTMAP' : '',
parameters.aoMap ? '#define USE_AOMAP' : '',
parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
parameters.bumpMap ? '#define USE_BUMPMAP' : '',
parameters.normalMap ? '#define USE_NORMALMAP' : '',
parameters.specularMap ? '#define USE_SPECULARMAP' : '',
......@@ -300,6 +301,8 @@ THREE.WebGLProgram = ( function () {
'precision ' + parameters.precision + ' float;',
'precision ' + parameters.precision + ' int;',
'#define SHADER_NAME ' + material.__webglShader.name,
customDefines,
'#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
......@@ -325,6 +328,7 @@ THREE.WebGLProgram = ( function () {
parameters.envMap ? '#define ' + envMapBlendingDefine : '',
parameters.lightMap ? '#define USE_LIGHTMAP' : '',
parameters.aoMap ? '#define USE_AOMAP' : '',
parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
parameters.bumpMap ? '#define USE_BUMPMAP' : '',
parameters.normalMap ? '#define USE_NORMALMAP' : '',
parameters.specularMap ? '#define USE_SPECULARMAP' : '',
......
......@@ -104,6 +104,8 @@
"src/renderers/shaders/ShaderChunk/common.glsl",
"src/renderers/shaders/ShaderChunk/default_vertex.glsl",
"src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl",
"src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl",
"src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl",
"src/renderers/shaders/ShaderChunk/envmap_fragment.glsl",
"src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl",
"src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册