Skip to content
Snippets Groups Projects
Select Git revision
  • 8d65ccabd2a8a1b1d349933e7d680574e64afb9c
  • master default protected
  • rednatco-v2
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • servers
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

direct-volume.ts

Blame
  • direct-volume.ts 2.99 KiB
    /**
     * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author Alexander Rose <alexander.rose@weirdbyte.de>
     */
    
    import { Renderable, RenderableState, createRenderable } from '../renderable';
    import { WebGLContext } from '../webgl/context';
    import { createGraphicsRenderItem } from '../webgl/render-item';
    import { AttributeSpec, Values, UniformSpec, GlobalUniformSchema, InternalSchema, TextureSpec, ElementsSpec, DefineSpec, InternalValues, GlobalTextureSchema, BaseSchema } from './schema';
    import { DirectVolumeShaderCode } from '../shader-code';
    import { ValueCell } from '../../mol-util';
    
    export const DirectVolumeSchema = {
        ...BaseSchema,
    
        aPosition: AttributeSpec('float32', 3, 0),
        elements: ElementsSpec('uint32'),
    
        uColor: UniformSpec('v3'),
        uColorTexDim: UniformSpec('v2'),
        tColor: TextureSpec('image-uint8', 'rgb', 'ubyte', 'nearest'),
        dColorType: DefineSpec('string', ['uniform', 'attribute', 'instance', 'group', 'groupInstance', 'vertex', 'vertexInstance']),
    
        uIsoValue: UniformSpec('v2'),
        uBboxMin: UniformSpec('v3'),
        uBboxMax: UniformSpec('v3'),
        uBboxSize: UniformSpec('v3'),
        uMaxSteps: UniformSpec('i'),
        uStepScale: UniformSpec('f'),
        uJumpLength: UniformSpec('f'),
        uTransform: UniformSpec('m4'),
        uGridDim: UniformSpec('v3'),
        dRenderMode: DefineSpec('string', ['isosurface', 'volume']),
        dSingleLayer: DefineSpec('boolean'),
        tTransferTex: TextureSpec('image-uint8', 'rgba', 'ubyte', 'linear'),
        uTransferScale: UniformSpec('f'),
    
        dGridTexType: DefineSpec('string', ['2d', '3d']),
        uGridTexDim: UniformSpec('v3'),
        tGridTex: TextureSpec('texture', 'rgba', 'ubyte', 'linear'),
        uGridStats: UniformSpec('v4'), // [min, max, mean, sigma]
    
        uCellDim: UniformSpec('v3'),
        uCartnToUnit: UniformSpec('m4'),
        uUnitToCartn: UniformSpec('m4'),
        dPackedGroup: DefineSpec('boolean'),
    
        dDoubleSided: DefineSpec('boolean'),
        dFlipSided: DefineSpec('boolean'),
        dFlatShaded: DefineSpec('boolean'),
        dIgnoreLight: DefineSpec('boolean'),
        dXrayShaded: DefineSpec('boolean'),
    };
    export type DirectVolumeSchema = typeof DirectVolumeSchema
    export type DirectVolumeValues = Values<DirectVolumeSchema>
    
    export function DirectVolumeRenderable(ctx: WebGLContext, id: number, values: DirectVolumeValues, state: RenderableState, materialId: number): Renderable<DirectVolumeValues> {
        const schema = { ...GlobalUniformSchema, ...GlobalTextureSchema, ...InternalSchema, ...DirectVolumeSchema };
        if (!ctx.isWebGL2) {
            // workaround for webgl1 limitation that loop counters need to be `const`
            (schema.uMaxSteps as any) = DefineSpec('number');
        }
        const internalValues: InternalValues = {
            uObjectId: ValueCell.create(id),
        };
        const shaderCode = DirectVolumeShaderCode;
        const renderItem = createGraphicsRenderItem(ctx, 'triangles', shaderCode, schema, { ...values, ...internalValues }, materialId);
        return createRenderable(renderItem, values, state);
    }