NormalMapNode.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.NormalMapNode = function( value, uv, scale, normal, position ) {
  5. THREE.TempNode.call( this, 'v3' );
  6. this.value = value;
  7. this.scale = scale || new THREE.FloatNode( 1 );
  8. this.normal = normal || new THREE.NormalNode( THREE.NormalNode.LOCAL );
  9. this.position = position || new THREE.PositionNode( THREE.NormalNode.VIEW );
  10. };
  11. THREE.NormalMapNode.prototype = Object.create( THREE.TempNode.prototype );
  12. THREE.NormalMapNode.prototype.constructor = THREE.NormalMapNode;
  13. THREE.NormalMapNode.prototype.generate = function( builder, output ) {
  14. var material = builder.material;
  15. builder.include( 'perturbNormal2Arb' );
  16. if ( builder.isShader( 'fragment' ) ) {
  17. return builder.format( 'perturbNormal2Arb(-' + this.position.build( builder, 'v3' ) + ',' +
  18. this.normal.build( builder, 'v3' ) + ',' +
  19. this.value.build( builder, 'v3' ) + ',' +
  20. this.value.coord.build( builder, 'v2' ) + ',' +
  21. this.scale.build( builder, 'v2' ) + ')', this.getType( builder ), output );
  22. } else {
  23. console.warn( "THREE.NormalMapNode is not compatible with " + builder.shader + " shader." );
  24. return builder.format( 'vec3( 0.0 )', this.getType( builder ), output );
  25. }
  26. };