提交 dc4a2dbb 编写于 作者: T Takahiro

Add MeshStandardMaterialSG

上级 d0af0b58
......@@ -5,6 +5,7 @@ export { ShaderMaterial } from './ShaderMaterial.js';
export { PointsMaterial } from './PointsMaterial.js';
export { MeshPhysicalMaterial } from './MeshPhysicalMaterial.js';
export { MeshStandardMaterial } from './MeshStandardMaterial.js';
export { MeshStandardMaterialSG } from './MeshStandardMaterialSG.js';
export { MeshPhongMaterial } from './MeshPhongMaterial.js';
export { MeshToonMaterial } from './MeshToonMaterial.js';
export { MeshNormalMaterial } from './MeshNormalMaterial.js';
......
import { Material } from './Material';
import { Vector2 } from '../math/Vector2';
import { Color } from '../math/Color';
/**
* @author takahiro / http://github.com/takahirox
*
* parameters = {
* color: <hex>,
* glossiness: <float>,
* specular2: <hex>,
* opacity: <float>,
*
* map: new THREE.Texture( <Image> ),
*
* lightMap: new THREE.Texture( <Image> ),
* lightMapIntensity: <float>
*
* aoMap: new THREE.Texture( <Image> ),
* aoMapIntensity: <float>
*
* emissive: <hex>,
* emissiveIntensity: <float>
* emissiveMap: new THREE.Texture( <Image> ),
*
* bumpMap: new THREE.Texture( <Image> ),
* bumpScale: <float>,
*
* normalMap: new THREE.Texture( <Image> ),
* normalScale: <Vector2>,
*
* displacementMap: new THREE.Texture( <Image> ),
* displacementScale: <float>,
* displacementBias: <float>,
*
* glossinessMap: new THREE.Texture( <Image> ),
*
* specular2Map: new THREE.Texture( <Image> ),
*
* alphaMap: new THREE.Texture( <Image> ),
*
* envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
* envMapIntensity: <float>
*
* refractionRatio: <float>,
*
* wireframe: <boolean>,
* wireframeLinewidth: <float>,
*
* skinning: <bool>,
* morphTargets: <bool>,
* morphNormals: <bool>
* }
*/
function MeshStandardMaterialSG( parameters ) {
Material.call( this );
this.defines = { 'STANDARD': '', 'STANDARD_SG': '' };
this.type = 'MeshStandardMaterialSG';
this.color = new Color( 0xffffff ); // diffuse
this.glossiness = 0.5;
this.specular2 = new Color ( 0x000000 );
this.map = null;
this.lightMap = null;
this.lightMapIntensity = 1.0;
this.aoMap = null;
this.aoMapIntensity = 1.0;
this.emissive = new Color( 0x000000 );
this.emissiveIntensity = 1.0;
this.emissiveMap = null;
this.bumpMap = null;
this.bumpScale = 1;
this.normalMap = null;
this.normalScale = new Vector2( 1, 1 );
this.displacementMap = null;
this.displacementScale = 1;
this.displacementBias = 0;
this.glossinessMap = null;
this.specular2Map = null;
this.alphaMap = null;
this.envMap = null;
this.envMapIntensity = 1.0;
this.refractionRatio = 0.98;
this.wireframe = false;
this.wireframeLinewidth = 1;
this.wireframeLinecap = 'round';
this.wireframeLinejoin = 'round';
this.skinning = false;
this.morphTargets = false;
this.morphNormals = false;
this.setValues( parameters );
}
MeshStandardMaterialSG.prototype = Object.create( Material.prototype );
MeshStandardMaterialSG.prototype.constructor = MeshStandardMaterialSG;
MeshStandardMaterialSG.prototype.isMeshStandardMaterialSG = true;
MeshStandardMaterialSG.prototype.copy = function ( source ) {
Material.prototype.copy.call( this, source );
this.defines = { 'STANDARD': '' };
this.color.copy( source.color );
this.glossiness = source.glossiness;
this.speculars.copy( source.specular2 );
this.map = source.map;
this.lightMap = source.lightMap;
this.lightMapIntensity = source.lightMapIntensity;
this.aoMap = source.aoMap;
this.aoMapIntensity = source.aoMapIntensity;
this.emissive.copy( source.emissive );
this.emissiveMap = source.emissiveMap;
this.emissiveIntensity = source.emissiveIntensity;
this.bumpMap = source.bumpMap;
this.bumpScale = source.bumpScale;
this.normalMap = source.normalMap;
this.normalScale.copy( source.normalScale );
this.displacementMap = source.displacementMap;
this.displacementScale = source.displacementScale;
this.displacementBias = source.displacementBias;
this.glossinessMap = source.glossinessMap;
this.specular2Map = source.specular2Map;
this.alphaMap = source.alphaMap;
this.envMap = source.envMap;
this.envMapIntensity = source.envMapIntensity;
this.refractionRatio = source.refractionRatio;
this.wireframe = source.wireframe;
this.wireframeLinewidth = source.wireframeLinewidth;
this.wireframeLinecap = source.wireframeLinecap;
this.wireframeLinejoin = source.wireframeLinejoin;
this.skinning = source.skinning;
this.morphTargets = source.morphTargets;
this.morphNormals = source.morphNormals;
return this;
};
export { MeshStandardMaterialSG };
......@@ -622,6 +622,7 @@ function WebGLRenderer( parameters ) {
if ( ! material.isMeshPhongMaterial &&
! material.isMeshStandardMaterial &&
! material.isMeshStandardMaterialSG &&
! material.isMeshNormalMaterial &&
material.shading === FlatShading ) {
......@@ -1724,6 +1725,7 @@ function WebGLRenderer( parameters ) {
if ( material.isShaderMaterial ||
material.isMeshPhongMaterial ||
material.isMeshStandardMaterial ||
material.isMeshStandardMaterialSG ||
material.envMap ) {
var uCamPos = p_uniforms.map.cameraPosition;
......@@ -1741,6 +1743,7 @@ function WebGLRenderer( parameters ) {
material.isMeshLambertMaterial ||
material.isMeshBasicMaterial ||
material.isMeshStandardMaterial ||
material.isMeshStandardMaterialSG ||
material.isShaderMaterial ||
material.skinning ) {
......@@ -1837,6 +1840,7 @@ function WebGLRenderer( parameters ) {
material.isMeshLambertMaterial ||
material.isMeshPhongMaterial ||
material.isMeshStandardMaterial ||
material.isMeshStandardMaterialSG ||
material.isMeshNormalMaterial ||
material.isMeshDepthMaterial ) {
......@@ -1879,6 +1883,10 @@ function WebGLRenderer( parameters ) {
refreshUniformsStandard( m_uniforms, material );
} else if ( material.isMeshStandardMaterialSG ) {
refreshUniformsStandardSG( m_uniforms, material );
} else if ( material.isMeshDepthMaterial ) {
if ( material.displacementMap ) {
......@@ -2135,22 +2143,7 @@ function WebGLRenderer( parameters ) {
}
function refreshUniformsStandard( uniforms, material ) {
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;
}
function refreshUniformsStandardCommon( uniforms, material ) {
if ( material.emissiveMap ) {
......@@ -2189,6 +2182,48 @@ function WebGLRenderer( parameters ) {
}
function refreshUniformsStandard( uniforms, material ) {
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;
}
refreshUniformsStandardCommon( uniforms, material );
}
function refreshUniformsStandardSG( uniforms, material ) {
uniforms.glossiness.value = material.roughness;
uniforms.specular2.value.copy( material.specular2 );
if ( material.glossinessMap ) {
uniforms.glossinessMap.value = material.glossinessMap;
}
if ( material.specular2Map ) {
uniforms.specular2Map.value = material.specular2Map;
}
refreshUniformsStandardCommon( uniforms, material );
}
function refreshUniformsPhysical( uniforms, material ) {
uniforms.clearCoat.value = material.clearCoat;
......
......@@ -32,6 +32,8 @@ import fog_vertex from './ShaderChunk/fog_vertex.glsl';
import fog_pars_vertex from './ShaderChunk/fog_pars_vertex.glsl';
import fog_fragment from './ShaderChunk/fog_fragment.glsl';
import fog_pars_fragment from './ShaderChunk/fog_pars_fragment.glsl';
import glossinessmap_fragment from './ShaderChunk/glossinessmap_fragment.glsl';
import glossinessmap_pars_fragment from './ShaderChunk/glossinessmap_pars_fragment.glsl';
import gradientmap_pars_fragment from './ShaderChunk/gradientmap_pars_fragment.glsl';
import lightmap_fragment from './ShaderChunk/lightmap_fragment.glsl';
import lightmap_pars_fragment from './ShaderChunk/lightmap_pars_fragment.glsl';
......@@ -73,6 +75,8 @@ import skinning_vertex from './ShaderChunk/skinning_vertex.glsl';
import skinnormal_vertex from './ShaderChunk/skinnormal_vertex.glsl';
import specularmap_fragment from './ShaderChunk/specularmap_fragment.glsl';
import specularmap_pars_fragment from './ShaderChunk/specularmap_pars_fragment.glsl';
import specular2map_fragment from './ShaderChunk/specular2map_fragment.glsl';
import specular2map_pars_fragment from './ShaderChunk/specular2map_pars_fragment.glsl';
import tonemapping_fragment from './ShaderChunk/tonemapping_fragment.glsl';
import tonemapping_pars_fragment from './ShaderChunk/tonemapping_pars_fragment.glsl';
import uv_pars_fragment from './ShaderChunk/uv_pars_fragment.glsl';
......@@ -143,6 +147,8 @@ export var ShaderChunk = {
fog_pars_vertex: fog_pars_vertex,
fog_fragment: fog_fragment,
fog_pars_fragment: fog_pars_fragment,
glossinessmap_fragment: glossinessmap_fragment,
glossinessmap_pars_fragment: glossinessmap_pars_fragment,
gradientmap_pars_fragment: gradientmap_pars_fragment,
lightmap_fragment: lightmap_fragment,
lightmap_pars_fragment: lightmap_pars_fragment,
......@@ -184,6 +190,8 @@ export var ShaderChunk = {
skinnormal_vertex: skinnormal_vertex,
specularmap_fragment: specularmap_fragment,
specularmap_pars_fragment: specularmap_pars_fragment,
specular2map_fragment: specular2map_fragment,
specular2map_pars_fragment: specular2map_pars_fragment,
tonemapping_fragment: tonemapping_fragment,
tonemapping_pars_fragment: tonemapping_pars_fragment,
uv_pars_fragment: uv_pars_fragment,
......
float glossinessFactor = glossiness;
#ifdef USE_GLOSSINESSMAP
vec4 texelGlossiness = texture2D( glossinessMap, vUv );
// reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture
glossinessFactor *= texelGlossiness.a;
#endif
#ifdef USE_GLOSSINESSMAP
uniform sampler2D glossinessMap;
#endif
\ No newline at end of file
PhysicalMaterial material;
material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
material.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );
#ifdef STANDARD
material.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );
#ifdef STANDARD_SG
material.diffuseColor = diffuseColor.rgb * ( 1.0 - max( max( specular2Factor.r, specular2Factor.g ), specular2Factor.b ) );
material.specularRoughness = clamp( 1.0 - glossinessFactor, 0.04, 1.0 );
material.specularColor = specular2Factor.rgb;
#else
material.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );
material.clearCoat = saturate( clearCoat ); // Burley clearcoat model
material.clearCoatRoughness = clamp( clearCoatRoughness, 0.04, 1.0 );
material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
material.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );
#ifdef STANDARD
material.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );
#else
material.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );
material.clearCoat = saturate( clearCoat ); // Burley clearcoat model
material.clearCoatRoughness = clamp( clearCoatRoughness, 0.04, 1.0 );
#endif
#endif
vec3 specular2Factor = specular2;
#ifdef USE_SPECULAR2MAP
vec4 texelSpecular2 = texture2D( specular2Map, vUv );
// reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture
specular2Factor *= texelSpecular2.rgb;
#endif
\ No newline at end of file
#ifdef USE_SPECULAR2MAP
uniform sampler2D specular2Map;
#endif
\ No newline at end of file
#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )
#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP ) || defined( USE_GLOSSINESSMAP) || defined( USE_SPECULAR2MAP )
varying vec2 vUv;
......
#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )
#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP ) || defined( USE_GLOSSINESSMAP) || defined( USE_SPECULAR2MAP )
varying vec2 vUv;
uniform vec4 offsetRepeat;
......
#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )
#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP ) || defined( USE_GLOSSINESSMAP) || defined( USE_SPECULAR2MAP )
vUv = uv * offsetRepeat.zw + offsetRepeat.xy;
......
......@@ -82,12 +82,16 @@ var ShaderLib = {
UniformsLib.displacementmap,
UniformsLib.roughnessmap,
UniformsLib.metalnessmap,
UniformsLib.glossinessmap,
UniformsLib.specular2map,
UniformsLib.fog,
UniformsLib.lights,
{
emissive: { value: new Color( 0x000000 ) },
roughness: { value: 0.5 },
metalness: { value: 0 },
glossiness: { value: 0.5 },
specular2: { value: new Color( 0x000000 ) },
envMapIntensity: { value: 1 } // temporary
}
] ),
......
......@@ -2,8 +2,15 @@
uniform vec3 diffuse;
uniform vec3 emissive;
uniform float roughness;
uniform float metalness;
#ifdef STANDARD_SG
uniform float glossiness;
uniform vec3 specular2;
#else
uniform float roughness;
uniform float metalness;
#endif
uniform float opacity;
#ifndef STANDARD
......@@ -38,8 +45,15 @@ varying vec3 vViewPosition;
#include <shadowmap_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <roughnessmap_pars_fragment>
#include <metalnessmap_pars_fragment>
#ifdef STANDARD_SG
#include <glossinessmap_pars_fragment>
#include <specular2map_pars_fragment>
#else
#include <roughnessmap_pars_fragment>
#include <metalnessmap_pars_fragment>
#endif
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
......@@ -57,8 +71,15 @@ void main() {
#include <alphamap_fragment>
#include <alphatest_fragment>
#include <specularmap_fragment>
#include <roughnessmap_fragment>
#include <metalnessmap_fragment>
#ifdef STANDARD_SG
#include <glossinessmap_fragment>
#include <specular2map_fragment>
#else
#include <roughnessmap_fragment>
#include <metalnessmap_fragment>
#endif
#include <normal_flip>
#include <normal_fragment>
#include <emissivemap_fragment>
......
......@@ -87,6 +87,18 @@ var UniformsLib = {
},
glossinessmap: {
glossinessMap: { value: null }
},
specular2map: {
specular2Map: { value: null }
},
fog: {
fogDensity: { value: 0.00025 },
......
......@@ -338,6 +338,8 @@ function WebGLProgram( renderer, code, material, parameters ) {
parameters.specularMap ? '#define USE_SPECULARMAP' : '',
parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
parameters.glossinessMap ? '#define USE_GLOSSINESSMAP' : '',
parameters.specular2Map ? '#define USE_SPECULAR2MAP' : '',
parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
parameters.vertexColors ? '#define USE_COLOR' : '',
......@@ -445,6 +447,8 @@ function WebGLProgram( renderer, code, material, parameters ) {
parameters.specularMap ? '#define USE_SPECULARMAP' : '',
parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
parameters.glossinessMap ? '#define USE_GLOSSINESSMAP' : '',
parameters.specular2Map ? '#define USE_SPECULAR2MAP' : '',
parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
parameters.vertexColors ? '#define USE_COLOR' : '',
......
......@@ -17,6 +17,7 @@ function WebGLPrograms( renderer, capabilities ) {
MeshPhongMaterial: 'phong',
MeshToonMaterial: 'phong',
MeshStandardMaterial: 'physical',
MeshStandardMaterialSG: 'physical',
MeshPhysicalMaterial: 'physical',
LineBasicMaterial: 'basic',
LineDashedMaterial: 'dashed',
......@@ -26,7 +27,7 @@ function WebGLPrograms( renderer, capabilities ) {
var parameterNames = [
"precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
"lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
"roughnessMap", "metalnessMap", "gradientMap",
"roughnessMap", "metalnessMap", "gradientMap", "glossinessMap", "specular2Map",
"alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
"flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
"maxBones", "useVertexTexture", "morphTargets", "morphNormals",
......@@ -149,6 +150,8 @@ function WebGLPrograms( renderer, capabilities ) {
displacementMap: !! material.displacementMap,
roughnessMap: !! material.roughnessMap,
metalnessMap: !! material.metalnessMap,
glossinessMap: !! material.glossinessMap,
specular2Map: !! material.specular2Map,
specularMap: !! material.specularMap,
alphaMap: !! material.alphaMap,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册