ScreenUVNode.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.ScreenUVNode = function ( resolution ) {
  5. THREE.TempNode.call( this, 'v2' );
  6. this.resolution = resolution;
  7. };
  8. THREE.ScreenUVNode.prototype = Object.create( THREE.TempNode.prototype );
  9. THREE.ScreenUVNode.prototype.constructor = THREE.ScreenUVNode;
  10. THREE.ScreenUVNode.prototype.nodeType = "ScreenUV";
  11. THREE.ScreenUVNode.prototype.generate = function ( builder, output ) {
  12. var material = builder.material;
  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. THREE.ScreenUVNode.prototype.toJSON = function ( meta ) {
  23. var data = this.getJSONNode( meta );
  24. if ( ! data ) {
  25. data = this.createJSONNode( meta );
  26. data.resolution = this.resolution.toJSON( meta ).uuid;
  27. }
  28. return data;
  29. };