Work on portal ball trail

This commit is contained in:
James Lambert 2023-09-17 22:35:38 -06:00
parent 79b64c72ba
commit 65eebe53d3
11 changed files with 186 additions and 13 deletions

View File

@ -198,6 +198,7 @@ build/src/scene/elevator.o: build/assets/models/props/round_elevator_collision.h
#
MODEL_LIST = assets/models/player/chell.blend \
assets/models/portal_gun/ball_trail.blend \
assets/models/portal_gun/v_portalgun.blend \
assets/models/portal_gun/w_portalgun.blend \
assets/models/props/round_elevator.blend \
@ -260,6 +261,7 @@ build/assets/models/props/combine_ball_catcher.h: assets/materials/ball_catcher.
build/assets/models/props/combine_ball_launcher.h: assets/materials/ball_catcher.skm.yaml
build/src/decor/decor_object_list.o: build/assets/models/dynamic_model_list.h build/assets/materials/static.h
build/src/effects/effect_definitions.o: build/assets/materials/static.h
build/src/effects/portal_trail.o: build/assets/materials/static.h build/assets/models/portal_gun/ball_trail.h
build/src/menu/controls.o: build/assets/materials/ui.h build/src/audio/clips.h
build/src/menu/game_menu.o: build/src/audio/clips.h build/assets/materials/ui.h build/assets/materials/images.h build/assets/test_chambers/test_chamber_00/test_chamber_00.h
build/src/menu/gameplay_options.o: build/assets/materials/ui.h build/src/audio/clips.h
@ -466,6 +468,21 @@ clean:
clean-src:
rm -rf build/src
rm -f $(CODESEGMENT)_debug.o
rm -f $(CODESEGMENT)_no_debug.o
rm -f $(BASE_TARGET_NAME)_debug.elf
rm -f $(BASE_TARGET_NAME).elf
rm -f $(BASE_TARGET_NAME).z64
rm -f $(BASE_TARGET_NAME)_debug.z64
clean-assets:
rm -rf build/assets
rm -f $(CODESEGMENT)_debug.o
rm -f $(CODESEGMENT)_no_debug.o
rm -f $(BASE_TARGET_NAME)_debug.elf
rm -f $(BASE_TARGET_NAME).elf
rm -f $(BASE_TARGET_NAME).z64
rm -f $(BASE_TARGET_NAME)_debug.z64
fix:
wine tools/romfix64.exe build/portal.z64

View File

@ -1120,4 +1120,33 @@ materials:
color: ["1", "PRIMITIVE", "TEXEL0_ALPHA", "PRIMITIVE"]
alpha: ["PRIMITIVE", "0", "TEXEL0", "0"]
gSPGeometryMode:
clear: [G_CULL_BACK, G_CULL_FRONT]
clear: [G_CULL_BACK, G_CULL_FRONT]
portal_trail:
gDPSetTile:
filename: ../../portal_pak_modified/materials/effects/brightglow_y.png
fmt: G_IM_FMT_I
siz: G_IM_SIZ_4b
s:
shift: 1
t:
shift: 1
gDPSetRenderMode:
flags:
- IM_RD
- CVG_DST_FULL
- FORCE_BL
- ZMODE_OPA
blend:
- G_BL_CLR_IN
- G_BL_A_IN
- G_BL_CLR_MEM
- G_BL_1MA
gDPSetCombineMode:
color: ["1", "PRIMITIVE", "TEXEL0", "PRIMITIVE"]
alpha: ["TEXEL0", "0", "SHADE", "0"]
gSPGeometryMode:
clear: [G_CULL_BACK, G_CULL_FRONT, G_ZBUFFER]
set: [G_FOG]

Binary file not shown.

View File

@ -0,0 +1 @@
-m assets/materials/static.skm.yaml --rotate 0,0,0 --sort-dir 0,1,0 --default-material brightglow_y

View File

@ -0,0 +1,58 @@
#include "portal_trail.h"
#include "../math/vector2.h"
#include "../defs.h"
#include "../build/assets/models/portal_gun/ball_trail.h"
#include "../build/assets/materials/static.h"
#include "../graphics/color.h"
struct Transform gTrailSectionOffset = {
{0.0f, 0.0f, -8.0f},
{0.0f, 0.0f, 0.0f, 1.0f},
{1.0f, 1.0f, 1.0f},
};
void portalTrailInit(struct PortalTrail* trail) {
transformToMatrixL(&gTrailSectionOffset, &trail->sectionOffset, SCENE_SCALE);
guMtxIdent(&trail->baseTransform[0]);
guMtxIdent(&trail->baseTransform[1]);
trail->currentBaseTransform = 0;
}
void portalTrailPlay(struct PortalTrail* trail, struct Vector3* from, struct Vector3* to) {
trail->trailTransform.position = *from;
struct Vector3 dir;
vector3Sub(to, from, &dir);
quatLook(&dir, &gUp, &trail->trailTransform.rotation);
trail->trailTransform.scale = gOneVec;
trail->currentBaseTransform ^= 1;
transformToMatrixL(&trail->trailTransform, &trail->baseTransform[trail->currentBaseTransform], SCENE_SCALE);
osWritebackDCache(&trail->baseTransform[trail->currentBaseTransform], sizeof(Mtx));
}
void portalTrailUpdate(struct PortalTrail* trail, float distance) {
}
struct Coloru8 gTrailColor[] = {
{200, 100, 50, 255},
{50, 70, 200, 255},
};
void portalTrailRender(struct PortalTrail* trail, struct RenderState* renderState, struct MaterialState* materialState) {
materialStateSet(materialState, PORTAL_TRAIL_INDEX, renderState);
struct Coloru8* color = &gTrailColor[0];
gSPFogPosition(renderState->dl++, 800, 999);
gDPSetPrimColor(renderState->dl++, 255, 255, color->r, color->g, color->b, color->a);
gSPMatrix(renderState->dl++, &trail->baseTransform[trail->currentBaseTransform], G_MTX_MODELVIEW | G_MTX_PUSH | G_MTX_MUL);
gSPDisplayList(renderState->dl++, portal_gun_ball_trail_model_gfx);
gSPPopMatrix(renderState->dl++, G_MTX_MODELVIEW);
}

View File

@ -0,0 +1,25 @@
#ifndef __PORTAL_TRAIL_H__
#define __PORTAL_TRAIL_H__
#include <ultra64.h>
#include "../math/vector3.h"
#include "../math/ray.h"
#include "../math/transform.h"
#include "../graphics/renderstate.h"
#include "../levels/material_state.h"
struct PortalTrail {
struct Transform trailTransform;
Mtx sectionOffset;
Mtx baseTransform[2];
struct Vector3 chunkOffset;
short currentBaseTransform;
};
void portalTrailInit(struct PortalTrail* trail);
void portalTrailPlay(struct PortalTrail* trail, struct Vector3* from, struct Vector3* to);
void portalTrailUpdate(struct PortalTrail* trail, float distance);
void portalTrailRender(struct PortalTrail* trail, struct RenderState* renderState, struct MaterialState* materialState);
#endif

View File

@ -279,4 +279,4 @@ int chamberNumberGetLevel(int chamberIndex) {
default:
return 0;
}
}
}

View File

@ -0,0 +1,19 @@
#include "material_state.h"
#include "levels.h"
void materialStateInit(struct MaterialState* state, short initialMaterial) {
state->materialIndex = initialMaterial;
}
void materialStateSet(struct MaterialState* state, short materialIndex, struct RenderState* renderState) {
if (state->materialIndex != materialIndex) {
if (state->materialIndex != -1) {
gSPDisplayList(renderState->dl++, levelMaterialRevert(state->materialIndex));
}
state->materialIndex = materialIndex;
gSPDisplayList(renderState->dl++, levelMaterial(materialIndex));
}
}

View File

@ -0,0 +1,13 @@
#ifndef __MATERIAL_STATE_H__
#define __MATERIAL_STATE_H__
#include "../graphics/renderstate.h"
struct MaterialState {
short materialIndex;
};
void materialStateInit(struct MaterialState* state, short initialMaterial);
void materialStateSet(struct MaterialState* state, short materialIndex, struct RenderState* renderState);
#endif

View File

@ -4,6 +4,8 @@
#include "../physics/collision_cylinder.h"
#include "./scene.h"
#include "../levels/material_state.h"
#include "../effects/effect_definitions.h"
#include "../../build/assets/models/grav_flare.h"
@ -50,6 +52,9 @@ void portalGunInit(struct PortalGun* portalGun, struct Transform* at){
portalGun->projectiles[0].roomIndex = -1;
portalGun->projectiles[1].roomIndex = -1;
portalTrailInit(&portalGun->projectiles[0].trail);
portalTrailInit(&portalGun->projectiles[1].trail);
}
#define PORTAL_PROJECTILE_RADIUS 0.15f
@ -61,7 +66,7 @@ struct Coloru8 gProjectileColor[] = {
{50, 70, 200, 255},
};
void portalBallRender(struct PortalGunProjectile* projectile, struct RenderState* renderState, struct Transform* fromView, int portalIndex) {
void portalBallRender(struct PortalGunProjectile* projectile, struct RenderState* renderState, struct MaterialState* materialState, struct Transform* fromView, int portalIndex) {
struct Transform transform;
if (projectile->distance < projectile->maxDistance) {
@ -82,9 +87,6 @@ void portalBallRender(struct PortalGunProjectile* projectile, struct RenderState
transformToMatrixL(&transform, mtx, SCENE_SCALE);
Gfx* material = static_brightglow_y;
Gfx* materialRevert = static_brightglow_y_revert;
struct Coloru8* color = &gProjectileColor[portalIndex];
float alpha = projectile->distance * DISTANCE_FADE_SCALAR;
@ -93,29 +95,33 @@ void portalBallRender(struct PortalGunProjectile* projectile, struct RenderState
alpha = 255.0f;
}
gDPSetPrimColor(renderState->dl++, 255, 255, color->r, color->g, color->b, (u8)alpha);
if (projectile->distance == 0.0f) {
material = static_portal_2_particle;
materialRevert = static_portal_2_particle_revert;
materialStateSet(materialState, PORTAL_2_PARTICLE_INDEX, renderState);
} else {
materialStateSet(materialState, BRIGHTGLOW_Y_INDEX, renderState);
gDPSetPrimColor(renderState->dl++, 255, 255, color->r, color->g, color->b, (u8)alpha);
}
gSPMatrix(renderState->dl++, mtx, G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_PUSH);
gSPDisplayList(renderState->dl++, material);
gSPDisplayList(renderState->dl++, grav_flare_model_gfx);
gSPDisplayList(renderState->dl++, materialRevert);
gSPPopMatrix(renderState->dl++, G_MTX_MODELVIEW);
}
void portalGunRenderReal(struct PortalGun* portalGun, struct RenderState* renderState, struct Transform* fromView){
void portalGunRenderReal(struct PortalGun* portalGun, struct RenderState* renderState, struct Transform* fromView) {
struct MaterialState materialState;
materialStateInit(&materialState, DEFAULT_INDEX);
for (int i = 0; i < 2; ++i) {
struct PortalGunProjectile* projectile = &portalGun->projectiles[i];
portalTrailRender(&projectile->trail, renderState, &materialState);
if (projectile->roomIndex == -1) {
continue;
}
portalBallRender(projectile, renderState, fromView, i);
portalBallRender(projectile, renderState, &materialState, fromView, i);
}
portalGun->rigidBody.transform.scale = gOneVec;
@ -217,4 +223,6 @@ void portalGunFire(struct PortalGun* portalGun, int portalIndex, struct Ray* ray
struct Vector3 fireFrom;
transformPoint(&portalGun->rigidBody.transform, &gPortalGunExit, &fireFrom);
vector3Sub(&fireFrom, &ray->origin, &projectile->effectOffset);
portalTrailPlay(&projectile->trail, &fireFrom, &hit.at);
}

View File

@ -9,6 +9,7 @@
#include "../scene/dynamic_scene.h"
#include "../player/player.h"
#include "../util/time.h"
#include "../effects/portal_trail.h"
struct PortalGunProjectile {
struct Ray positionDirection;
@ -17,6 +18,8 @@ struct PortalGunProjectile {
struct Vector3 effectOffset;
struct PortalTrail trail;
float distance;
float maxDistance;