当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ShaderBuilder.addFragmentCode方法代码示例

本文整理汇总了TypeScript中neuroglancer/webgl/shader.ShaderBuilder.addFragmentCode方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ShaderBuilder.addFragmentCode方法的具体用法?TypeScript ShaderBuilder.addFragmentCode怎么用?TypeScript ShaderBuilder.addFragmentCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在neuroglancer/webgl/shader.ShaderBuilder的用法示例。


在下文中一共展示了ShaderBuilder.addFragmentCode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: defineShader

  defineShader(builder: ShaderBuilder) {
    super.defineShader(builder);
    let {textureAccessHelper} = this;
    builder.addFragmentCode(
        textureAccessHelper.getAccessor('readVolumeData', 'uVolumeChunkSampler', this.dataType));

    let {numChannels} = this;
    if (numChannels > 1) {
      builder.addUniform('highp int', 'uChannelStride');
      builder.addFragmentCode(`
highp int getChannelOffset(highp int channelIndex) {
  return channelIndex * uChannelStride;
}
`);
    } else {
      builder.addFragmentCode(`highp int getChannelOffset(highp int channelIndex) { return 0; }`);
    }
    const shaderType = getShaderType(this.dataType);
    builder.addFragmentCode(`
${shaderType} getDataValue (highp int channelIndex) {
  highp ivec3 p = getPositionWithinChunk();
  return readVolumeData(ivec3(p.x, p.y, p.z + getChannelOffset(channelIndex)));
}
`);
  }
开发者ID:google,项目名称:neuroglancer,代码行数:25,代码来源:uncompressed_chunk_format.ts

示例2: defineShader

  defineShader(builder: ShaderBuilder) {
    super.defineShader(builder);
    let {textureAccessHelper} = this;
    textureAccessHelper.defineShader(builder);
    builder.addFragmentCode(
        textureAccessHelper.getAccessor('readVolumeData', 'uVolumeChunkSampler', this.dataType));

    let {numChannels} = this;
    if (numChannels > 1) {
      builder.addUniform('highp float', 'uChannelStride');
      builder.addFragmentCode(`
float getChannelOffset(int channelIndex) {
  return float(channelIndex) * uChannelStride;
}
`);
    } else {
      builder.addFragmentCode(`float getChannelOffset(int channelIndex) { return 0.0; }`);
    }

    builder.addFragmentCode(`
float getIndexIntoChunk (int channelIndex) {
  vec3 chunkDataPosition = getPositionWithinChunk();
  return chunkDataPosition.x + uChunkDataSize.x * (chunkDataPosition.y + uChunkDataSize.y * chunkDataPosition.z) + getChannelOffset(channelIndex);
}
`);
    const shaderType = getShaderType(this.dataType);
    builder.addFragmentCode(`
${shaderType} getDataValue (int channelIndex) {
  return readVolumeData(getIndexIntoChunk(channelIndex));
}
`);
  }
开发者ID:stephenplaza,项目名称:neuroglancer,代码行数:32,代码来源:uncompressed_chunk_format.ts

示例3: ShaderBuilder

      `elementWiseTextureShader:${numTextures}:${getObjectId(shaderModule)}`, () => {
        let builder = new ShaderBuilder(gl);
        builder.addVarying('vec2', 'vTexCoord');
        builder.addUniform('sampler2D', 'uSampler', numTextures);
        builder.addInitializer(shader => {
          let textureIndices: number[] = [];
          for (let i = 0; i < numTextures; ++i) {
            textureIndices[i] = i;
          }
          gl.uniform1iv(shader.uniform('uSampler'), textureIndices);
        });
        for (let i = 0; i < numTextures; ++i) {
          builder.addFragmentCode(`
vec4 getValue${i}() {
  return texture2D(uSampler[${i}], vTexCoord);
}
`);
        }
        builder.addUniform('mat4', 'uProjectionMatrix');
        builder.require(shaderModule);
        builder.addAttribute('vec4', 'aVertexPosition');
        builder.addAttribute('vec2', 'aTexCoord');
        builder.setVertexMain(
            'vTexCoord = aTexCoord; gl_Position = uProjectionMatrix * aVertexPosition;');
        return builder.build();
      });
开发者ID:janelia-flyem,项目名称:neuroglancer,代码行数:26,代码来源:trivial_shaders.ts

示例4: defineShader

  protected defineShader(builder: ShaderBuilder) {
    super.defineShader(builder);
    builder.addUniform('highp float', 'uOpacity');
    builder.addFragmentCode(`
void emitRGBA(vec4 rgba) {
  emit(vec4(rgba.rgb, rgba.a * uOpacity));
}
void emitRGB(vec3 rgb) {
  emit(vec4(rgb, uOpacity));
}
void emitGrayscale(float value) {
  emit(vec4(value, value, value, uOpacity));
}
void emitTransparent() {
  emit(vec4(0.0, 0.0, 0.0, 0.0));
}
`);
    builder.addFragmentCode(glsl_COLORMAPS);
    builder.setFragmentMainFunction(FRAGMENT_MAIN_START + '\n' + this.fragmentMain.value);
  }
开发者ID:google,项目名称:neuroglancer,代码行数:20,代码来源:image_renderlayer.ts

示例5: defineShader

  defineShader(builder: ShaderBuilder) {
    super.defineShader(builder);
    builder.addUniform('highp vec3', 'uChunkDataSize');

    // [ 1.0/dataPointsPerTextureWidth, 1.0/numDataPoints ]
    builder.addUniform('highp vec2', 'uUncompressedTextureAccessCoefficients');
    builder.addFragmentCode(`
vec3 getPositionWithinChunk () {
  return floor(min(vChunkPosition * uChunkDataSize, uChunkDataSize - 1.0));
}
vec2 getDataTextureCoords () {
  vec3 chunkDataPosition = getPositionWithinChunk();
  float offset = chunkDataPosition.x + uChunkDataSize.x * (chunkDataPosition.y + uChunkDataSize.y * chunkDataPosition.z);
  return vec2(fract(offset * uUncompressedTextureAccessCoefficients.x),
              offset * uUncompressedTextureAccessCoefficients.y);
}
`);
    switch (this.dataType) {
      case DataType.UINT8:
      case DataType.FLOAT32:
        builder.addFragmentCode(`
float getDataValue () {
  return texture2D(uVolumeChunkSampler, getDataTextureCoords()).x;
}
`);
        break;
      case DataType.UINT32:
        builder.addFragmentCode(glsl_uint64);
        builder.addFragmentCode(`
uint64_t getDataValue () {
  uint64_t value;
  vec2 texCoords = getDataTextureCoords();
  value.low = texture2D(uVolumeChunkSampler, texCoords);
  value.high = vec4(0, 0, 0, 0);
  return value;
}
`);
        break;
      case DataType.UINT64:
        builder.addFragmentCode(glsl_uint64);
        builder.addFragmentCode(`
uint64_t getDataValue () {
  uint64_t value;
  vec2 texCoords = getDataTextureCoords();
  value.low = texture2D(uVolumeChunkSampler, texCoords);
  value.high = texture2D(uVolumeChunkSampler, vec2(texCoords.x + 0.5 * uUncompressedTextureAccessCoefficients.x, texCoords.y));
  return value;
}
`);
        break;
    }
  }
开发者ID:j6k4m8,项目名称:neuroglancer,代码行数:52,代码来源:uncompressed_chunk_format.ts

示例6: defineShader

  defineShader(builder: ShaderBuilder) {
    builder.addUniform('highp vec4', 'uColor');
    builder.addUniform('highp vec4', 'uColorSelected');
    builder.addUniform('highp uint', 'uSelectedIndex');
    builder.addVarying('highp vec4', 'vColor');
    // Transform from camera to clip coordinates.
    builder.addUniform('highp mat4', 'uProjection');
    builder.addUniform('highp uint', 'uPickID');
    builder.addVarying('highp uint', 'vPickID', 'flat');

    builder.addVertexCode(`
highp uint getPickBaseOffset() { return uint(gl_InstanceID) * ${this.pickIdsPerInstance}u; }
`);

    builder.addFragmentCode(`
void emitAnnotation(vec4 color) {
  emit(color, vPickID);
}
`);
  }
开发者ID:google,项目名称:neuroglancer,代码行数:20,代码来源:type_handler.ts

示例7: defineShader

  defineShader(builder: ShaderBuilder) {
    super.defineShader(builder);
    this.textureAccessHelper.defineShader(builder);
    let local = (x: string) => 'compressedSegmentationChunkFormat_' + x;
    builder.addUniform('highp vec3', 'uSubchunkGridSize');
    builder.addUniform('highp vec3', 'uSubchunkSize');
    builder.addFragmentCode(glsl_getFortranOrderIndexFromNormalized);
    const {dataType} = this;
    const glslType = GLSL_TYPE_FOR_DATA_TYPE.get(dataType);

    if (dataType === DataType.UINT64) {
      builder.addFragmentCode(glsl_uint64);
    } else {
      builder.addFragmentCode(glsl_uint32);
    }

    let fragmentCode = `
vec4 ${local('readTextureValue')}(float offset) {
  vec4 result;
  ${this.textureAccessHelper.readTextureValue}(uVolumeChunkSampler, offset, result);
  return result;
}
float ${local('getChannelOffset')}(int channelIndex) {
  if (channelIndex == 0) {
    return ${this.numChannels}.0;
  }
  vec4 v = ${local('readTextureValue')}(float(channelIndex));
  return v.x * 255.0 + v.y * 255.0 * 256.0 + v.z * 255.0 * 256.0 * 256.0;
}
${glslType} getDataValue (int channelIndex) {
  vec3 chunkPosition = getPositionWithinChunk();

  // TODO: maybe premultiply this and store as uniform.
  vec3 subchunkGridPosition = floor(chunkPosition / uSubchunkSize);
  float subchunkGridOffset = getFortranOrderIndex(subchunkGridPosition, uSubchunkGridSize);

  float channelOffset = ${local('getChannelOffset')}(channelIndex);

  // TODO: Maybe just combine this offset into subchunkGridStrides.
  float subchunkHeaderOffset = subchunkGridOffset * 2.0 + channelOffset;

  vec4 subchunkHeader0 = ${local('readTextureValue')}(subchunkHeaderOffset);
  vec4 subchunkHeader1 = ${local('readTextureValue')}(subchunkHeaderOffset + 1.0);

  float outputValueOffset = dot(subchunkHeader0.xyz, vec3(255, 256 * 255, 256 * 256 * 255)) + channelOffset;
  float encodingBits = subchunkHeader0[3] * 255.0;
  if (encodingBits > 0.0) {
    vec3 subchunkPosition = floor(min(chunkPosition - subchunkGridPosition * uSubchunkSize, uSubchunkSize - 1.0));
    float subchunkOffset = getFortranOrderIndex(subchunkPosition, uSubchunkSize);
    highp float encodedValueBaseOffset = dot(subchunkHeader1.xyz, vec3(255.0, 256.0 * 255.0, 256.0 * 256.0 * 255.0)) + channelOffset;
    highp float encodedValueOffset = floor(encodedValueBaseOffset + subchunkOffset * encodingBits / 32.0);
    vec4 encodedValue = ${local('readTextureValue')}(encodedValueOffset);
    float wordOffset = mod(subchunkOffset * encodingBits, 32.0);
    // If the value is in the first byte, then 0 <= wordOffset < 8.
    // We need to mod by 2**encodedBits
    float wordShifter = pow(2.0, -wordOffset);
    float encodedValueMod = pow(2.0, encodingBits);
    float encodedValueShifted;
    if (wordOffset < 16.0) {
      encodedValueShifted = dot(encodedValue.xy, vec2(255.0, 255.0 * 256.0));
    } else {
      encodedValueShifted = dot(encodedValue.zw, vec2(255.0 * 256.0 * 256.0, 255.0 * 256.0 * 256.0 * 256.0));
    }
    encodedValueShifted = floor(encodedValueShifted * wordShifter);
    float decodedValue = mod(encodedValueShifted, encodedValueMod);
    outputValueOffset += decodedValue * ${this.dataType === DataType.UINT64 ? '2.0' : '1.0'};
  }
  ${glslType} result;
`;
    if (dataType === DataType.UINT64) {
      fragmentCode += `
  result.low = ${local('readTextureValue')}(outputValueOffset);
  result.high = ${local('readTextureValue')}(outputValueOffset+1.0);
`;
    } else {
      fragmentCode += `
  result.value = ${local('readTextureValue')}(outputValueOffset);
`;
    }
    fragmentCode += `
  return result;
}
`;
    builder.addFragmentCode(fragmentCode);
  }
开发者ID:funkey,项目名称:neuroglancer,代码行数:85,代码来源:chunk_format.ts

示例8: defineShader

  defineShader(builder: ShaderBuilder) {
    super.defineShader(builder);
    this.textureAccessHelper.defineShader(builder);

    let {numChannels} = this;
    if (numChannels > 1) {
      builder.addUniform('highp float', 'uChannelStride');
      builder.addFragmentCode(`
float getChannelOffset(int channelIndex) {
  return float(channelIndex) * uChannelStride;
}
`);
    } else {
      builder.addFragmentCode(`float getChannelOffset(int channelIndex) { return 0.0; }`);
    }

    builder.addFragmentCode(`
float getIndexIntoChunk (int channelIndex) {
  vec3 chunkDataPosition = getPositionWithinChunk();
  return chunkDataPosition.x + uChunkDataSize.x * (chunkDataPosition.y + uChunkDataSize.y * chunkDataPosition.z) + getChannelOffset(channelIndex);
}
`);
    switch (this.dataType) {
      case DataType.UINT8:
        builder.addFragmentCode(glsl_uint8);
        builder.addFragmentCode(`
uint8_t getDataValue (int channelIndex) {
  uint8_t result;
  vec4 temp;
  ${this.textureAccessHelper.readTextureValue}(uVolumeChunkSampler, getIndexIntoChunk(channelIndex), temp);
  result.value = temp.x;
  return result;
}
`);
        break;
      case DataType.FLOAT32:
        builder.addFragmentCode(glsl_float);
        builder.addFragmentCode(`
float getDataValue (int channelIndex) {
  vec4 temp;
  ${this.textureAccessHelper.readTextureValue}(uVolumeChunkSampler, getIndexIntoChunk(channelIndex), temp);
  return temp.x;
}
`);
        break;
      case DataType.UINT16:
        builder.addFragmentCode(glsl_uint16);
        builder.addFragmentCode(`
uint16_t getDataValue (int channelIndex) {
  uint16_t result;
  vec4 temp;
  ${this.textureAccessHelper.readTextureValue}(uVolumeChunkSampler, getIndexIntoChunk(channelIndex), temp);
  result.value = temp.xw;
  return result;
}
`);
        break;
      case DataType.UINT32:
        builder.addFragmentCode(glsl_uint32);
        builder.addFragmentCode(`
uint32_t getDataValue (int channelIndex) {
  uint32_t result;
  ${this.textureAccessHelper.readTextureValue}(uVolumeChunkSampler, getIndexIntoChunk(channelIndex), result.value);
  return result;
}
`);
        break;
      case DataType.UINT64:
        builder.addFragmentCode(glsl_uint64);
        builder.addFragmentCode(`
uint64_t getDataValue (int channelIndex) {
  uint64_t result;
  ${this.textureAccessHelper.readTextureValue}(uVolumeChunkSampler, getIndexIntoChunk(channelIndex), result.low, result.high);
  return result;
}
`);
        break;
    }
  }
开发者ID:funkey,项目名称:neuroglancer,代码行数:79,代码来源:uncompressed_chunk_format.ts

示例9: defineShader

  defineShader(builder: ShaderBuilder) {
    super.defineShader(builder);
    let local = (x: string) => 'compressedSegmentationChunkFormat_' + x;
    builder.addUniform('highp vec2', 'uCompressedSegmentationTextureAccessCoefficients');
    builder.addUniform('highp vec3', 'uSubchunkGridSize');
    builder.addUniform('highp vec3', 'uChunkDataSize');
    builder.addFragmentCode(glsl_getFortranOrderIndexFromNormalized);
    builder.addFragmentCode(glsl_uint64);
    // We add 0.5 to avoid being right at a texel boundary.
    let fragmentCode = `
vec4 ${local('readTextureValue')}(float offset) {
  offset += 0.5;
  return texture2D(uVolumeChunkSampler,
                   vec2(fract(offset * uCompressedSegmentationTextureAccessCoefficients.x),
                        offset * uCompressedSegmentationTextureAccessCoefficients.y));
}
uint64_t getDataValue () {
  const vec3 uSubchunkSize = ${vec3.str(this.subchunkSize)};

  vec3 chunkPosition = getSubscriptsFromNormalized(vChunkPosition, uChunkDataSize);

  // TODO: maybe premultiply this and store as uniform.
  vec3 subchunkGridPosition = floor(chunkPosition / uSubchunkSize);
  float subchunkGridOffset = getFortranOrderIndex(subchunkGridPosition, uSubchunkGridSize);

  // TODO: Maybe just combine this offset into subchunkGridStrides.
  float subchunkHeaderOffset = subchunkGridOffset * 2.0;

  vec4 subchunkHeader0 = ${local('readTextureValue')}(subchunkHeaderOffset);
  vec4 subchunkHeader1 = ${local('readTextureValue')}(subchunkHeaderOffset + 1.0);

  float outputValueOffset = dot(subchunkHeader0.xyz, vec3(255, 256 * 255, 256 * 256 * 255));
  float encodingBits = subchunkHeader0[3] * 255.0;
  if (encodingBits > 0.0) {
    vec3 subchunkPosition = floor(min(chunkPosition - subchunkGridPosition * uSubchunkSize, uSubchunkSize - 1.0));
    float subchunkOffset = getFortranOrderIndex(subchunkPosition, uSubchunkSize);
    highp float encodedValueBaseOffset = dot(subchunkHeader1.xyz, vec3(255.0, 256.0 * 255.0, 256.0 * 256.0 * 255.0));
    highp float encodedValueOffset = floor(encodedValueBaseOffset + subchunkOffset * encodingBits / 32.0);
    vec4 encodedValue = ${local('readTextureValue')}(encodedValueOffset);
    float wordOffset = mod(subchunkOffset * encodingBits, 32.0);
    // If the value is in the first byte, then 0 <= wordOffset < 8.
    // We need to mod by 2**encodedBits
    float wordShifter = pow(2.0, -wordOffset);
    float encodedValueMod = pow(2.0, encodingBits);
    float encodedValueShifted;
    if (wordOffset < 16.0) {
      encodedValueShifted = dot(encodedValue.xy, vec2(255.0, 255.0 * 256.0));
    } else {
      encodedValueShifted = dot(encodedValue.zw, vec2(255.0 * 256.0 * 256.0, 255.0 * 256.0 * 256.0 * 256.0));
    }
    encodedValueShifted = floor(encodedValueShifted * wordShifter);
    float decodedValue = mod(encodedValueShifted, encodedValueMod);
    outputValueOffset += decodedValue * ${this.dataType === DataType.UINT64 ? '2.0' : '1.0'};
  }
  uint64_t value;
  value.low = ${local('readTextureValue')}(outputValueOffset);
`;
    if (this.dataType === DataType.UINT64) {
      fragmentCode += `
  value.high = ${local('readTextureValue')}(outputValueOffset+1.0);
`;
    } else {
      fragmentCode += `
  value.high = vec4(0.0, 0.0, 0.0, 0.0);
`;
    }
    fragmentCode += `
  return value;
}
`;
    builder.addFragmentCode(fragmentCode);
  }
开发者ID:j6k4m8,项目名称:neuroglancer,代码行数:72,代码来源:chunk_format.ts

示例10: defineShader

  defineShader(builder: ShaderBuilder) {
    super.defineShader(builder);
    let {textureAccessHelper} = this;
    textureAccessHelper.defineShader(builder);
    let local = (x: string) => 'compressedSegmentationChunkFormat_' + x;
    builder.addUniform('highp ivec3', 'uSubchunkGridSize');
    builder.addUniform('highp ivec3', 'uSubchunkSize');
    builder.addFragmentCode(glsl_getFortranOrderIndex);
    const {dataType} = this;
    const glslType = getShaderType(dataType);

    if (dataType === DataType.UINT64) {
      builder.addFragmentCode(glsl_uint64);
    } else {
      builder.addFragmentCode(glsl_uint32);
    }
    builder.addFragmentCode(textureAccessHelper.getAccessor(
        local('readTextureValue'), 'uVolumeChunkSampler', DataType.UINT32, 1));
    let fragmentCode = `
uint ${local('getChannelOffset')}(int channelIndex) {
  if (channelIndex == 0) {
    return ${this.numChannels}u;
  }
  return ${local('readTextureValue')}(uint(channelIndex)).value;
}
${glslType} getDataValue (int channelIndex) {
  ivec3 chunkPosition = getPositionWithinChunk();

  // TODO: maybe premultiply this and store as uniform.
  ivec3 subchunkGridPosition = chunkPosition / uSubchunkSize;
  int subchunkGridOffset = getFortranOrderIndex(subchunkGridPosition, uSubchunkGridSize);

  int channelOffset = int(${local('getChannelOffset')}(channelIndex));

  // TODO: Maybe just combine this offset into subchunkGridStrides.
  int subchunkHeaderOffset = subchunkGridOffset * 2 + channelOffset;

  highp uint subchunkHeader0 = ${local('readTextureValue')}(uint(subchunkHeaderOffset)).value;
  highp uint subchunkHeader1 = ${local('readTextureValue')}(uint(subchunkHeaderOffset + 1)).value;
  highp uint outputValueOffset = (subchunkHeader0 & 0xFFFFFFu) + uint(channelOffset);
  highp uint encodingBits = subchunkHeader0 >> 24u;
  if (encodingBits > 0u) {
    ivec3 subchunkPosition = chunkPosition - subchunkGridPosition * uSubchunkSize;
    int subchunkOffset = getFortranOrderIndex(subchunkPosition, uSubchunkSize);
    uint encodedValueBaseOffset = subchunkHeader1 + uint(channelOffset);
    uint encodedValueOffset = encodedValueBaseOffset + uint(subchunkOffset) * encodingBits / 32u;
    uint encodedValue = ${local('readTextureValue')}(encodedValueOffset).value;
    uint wordOffset = uint(subchunkOffset) * encodingBits % 32u;
    uint encodedValueShifted = encodedValue >> wordOffset;
    uint decodedValue = encodedValueShifted - (encodedValueShifted >> encodingBits << encodingBits);
    outputValueOffset += decodedValue * ${this.dataType === DataType.UINT64 ? '2u' : '1u'};
  }
  ${glslType} result;
`;
    if (dataType === DataType.UINT64) {
      fragmentCode += `
  result.value[0] = ${local('readTextureValue')}(outputValueOffset).value;
  result.value[1] = ${local('readTextureValue')}(outputValueOffset+1u).value;
`;
    } else {
      fragmentCode += `
  result.value = ${local('readTextureValue')}(outputValueOffset).value;
`;
    }
    fragmentCode += `
  return result;
}
`;
    builder.addFragmentCode(fragmentCode);
  }
开发者ID:google,项目名称:neuroglancer,代码行数:70,代码来源:chunk_format.ts


注:本文中的neuroglancer/webgl/shader.ShaderBuilder.addFragmentCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。