Uniform.js 976 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Represents a uniform which is a global shader variable. They are passed to shader programs.
  3. *
  4. * When declaring a uniform of a {@link ShaderMaterial}, it is declared by value or by object.
  5. * ```js
  6. * uniforms: {
  7. * time: { value: 1.0 },
  8. * resolution: new Uniform( new Vector2() )
  9. * };
  10. * ```
  11. * Since this class can only be used in context of {@link ShaderMaterial}, it is only supported
  12. * in {@link WebGLRenderer}.
  13. */
  14. class Uniform {
  15. /**
  16. * Constructs a new uniform.
  17. *
  18. * @param {any} value - The uniform value.
  19. */
  20. constructor( value ) {
  21. /**
  22. * The uniform value.
  23. *
  24. * @type {any}
  25. */
  26. this.value = value;
  27. }
  28. /**
  29. * Returns a new uniform with copied values from this instance.
  30. * If the value has a `clone()` method, the value is cloned as well.
  31. *
  32. * @return {Uniform} A clone of this instance.
  33. */
  34. clone() {
  35. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  36. }
  37. }
  38. export { Uniform };
粤ICP备19079148号