Hi! I am currently working on implementing post-processing into my game engine although Im currently struggling to get anything working.
Ive created this new file, gzjs.postprocessing.js
import * as THREE from 'three';
import { gzjs } from './../glunzunk.js';
import { scene, camera } from './../../editor/init.js';
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
import { GlitchPass } from 'three/addons/postprocessing/GlitchPass.js';
let composer; // Declare composer but initialize later
async function initComposer() {
const { renderer } = await import('./../../editor/init.js'); // Lazy import to break circular dependency
composer = new EffectComposer( renderer) ;
composer.addPass( new RenderPass(scene, camera) );
// const outputPass = new OutputPass();
// composer.addPass(outputPass);
}
await initComposer(); // Initialize composer after renderer is available
gzjs.postProcessing = async function(name, properties = {}) {
if (!composer) {
console.error('Composer is not initialized yet!');
return;
}
composer.passes = composer.passes.filter(pass => !(pass instanceof OutputPass));
if (name === 'glitch') {
const glitchPass = new GlitchPass();
glitchPass.goWild = true; // Force extreme glitching
composer.addPass(glitchPass);
}
const outputPass = new OutputPass();
composer.addPass(outputPass);
};
export { composer };
and imported it into the init.js
(the first script to be ran in-editor)
/*
Editor Initilization
Written by: MTSyntho
Jan 2025
*/
import * as THREE from 'three';
import { gzjs } from './../engine/glunzunk.js';
import { TransformControls } from 'three/addons/controls/TransformControls.js';
// import animate from '/scripts/editor/render.js';
import { handleCamera } from './../editor/camera.js';
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 1000 );
// const gamecamera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 1000 );
const inEngine = true;
const renderer = new THREE.WebGLRenderer({ canvas: renderCanvas, antialias:true });
renderer.setSize( window.innerWidth, window.innerHeight );
// renderer.setAnimationLoop( animate );
renderer.setPixelRatio(1)
// const camera = gzjs.newCamera( 60, scene, window.innerWidth / window.innerHeight, 0.1, 1000 );
// export { scene, renderer, camera };
// Function to handle window resizing
function onWindowResize() {
// Update the camera's aspect ratio
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix(); // Update the camera's projection matrix
// Update the renderer's size
renderer.setSize(window.innerWidth, window.innerHeight);
}
// Listen for the window resize event
window.addEventListener('resize', onWindowResize, false);
camera.position.y = 1;
camera.position.z = 5;
// gamecamera.position.y = 3;
// gamecamera.position.z = 3;
let activeCamera = camera; // Default to editor camera
// const raycaster = new THREE.Raycaster();
// const mouse = new THREE.Vector2();
const gizmoObjects = []; // Store selectable objects
const sceneObjects = {}
export { renderer, scene, camera, activeCamera, gizmoObjects, sceneObjects, inEngine };
const clock = new THREE.Clock();
async function animate() {
// requestAnimationFrame(animate);
const delta = clock.getDelta(); // Get time since last frame
handleCamera();
const { composer } = await import('./../engine/gzjs/gzjs.postprocessing.js');
composer.render();
// renderer.render(scene, activeCamera);
}
animate();
Although nothing seems to work
what am i missing
i would link the repo although i cant make any commits for the weekend due to some stuff at home
Although you may check out the engine for funsies if you wish:
https://mtsyntho.github.io/glunzunk-engine