Skip to content

Commit

Permalink
MeshMatcapMaterial no longer requiring a matcap.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Nov 26, 2018
1 parent 093c415 commit bce9345
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 31 deletions.
18 changes: 8 additions & 10 deletions examples/webgl_materials_matcap.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
function init() {

// renderer
renderer = new THREE.WebGLRenderer();
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
Expand Down Expand Up @@ -100,8 +100,6 @@

matcap.encoding = THREE.sRGBEncoding;

if ( mesh ) mesh.material.needsUpdate = true;

} );

// model
Expand Down Expand Up @@ -185,18 +183,18 @@

function imgCallback( event ) {

var matcap = mesh.material.matcap;
if ( mesh.material.matcap ) {

matcap.image = event.target;
mesh.material.matcap.dispose();

matcap.needsUpdate = true;
}

API.color = 0xffffff;
mesh.material.color.set( API.color );
mesh.material.matcap = new THREE.Texture( event.target );
mesh.material.matcap.needsUpdate = true;

render();
image.src = mesh.material.matcap.image.src; // corner div

image.src = matcap.image.src; // corner div
render();

}

Expand Down
17 changes: 0 additions & 17 deletions src/materials/MeshMatcapMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,6 @@ function MeshMatcapMaterial( parameters ) {

this.setValues( parameters );

// a matcap is required

if ( this.matcap === null ) {

var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
canvas.width = 1;
canvas.height = 1;

var context = canvas.getContext( '2d' );

context.fillStyle = '#fff';
context.fillRect( 0, 0, 1, 1 );

this.matcap = new THREE.CanvasTexture( canvas );

}

}

MeshMatcapMaterial.prototype = Object.create( Material.prototype );
Expand Down
3 changes: 2 additions & 1 deletion src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ import { WebXRManager } from './webvr/WebXRManager.js';

function WebGLRenderer( parameters ) {

console.log( 'THREE.WebGLRenderer', REVISION );
// console.log( 'THREE.WebGLRenderer', REVISION );
window.dispatchEvent( new CustomEvent( 'three-renderer', { detail: this } ) );

parameters = parameters || {};

Expand Down
11 changes: 9 additions & 2 deletions src/renderers/shaders/ShaderLib/meshmatcap_frag.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,16 @@ void main() {
vec3 y = cross( viewDir, x );
vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5; // 0.495 to remove artifacts caused by undersized matcap disks
vec4 matcapColor = texture2D( matcap, uv );
#ifdef USE_MATCAP
matcapColor = matcapTexelToLinear( matcapColor );
vec4 matcapColor = texture2D( matcap, uv );
matcapColor = matcapTexelToLinear( matcapColor );
#else
vec4 matcapColor = vec4( 1.0 );
#endif
vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;
Expand Down
1 change: 1 addition & 0 deletions src/renderers/webgl/WebGLProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters,
( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',

parameters.map ? '#define USE_MAP' : '',
parameters.matcap ? '#define USE_MATCAP' : '',
parameters.envMap ? '#define USE_ENVMAP' : '',
parameters.envMap ? '#define ' + envMapTypeDefine : '',
parameters.envMap ? '#define ' + envMapModeDefine : '',
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/webgl/WebGLPrograms.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) {
};

var parameterNames = [
"precision", "supportsVertexTextures", "map", "mapEncoding", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
"precision", "supportsVertexTextures", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
"lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "displacementMap", "specularMap",
"roughnessMap", "metalnessMap", "gradientMap",
"alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
Expand Down

0 comments on commit bce9345

Please sign in to comment.