RoughnessToBlinnExponentNode.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.RoughnessToBlinnExponentNode = function() {
  5. THREE.TempNode.call( this, 'fv1', { unique: true } );
  6. };
  7. THREE.RoughnessToBlinnExponentNode.prototype = Object.create( THREE.TempNode.prototype );
  8. THREE.RoughnessToBlinnExponentNode.prototype.constructor = THREE.RoughnessToBlinnExponentNode;
  9. THREE.RoughnessToBlinnExponentNode.prototype.generate = function( builder, output ) {
  10. var material = builder.material;
  11. if ( builder.isShader( 'fragment' ) ) {
  12. if ( material.isDefined( 'STANDARD' ) ) {
  13. material.addFragmentNode( 'float specularMIPLevel = GGXRoughnessToBlinnExponent( 1.0 - material.specularRoughness );' );
  14. }
  15. else {
  16. console.warn( "THREE.RoughnessToBlinnExponentNode is compatible with StandardMaterial only" );
  17. material.addFragmentNode( 'float specularMIPLevel = 0.0;' );
  18. }
  19. return builder.format( 'specularMIPLevel', this.type, output );
  20. }
  21. else {
  22. console.warn( "THREE.RoughnessToBlinnExponentNode is not compatible with " + builder.shader + " shader" );
  23. return builder.format( '0.0', this.type, output );
  24. }
  25. };