ScreenUVNode.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. return this;
  27. };
  28. ScreenUVNode.prototype.toJSON = function ( meta ) {
  29. var data = this.getJSONNode( meta );
  30. if ( ! data ) {
  31. data = this.createJSONNode( meta );
  32. data.resolution = this.resolution.toJSON( meta ).uuid;
  33. }
  34. return data;
  35. };
  36. export { ScreenUVNode };