ScreenUVNode.js 1.2 KB

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