NormalMapNode.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.NormalMapNode = function ( value, scale ) {
  5. THREE.TempNode.call( this, 'v3' );
  6. this.value = value;
  7. this.scale = scale || new THREE.Vector2Node( 1, 1 );
  8. };
  9. THREE.NormalMapNode.prototype = Object.create( THREE.TempNode.prototype );
  10. THREE.NormalMapNode.prototype.constructor = THREE.NormalMapNode;
  11. THREE.NormalMapNode.prototype.nodeType = "NormalMap";
  12. THREE.NormalMapNode.prototype.generate = function ( builder, output ) {
  13. var material = builder.material;
  14. if ( builder.isShader( 'fragment' ) ) {
  15. builder.include( 'perturbNormal2Arb' );
  16. this.normal = this.normal || new THREE.NormalNode( THREE.NormalNode.VIEW );
  17. this.position = this.position || new THREE.PositionNode( THREE.NormalNode.VIEW );
  18. this.uv = this.uv || new THREE.UVNode();
  19. return builder.format( 'perturbNormal2Arb( -' + this.position.build( builder, 'v3' ) + ', ' +
  20. this.normal.build( builder, 'v3' ) + ', ' +
  21. this.value.build( builder, 'v3' ) + ', ' +
  22. this.uv.build( builder, 'v2' ) + ', ' +
  23. this.scale.build( builder, 'v2' ) + ' )', this.getType( builder ), output );
  24. } else {
  25. console.warn( "THREE.NormalMapNode is not compatible with " + builder.shader + " shader." );
  26. return builder.format( 'vec3( 0.0 )', this.getType( builder ), output );
  27. }
  28. };
  29. THREE.NormalMapNode.prototype.copy = function ( source ) {
  30. THREE.GLNode.prototype.copy.call( this, source );
  31. this.value = source.value;
  32. this.scale = source.scale;
  33. };
  34. THREE.NormalMapNode.prototype.toJSON = function ( meta ) {
  35. var data = this.getJSONNode( meta );
  36. if ( ! data ) {
  37. data = this.createJSONNode( meta );
  38. data.value = this.value.toJSON( meta ).uuid;
  39. data.scale = this.scale.toJSON( meta ).uuid;
  40. }
  41. return data;
  42. };