Home Reference Source Repository

js/SceneKit/SCNShadable.js

  1. 'use strict'
  2.  
  3. //import SCNProgram from './SCNProgram'
  4. //import SCNShaderModifierEntryPoint from './SCNShaderModifierEntryPoint'
  5. //import SCNBindingBlock from './SCNBindingBlock'
  6.  
  7.  
  8. /**
  9. * Methods for customizing SceneKit's rendering of geometry and materials using Metal or OpenGL shader programs.
  10. * @interface
  11. * @see https://developer.apple.com/documentation/scenekit/scnshadable
  12. */
  13. export default class SCNShadable {
  14.  
  15. /**
  16. * constructor
  17. * @access public
  18. * @returns {void}
  19. */
  20. init() {
  21.  
  22. // Assigning a Custom Shader Program
  23.  
  24. /**
  25. * A program used when rendering the object.
  26. * @type {?SCNProgram}
  27. * @see https://developer.apple.com/documentation/scenekit/scnshadable/1523689-program
  28. */
  29. this.program = null
  30.  
  31.  
  32. // Customizing SceneKit’s Shader Programs
  33.  
  34. /**
  35. * A dictionary of GLSL source code snippets for customizing the shader programs provided by SceneKit.
  36. * @type {?Map<SCNShaderModifierEntryPoint, string>}
  37. * @see https://developer.apple.com/documentation/scenekit/scnshadable/1523348-shadermodifiers
  38. */
  39. this.shaderModifiers = null
  40.  
  41. }
  42.  
  43. // Handling Parameters in Custom OpenGL Shader Programs
  44.  
  45. /**
  46. * Specifies a block to be called before rendering with programs with the specified GLSL uniform variable or attribute name.
  47. * @access public
  48. * @param {string} symbol - A GLSL uniform variable or attribute name.
  49. * @param {?SCNBindingBlock} [block = null] - A block to be called by SceneKit.
  50. * @returns {void}
  51. * @desc Use this method to associate a block with a SceneKit object (geometry or material) to handle setup of an attribute or uniform variable in a custom SCNProgram shader associated with that object. SceneKit calls your block before rendering the object. In the block, you can execute any OpenGL commands or other code necessary for preparing your custom shader. For example, the following block updates the time uniform variable in a custom fragment shader for producing animated effects:CFTimeInterval startTime = CFAbsoluteTimeGetCurrent();
  52. [myNode.geometry.firstMaterial handleBindingOfSymbol:@"time" usingBlock:
  53. ^(unsigned int programID, unsigned int location, SCNNode *renderedNode, SCNRenderer *renderer) {
  54. glUniform1f(location, CFAbsoluteTimeGetCurrent() - startTime);
  55. }];
  56. This method is for OpenGL shader programs only. To bind custom variable data for Metal shader programs, use the handleBinding(ofBufferNamed:frequency:handler:) method.CFTimeInterval startTime = CFAbsoluteTimeGetCurrent();
  57. [myNode.geometry.firstMaterial handleBindingOfSymbol:@"time" usingBlock:
  58. ^(unsigned int programID, unsigned int location, SCNNode *renderedNode, SCNRenderer *renderer) {
  59. glUniform1f(location, CFAbsoluteTimeGetCurrent() - startTime);
  60. }];
  61.  
  62. * @see https://developer.apple.com/documentation/scenekit/scnshadable/1523063-handlebinding
  63. */
  64. handleBindingOfSymbolHandler(symbol, block = null) {
  65. }
  66.  
  67. /**
  68. * Specifies a block to be called after rendering with programs with the specified GLSL uniform variable or attribute name.
  69. * @access public
  70. * @param {string} symbol - A GLSL uniform variable or attribute name.
  71. * @param {?SCNBindingBlock} [block = null] - A block to be called by SceneKit.
  72. * @returns {void}
  73. * @desc Use this method to associate a block with a SceneKit object (geometry or material) to handle cleanup related to an attribute or uniform variable in a custom SCNProgram shader associated with that object. SceneKit will call your block after rendering the object. In the block, you can execute any OpenGL commands or other code necessary for post-rendering tasks.This method is for OpenGL shader programs only. To bind custom variable data for Metal shader programs, use the handleBinding(ofBufferNamed:frequency:handler:) method.
  74. * @see https://developer.apple.com/documentation/scenekit/scnshadable/1522783-handleunbinding
  75. */
  76. handleUnbindingOfSymbolHandler(symbol, block = null) {
  77. }
  78. }