From 56b278a47f6161f7284be2086ee2409a9a9bcbf9 Mon Sep 17 00:00:00 2001 From: James Lambert Date: Mon, 6 Jun 2022 13:04:37 -0600 Subject: [PATCH] Fix portal backface culling --- README.md | 6 ++++-- src/main.c | 13 ++++++------- src/scene/portal.c | 9 ++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a82af01..996c1bc 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,11 @@ where `/home/james/Blender/blender-2.93.1-linux-x64` is the folder where blender ## Current TODO list -Portal culling Doorway collision Implement collider bitmask Cylinder touching bug -Blank screen on game start +Radio + Create radio model + Create radio texture + Implement 3D sound cube dispenser \ No newline at end of file diff --git a/src/main.c b/src/main.c index 92bb157..f4b833f 100644 --- a/src/main.c +++ b/src/main.c @@ -123,10 +123,13 @@ static void gameProc(void* arg) { OS_VI_DIVOT_OFF | OS_VI_DITHER_FILTER_OFF); + osViBlack(1); + u32 pendingGFX = 0; u32 drawBufferIndex = 0; u8 frameControl = 0; - u8 inputIgnore = 6; + u8 inputIgnore = 5; + u8 drawingEnabled = 0; u16* memoryEnd = graphicsLayoutScreenBuffers((u16*)PHYS_TO_K0(osMemSize)); @@ -162,22 +165,18 @@ static void gameProc(void* arg) { break; } - static int renderSkip = 1; - - if (pendingGFX < 2 && !renderSkip) { + if (pendingGFX < 2 && drawingEnabled) { graphicsCreateTask(&gGraphicsTasks[drawBufferIndex], (GraphicsCallback)sceneRender, &gScene); drawBufferIndex = drawBufferIndex ^ 1; ++pendingGFX; - } else if (renderSkip) { - --renderSkip; } controllersTriggerRead(); if (inputIgnore) { --inputIgnore; } else { - sceneUpdate(&gScene); + drawingEnabled = 1; } timeUpdateDelta(); soundPlayerUpdate(); diff --git a/src/scene/portal.c b/src/scene/portal.c index 27b3efe..4bd745e 100644 --- a/src/scene/portal.c +++ b/src/scene/portal.c @@ -121,7 +121,7 @@ void renderPropsNext(struct RenderProps* current, struct RenderProps* next, stru next->aspectRatio = current->aspectRatio; transformConcat(&portalCombined, ¤t->camera.transform, &next->camera.transform); - float zBias = (STARTING_RENDER_DEPTH - current->currentDepth - 1) * (-0.01f / STARTING_RENDER_DEPTH); + float zBias = (STARTING_RENDER_DEPTH - current->currentDepth - 1) * -0.005f; // render any objects halfway through portals cameraSetupMatrices(&next->camera, renderState, next->aspectRatio, &next->perspectiveCorrect, current->viewport, NULL, 0.0f); @@ -177,12 +177,11 @@ void portalRender(struct Portal* portal, struct Portal* otherPortal, struct Rend struct Vector3 worldForward; quatMultVector(&portal->transform.rotation, &forward, &worldForward); - struct Quaternion inverseCamera; - quatConjugate(&props->camera.transform.rotation, &inverseCamera); - quatMultVector(&inverseCamera, &worldForward, &forward); + struct Vector3 offsetFromCamera; + vector3Sub(&props->camera.transform.position, &portal->transform.position, &offsetFromCamera); // don't render the portal if it is facing the wrong way - if (forward.z < 0.0f) { + if (vector3Dot(&worldForward, &offsetFromCamera) < 0.0f) { return; }