1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-10-29 11:16:09 +01:00

3DS fix lighting, sprites, FOV math

set default sound volume level to maximum (except web version)
remove unused uFlags from shaders
reduce camera position offset for combat mode
This commit is contained in:
XProger
2020-02-27 04:22:43 +03:00
parent dc9badd801
commit d511993605
13 changed files with 86 additions and 80 deletions

View File

@@ -10,18 +10,19 @@
#define CAM_SPEED_COMBAT 8
#define CAM_EYE_SEPARATION 16.0f
#ifdef _OS_3DS
#define CAM_FOCAL_LENGTH 512.0f
#define CAM_OFFSET_FOLLOW (1024.0f + 512.0f + 256.0f)
#else
#define CAM_FOCAL_LENGTH 1536.0f
#define CAM_OFFSET_FOLLOW (1024.0f + 512.0f)
#endif
#define CAM_OFFSET_FOLLOW (1024.0f + 512.0f)
#ifdef _OS_BITTBOY
#define CAM_OFFSET_COMBAT CAM_OFFSET_FOLLOW
#else
#define CAM_OFFSET_COMBAT (2048.0f + 512.0f)
#define CAM_OFFSET_COMBAT (CAM_OFFSET_FOLLOW + 512.0f)
#endif
#define CAM_OFFSET_LOOK (512.0f)
@@ -688,12 +689,7 @@ struct Camera : ICamera {
if (firstPerson)
smooth = false;
#ifdef _OS_3DS
fov = firstPerson ? 65.0f : 55.0f;
#else
fov = firstPerson ? 90.0f : 65.0f;
#endif
fov = firstPerson ? 90.0f : 65.0f;
znear = firstPerson ? 16.0f : 32.0f;
zfar = 45.0f * 1024.0f;

View File

@@ -531,7 +531,6 @@ struct MeshRange {
E( sMask )
#define SHADER_UNIFORMS(E) \
E( uFlags ) \
E( uParam ) \
E( uTexParam ) \
E( uViewProj ) \
@@ -870,8 +869,8 @@ namespace Core {
settings.detail.vsync = true;
settings.detail.stereo = Settings::STEREO_OFF;
settings.detail.scale = Settings::SCALE_100;
settings.audio.music = 14;
settings.audio.sound = 14;
settings.audio.music = SND_MAX_VOLUME;
settings.audio.sound = SND_MAX_VOLUME;
settings.audio.reverb = true;
settings.audio.subtitles = true;
settings.audio.language = defLang;
@@ -933,6 +932,9 @@ namespace Core {
#ifdef _OS_WEB
settings.controls[0].keys[ cJump ].key = ikD;
settings.controls[0].keys[ cInventory ].key = ikTab;
settings.audio.music = 14;
settings.audio.sound = 14;
#endif
#if defined(_OS_RPI) || defined(_OS_CLOVER)

View File

@@ -27,7 +27,7 @@ namespace GAPI {
struct Vertex {
short4 coord;
ubyte4 normal;
short2 texCoord;
short4 texCoord;
ubyte4 color;
ubyte4 light;
};
@@ -106,7 +106,6 @@ namespace GAPI {
#define SHADER_FREE(v) DVLB_Free(v);
static const int bindings[uMAX] = {
94, // uFlags
0, // uParam
1, // uTexParam
2, // uViewProj
@@ -120,7 +119,7 @@ namespace GAPI {
87, // uLightColor
91, // uRoomSize
92, // uPosScale
98, // uContacts
0, // uContacts (unused)
};
SHADERS_LIST(SHADER_DECL);
@@ -269,16 +268,16 @@ namespace GAPI {
void setParam(UniformType uType, const vec4 &value, int count = 1) {
if (uID[uType] == -1) return;
cbCount[uType] = count;
memcpy(cbMem + bindings[uType], &value, count * 16);
cbCount[uType] = max(cbCount[uType], count);
memcpy(cbMem + bindings[uType], &value, count * sizeof(value));
}
void setParam(UniformType uType, const mat4 &value, int count = 1) {
if (uID[uType] == -1) return;
cbCount[uType] = count * 4;
cbCount[uType] = max(cbCount[uType], count * 4);
ASSERT(count == 1);
memcpy(cbMem + bindings[uType], &value, sizeof(value));
memcpy(cbMem + bindings[uType], &value, count * sizeof(value));
}
};
@@ -794,7 +793,7 @@ namespace GAPI {
AttrInfo_Init(&vertexAttribs);
AttrInfo_AddLoader(&vertexAttribs, aCoord , GPU_SHORT , 4);
AttrInfo_AddLoader(&vertexAttribs, aNormal , GPU_UNSIGNED_BYTE , 4);
AttrInfo_AddLoader(&vertexAttribs, aTexCoord , GPU_SHORT , 2);
AttrInfo_AddLoader(&vertexAttribs, aTexCoord , GPU_SHORT , 4);
AttrInfo_AddLoader(&vertexAttribs, aColor , GPU_UNSIGNED_BYTE , 4);
AttrInfo_AddLoader(&vertexAttribs, aLight , GPU_UNSIGNED_BYTE , 4);

View File

@@ -89,7 +89,6 @@ namespace GAPI {
int reg;
int usage;
} bindings[uMAX] = {
{ 0, USAGE_VS | USAGE_PS }, // uFlags
{ 0, USAGE_VS | USAGE_PS }, // uParam
{ 1, USAGE_VS | USAGE_PS }, // uTexParam
{ 2, USAGE_VS | USAGE_PS }, // uViewProj
@@ -126,12 +125,8 @@ namespace GAPI {
for (int i = 0; i < defCount; i++) {
switch (def[i]) {
case SD_UNDERWATER : underwater = true; break;
case SD_ALPHA_TEST : alphatest = true; break;
case SD_OPT_AMBIENT : cbMem[uFlags].x = 1.0f; break;
case SD_OPT_SHADOW : cbMem[uFlags].y = 1.0f; break;
case SD_OPT_CONTACT : cbMem[uFlags].z = 1.0f; break;
case SD_OPT_CAUSTICS : cbMem[uFlags].w = 1.0f; break;
case SD_UNDERWATER : underwater = true; break;
case SD_ALPHA_TEST : alphatest = true; break;
}
}

View File

@@ -102,7 +102,6 @@ namespace GAPI {
int reg;
int usage;
} bindings[uMAX] = {
{ 0, USAGE_VS | USAGE_PS }, // uFlags
{ 0, USAGE_VS | USAGE_PS }, // uParam
{ 1, USAGE_VS | USAGE_PS }, // uTexParam
{ 2, USAGE_VS | USAGE_PS }, // uViewProj

View File

@@ -514,7 +514,6 @@ namespace GAPI {
bool vec; // true - vec4, false - mat4
int reg;
} bindings[uMAX] = {
{ true, 94 }, // uFlags
{ true, 0 }, // uParam
{ true, 1 }, // uTexParam
{ false, 2 }, // uViewProj

View File

@@ -432,7 +432,6 @@ namespace GAPI {
#include "shaders/gxm/shaders.h"
static const int bindings[uMAX] = {
94, // uFlags
0, // uParam
1, // uTexParam
2, // uViewProj
@@ -473,24 +472,18 @@ namespace GAPI {
bool rebind;
void init(Pass pass, int type, int *def, int defCount) {
LOG("init shader %d %d ", int(pass), int(type));
LOG("init shader %d %d ", int(pass), int(type));
memset(pso, 0, sizeof(pso));
outputFmt = SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4;
float *flags = (float*)(cbMem + bindings[uFlags]);
bool underwater = false;
bool alphatest = false;
for (int i = 0; i < defCount; i++) {
switch (def[i]) {
case SD_UNDERWATER : underwater = true; break;
case SD_ALPHA_TEST : alphatest = true; break;
case SD_OPT_AMBIENT : flags[0] = 1.0f; break;
case SD_OPT_SHADOW : flags[1] = 1.0f; break;
case SD_OPT_CONTACT : flags[2] = 1.0f; break;
case SD_OPT_CAUSTICS : flags[3] = 1.0f; break;
case SD_UNDERWATER : underwater = true; break;
case SD_ALPHA_TEST : alphatest = true; break;
}
}
@@ -697,7 +690,6 @@ namespace GAPI {
active.shader = this;
memset(cbCount, 0, sizeof(cbCount));
cbCount[uFlags] = 16;
rebind = true;
}

View File

@@ -586,8 +586,9 @@ struct Level : IGame {
Core::updateLights();
if (Core::settings.detail.shadows > Core::Settings::MEDIUM)
if (Core::settings.detail.shadows > Core::Settings::MEDIUM) {
Core::active.shader->setParam(uContacts, Core::contacts[0], MAX_CONTACTS);
}
}
virtual void setupBinding() {
@@ -3047,10 +3048,11 @@ struct Level : IGame {
if (gfxIs3D() != isStereo) {
gfxSet3D(isStereo);
Core::settings.detail.stereo = isStereo ? Core::Settings::STEREO_ANAGLYPH : Core::Settings::STEREO_OFF;
needRedrawTitleBG = inventory->active && !level.isTitle();
}
Core::settings.detail.stereo = isStereo ? Core::Settings::STEREO_ANAGLYPH : Core::Settings::STEREO_OFF;
if (slider != sliderState) {
sliderState = slider;
needRedrawTitleBG = inventory->active && !level.isTitle();

View File

@@ -253,19 +253,25 @@ struct MuzzleFlash : Controller {
vec4 lightPos = vec4(owner->getJoint(joint).pos, 0);
vec4 lightColor = FLASH_LIGHT_COLOR * vec4(intensity, intensity, intensity, 1.0f / sqrtf(intensity));
if (lightIndex > -1) {
ASSERT(lightIndex + 1 < MAX_LIGHTS);
Core::lightPos[lightIndex] = lightPos;
Core::lightColor[lightIndex] = lightColor;
} else
} else {
getRoom().addDynLight(owner->entity, lightPos, lightColor, true);
}
} else {
if (lightIndex > -1) {
ASSERT(lightIndex < MAX_LIGHTS);
Core::lightPos[lightIndex] = vec4(0);
Core::lightColor[lightIndex] = vec4(0, 0, 0, 1);
} else
} else {
getRoom().removeDynLight(owner->entity);
}
game->removeEntity(this);
}
}

View File

@@ -63,7 +63,7 @@
mad tmp, pos.y, uViewProj[1], tmp
mad tmp, pos.z, uViewProj[2], tmp
mad vPosition, pos.w, uViewProj[3], tmp
; lighting
; lv[0..3] = (uLightPos[0..3].xyz - pos) * uLightColor[0..3].w;
add lv0.xyz, uLightPos[0], -pos
@@ -74,37 +74,41 @@
mul lv1.xyz, uLightColor[1].w, lv1
mul lv2.xyz, uLightColor[2].w, lv2
mul lv3.xyz, uLightColor[3].w, lv3
; att[0..3] = dot(lv[0..3], lv[0..3])
dp3 att.x, lv0, lv0
dp3 att.y, lv1, lv1
dp3 att.z, lv2, lv2
dp3 att.w, lv3, lv3
; normalize lv[0..3]
rsq tmp, att
mul lv0.xyz, lv0, tmp.x
mul lv1.xyz, lv1, tmp.y
mul lv2.xyz, lv2, tmp.z
mul lv3.xyz, lv3, tmp.w
; att = max(0, 1 - att)
; att = max(0, 1 - att) / sqrt(att)
rsq tmp.x, att.x
rsq tmp.y, att.y
rsq tmp.z, att.z
rsq tmp.w, att.w
add att, ONE, -att
max att, ZERO, att
mul att, tmp, att
; normal = mulQuat(uBasis[joint], aNormal/127 - 1)
mul normal, INV_127, aNormal
add normal, -ONE, normal
mul pos.xyz, uBasis[0], normal.zxyw
mad pos.xyz, normal, uBasis[0].zxyw, -pos
mad pos.xyz, normal.yzxw, uBasis[0].w, pos
mul tmp.xyz, uBasis[0].zxyw, pos
mad pos.xyz, pos.yzxw, uBasis[0].yzxw, -tmp
mul normal.xyz, INV_127, aNormal
add normal.xyz, -ONE, normal
mul pos.xyz, uBasis[a0.x], normal.zxyw
mad pos.xyz, normal, uBasis[a0.x].zxyw, -pos
mad pos.xyz, normal.yzxw, uBasis[a0.x].w, pos
mul tmp.xyz, uBasis[a0.x].zxyw, pos
mad pos.xyz, pos.yzxw, uBasis[a0.x].yzxw, -tmp
mad normal.xyz, pos, TWO, normal
; light = max(0, dot(normal, lv[0..3]))
dp3 light.x, lv0, normal
dp3 light.y, lv1, normal
dp3 light.z, lv2, normal
dp3 light.w, lv3, normal
; light = max(0, light)
; light = max(0, light) * att
max light, ZERO, light
; light *= att
mul light, light, att
; vColor = aColor/255 * material.alpha * (material.ambient + light[0..3] * uLightColor[0..3])

View File

@@ -55,7 +55,7 @@
mad tmp, pos.y, uViewProj[1], tmp
mad tmp, pos.z, uViewProj[2], tmp
mad vPosition, pos.w, uViewProj[3], tmp
; lighting
; lv[1..3] = (uLightPos[1..3].xyz - pos) * uLightColor[1..3].w;
add lv1.xyz, uLightPos[1], -pos
@@ -64,29 +64,34 @@
mul lv1.xyz, uLightColor[1].w, lv1
mul lv2.xyz, uLightColor[2].w, lv2
mul lv3.xyz, uLightColor[3].w, lv3
; att[1..3] = dot(lv[1..3], lv[1..3])
mov att.x, ONE
dp3 att.y, lv1, lv1
dp3 att.z, lv2, lv2
dp3 att.w, lv3, lv3
; normalize lv[1..3]
rsq tmp, att
mul lv1.xyz, lv1, tmp.y
mul lv2.xyz, lv2, tmp.z
mul lv3.xyz, lv3, tmp.w
; att = max(0, 1 - att)
; att = max(0, 1 - att) / sqrt(att)
rsq tmp.y, att.y
rsq tmp.z, att.z
rsq tmp.w, att.w
add att, ONE, -att
max att, ZERO, att
mul att, tmp, att
; normal = aNormal/127 - 1
mul normal, INV_127, aNormal
add normal, -ONE, normal
mul normal.xyz, INV_127, aNormal
add normal.xyz, -ONE, normal
; light = max(0, dot(normal, lv[1..3]))
mov light.x, ZERO
dp3 light.y, lv1, normal
dp3 light.z, lv2, normal
dp3 light.w, lv3, normal
; light = max(0, light) * att
max light, ZERO, light
; light *= att
mul light, light, att
; vColor = (aLight/255 + light[1..3] * uLightColor[1..3]) * aColor/255

View File

@@ -74,34 +74,40 @@
mul lv1.xyz, uLightColor[1].w, lv1
mul lv2.xyz, uLightColor[2].w, lv2
mul lv3.xyz, uLightColor[3].w, lv3
; att[1..3] = dot(lv[1..3], lv[1..3])
mov att.x, ONE
dp3 att.y, lv1, lv1
dp3 att.z, lv2, lv2
dp3 att.w, lv3, lv3
; normalize lv[1..3]
rsq tmp, att
mul lv1.xyz, lv1, tmp.y
mul lv2.xyz, lv2, tmp.z
mul lv3.xyz, lv3, tmp.w
; att = max(0, 1 - att)
; att = max(0, 1 - att) / sqrt(att)
rsq tmp.y, att.y
rsq tmp.z, att.z
rsq tmp.w, att.w
add att, ONE, -att
max att, ZERO, att
mul att, tmp, att
; viewVec = uViewPos - pos
add vv.xyz, uViewPos, -pos
; normal = normalize(viewVec)
dp3 tmp.x, vv, vv
rsq tmp.x, tmp.x
mul normal, vv, tmp.x
; light = max(0, dot(normal, lv[1..3]))
mov light.x, MAT_AMBIENT
dp3 light.y, lv1, normal
dp3 light.z, lv2, normal
dp3 light.w, lv3, normal
; light = max(0, light) * att
max light, ZERO, light
; light *= att
mul light, light, att
; vColor = vec4(aLight.rgb * aLight.a, aLight.a)
mul tmp, INV_BYTE, aLight
mad tmp.xyz, light.x, uLightColor[0], tmp

View File

@@ -720,12 +720,13 @@ struct mat4 {
void perspective(ProjRange range, float fov, float aspect, float znear, float zfar, float eye = 0.0f, bool rotate90 = false) {
float y = tanf(fov * 0.5f * DEG2RAD) * znear;
float x = y;
float eyeX, eyeY;
if (rotate90) {
eyeX = 0.0f;
eyeY = -eye;
aspect = 1.0f / aspect;
swap(x, y);
} else {
eyeX = eye;
eyeY = 0.0f;