direct-volume.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { Renderable, RenderableState, createRenderable } from '../renderable'
  7. import { WebGLContext } from '../webgl/context';
  8. import { createRenderItem } from '../webgl/render-item';
  9. import { AttributeSpec, Values, UniformSpec, GlobalUniformSchema, InternalSchema, TextureSpec, ValueSpec, ElementsSpec, DefineSpec, InternalValues } from './schema';
  10. import { DirectVolumeShaderCode } from '../shader-code';
  11. import { ValueCell } from 'mol-util';
  12. export const DirectVolumeSchema = {
  13. uColor: UniformSpec('v3'),
  14. uColorTexDim: UniformSpec('v2'),
  15. tColor: TextureSpec('image-uint8', 'rgb', 'ubyte', 'nearest'),
  16. dColorType: DefineSpec('string', ['uniform', 'instance', 'group', 'group_instance']),
  17. uMarkerTexDim: UniformSpec('v2'),
  18. tMarker: TextureSpec('image-uint8', 'alpha', 'ubyte', 'nearest'),
  19. uInstanceCount: UniformSpec('i'),
  20. uGroupCount: UniformSpec('i'),
  21. aInstance: AttributeSpec('float32', 1, 1),
  22. aTransform: AttributeSpec('float32', 16, 1),
  23. drawCount: ValueSpec('number'),
  24. instanceCount: ValueSpec('number'),
  25. transform: AttributeSpec('float32', 16, 1),
  26. boundingSphere: ValueSpec('sphere'),
  27. invariantBoundingSphere: ValueSpec('sphere'),
  28. aPosition: AttributeSpec('float32', 3, 0),
  29. elements: ElementsSpec('uint32'),
  30. uAlpha: UniformSpec('f'),
  31. uHighlightColor: UniformSpec('v3'),
  32. uSelectColor: UniformSpec('v3'),
  33. dUseFog: DefineSpec('boolean'),
  34. uIsoValue: UniformSpec('f'),
  35. uBboxMin: UniformSpec('v3'),
  36. uBboxMax: UniformSpec('v3'),
  37. uBboxSize: UniformSpec('v3'),
  38. dMaxSteps: DefineSpec('number'),
  39. uTransform: UniformSpec('m4'),
  40. uGridDim: UniformSpec('v3'),
  41. dRenderMode: DefineSpec('string', ['isosurface', 'volume']),
  42. tTransferTex: TextureSpec('image-uint8', 'rgba', 'ubyte', 'linear'),
  43. dGridTexType: DefineSpec('string', ['2d', '3d']),
  44. uGridTexDim: UniformSpec('v3'),
  45. tGridTex: TextureSpec('texture', 'rgba', 'ubyte', 'linear'),
  46. }
  47. export type DirectVolumeSchema = typeof DirectVolumeSchema
  48. export type DirectVolumeValues = Values<DirectVolumeSchema>
  49. export function DirectVolumeRenderable(ctx: WebGLContext, id: number, values: DirectVolumeValues, state: RenderableState): Renderable<DirectVolumeValues> {
  50. const schema = { ...GlobalUniformSchema, ...InternalSchema, ...DirectVolumeSchema }
  51. const internalValues: InternalValues = {
  52. uObjectId: ValueCell.create(id),
  53. uPickable: ValueCell.create(state.pickable ? 1 : 0)
  54. }
  55. const shaderCode = DirectVolumeShaderCode
  56. const renderItem = createRenderItem(ctx, 'triangles', shaderCode, schema, { ...values, ...internalValues })
  57. const renderable = createRenderable(renderItem, values, state);
  58. return renderable
  59. }