本文整理汇总了TypeScript中neuroglancer/webgl/shader_lib.getShaderType函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getShaderType函数的具体用法?TypeScript getShaderType怎么用?TypeScript getShaderType使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getShaderType函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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));
}
`);
}
示例2: 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)));
}
`);
}
示例3: defineShader
defineShader(builder: ShaderBuilder) {
super.defineShader(builder);
let {textureAccessHelper} = 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 = getShaderType(dataType);
if (dataType === DataType.UINT64) {
builder.addFragmentCode(glsl_uint64);
}
builder.addFragmentCode(textureAccessHelper.getAccessor(
local('readTextureValue'), 'uVolumeChunkSampler', DataType.UINT32));
builder.addFragmentCode(glsl_unnormalizeUint8);
builder.addFragmentCode(glsl_uintleToFloat);
let fragmentCode = `
float ${local('getChannelOffset')}(int channelIndex) {
if (channelIndex == 0) {
return ${this.numChannels}.0;
}
vec4 v = ${local('readTextureValue')}(float(channelIndex)).value;
return uintleToFloat(v.xyz);
}
${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).value;
vec4 subchunkHeader1 = ${local('readTextureValue')}(subchunkHeaderOffset + 1.0).value;
float outputValueOffset = uintleToFloat(subchunkHeader0.xyz) + channelOffset;
float encodingBits = unnormalizeUint8(subchunkHeader0[3]);
if (encodingBits > 0.0) {
vec3 subchunkPosition = floor(min(chunkPosition - subchunkGridPosition * uSubchunkSize, uSubchunkSize - 1.0));
float subchunkOffset = getFortranOrderIndex(subchunkPosition, uSubchunkSize);
highp float encodedValueBaseOffset = uintleToFloat(subchunkHeader1.xyz) + channelOffset;
highp float encodedValueOffset = floor(encodedValueBaseOffset + subchunkOffset * encodingBits / 32.0);
vec4 encodedValue = ${local('readTextureValue')}(encodedValueOffset).value;
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(unnormalizeUint8(encodedValue.xy), vec2(1.0, 256.0));
} else {
encodedValueShifted = dot(unnormalizeUint8(encodedValue.zw), vec2(256.0 * 256.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).value;
result.high = ${local('readTextureValue')}(outputValueOffset+1.0).value;
`;
} else {
fragmentCode += `
result.value = ${local('readTextureValue')}(outputValueOffset).value;
`;
}
fragmentCode += `
return result;
}
`;
builder.addFragmentCode(fragmentCode);
}
示例4: 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);
}