Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Merge branch 'worktree-agent-abf010539542ad9da' into feat/scene-kits

Nguyen Xuan Anba1d8b20d77b
diff --cc src/renderer.js
index 42f43456,037d5c21..b0747491
--- a/src/renderer.js
+++ b/src/renderer.js
@@@ -39,9 -39,11 +40,13 @@@ export function resolveLiquidOptics(opt
return optics;
}
const SKIN_UNIFORMS = ['skinEnabled', 'skinInfluences', 'jointPalette'];
+const ALPHA_UNIFORMS = ['alphaMode', 'alphaCutoff', 'materialOpacity', 'alphaToCoverage', 'doubleSided'];
+const DEPTH_ALPHA_UNIFORMS = ['alphaMasked', 'alphaCutoff', 'materialOpacity', 'hasBaseMap', 'baseMap'];
const MORPH_UNIFORMS = ['morphEnabled', 'morphVertexCount', 'morphTargetCount', 'morphWeights[0]', 'morphTargets'];
+ const ENVIRONMENT_LOOKUP_UNIFORMS = ['environmentSpecular', 'environmentEnabled', 'environmentIntensity', 'environmentRotation', 'environmentLevelMax'];
+ const ENVIRONMENT_UNIFORMS = [...ENVIRONMENT_LOOKUP_UNIFORMS, 'environmentBrdf', 'environmentIrradiance[0]'];
+ const ENVIRONMENT_SPECULAR_UNIT = 9;
+ const ENVIRONMENT_BRDF_UNIT = 10;
function validateMaterialMaps(material) {
if (PROCEDURAL_MATERIAL_TAGS.has(material.tag)) {
@@@ -365,9 -348,8 +375,9 @@@ export class Renderer67
this.bloomUniforms = Object.fromEntries(['sourceTexture', 'texelDirection', 'threshold', 'extract'].map(name => [name, this.context.getUniformLocation(this.bloomProgram, name)]));
this.skyUniforms = Object.fromEntries(['skyTop', 'skyBottom', 'sunDirection', 'inverseViewProjection', 'eye', 'time', 'daylight', 'hdrEnabled'].map((name) => [name, this.context.getUniformLocation(this.skyProgram, name)]));
this.liquidProgram = compileProgram(this.context, vertexShader, liquidFragmentShader);
- this.liquidUniforms = Object.fromEntries(['viewProjection', 'lightProjection', 'eye', 'sceneColor', 'resolution', 'exposure', 'hdrEnabled', 'worldMode', 'daylight', 'lightDirection', 'keyColor', 'ambientIntensity', 'fogColor', 'fogDensity', 'liquidOptics', 'foamShape', 'time', 'wind', 'explosionProgress', 'explosionCenter', 'assemblyAmount', ...SKIN_UNIFORMS, ...MORPH_UNIFORMS].map((name) => [name, this.context.getUniformLocation(this.liquidProgram, name)]));
+ this.liquidUniforms = Object.fromEntries(['viewProjection', 'lightProjection', 'eye', 'sceneColor', 'resolution', 'exposure', 'hdrEnabled', 'worldMode', 'daylight', 'lightDirection', 'keyColor', 'ambientIntensity', 'fogColor', 'fogDensity', 'liquidOptics', 'foamShape', ...ENVIRONMENT_LOOKUP_UNIFORMS, 'time', 'wind', 'explosionProgress', 'explosionCenter', 'assemblyAmount', ...SKIN_UNIFORMS, ...MORPH_UNIFORMS].map((name) => [name, this.context.getUniformLocation(this.liquidProgram, name)]));
}
+ this.depthAlphaUniforms = Object.fromEntries(DEPTH_ALPHA_UNIFORMS.map(name => [name, this.context.getUniformLocation(this.depthProgram, name)]));
this.depthUniform = this.context.getUniformLocation(this.depthProgram, 'lightProjection');
this.depthAssemblyUniform = this.context.getUniformLocation(this.depthProgram, 'assemblyAmount');
this.partCount = parts.length;
@@@ -1238,18 -1203,12 +1334,19 @@@
context.activeTexture(context.TEXTURE0);
context.bindTexture(context.TEXTURE_2D, this.shadowTexture);
context.uniform1i(this.uniforms.shadowMap, 0);
+ this.applyEnvironmentUniforms(environmentMap);
for (const batch of this.batches) {
- if (this.benchmark || batchPass(batch) === 'opaque') this.drawBatch(batch, true);
+ if (this.benchmark) {
+ this.drawBatch(batch, true);
+ } else if (batchPass(batch) === 'opaque' && batch.alphaMode !== 'blend') {
+ this.drawAlphaBatch(batch, true);
+ }
}
+ context.disable(context.SAMPLE_ALPHA_TO_COVERAGE);
+ context.enable(context.CULL_FACE);
context.bindVertexArray(null);
- if (!this.benchmark) this.drawTranslucent(frame, environment, assemblyAmount);
+ if (!this.benchmark) this.drawTranslucent(frame, environment, assemblyAmount, environmentMap);
+ if (!this.benchmark) this.drawBlendBatches(frame);
if (!this.benchmark) this.resolveFrame(frame, effects, environment, volume);
this.cpuMilliseconds = performance.now() - start;
}