提交 f8df139d 编写于 作者: W WestLangley 提交者: Mr.doob

MeshBasicMaterial: Add support for lightMap (#9975)

上级 f1edcc01
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta charset="utf-8" />
<base href="../../" />
<script src="list.js"></script>
<script src="page.js"></script>
......@@ -41,6 +41,8 @@
<div>
color — geometry color in hexadecimal. Default is 0xffffff.<br />
map — Set texture map. Default is null <br />
lightMap — Set light map. Default is null.<br />
lightMapIntensity — Set light map intensity. Default is 1.<br />
aoMap — Set ao map. Default is null.<br />
aoMapIntensity — Set ao map intensity. Default is 1.<br />
specularMap — Set specular map. Default is null.<br />
......@@ -71,11 +73,17 @@
Set texture map. Default is null.
</div>
<h3>[property:Texture lightMap]</h3>
<div>Set light map. Default is null. The lightMap requires a second set of UVs.</div>
<h3>[property:Float lightMapIntensity]</h3>
<div>Intensity of the baked light. Default is 1.</div>
<h3>[property:Texture aoMap]</h3>
<div>Set ambient occlusion map. Default is null.</div>
<h3>[property:Float aoMapIntensity]</h3>
<div>TODO</div>
<div>Intensity of the ambient occlusion effect. Default is 1. Zero is no occlusion effect.</div>
<h3>[property:Texture specularMap]</h3>
<div>Set specular map. Default is null.</div>
......
......@@ -11,6 +11,9 @@ import { Color } from '../math/Color';
* opacity: <float>,
* map: new THREE.Texture( <Image> ),
*
* lightMap: new THREE.Texture( <Image> ),
* lightMapIntensity: <float>
*
* aoMap: new THREE.Texture( <Image> ),
* aoMapIntensity: <float>
*
......@@ -45,6 +48,9 @@ function MeshBasicMaterial( parameters ) {
this.map = null;
this.lightMap = null;
this.lightMapIntensity = 1.0;
this.aoMap = null;
this.aoMapIntensity = 1.0;
......@@ -84,6 +90,9 @@ MeshBasicMaterial.prototype.copy = function ( source ) {
this.map = source.map;
this.lightMap = source.lightMap;
this.lightMapIntensity = source.lightMapIntensity;
this.aoMap = source.aoMap;
this.aoMapIntensity = source.aoMapIntensity;
......
......@@ -1945,6 +1945,13 @@ function WebGLRenderer( parameters ) {
uniforms.specularMap.value = material.specularMap;
uniforms.alphaMap.value = material.alphaMap;
if ( material.lightMap ) {
uniforms.lightMap.value = material.lightMap;
uniforms.lightMapIntensity.value = material.lightMapIntensity;
}
if ( material.aoMap ) {
uniforms.aoMap.value = material.aoMap;
......@@ -2083,13 +2090,6 @@ function WebGLRenderer( parameters ) {
function refreshUniformsLambert( uniforms, material ) {
if ( material.lightMap ) {
uniforms.lightMap.value = material.lightMap;
uniforms.lightMapIntensity.value = material.lightMapIntensity;
}
if ( material.emissiveMap ) {
uniforms.emissiveMap.value = material.emissiveMap;
......@@ -2103,13 +2103,6 @@ function WebGLRenderer( parameters ) {
uniforms.specular.value = material.specular;
uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
if ( material.lightMap ) {
uniforms.lightMap.value = material.lightMap;
uniforms.lightMapIntensity.value = material.lightMapIntensity;
}
if ( material.emissiveMap ) {
uniforms.emissiveMap.value = material.emissiveMap;
......@@ -2157,13 +2150,6 @@ function WebGLRenderer( parameters ) {
}
if ( material.lightMap ) {
uniforms.lightMap.value = material.lightMap;
uniforms.lightMapIntensity.value = material.lightMapIntensity;
}
if ( material.emissiveMap ) {
uniforms.emissiveMap.value = material.emissiveMap;
......
......@@ -16,6 +16,7 @@ var ShaderLib = {
uniforms: Object.assign( {},
UniformsLib.common,
UniformsLib.aomap,
UniformsLib.lightmap,
UniformsLib.fog
),
......
......@@ -14,6 +14,7 @@ uniform float opacity;
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <envmap_pars_fragment>
#include <fog_pars_fragment>
#include <specularmap_pars_fragment>
......@@ -33,14 +34,24 @@ void main() {
#include <alphatest_fragment>
#include <specularmap_fragment>
ReflectedLight reflectedLight;
reflectedLight.directDiffuse = vec3( 0.0 );
reflectedLight.directSpecular = vec3( 0.0 );
reflectedLight.indirectDiffuse = diffuseColor.rgb;
reflectedLight.indirectSpecular = vec3( 0.0 );
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
// accumulation (baked indirect lighting only)
#ifdef USE_LIGHTMAP
reflectedLight.indirectDiffuse += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;
#else
reflectedLight.indirectDiffuse += vec3( 1.0 );
#endif
// modulation
#include <aomap_fragment>
reflectedLight.indirectDiffuse *= diffuseColor.rgb;
vec3 outgoingLight = reflectedLight.indirectDiffuse;
#include <normal_flip>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册