ScreenUVNode.js 1020 B

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