Improve shadows and add antialiasing

This commit is contained in:
schmelczerandras 2020-09-25 15:40:10 +02:00
parent 7d2c74d6a8
commit 40b9644171
13 changed files with 182 additions and 187 deletions

View file

@ -21,8 +21,6 @@ export abstract class FrameBuffer {
});
this.gl.viewport(0, 0, this.size.x, this.size.y);
this.gl.clearColor(0, 0, 0, 0);
this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);
}
public destroy(): void {

View file

@ -1,4 +1,4 @@
import { mat3, ReadonlyVec3, vec2, vec3 } from 'gl-matrix';
import { mat3, ReadonlyVec3, ReadonlyVec4, vec2, vec3, vec4 } from 'gl-matrix';
import { UniversalRenderingContext } from '../universal-rendering-context';
const loaderMat3 = mat3.create();
@ -71,6 +71,30 @@ export const loadUniform = (
}
);
converters.set(
WebGLRenderingContext.FLOAT_VEC4,
(gl, v: ReadonlyVec4 | Array<vec4>, l) => {
if (v.length == 0) {
return;
}
if (v[0] instanceof Array || v[0] instanceof Float32Array) {
const result = new Float32Array(v.length * 4);
for (let i = 0; i < v.length; i++) {
result[3 * i] = (v[i] as Array<number>)[0];
result[3 * i + 1] = (v[i] as Array<number>)[1];
result[3 * i + 2] = (v[i] as Array<number>)[2];
result[3 * i + 3] = (v[i] as Array<number>)[3];
}
gl.uniform4fv(l, result);
} else {
gl.uniform4fv(l, v as vec4);
}
}
);
converters.set(WebGLRenderingContext.FLOAT_MAT3, (gl, v, l) => {
if (gl.isWebGL2) {
gl.uniformMatrix3fv(l, true, mat3.fromMat2d(loaderMat3, v));

View file

@ -38,12 +38,10 @@ export class PaletteTexture {
imageData.data[4 * i + 0] = c[0] * 255;
imageData.data[4 * i + 1] = c[1] * 255;
imageData.data[4 * i + 2] = c[2] * 255;
imageData.data[4 * i + 3] = c.length == 4 ? c[3] : 255;
imageData.data[4 * i + 3] = c.length == 4 ? c[3] * 255 : 255;
});
ctx.putImageData(imageData, 0, 0);
document.body.appendChild(canvas);
this.setImage(canvas);
}

View file

@ -144,10 +144,15 @@ export class UniformArrayAutoScalingProgram implements IProgram {
descriptors[i].sdf!.distanceFunctionName
}(position, objectColor);
color = mix(objectColor / {paletteSize}, color, step(
distanceNdcPixelSize + SURFACE_OFFSET,
objectMinDistance
));
color = mix(
objectColor / {paletteSize},
color,
${
descriptors[i].sdf?.isInverted
? `step(-distanceNdcPixelSize, -objectMinDistance)`
: `step(distanceNdcPixelSize, objectMinDistance)`
}
);
minDistance = min(minDistance, objectMinDistance);
`;