hwr: add smoother shadow

This commit is contained in:
oziphantom 2021-10-28 05:36:56 +11:00 committed by GitHub
parent ee263bf6ca
commit 0950c33484
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 62 additions and 56 deletions

View file

@ -157,10 +157,12 @@
"resolution_width": -1,
"resolution_height": -1,
// Enable XBox One Controller with PS1 layout and Per Axis Dead Zone
// Enables XBox One Controller with PS1 layout and Per Axis Dead Zone.
"enable_xbox_one_controller": true,
// Overrides ingame brightness.
"brightness": 1.0,
// Enable round shadow instead of the default octagon one.
"enable_round_shadow": true,
}

View file

@ -154,6 +154,7 @@ int8_t T1MReadConfigFromJson(const char *cfg_data)
READ_BOOL(disable_music_in_menu, 0);
READ_BOOL(enable_xbox_one_controller, 0);
READ_FLOAT(brightness, 1.0);
READ_BOOL(enable_round_shadow, 1);
READ_BAR_SHOWING_MODE(healthbar_showing_mode, T1M_BSM_FLASHING_OR_DEFAULT);
READ_BAR_SHOWING_MODE(airbar_showing_mode, T1M_BSM_DEFAULT);

View file

@ -69,6 +69,7 @@ typedef struct {
int32_t resolution_height;
int8_t enable_xbox_one_controller;
float brightness;
int8_t enable_round_shadow;
} T1MConfigStruct;
extern T1MConfigStruct T1MConfig;

View file

@ -222,6 +222,8 @@
#define RESOLUTIONS_SIZE 12
#define HWR_CLIP_VERTCOUNT_SCALE 4
#if _MSC_VER > 0x500
#define strdup _strdup // fixes error about POSIX function
#define _USE_MATH_DEFINES // makes maths.h also define M_PI

View file

@ -1703,7 +1703,7 @@ typedef struct SHADOW_INFO {
/* 0006 */ int16_t radius;
/* 0008 */ int16_t poly_count;
/* 000A */ int16_t vertex_count;
/* 000C */ POS_3D vertex[8];
/* 000C */ POS_3D vertex[32];
/* 003C end */
} SHADOW_INFO;

View file

@ -100,6 +100,7 @@ int32_t RoomsToDrawNum;
int32_t NumberCameras;
int32_t NumberSoundEffects;
OBJECT_VECTOR *SoundEffectsTable;
SHADOW_INFO ShadowInfo;
int16_t *TriggerIndex;
int32_t FlipTimer = 0;

View file

@ -63,7 +63,6 @@
#define FadeValue VAR_I_(0x00453568, int32_t, 0x100000)
#define FadeLimit VAR_I_(0x0045356C, int32_t, 0x100000)
#define FadeAdder VAR_I_(0x00453570, int32_t, 0x8000)
#define ShadowInfo VAR_U_(0x004567B8, SHADOW_INFO)
#define LsAdder VAR_U_(0x0068F3A0, int32_t)
#define LsYaw VAR_U_(0x0068F3B4, int32_t)
#define LsPitch VAR_U_(0x006D4DE4, int32_t)
@ -268,6 +267,7 @@ extern int32_t RoomsToDrawNum;
extern int32_t NumberCameras;
extern int32_t NumberSoundEffects;
extern OBJECT_VECTOR *SoundEffectsTable;
extern SHADOW_INFO ShadowInfo;
extern int16_t *TriggerIndex;
extern int32_t FlipTimer;

View file

@ -10,6 +10,7 @@
#include "util.h"
#include <stdlib.h>
#include <assert.h>
typedef struct HWR_LIGHTNING {
int32_t x1;
@ -570,14 +571,14 @@ void HWR_DrawLightningSegment(
HWR_LightningCount++;
}
void HWR_PrintShadow(PHD_VBUF *vbufs, int clip)
void HWR_PrintShadow(PHD_VBUF *vbufs, int clip, int vertex_count)
{
// needs to be more than 8 cause clipping might return more polygons.
C3D_VTCF vertices[30];
C3D_VTCF vertices[vertex_count * HWR_CLIP_VERTCOUNT_SCALE];
int i;
int32_t tmp;
int32_t vertex_count = 8;
for (int i = 0; i < vertex_count; i++) {
for (i = 0; i < vertex_count; i++) {
C3D_VTCF *vertex = &vertices[i];
PHD_VBUF *vbuf = &vbufs[i];
vertex->x = vbuf->xs;
@ -590,7 +591,9 @@ void HWR_PrintShadow(PHD_VBUF *vbufs, int clip)
}
if (clip) {
int original = vertex_count;
vertex_count = HWR_ClipVertices(vertex_count, vertices);
assert(vertex_count < original * HWR_CLIP_VERTCOUNT_SCALE);
}
if (!vertex_count) {
@ -705,12 +708,14 @@ void HWR_RenderLightningSegment(
int32_t HWR_ClipVertices(int32_t num, C3D_VTCF *source)
{
float scale;
C3D_VTCF vertices[20];
C3D_VTCF vertices[num * HWR_CLIP_VERTCOUNT_SCALE];
C3D_VTCF *l = &source[num - 1];
int j = 0;
int i;
for (int i = 0; i < num; i++) {
for (i = 0; i < num; i++) {
assert(j < num * HWR_CLIP_VERTCOUNT_SCALE);
C3D_VTCF *v1 = &vertices[j];
C3D_VTCF *v2 = l;
l = &source[i];
@ -783,7 +788,7 @@ int32_t HWR_ClipVertices(int32_t num, C3D_VTCF *source)
l = &vertices[j - 1];
j = 0;
for (int i = 0; i < num; i++) {
for (i = 0; i < num; i++) {
C3D_VTCF *v1 = &source[j];
C3D_VTCF *v2 = l;
l = &vertices[i];

View file

@ -45,7 +45,7 @@ void HWR_Draw2DQuad(
int32_t x1, int32_t y1, int32_t x2, int32_t y2, RGB888 tl, RGB888 tr,
RGB888 bl, RGB888 br);
void HWR_DrawTranslucentQuad(int32_t x1, int32_t y1, int32_t x2, int32_t y2);
void HWR_PrintShadow(PHD_VBUF *vbufs, int clip);
void HWR_PrintShadow(PHD_VBUF *vbufs, int clip, int vertex_count);
void HWR_DrawLightningSegment(
int x1, int y1, int z1, int thickness1, int x2, int y2, int z2,
int thickness2);

View file

@ -89,8 +89,7 @@ static HRESULT DInputJoystickCreate();
static void DInputJoystickRelease();
static BOOL CALLBACK
EnumAxesCallback(LPCDIDEVICEOBJECTINSTANCE instance, LPVOID context);
static BOOL CALLBACK
EnumCallback(LPCDIDEVICEINSTANCEA instance, LPVOID context);
static BOOL CALLBACK EnumCallback(LPCDIDEVICEINSTANCE instance, LPVOID context);
void InputInit()
{

View file

@ -1,6 +1,7 @@
#include "specific/output.h"
#include "3dsystem/3d_gen.h"
#include "3dsystem/phd_math.h"
#include "config.h"
#include "global/const.h"
#include "global/types.h"
@ -472,59 +473,53 @@ void S_DrawLightningSegment(
void S_PrintShadow(int16_t size, int16_t *bptr, ITEM_INFO *item)
{
int32_t x0 = bptr[0];
int32_t x1 = bptr[1];
int32_t y0 = bptr[4];
int32_t y1 = bptr[5];
int i;
ShadowInfo.vertex_count = T1MConfig.enable_round_shadow ? 32 : 8;
int32_t x0 = bptr[FRAME_BOUND_MIN_X];
int32_t x1 = bptr[FRAME_BOUND_MAX_X];
int32_t z0 = bptr[FRAME_BOUND_MIN_Z];
int32_t z1 = bptr[FRAME_BOUND_MAX_Z];
int32_t x_mid = (x0 + x1) / 2;
int32_t y_mid = (y0 + y1) / 2;
int32_t z_mid = (z0 + z1) / 2;
int32_t x_add = size * (x1 - x0) / 1024;
int32_t y_add = size * (y1 - y0) / 1024;
int32_t x_add = (x1 - x0) * size / 1024;
int32_t z_add = (z1 - z0) * size / 1024;
ShadowInfo.vertex[0].x = x_mid - x_add;
ShadowInfo.vertex[0].z = y_mid + y_add * 2;
ShadowInfo.vertex[1].x = x_mid + x_add;
ShadowInfo.vertex[1].z = y_mid + y_add * 2;
ShadowInfo.vertex[2].x = x_mid + x_add * 2;
ShadowInfo.vertex[2].z = y_add + y_mid;
ShadowInfo.vertex[3].x = x_mid + x_add * 2;
ShadowInfo.vertex[3].z = y_mid - y_add;
ShadowInfo.vertex[4].x = x_mid + x_add;
ShadowInfo.vertex[4].z = y_mid - y_add * 2;
ShadowInfo.vertex[5].x = x_mid - x_add;
ShadowInfo.vertex[5].z = y_mid - y_add * 2;
ShadowInfo.vertex[6].x = x_mid - x_add * 2;
ShadowInfo.vertex[6].z = y_mid - y_add;
ShadowInfo.vertex[7].x = x_mid - x_add * 2;
ShadowInfo.vertex[7].z = y_add + y_mid;
for (i = 0; i < ShadowInfo.vertex_count; i++) {
int32_t angle = (PHD_180 + i * PHD_360) / ShadowInfo.vertex_count;
ShadowInfo.vertex[i].x = x_mid + (x_add * 2) * phd_sin(angle) / PHD_90;
ShadowInfo.vertex[i].z = z_mid + (z_add * 2) * phd_cos(angle) / PHD_90;
ShadowInfo.vertex[i].y = 0;
}
phd_PushMatrix();
phd_TranslateAbs(item->pos.x, item->floor, item->pos.z);
phd_RotY(item->pos.y_rot);
if (calc_object_vertices(&ShadowInfo.poly_count)) {
PHD_VBUF *vn1 = &PhdVBuf[0];
PHD_VBUF *vn2 = &PhdVBuf[1];
PHD_VBUF *vn3 = &PhdVBuf[2];
PHD_VBUF *vn4 = &PhdVBuf[3];
PHD_VBUF *vn5 = &PhdVBuf[4];
PHD_VBUF *vn6 = &PhdVBuf[5];
PHD_VBUF *vn7 = &PhdVBuf[6];
PHD_VBUF *vn8 = &PhdVBuf[7];
if (!(vn1->clip & vn2->clip & vn3->clip & vn4->clip & vn5->clip
& vn6->clip & vn7->clip & vn8->clip)
&& vn1->clip >= 0 && vn2->clip >= 0 && vn3->clip >= 0
&& vn4->clip >= 0 && vn5->clip >= 0 && vn6->clip >= 0
&& vn7->clip >= 0 && vn8->clip >= 0 && VISIBLE(vn1, vn2, vn3)) {
int clip = (vn1->clip | vn2->clip | vn3->clip | vn4->clip
| vn5->clip | vn6->clip | vn7->clip | vn8->clip)
? 1
: 0;
HWR_PrintShadow(&PhdVBuf[0], clip);
if (calc_object_vertices(&ShadowInfo.poly_count)) {
int16_t clip_and = 1;
int16_t clip_positive = 1;
int16_t clip_or = 0;
for (i = 0; i < ShadowInfo.vertex_count; i++) {
clip_and &= PhdVBuf[i].clip;
clip_positive &= PhdVBuf[i].clip >= 0;
clip_or |= PhdVBuf[i].clip;
}
PHD_VBUF *vn1 = &PhdVBuf[0];
PHD_VBUF *vn2 = &PhdVBuf[T1MConfig.enable_round_shadow ? 4 : 1];
PHD_VBUF *vn3 = &PhdVBuf[T1MConfig.enable_round_shadow ? 8 : 2];
int visible = VISIBLE(vn1, vn2, vn3);
if (!clip_and && clip_positive && visible) {
HWR_PrintShadow(
&PhdVBuf[0], clip_or ? 1 : 0, ShadowInfo.vertex_count);
}
}
phd_PopMatrix();
}