Skip to content
Snippets Groups Projects
Commit b0127d74 authored by Alexander Rose's avatar Alexander Rose
Browse files

add bool uniform support

parent 5a66ca69
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@ const AlphaOrbitalsSchema = {
uNAlpha: UniformSpec('i'),
uNCoeff: UniformSpec('i'),
uMaxCoeffs: UniformSpec('i'),
uLittleEndian: UniformSpec('i') // TODO: boolean uniforms
uLittleEndian: UniformSpec('b')
};
const AlphaOrbitalsShaderCode = ShaderCode('postprocessing', quad_vert, shader_frag);
type AlphaOrbitalsRenderable = ComputeRenderable<Values<typeof AlphaOrbitalsSchema>>
......
......@@ -28,7 +28,7 @@ uniform float uWidth;
uniform int uNCoeff;
uniform int uNAlpha;
uniform int uLittleEndian;
uniform bool uLittleEndian;
float shiftRight (float v, float amt) {
v = floor(v) + 0.5;
......@@ -61,7 +61,7 @@ vec4 floatToRgba(float texelFloat) {
float byte2 = (last_bit_of_biased_exponent * 128.0 + extractBits(fraction, 16.0, 23.0)) / 255.0;
float byte1 = (sign * 128.0 + remaining_bits_of_biased_exponent) / 255.0;
return (
uLittleEndian > 0
uLittleEndian
? vec4(byte4, byte3, byte2, byte1)
: vec4(byte1, byte2, byte3, byte4)
);
......
......@@ -129,7 +129,7 @@ export const GlobalUniformSchema = {
uFogFar: UniformSpec('f'),
uFogColor: UniformSpec('v3'),
uTransparentBackground: UniformSpec('i'),
uTransparentBackground: UniformSpec('b'),
uClipObjectType: UniformSpec('i[]'),
uClipObjectPosition: UniformSpec('v3[]'),
......@@ -149,7 +149,7 @@ export const GlobalUniformSchema = {
uPickingAlphaThreshold: UniformSpec('f'),
uInteriorDarkening: UniformSpec('f'),
uInteriorColorFlag: UniformSpec('i'),
uInteriorColorFlag: UniformSpec('b'),
uInteriorColor: UniformSpec('v3'),
uHighlightColor: UniformSpec('v3'),
......
......@@ -203,7 +203,7 @@ namespace Renderer {
uFogNear: ValueCell.create(1),
uFogFar: ValueCell.create(10000),
uFogColor: ValueCell.create(bgColor),
uTransparentBackground: ValueCell.create(0),
uTransparentBackground: ValueCell.create(false),
uClipObjectType: ValueCell.create(clip.objects.type),
uClipObjectPosition: ValueCell.create(clip.objects.position),
......@@ -221,7 +221,7 @@ namespace Renderer {
uPickingAlphaThreshold: ValueCell.create(p.pickingAlphaThreshold),
uInteriorDarkening: ValueCell.create(p.interiorDarkening),
uInteriorColorFlag: ValueCell.create(p.interiorColorFlag ? 1 : 0),
uInteriorColorFlag: ValueCell.create(p.interiorColorFlag),
uInteriorColor: ValueCell.create(Color.toVec3Normalized(Vec3(), p.interiorColor)),
uHighlightColor: ValueCell.create(Color.toVec3Normalized(Vec3(), p.highlightColor)),
......@@ -322,7 +322,7 @@ namespace Renderer {
ValueCell.update(globalUniforms.uFogFar, camera.fogFar);
ValueCell.update(globalUniforms.uFogNear, camera.fogNear);
ValueCell.update(globalUniforms.uTransparentBackground, transparentBackground ? 1 : 0);
ValueCell.update(globalUniforms.uTransparentBackground, transparentBackground);
globalUniformsNeedUpdate = true;
state.currentRenderItemId = -1;
......@@ -409,7 +409,7 @@ namespace Renderer {
}
if (props.interiorColorFlag !== undefined && props.interiorColorFlag !== p.interiorColorFlag) {
p.interiorColorFlag = props.interiorColorFlag;
ValueCell.update(globalUniforms.uInteriorColorFlag, p.interiorColorFlag ? 1 : 0);
ValueCell.update(globalUniforms.uInteriorColorFlag, p.interiorColorFlag);
}
if (props.interiorColor !== undefined && props.interiorColor !== p.interiorColor) {
p.interiorColor = props.interiorColor;
......
......@@ -2,7 +2,7 @@ export default `
float fogDepth = length(vViewPosition);
float fogFactor = smoothstep(uFogNear, uFogFar, fogDepth);
float fogAlpha = (1.0 - fogFactor) * gl_FragColor.a;
if (uTransparentBackground == 0) {
if (!uTransparentBackground) {
gl_FragColor.rgb = mix(gl_FragColor.rgb, uFogColor, fogFactor);
if (gl_FragColor.a < 1.0)
gl_FragColor.a = fogAlpha;
......
export default `
if (interior) {
if (uInteriorColorFlag == 1) {
if (uInteriorColorFlag) {
gl_FragColor.rgb = uInteriorColor;
} else {
gl_FragColor.rgb *= 1.0 - uInteriorDarkening;
......
......@@ -37,10 +37,10 @@ uniform vec3 uFogColor;
uniform float uAlpha;
uniform float uPickingAlphaThreshold;
uniform int uTransparentBackground;
uniform bool uTransparentBackground;
uniform float uInteriorDarkening;
uniform int uInteriorColorFlag;
uniform bool uInteriorColorFlag;
uniform vec3 uInteriorColor;
bool interior;
`;
\ No newline at end of file
......@@ -51,10 +51,10 @@ uniform vec3 uFogColor;
uniform float uAlpha;
uniform float uPickingAlphaThreshold;
uniform int uTransparentBackground;
uniform bool uTransparentBackground;
uniform float uInteriorDarkening;
uniform int uInteriorColorFlag;
uniform bool uInteriorColorFlag;
uniform vec3 uInteriorColor;
bool interior;
......
......@@ -11,6 +11,7 @@ import { RenderableSchema } from '../../mol-gl/renderable/schema';
import { ValueOf } from '../../mol-util/type-helpers';
export type UniformKindValue = {
'b': boolean; 'b[]': boolean[]
'f': number; 'f[]': number[]
'i': number; 'i[]': number[]
'v2': Vec2; 'v2[]': number[]
......@@ -28,6 +29,7 @@ export type UniformsList = [string, ValueCell<UniformType>][]
export function getUniformType(gl: GLRenderingContext, kind: UniformKind) {
switch (kind) {
case 'b': case 'b[]': return gl.BOOL;
case 'f': case 'f[]': return gl.FLOAT;
case 'i': case 'i[]': return gl.INT;
case 'v2': case 'v2[]': return gl.FLOAT_VEC2;
......@@ -56,8 +58,8 @@ function getUniformSetter(kind: UniformKind): UniformSetter {
switch (kind) {
case 'f': return uniform1f;
case 'f[]': return uniform1fv;
case 'i': case 't': return uniform1i;
case 'i[]': case 't[]': return uniform1iv;
case 'i': case 't': case 'b': return uniform1i;
case 'i[]': case 't[]': case 'b[]': return uniform1iv;
case 'v2': case 'v2[]': return uniform2fv;
case 'v3': case 'v3[]': return uniform3fv;
case 'v4': case 'v4[]': return uniform4fv;
......
......@@ -10,6 +10,5 @@ export function isLittleEndian() {
const uint16array = new Uint16Array(arrayBuffer);
uint8Array[0] = 0xAA;
uint8Array[1] = 0xBB;
if (uint16array[0] === 0xBBAA) return 1;
return 0;
return uint16array[0] === 0xBBAA;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment