ScreenUVNode.js 1.2 KB

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