1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-02-24 07:22:58 +01:00

#15 PSV add livearea resources, fix shadows, fix clip planes, fix inventory lighting, shader optimizations

This commit is contained in:
XProger 2019-01-03 10:49:26 +03:00
parent 4beff89fb1
commit 34a300faf9
15 changed files with 103 additions and 65 deletions

View File

@ -223,6 +223,9 @@ struct ShaderCache {
void bind(Core::Pass pass, Shader::Type type, int fx) {
Core::pass = pass;
if (Core::support.clipDist)
fx &= ~ShaderCache::FX_CLIP_PLANE;
Shader *shader = getShader(pass, type, fx);
if (shader)
shader->setup();

View File

@ -102,8 +102,7 @@
#include "utils.h"
// muse be equal with base shader
#define SHADOW_TEX_WIDTH 1024
#define SHADOW_TEX_HEIGHT 1024
#define SHADOW_TEX_SIZE 1024
extern void* osMutexInit ();
extern void osMutexFree (void *obj);
@ -588,7 +587,7 @@ namespace Core {
int tFrame;
#endif
Stats() : frame(0), fps(0), fpsTime(0), frameIndex(0) {}
Stats() : frame(0), fps(0), frameIndex(0), fpsTime(0) {}
void start() {
dips = tris = rt = cb = 0;

View File

@ -396,6 +396,8 @@ namespace GAPI {
int colorMask, blendMode;
bool rebind;
void init(Pass pass, int type, int *def, int defCount) {
const uint8 *vpSrc, *fpSrc;
switch (pass) {
@ -606,8 +608,10 @@ namespace GAPI {
{ 32, SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ARGB , SCE_GXM_COLOR_FORMAT_A8R8G8B8 }, // RGBA
{ 16, SCE_GXM_TEXTURE_FORMAT_U5U6U5_RGB , SCE_GXM_COLOR_FORMAT_U5U6U5_RGB }, // RGB16
{ 16, SCE_GXM_TEXTURE_FORMAT_U1U5U5U5_ARGB , SCE_GXM_COLOR_FORMAT_U1U5U5U5_ARGB }, // RGBA16
{ 64, SCE_GXM_COLOR_FORMAT_A8R8G8B8 , SCE_GXM_COLOR_FORMAT_A8R8G8B8 }, // RGBA_FLOAT // not supported
{ 64, SCE_GXM_COLOR_FORMAT_A8R8G8B8 , SCE_GXM_COLOR_FORMAT_A8R8G8B8 }, // RGBA_HALF
{ 32, SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ARGB , SCE_GXM_COLOR_FORMAT_A8R8G8B8 }, // RGBA
{ 32, SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ARGB , SCE_GXM_COLOR_FORMAT_A8R8G8B8 }, // RGBA
// { 64, SCE_GXM_TEXTURE_FORMAT_F16F16F16F16_ARGB , SCE_GXM_COLOR_FORMAT_F16F16F16F16_RGBA }, // RGBA_FLOAT // not supported
// { 64, SCE_GXM_TEXTURE_FORMAT_F16F16F16F16_ARGB , SCE_GXM_COLOR_FORMAT_F16F16F16F16_RGBA }, // RGBA_HALF
{ 32, SCE_GXM_TEXTURE_FORMAT_F32M_R , SCE_GXM_DEPTH_STENCIL_FORMAT_DF32 }, // DEPTH
{ 32, SCE_GXM_TEXTURE_FORMAT_F32M_R , SCE_GXM_DEPTH_STENCIL_FORMAT_DF32 }, // SHADOW
};
@ -667,8 +671,6 @@ namespace GAPI {
SCE_GXM_DEPTH_STENCIL_SURFACE_TILED,
aWidth, this->data, NULL);
sceGxmDepthStencilSurfaceSetForceStoreMode ( &depthSurface, SCE_GXM_DEPTH_STENCIL_FORCE_STORE_ENABLED );
} else {
sceGxmColorSurfaceInit(&colorSurface,
SceGxmColorFormat(desc.targetFormat),
@ -738,6 +740,10 @@ namespace GAPI {
if (active.textures[sampler] != this) {
active.textures[sampler] = this;
sceGxmSetFragmentTexture(Context::gxmContext, sampler, &ID);
if (opt & OPT_VERTEX) {
sceGxmSetVertexTexture(Context::gxmContext, sampler, &ID);
}
}
}
@ -999,8 +1005,8 @@ namespace GAPI {
bool loadDepth = (Core::reqTarget.op & RT_LOAD_DEPTH);
bool storeDepth = (Core::reqTarget.op & RT_STORE_DEPTH);
//sceGxmDepthStencilSurfaceSetForceLoadMode ( &target->depthSurface, loadDepth ? SCE_GXM_DEPTH_STENCIL_FORCE_LOAD_ENABLED : SCE_GXM_DEPTH_STENCIL_FORCE_LOAD_DISABLED );
//sceGxmDepthStencilSurfaceSetForceStoreMode ( &target->depthSurface, storeDepth ? SCE_GXM_DEPTH_STENCIL_FORCE_STORE_ENABLED : SCE_GXM_DEPTH_STENCIL_FORCE_STORE_DISABLED );
sceGxmDepthStencilSurfaceSetForceLoadMode ( &target->depthSurface, loadDepth ? SCE_GXM_DEPTH_STENCIL_FORCE_LOAD_ENABLED : SCE_GXM_DEPTH_STENCIL_FORCE_LOAD_DISABLED );
sceGxmDepthStencilSurfaceSetForceStoreMode ( &target->depthSurface, storeDepth ? SCE_GXM_DEPTH_STENCIL_FORCE_STORE_ENABLED : SCE_GXM_DEPTH_STENCIL_FORCE_STORE_DISABLED );
sceGxmBeginScene(Context::gxmContext, 0, target->renderTarget, NULL, NULL, NULL, colorSurface, &target->depthSurface);
@ -1155,6 +1161,9 @@ namespace GAPI {
}
vec4 copyPixel(int x, int y) {
// GAPI::Texture *t = Core::active.target;
// Color32 *color = (Color32*)t->data;
// return vec4(color->r, color->g, color->b, 255.0f) * (1.0f / 255.0f);
return vec4(0.0f); // TODO: read from framebuffer
}

View File

@ -1137,16 +1137,17 @@ struct Inventory {
bool ready = active && phaseRing == 1.0f && phasePage == 1.0f;
Input::Joystick &joy = Input::joy[Core::settings.controls[playerIndex].joyIndex];
Input::Joystick &joy = Input::joy[Core::settings.controls[playerIndex].joyIndex];
Input::Joystick &joyMain = Input::joy[0];
ControlKey key = cMAX;
if (Input::down[ikCtrl] || Input::down[ikEnter] || Input::lastState[playerIndex] == cAction || joy.down[jkA])
key = cAction;
else if (Input::down[ikAlt] || joy.down[jkB] || Input::lastState[playerIndex] == cInventory)
key = cInventory;
else if (Input::down[ikLeft] || joy.down[jkLeft] || joy.L.x < -0.5f)
else if (Input::down[ikLeft] || joy.down[jkLeft] || joy.L.x < -0.5f || joyMain.down[jkLeft] || joyMain.L.x < -0.5f)
key = cLeft;
else if (Input::down[ikRight] || joy.down[jkRight] || joy.L.x > 0.5f)
else if (Input::down[ikRight] || joy.down[jkRight] || joy.L.x > 0.5f || joyMain.down[jkRight] || joyMain.L.x > 0.5f)
key = cRight;
else if (Input::down[ikUp] || joy.down[jkUp] || joy.L.y < -0.5f)
key = cUp;
@ -1854,8 +1855,6 @@ struct Inventory {
// items
game->setupBinding();
Core::mLightProj.identity();
setupCamera(aspect);
UI::setupInventoryShading();

View File

@ -339,9 +339,12 @@ struct Level : IGame {
void initShadow() {
delete shadow;
if (Core::settings.detail.shadows > Core::Settings::LOW)
shadow = new Texture(SHADOW_TEX_WIDTH, SHADOW_TEX_HEIGHT, FMT_SHADOW, OPT_TARGET);
else
if (Core::settings.detail.shadows > Core::Settings::LOW) {
if (level.isTitle())
shadow = new Texture(32, 32, FMT_SHADOW); // init dummy shadow map
else
shadow = new Texture(SHADOW_TEX_SIZE, SHADOW_TEX_SIZE, FMT_SHADOW, OPT_TARGET);
} else
shadow = NULL;
}
@ -551,6 +554,7 @@ struct Level : IGame {
Core::whiteTex->bind(sMask);
Core::whiteTex->bind(sReflect);
Core::whiteCube->bind(sEnvironment);
if (shadow) shadow->bind(sShadow);
Core::basis.identity();
}
@ -846,6 +850,8 @@ struct Level : IGame {
needRedrawTitleBG = false;
needRedrawReflections = true;
initShadow();
if (!(lastTitle = level.isTitle())) {
ASSERT(players[0] != NULL);
player = players[0];
@ -860,8 +866,6 @@ struct Level : IGame {
ambientCache->getAmbient(players[0]->getRoomIndex(), players[0]->pos, cube); // add to queue
}
initShadow();
for (int i = 0; i < level.soundSourcesCount; i++) {
TR::SoundSource &src = level.soundSources[i];
int flags = Sound::PAN;

View File

@ -0,0 +1 @@
curl --ftp-method nocwd -T OpenLara.self ftp://192.168.1.39:1337/ux0:/app/OPENLARA1/eboot.bin

Binary file not shown.

After

Width:  |  Height:  |  Size: 896 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<livearea style="a1" format-ver="01.00" content-rev="1">
<livearea-background>
<image>bg.png</image>
</livearea-background>
<gate>
<startup-image>startup.png</startup-image>
</gate>
</livearea>

View File

@ -17,20 +17,20 @@ psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/clear_vp.gxp clear.hlsl
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/clear_fp.gxp clear.hlsl -DPIXEL
cd gxm
C:\pspsdk\bin\bin2c.exe compose_vp.gxp compose_vp.h COMPOSE_VP
C:\pspsdk\bin\bin2c.exe compose_fp.gxp compose_fp.h COMPOSE_FP
C:\pspsdk\bin\bin2c.exe shadow_vp.gxp shadow_vp.h SHADOW_VP
C:\pspsdk\bin\bin2c.exe shadow_fp.gxp shadow_fp.h SHADOW_FP
C:\pspsdk\bin\bin2c.exe ambient_vp.gxp ambient_vp.h AMBIENT_VP
C:\pspsdk\bin\bin2c.exe ambient_fp.gxp ambient_fp.h AMBIENT_FP
C:\pspsdk\bin\bin2c.exe water_vp.gxp water_vp.h WATER_VP
C:\pspsdk\bin\bin2c.exe water_fp.gxp water_fp.h WATER_FP
C:\pspsdk\bin\bin2c.exe filter_vp.gxp filter_vp.h FILTER_VP
C:\pspsdk\bin\bin2c.exe filter_fp.gxp filter_fp.h FILTER_FP
C:\pspsdk\bin\bin2c.exe gui_vp.gxp gui_vp.h GUI_VP
C:\pspsdk\bin\bin2c.exe gui_fp.gxp gui_fp.h GUI_FP
C:\pspsdk\bin\bin2c.exe clear_vp.gxp clear_vp.h CLEAR_VP
C:\pspsdk\bin\bin2c.exe clear_fp.gxp clear_fp.h CLEAR_FP
..\bin2c.exe compose_vp.gxp compose_vp.h COMPOSE_VP
..\bin2c.exe compose_fp.gxp compose_fp.h COMPOSE_FP
..\bin2c.exe shadow_vp.gxp shadow_vp.h SHADOW_VP
..\bin2c.exe shadow_fp.gxp shadow_fp.h SHADOW_FP
..\bin2c.exe ambient_vp.gxp ambient_vp.h AMBIENT_VP
..\bin2c.exe ambient_fp.gxp ambient_fp.h AMBIENT_FP
..\bin2c.exe water_vp.gxp water_vp.h WATER_VP
..\bin2c.exe water_fp.gxp water_fp.h WATER_FP
..\bin2c.exe filter_vp.gxp filter_vp.h FILTER_VP
..\bin2c.exe filter_fp.gxp filter_fp.h FILTER_FP
..\bin2c.exe gui_vp.gxp gui_vp.h GUI_VP
..\bin2c.exe gui_fp.gxp gui_fp.h GUI_FP
..\bin2c.exe clear_vp.gxp clear_vp.h CLEAR_VP
..\bin2c.exe clear_fp.gxp clear_fp.h CLEAR_FP
cd ..

View File

@ -12,7 +12,7 @@ struct VS_OUTPUT {
float4 light : TEXCOORD7;
float4 lightProj : TEXCOORD8;
#ifdef _GAPI_GXM
//float clipDist : CLP0;
float clipDist : CLP0;
#endif
};
@ -129,9 +129,17 @@ VS_OUTPUT main(VS_INPUT In) {
}
Out.pos = mul(uViewProj, float4(Out.coord, rBasisPos.w));
Out.lightProj = mul(uLightProj, float4(Out.coord, 1.0));
Out.lightProj = mul(uLightProj, float4(Out.coord, 1.0));
/*
if (TYPE_ROOM) {
float3 lightVec = uLightPos[0].xyz - Out.coord;
if (dot(Out.normal.xyz, lightVec) < 0.0) {
Out.lightProj.w = -1.0;
}
}
*/
#ifdef _GAPI_GXM
//Out.clipDist = uParam.w - Out.viewVec.w;
Out.clipDist = uParam.w - Out.viewVec.w;
#endif
return Out;
@ -141,23 +149,24 @@ Out.lightProj = mul(uLightProj, float4(Out.coord, 1.0));
float SHADOW(float2 p) {
#ifdef SHADOW_DEPTH
return tex2D(sShadow, p).x;
return tex2Dlod(sShadow, float4(p, 0, 0)).x;
#else
return unpack(tex2D(sShadow, p));
return unpack(tex2Dlod(sShadow, float4(p, 0, 0)));
#endif
}
float getShadow(float3 lightVec, float3 normal, float4 lightProj) {
/*
float sMin = min(lightProj.x, lightProj.y);
float sMax = max(lightProj.x, lightProj.y);
//float vis = lightProj.w;
//if (TYPE_ROOM) {
// vis = min(vis, dot(normal, lightVec));
//}
//sMin = min(vis, sMin);
float factor = step(0.0, lightProj.w); //((sMin > 0.0f) && (sMax < lightProj.w));
float vis = lightProj.w;
if (TYPE_ROOM) {
vis = min(vis, dot(normal, lightVec));
}
sMin = min(vis, sMin);
*/
float factor = step(0.0, lightProj.w); //float((sMin > 0.0f) && (sMax < lightProj.w)); //
lightProj.xyz *= factor;
#ifdef _GAPI_GXM
lightProj.z += SHADOW_CONST_BIAS * SHADOW_TEXEL.x * lightProj.w;
@ -182,7 +191,7 @@ float getShadow(float3 lightVec, float3 normal, float4 lightProj) {
float rShadow = lerp(samples.x, samples.y, f.y);
#endif
rShadow = lerp(1.0, rShadow, factor);
//rShadow = lerp(1.0, rShadow, factor);
float fade = saturate(dot(lightVec, lightVec));
return rShadow + (1.0 - rShadow) * fade;
@ -207,7 +216,7 @@ float getContactAO(float3 p, float3 n) {
float calcCaustics(float3 coord, float3 n) {
float2 cc = saturate((coord.xz - uRoomSize.xy) / uRoomSize.zw);
return tex2D(sReflect, float2(cc.x, 1.0 - cc.y)).x * max(0.0, -n.y);
return tex2Dlod(sReflect, float4(cc.x, 1.0 - cc.y, 0, 0)).x * max(0.0, -n.y);
}
float calcSpecular(float3 normal, float3 viewVec, float3 lightVec, float intensity) {
@ -220,14 +229,6 @@ float calcSpecular(float3 normal, float3 viewVec, float3 lightVec, float intensi
float4 main(VS_OUTPUT In) : COLOR0 {
float2 uv = In.texCoord.xy;
#ifndef _GAPI_GXM
if (CLIP_PLANE) {
if (In.viewVec.w > uParam.w) {
discard;
}
}
#endif
if (!TYPE_SPRITE) {
uv /= In.texCoord.zw;
}
@ -246,6 +247,14 @@ float4 main(VS_OUTPUT In) : COLOR0 {
}
}
#ifndef _GAPI_GXM
if (CLIP_PLANE) {
if (In.viewVec.w > uParam.w) {
discard;
}
}
#endif
color *= In.diffuse;
if (TYPE_FLASH) {

View File

@ -33,7 +33,7 @@ float4 downsample(float2 uv) { // uParam (1 / textureSize, unused, unused, unuse
for (float y = -1.5; y < 2.0; y++) {
for (float x = -1.5; x < 2.0; x++) {
float4 p;
p.xyz = tex2D(sDiffuse, uv + float2(x, y) * uParam.x).xyz;
p.xyz = tex2Dlod(sDiffuse, float4(uv + float2(x, y) * uParam.x, 0, 0)).xyz;
p.w = dot(p.xyz, float3(0.299, 0.587, 0.114));
p.xyz *= p.w;
color += p;

View File

@ -182,7 +182,7 @@ float4 rays(VS_OUTPUT In, float2 pixelCoord) {
float3 p0 = uViewPos.xyz - viewVec * t;
float3 p1 = In.coord.xyz;
float dither = tex2D(sMask, pixelCoord * (1.0 / 8.0)).x;
float dither = tex2Dlod(sMask, float4(pixelCoord * (1.0 / 8.0), 0, 0)).x;
float3 delta = (p1 - p0) / RAY_STEPS;
float3 pos = p0 + delta * dither;
@ -191,7 +191,7 @@ float4 rays(VS_OUTPUT In, float2 pixelCoord) {
for (float i = 0.0; i < RAY_STEPS; i++) {
float3 wpos = (pos - uPosScale[0].xyz) / uPosScale[1].xyz;
float2 tc = wpos.xz * 0.5 + 0.5;
float light = tex2D(sReflect, tc).x;
float light = tex2Dlod(sReflect, float4(tc, 0, 0)).x;
sum += light * (1.0 - (clamp(wpos.y, -1.0, 1.0) * 0.5 + 0.5));
pos += delta;
}
@ -234,15 +234,15 @@ float4 compose(VS_OUTPUT In) {
dist *= step(In.coord.y, uViewPos.y);
color.xyz *= lerp(float3(1.0, 1.0, 1.0), UNDERWATER_COLOR, clamp(dist * WATER_COLOR_DIST, 0.0, 2.0));
float fog = saturate(1.0 / exp(dist * WATER_FOG_DIST));
color.xyz = lerp(UNDERWATER_COLOR * 0.2, color.xyz, fog);
return float4(tex2D(sReflect, tc.xy).xyz, 1.0); // color
color.xyz = lerp(UNDERWATER_COLOR * 0.2, color.xyz, fog);
return color;
}
#ifndef _GAPI_GXM
float4 main(VS_OUTPUT In, float4 pixelCoord: VPOS) : COLOR0 {
#else
#ifdef _GAPI_GXM
float4 main(VS_OUTPUT In) : COLOR0 {
float2 pixelCoord = float2(__pixel_x(), __pixel_y());
#else
float4 main(VS_OUTPUT In, float4 pixelCoord: VPOS) : COLOR0 {
#endif
if (WATER_DROP)
return drop(In);

View File

@ -635,7 +635,10 @@ namespace UI {
}
void setupInventoryShading() {
Core::whiteTex->bind(sShadow);
Core::mView.identity();
Core::mProj = GAPI::perspective(1.0f, 1.0f, 1.0f, 2.0f);
Core::mLightProj = Core::mProj * Core::mView;
game->setShader(Core::passCompose, Shader::ENTITY, false, false);
Core::setMaterial(1.0f, 0.0f, 0.0f, 1.0f);