ScreenUVNode.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. import { TempNode } from '../core/TempNode.js';
  5. import { ResolutionNode } from './ResolutionNode.js';
  6. function ScreenUVNode( resolution ) {
  7. TempNode.call( this, 'v2' );
  8. this.resolution = resolution || new ResolutionNode();
  9. }
  10. ScreenUVNode.prototype = Object.create( TempNode.prototype );
  11. ScreenUVNode.prototype.constructor = ScreenUVNode;
  12. ScreenUVNode.prototype.nodeType = "ScreenUV";
  13. ScreenUVNode.prototype.generate = function ( builder, output ) {
  14. var result;
  15. if ( builder.isShader( 'fragment' ) ) {
  16. result = '( gl_FragCoord.xy / ' + this.resolution.build( builder, 'v2' ) + ')';
  17. } else {
  18. console.warn( "THREE.ScreenUVNode is not compatible with " + builder.shader + " shader." );
  19. result = 'vec2( 0.0 )';
  20. }
  21. return builder.format( result, this.getType( builder ), output );
  22. };
  23. ScreenUVNode.prototype.copy = function ( source ) {
  24. TempNode.prototype.copy.call( this, source );
  25. this.resolution = source.resolution;
  26. };
  27. ScreenUVNode.prototype.toJSON = function ( meta ) {
  28. var data = this.getJSONNode( meta );
  29. if ( ! data ) {
  30. data = this.createJSONNode( meta );
  31. data.resolution = this.resolution.toJSON( meta ).uuid;
  32. }
  33. return data;
  34. };
  35. export { ScreenUVNode };