Render portal gun with smaller near clip plane.

This commit is contained in:
Matt Thompson 2023-09-04 00:43:54 -04:00
parent f0be2b4048
commit 510623ca54
4 changed files with 23 additions and 0 deletions

View file

@ -140,6 +140,26 @@ error:
return 0;
}
void cameraModifyProjectionViewForPortalGun(struct Camera* camera, struct RenderState* renderState, float newNearPlane, float aspectRatio)
{
Mtx* portalGunProjectionView = renderStateRequestMatrices(renderState, 1);
if(!portalGunProjectionView)
return;
struct Camera portalCam = *camera;
portalCam.nearPlane = newNearPlane;
float view[4][4];
float projectionView[4][4];
unsigned short perspectiveNormalize;
cameraBuildProjectionMatrix(&portalCam, projectionView, &perspectiveNormalize, aspectRatio);
cameraBuildViewMatrix(&portalCam, view);
guMtxCatF(view, projectionView, projectionView);
guMtxF2L(projectionView, portalGunProjectionView);
gSPMatrix(renderState->dl++, osVirtualToPhysical(portalGunProjectionView), G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);
gSPPerspNormalize(renderState->dl++, perspectiveNormalize);
}
int cameraApplyMatrices(struct RenderState* renderState, struct CameraMatrixInfo* matrixInfo) {
Mtx* modelMatrix = renderStateRequestMatrices(renderState, 1);

View file

@ -41,6 +41,7 @@ void cameraInit(struct Camera* camera, float fov, float near, float far);
void cameraBuildViewMatrix(struct Camera* camera, float matrix[4][4]);
void cameraBuildProjectionMatrix(struct Camera* camera, float matrix[4][4], u16* perspectiveNorm, float aspectRatio);
int cameraSetupMatrices(struct Camera* camera, struct RenderState* renderState, float aspectRatio, Vp* viewport, int extractClippingPlanes, struct CameraMatrixInfo* output);
void cameraModifyProjectionViewForPortalGun(struct Camera* camera, struct RenderState* renderState, float newNearPlane, float aspectRatio);
int cameraApplyMatrices(struct RenderState* renderState, struct CameraMatrixInfo* matrixInfo);

View file

@ -6,6 +6,7 @@
#define DEFAULT_FAR_PLANE 30.0f
#define DEFAULT_NEAR_PLANE 0.125f
#define PORTAL_GUN_NEAR_PLANE 0.05f
#define MAX_PORTAL_STEPS 6

View file

@ -299,6 +299,7 @@ void sceneRender(struct Scene* scene, struct RenderState* renderState, struct Gr
renderPlanBuild(&renderPlan, scene, renderState);
renderPlanExecute(&renderPlan, scene, staticMatrices, renderState);
cameraModifyProjectionViewForPortalGun(&scene->camera, renderState, PORTAL_GUN_NEAR_PLANE * SCENE_SCALE, renderPlan.stageProps[0].aspectRatio);
portalGunRenderReal(&scene->portalGun, renderState);
gDPPipeSync(renderState->dl++);