diff --git a/src/cache.h b/src/cache.h index 419c0bf..cf116b2 100644 --- a/src/cache.h +++ b/src/cache.h @@ -214,6 +214,8 @@ struct ShaderCache { shader->setParam(uLightProj, Core::mLightProj); shader->setParam(uViewPos, Core::viewPos); shader->setParam(uParam, Core::params); + #else + Core::setAlphaTest((fx & FX_ALPHA_TEST) != 0); #endif } diff --git a/src/core.h b/src/core.h index ed3970a..d4b2bef 100644 --- a/src/core.h +++ b/src/core.h @@ -146,9 +146,9 @@ #include #define FFP - //#define TEX_SWIZZLE - #define EDRAM_MESH - //#define EDRAM_TEX + #define TEX_SWIZZLE + //#define EDRAM_MESH + #define EDRAM_TEX #endif #ifdef USE_INFLATE @@ -500,6 +500,7 @@ enum RenderState { RS_BLEND_MULT = 1 << 12, RS_BLEND_PREMULT = 1 << 13, RS_BLEND = RS_BLEND_ADD | RS_BLEND_ALPHA | RS_BLEND_MULT | RS_BLEND_PREMULT, + RS_ALPHA_TEST = 1 << 14, }; typedef uint16 Index; @@ -689,7 +690,7 @@ namespace Core { static int EDRAM_SIZE; void* allocEDRAM(int size) { - LOG("EDRAM ALLOC: offset: %d size %d\n", Core::EDRAM_OFFSET, size); + LOG("EDRAM ALLOC: offset: %d size %d (free %d)\n", Core::EDRAM_OFFSET, size, EDRAM_SIZE - (Core::EDRAM_OFFSET + size)); if (Core::EDRAM_OFFSET + size > EDRAM_SIZE) LOG("! EDRAM overflow !\n"); @@ -931,7 +932,6 @@ namespace Core { sceGuShadeModel(GU_SMOOTH); sceGuAlphaFunc(GU_GREATER, 127, 255); - sceGuEnable(GU_ALPHA_TEST); int swizzle = GU_FALSE; #ifdef TEX_SWIZZLE @@ -955,13 +955,10 @@ namespace Core { sceGuSetDither(&dith); sceGuEnable(GU_DITHER); - sceGuEnable(GU_LIGHT0); - sceGuDisable(GU_LIGHT1); - sceGuDisable(GU_LIGHT2); - sceGuDisable(GU_LIGHT3); sceGuAmbientColor(0xFFFFFFFF); sceGuColor(0xFFFFFFFF); - sceGuClearColor(0xffff00ff); + sceGuClearColor(0x00000000); + sceGuColorMaterial(GU_AMBIENT | GU_DIFFUSE); freeEDRAM(); #else @@ -971,19 +968,12 @@ namespace Core { glEnableClientState(GL_VERTEX_ARRAY); glAlphaFunc(GL_GREATER, 0.5f); - glEnable(GL_ALPHA_TEST); - - glEnable(GL_LIGHT0); - glDisable(GL_LIGHT1); - glDisable(GL_LIGHT2); - glDisable(GL_LIGHT3); - glEnable(GL_NORMALIZE); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glScalef(1.0f / 32767.0f, 1.0f / 32767.0f, 1.0f / 32767.0f); - glClearColor(1, 0, 1, 1); + glClearColor(0, 0, 0, 0); #endif #endif @@ -1289,6 +1279,20 @@ namespace Core { #endif } + if (mask & RS_ALPHA_TEST) { + #ifdef _PSP + if (renderState & RS_ALPHA_TEST) + sceGuEnable(GU_ALPHA_TEST); + else + sceGuDisable(GU_ALPHA_TEST); + #else + if (renderState & RS_ALPHA_TEST) + glEnable(GL_ALPHA_TEST); + else + glDisable(GL_ALPHA_TEST); + #endif + } + if (mask & RS_TARGET) { if (reqTarget.clear) { #ifdef _PSP @@ -1340,6 +1344,12 @@ namespace Core { } } + void setAlphaTest(bool value) { + renderState &= ~RS_ALPHA_TEST; + if (value) + renderState |= RS_ALPHA_TEST; + } + void setColorWrite(bool r, bool g, bool b, bool a) { renderState &= ~RS_COLOR_WRITE; if (r) renderState |= RS_COLOR_WRITE_R; diff --git a/src/inventory.h b/src/inventory.h index a8c64b0..8bf7c65 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -1076,6 +1076,9 @@ struct Inventory { } void prepareBackground() { + #ifdef _PSP + return; + #endif Core::defaultTarget = getBackgroundTarget(); game->renderGame(false); Core::defaultTarget = NULL; @@ -1266,6 +1269,125 @@ struct Inventory { } } + void renderTitleBG() { + float aspectSrc = float(background[0]->origWidth) / float(background[0]->origHeight); + float aspectDst = float(Core::width) / float(Core::height); + float aspectImg = aspectSrc / aspectDst; + float ax = background[0]->origWidth / float(background[0]->width); + + #ifdef FFP + mat4 m; + m.identity(); + Core::setViewProj(m, m); + Core::mModel.identity(); + Core::mModel.scale(vec3(1.0f / 32767.0f)); + #endif + + uint8 alpha; + if (!isActive() && titleTimer > 0.0f && titleTimer < 1.0f) { + Core::setBlending(bmAlpha); + alpha = uint8(titleTimer * 255); + } else { + Core::setBlending(bmNone); + alpha = 255; + } + + Index indices[6 * 3] = { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11 }; + Vertex vertices[4 * 3]; + + short2 size; + if (aspectImg < 1.0f) { + size.x = short(32767 * aspectImg); + size.y = 32767; + + vertices[ 4].coord = short4( -32767, size.y, 0, 0); + vertices[ 5].coord = short4(-size.x, size.y, 0, 0); + vertices[ 6].coord = short4(-size.x, -size.y, 0, 0); + vertices[ 7].coord = short4( -32767, -size.y, 0, 0); + + vertices[ 8].coord = short4( size.x, size.y, 0, 0); + vertices[ 9].coord = short4( 32767, size.y, 0, 0); + vertices[10].coord = short4( 32767, -size.y, 0, 0); + vertices[11].coord = short4( size.x, -size.y, 0, 0); + } else { + size.x = 32767; + size.y = short(32767 / aspectImg); + + vertices[ 4].coord = short4(-size.x, 32767, 0, 0); + vertices[ 5].coord = short4( size.x, 32767, 0, 0); + vertices[ 6].coord = short4( size.x, size.y, 0, 0); + vertices[ 7].coord = short4(-size.x, size.y, 0, 0); + + vertices[ 8].coord = short4(-size.x, -size.y, 0, 0); + vertices[ 9].coord = short4( size.x, -size.y, 0, 0); + vertices[10].coord = short4( size.x, -32767, 0, 0); + vertices[11].coord = short4(-size.x, -32767, 0, 0); + } + + short tw = short(ax * 32767); + vertices[ 0].coord = short4(-size.x, size.y, 0, 0); + vertices[ 1].coord = short4( size.x, size.y, 0, 0); + vertices[ 2].coord = short4( size.x, -size.y, 0, 0); + vertices[ 3].coord = short4(-size.x, -size.y, 0, 0); + + vertices[ 0].light = + vertices[ 1].light = + vertices[ 2].light = + vertices[ 3].light = ubyte4(255, 255, 255, alpha); + vertices[ 4].light = + vertices[ 5].light = + vertices[ 6].light = + vertices[ 7].light = + vertices[ 8].light = + vertices[ 9].light = + vertices[10].light = + vertices[11].light = ubyte4(0, 0, 0, alpha); + + vertices[ 0].texCoord = short4( 0, 0, 0, 0); + vertices[ 1].texCoord = short4(tw, 0, 0, 0); + vertices[ 2].texCoord = short4(tw, 32767, 0, 0); + vertices[ 3].texCoord = short4( 0, 32767, 0, 0); + vertices[ 4].texCoord = + vertices[ 5].texCoord = + vertices[ 6].texCoord = + vertices[ 7].texCoord = + vertices[ 8].texCoord = + vertices[ 9].texCoord = + vertices[10].texCoord = + vertices[11].texCoord = short4(0, 0, 0, 0); + + game->setShader(Core::passFilter, Shader::DEFAULT, false, false); + background[0]->bind(sDiffuse); + game->getMesh()->renderBuffer(indices, COUNT(indices), vertices, COUNT(vertices)); + } + + void renderGameBG() { + #ifdef _PSP + return; + #endif + Index indices[6] = { 0, 1, 2, 0, 2, 3 }; + Vertex vertices[4]; + vertices[ 0].coord = short4(-32767, 32767, 0, 0); + vertices[ 1].coord = short4( 32767, 32767, 0, 0); + vertices[ 2].coord = short4( 32767, -32767, 0, 0); + vertices[ 3].coord = short4(-32767, -32767, 0, 0); + vertices[ 0].light = + vertices[ 1].light = + vertices[ 2].light = + vertices[ 3].light = ubyte4(255, 255, 255, uint8(phaseRing * 255)); + vertices[ 0].texCoord = short4( 0, 32767, 0, 0); + vertices[ 1].texCoord = short4(32767, 32767, 0, 0); + vertices[ 2].texCoord = short4(32767, 0, 0, 0); + vertices[ 3].texCoord = short4( 0, 0, 0, 0); + + game->setShader(Core::passFilter, Shader::DEFAULT, false, false); + + // blured grayscale image + background[1]->bind(sDiffuse); + Core::setBlending(phaseRing < 1.0f ? bmAlpha : bmNone); + game->getMesh()->renderBuffer(indices, COUNT(indices), vertices, COUNT(vertices)); + } + void renderBackground() { if (!isActive() && titleTimer == 0.0f) return; @@ -1273,43 +1395,14 @@ struct Inventory { Core::setDepthTest(false); if (background[0]) { - #ifdef FFP - mat4 m; - m.identity(); - Core::setViewProj(m, m); - Core::mModel.identity(); - // Core::mModel.scale(vec3(0.9f)); - #endif - - background[0]->bind(sDiffuse); // orignal image - if (background[1]) { - game->setShader(Core::passFilter, Shader::FILTER_MIXER, false, false); - Core::active.shader->setParam(uParam, vec4(phaseRing, 1.0f - phaseRing * 0.4f, 0, 0));; - background[1]->bind(sNormal); // blured grayscale image - Core::setBlending(bmNone); - } else { - game->setShader(Core::passFilter, Shader::DEFAULT, false, false); - - float aspectSrc = float(background[0]->origWidth) / float(background[0]->origHeight); - float aspectDst = float(Core::width) / float(Core::height); - float aspectImg = aspectDst / aspectSrc; - float ax = background[0]->origWidth / float(background[0]->width); - float ay = background[0]->origHeight / float(background[0]->height); - Core::active.shader->setParam(uParam, vec4(ax * aspectImg, -ay, (0.5f - aspectImg * 0.5f) * ax, ay)); - - if (!isActive() && titleTimer > 0.0f && titleTimer < 1.0f) { - Core::setBlending(bmAlpha); - Core::active.shader->setParam(uMaterial, vec4(1, 1, 1, titleTimer)); - } else { - Core::setBlending(bmNone); - Core::active.shader->setParam(uMaterial, vec4(1)); - } - } - game->getMesh()->renderQuad(); + if (background[1]) + renderGameBG(); + else + renderTitleBG(); } - Core::setDepthTest(true); Core::setBlending(bmAlpha); + Core::setDepthTest(true); } void render(float aspect) { diff --git a/src/level.h b/src/level.h index 284abf1..904bb73 100644 --- a/src/level.h +++ b/src/level.h @@ -1271,6 +1271,9 @@ struct Level : IGame { dir = -1; } + beginLighting(true); + updateLighting(); + while (i != end) { int roomIndex = roomsList[i]; MeshBuilder::RoomRange &range = mesh->rooms[roomIndex]; @@ -1329,6 +1332,7 @@ struct Level : IGame { mesh->renderRoomSprites(roomIndex); } } + endLighting(); Core::setBlending(bmNone); } @@ -1368,6 +1372,8 @@ struct Level : IGame { } else setRoomParams(roomIndex, type, 1.0f, intensity, controller->specular, 1.0f, mesh->transparent == 1); + updateLighting(); + if (isModel) { // model vec3 pos = controller->getPos(); if (ambientCache) { @@ -1514,6 +1520,82 @@ struct Level : IGame { } } + void updateLighting() { + #ifdef FFP + #ifdef _PSP + ubyte4 ambient; + ambient.x = ambient.y = ambient.z = clamp(int(Core::active.material.y * 255), 0, 255); + ambient.w = 255; + sceGuAmbient(*(uint32*)&ambient); + + for (int i = 0; i < 2 /*MAX_LIGHTS*/; i++) { + ScePspFVector3 pos; + pos.x = Core::lightPos[i].x; + pos.y = Core::lightPos[i].y; + pos.z = Core::lightPos[i].z; + + sceGuLight(i, GU_POINTLIGHT, GU_DIFFUSE, &pos); + + ubyte4 color; + color.x = clamp(int(Core::lightColor[i].x * 255), 0, 255); + color.y = clamp(int(Core::lightColor[i].y * 255), 0, 255); + color.z = clamp(int(Core::lightColor[i].z * 255), 0, 255); + color.w = 255; + + sceGuLightColor(i, GU_DIFFUSE, *(uint32*)&color); + sceGuLightAtt(i, 1.0f, 0.0f, Core::lightColor[i].w * Core::lightColor[i].w); + } + #else + vec4 ambient(vec3(Core::active.material.y), 1.0f); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, (GLfloat*)&ambient); + + for (int i = 0; i < 2 /*MAX_LIGHTS*/; i++) { + vec4 pos(Core::lightPos[i].xyz(), 1.0f); + vec4 color(Core::lightColor[i].xyz(), 1.0f); + float att = Core::lightColor[i].w; + att *= att; + + glLightfv(GL_LIGHT0 + i, GL_POSITION, (GLfloat*)&pos); + glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, (GLfloat*)&color); + glLightfv(GL_LIGHT0 + i, GL_QUADRATIC_ATTENUATION, (GLfloat*)&att); + } + #endif + #endif + } + + void beginLighting(bool room) { + #ifdef FFP + Core::mModel.identity(); + #ifdef _PSP + sceGuEnable(GU_LIGHTING); + if (room) + sceGuDisable(GU_LIGHT0); + else + sceGuEnable(GU_LIGHT0); + sceGuEnable(GU_LIGHT1); + #else + glEnable(GL_COLOR_MATERIAL); + glEnable(GL_LIGHTING); + if (room) + glDisable(GL_LIGHT0); + else + glEnable(GL_LIGHT0); + glEnable(GL_LIGHT1); + #endif + #endif + } + + void endLighting() { + #ifdef FFP + #ifdef _PSP + sceGuDisable(GU_LIGHTING); + #else + glDisable(GL_COLOR_MATERIAL); + glDisable(GL_LIGHTING); + #endif + #endif + } + void setup() { camera->setup(Core::pass == Core::passCompose); setupBinding(); @@ -1534,6 +1616,8 @@ struct Level : IGame { PROFILE_MARKER("ENTITIES"); + beginLighting(false); + if (transp == 0) { Core::setBlending(bmNone); renderEntitiesTransp(transp); @@ -1559,6 +1643,8 @@ struct Level : IGame { renderEntitiesTransp(transp); Core::setDepthWrite(true); } + + endLighting(); } bool checkPortal(const TR::Room &room, const TR::Room::Portal &portal, const vec4 &viewPort, vec4 &clipPort) { @@ -1704,6 +1790,8 @@ struct Level : IGame { } prepareRooms(roomsList, roomsCount); + + updateLighting(); for (int transp = 0; transp < 3; transp++) { renderRooms(roomsList, roomsCount, transp); renderEntities(transp); @@ -2212,8 +2300,12 @@ struct Level : IGame { inventory.prepareBackground(); } - if (!title && inventory.titleTimer <= 1.0f) - renderGame(true); + if (!level.isTitle()) { + if (inventory.phaseRing < 1.0f && inventory.titleTimer <= 1.0f) { + renderGame(true); + title = false; + } + } renderInventory(title); } diff --git a/src/mesh.h b/src/mesh.h index 2ccd7a4..a5f39c1 100644 --- a/src/mesh.h +++ b/src/mesh.h @@ -126,7 +126,7 @@ struct Mesh { for (int i = 0; i < vCount; i++) { dst->texCoord = short2(src->texCoord.x, src->texCoord.y); - dst->color = ubyte4(src->light.x, src->light.y, src->light.z, 255); //color; + dst->color = ubyte4(src->light.x, src->light.y, src->light.z, src->light.w); //color; dst->normal = src->normal; dst->coord = src->coord; @@ -205,18 +205,6 @@ struct Mesh { } }; - -#define CHECK_NORMAL(n) \ - if (!(n.x | n.y | n.z)) {\ - vec3 o(mVertices[f.vertices[0]]);\ - vec3 a = o - mVertices[f.vertices[1]];\ - vec3 b = o - mVertices[f.vertices[2]];\ - o = b.cross(a).normal() * 32767.0f;\ - n.x = (int)o.x;\ - n.y = (int)o.y;\ - n.z = (int)o.z;\ - }\ - #define CHECK_ROOM_NORMAL(f) \ vec3 o(d.vertices[f.vertices[0]].vertex);\ vec3 a = o - d.vertices[f.vertices[1]].vertex;\ @@ -234,11 +222,11 @@ struct Mesh { d.vertices[f.vertices[3]].vertex);\ for (int k = 0; k < f.vCount; k++) {\ TR::Room::Data::Vertex &v = d.vertices[f.vertices[k]];\ - vertices[vCount].coord = short4( v.vertex.x, v.vertex.y, v.vertex.z, 0 );\ - vertices[vCount].normal = short4( f.normal.x, f.normal.y, f.normal.z, 0 );\ - vertices[vCount].color = ubyte4( 255, 255, 255, 255 );\ - vertices[vCount].light = ubyte4( v.color.r, v.color.g, v.color.b, 255 );\ - vCount++;\ + Vertex &rv = vertices[vCount++];\ + rv.coord = short4( v.vertex.x, v.vertex.y, v.vertex.z, 0 );\ + rv.normal = short4( f.normal.x, f.normal.y, f.normal.z, 0 );\ + rv.color = ubyte4( 255, 255, 255, 255 );\ + rv.light = ubyte4( v.color.r, v.color.g, v.color.b, 255 );\ } @@ -646,15 +634,15 @@ struct MeshBuilder { quad.iCount = 2 * 3; addQuad(indices, iCount, vCount, vStartCommon, vertices, &whiteTile, false); - vertices[vCount + 3].coord = short4( -1, -1, 0, 0 ); - vertices[vCount + 2].coord = short4( 1, -1, 1, 0 ); - vertices[vCount + 1].coord = short4( 1, 1, 1, 1 ); - vertices[vCount + 0].coord = short4( -1, 1, 0, 1 ); + vertices[vCount + 0].coord = short4( -32767, 32767, 0, 1 ); + vertices[vCount + 1].coord = short4( 32767, 32767, 1, 1 ); + vertices[vCount + 2].coord = short4( 32767, -32767, 1, 0 ); + vertices[vCount + 3].coord = short4( -32767, -32767, 0, 0 ); - vertices[vCount + 3].texCoord = short4( 0, 0, 0, 0 ); - vertices[vCount + 2].texCoord = short4( 32767, 0, 0, 0 ); - vertices[vCount + 1].texCoord = short4( 32767, 32767, 0, 0 ); vertices[vCount + 0].texCoord = short4( 0, 32767, 0, 0 ); + vertices[vCount + 1].texCoord = short4( 32767, 32767, 0, 0 ); + vertices[vCount + 2].texCoord = short4( 32767, 0, 0, 0 ); + vertices[vCount + 3].texCoord = short4( 0, 0, 0, 0 ); for (int i = 0; i < 4; i++) { Vertex &v = vertices[vCount + i]; @@ -716,7 +704,7 @@ struct MeshBuilder { plane.iCount = 0; #endif - LOG("MegaMesh (i:%d v:%d a:%d)\n", iCount, vCount, aCount); + LOG("MegaMesh (i:%d v:%d a:%d, size:%d)\n", iCount, vCount, aCount, iCount * sizeof(Index) + vCount * sizeof(VertexGPU)); // compile buffer and ranges mesh = new Mesh(indices, iCount, vertices, vCount, aCount); @@ -948,8 +936,9 @@ struct MeshBuilder { TR::Mesh::Vertex &v = mesh.vertices[f.vertices[k]]; vertices[vCount].coord = transform(v.coord, joint, x, y, z, dir); + vec3 n = vec3(v.normal.x, v.normal.y, v.normal.z).normal() * 32767.0f; + v.normal = short4(short(n.x), short(n.y), short(n.z), 0); vertices[vCount].normal = rotate(v.normal, dir); - vertices[vCount].normal.w = t.attribute == 2 ? 0 : 32767; vertices[vCount].color = ubyte4( c.r, c.g, c.b, 255 ); vertices[vCount].light = ubyte4( light.r, light.g, light.b, 255 ); @@ -1327,59 +1316,6 @@ struct MeshBuilder { } void renderModel(int modelIndex, bool underwater = false) { - #ifdef FFP - Core::mModel.identity(); - - #ifdef _PSP - //sceGuDisable(GU_TEXTURE_2D); - //Core::setBlending(bmNone); - sceGuEnable(GU_LIGHTING); - - ubyte4 ambient; - ambient.x = ambient.y = ambient.z = clamp(int(Core::active.material.y * 255), 0, 255); - ambient.w = 255; - sceGuAmbient(*(uint32*)&ambient); - - for (int i = 0; i < 1 /*MAX_LIGHTS*/; i++) { - ScePspFVector3 pos; - pos.x = Core::lightPos[i].x; - pos.y = Core::lightPos[i].y; - pos.z = Core::lightPos[i].z; - - sceGuLight(i, GU_POINTLIGHT, GU_DIFFUSE, &pos); - - ubyte4 color; - color.x = clamp(int(Core::lightColor[i].x * 255), 0, 255); - color.y = clamp(int(Core::lightColor[i].y * 255), 0, 255); - color.z = clamp(int(Core::lightColor[i].z * 255), 0, 255); - color.w = 255; - - sceGuLightColor(i, GU_DIFFUSE, *(uint32*)&color); - sceGuLightAtt(i, 1.0f, 0.0f, Core::lightColor[i].w * Core::lightColor[i].w); - } - #else - glEnable(GL_LIGHTING); - glEnable(GL_COLOR_MATERIAL); - - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf((GLfloat*)&Core::mView); - - vec4 ambient(vec3(Core::active.material.y), 1.0f); - glLightModelfv(GL_LIGHT_MODEL_AMBIENT, (GLfloat*)&ambient); - - for (int i = 0; i < 1 /*MAX_LIGHTS*/; i++) { - vec4 pos(Core::lightPos[i].xyz(), 1.0f); - vec4 color(Core::lightColor[i].xyz(), 1.0f); - float att = Core::lightColor[i].w; - att *= att; - - glLightfv(GL_LIGHT0 + i, GL_POSITION, (GLfloat*)&pos); - glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, (GLfloat*)&color); - glLightfv(GL_LIGHT0 + i, GL_QUADRATIC_ATTENUATION, (GLfloat*)&att); - } - #endif - #endif - ASSERT(level->models[modelIndex].mCount == Core::active.basisCount); int part = 0; @@ -1398,7 +1334,7 @@ struct MeshBuilder { continue; } #ifdef FFP -// Core::setMatrix(NULL, NULL, &m); + Core::mModel.identity(); Core::mModel.setRot(basis.rot); Core::mModel.setPos(basis.pos); #endif @@ -1417,15 +1353,6 @@ struct MeshBuilder { mesh->render(range); } } - - #ifdef FFP - #ifdef _PSP - sceGuDisable(GU_LIGHTING); - #else - glDisable(GL_COLOR_MATERIAL); - glDisable(GL_LIGHTING); - #endif - #endif } void renderSprite(int sequenceIndex, int frame) { @@ -1434,8 +1361,8 @@ struct MeshBuilder { Core::mModel.setPos(Core::active.basis[0].pos); int vCount = 0, iCount = 0; - Index indices[1 * 6]; - Vertex vertices[1 * 4]; + Index indices[6]; + Vertex vertices[4]; TR::SpriteTexture &sprite = level->spriteTextures[level->spriteSequences[sequenceIndex].sStart + frame]; diff --git a/src/shaders/filter.glsl b/src/shaders/filter.glsl index 98fa9aa..6b525bb 100644 --- a/src/shaders/filter.glsl +++ b/src/shaders/filter.glsl @@ -5,19 +5,18 @@ R"====( #endif varying vec2 vTexCoord; -uniform vec4 uMaterial; +varying vec4 vColor; uniform vec4 uParam; #ifdef VERTEX attribute vec4 aCoord; + attribute vec4 aTexCoord; + attribute vec4 aLight; void main() { - #ifdef FILTER_DEFAULT - vTexCoord = aCoord.zw * uParam.xy + uParam.zw; - #else - vTexCoord = aCoord.zw; - #endif - gl_Position = vec4(aCoord.xy, 0.0, 1.0); + vTexCoord = aTexCoord.xy; + vColor = aLight; + gl_Position = vec4(aCoord.xy * (1.0 / 32767.0), 0.0, 1.0); } #else uniform sampler2D sDiffuse; @@ -95,7 +94,7 @@ uniform vec4 uParam; return equirectangular(); #endif - return texture2D(sDiffuse, vTexCoord) * uMaterial; + return texture2D(sDiffuse, vTexCoord) * vColor; } void main() { diff --git a/src/shaders/water.glsl b/src/shaders/water.glsl index 3ee36a3..00313b7 100644 --- a/src/shaders/water.glsl +++ b/src/shaders/water.glsl @@ -29,7 +29,8 @@ uniform sampler2D sNormal; attribute vec4 aCoord; void main() { - vTexCoord = (aCoord.xy * 0.5 + 0.5) * uTexParam.zw; + vec3 coord = aCoord.xyz * (1.0 / 32767.0); + vTexCoord = (coord.xy * 0.5 + 0.5) * uTexParam.zw; #if defined(WATER_MASK) || defined(WATER_COMPOSE) @@ -37,12 +38,12 @@ uniform sampler2D sNormal; #ifdef WATER_COMPOSE #ifdef WATER_USE_GRID - vTexCoord = (aCoord.xy * (1.0 / 48.0) * 0.5 + 0.5) * uTexParam.zw; + vTexCoord = (coord.xy * (1.0 / 48.0) * 0.5 + 0.5) * uTexParam.zw; height = texture2D(sNormal, vTexCoord).x; #endif #endif - vCoord = vec3(aCoord.x, height, aCoord.y) * uPosScale[1] + uPosScale[0]; + vCoord = vec3(coord.x, height, coord.y) * uPosScale[1] + uPosScale[0]; vec4 cp = uViewProj * vec4(vCoord, 1.0); @@ -50,9 +51,9 @@ uniform sampler2D sNormal; gl_Position = cp; #else vProjCoord = vec4(0.0); - vCoord = vec3(aCoord.xy, 0.0); + vCoord = vec3(coord.xy, 0.0); #ifdef WATER_CAUSTICS - vec3 rCoord = vec3(aCoord.x, aCoord.y, 0.0) * uPosScale[1].xzy; + vec3 rCoord = vec3(coord.x, coord.y, 0.0) * uPosScale[1].xzy; vec4 info = texture2D(sNormal, (rCoord.xy * 0.5 + 0.5) * uTexParam.zw); vec3 normal = vec3(info.z, info.w, sqrt(1.0 - dot(info.zw, info.zw))); @@ -67,7 +68,7 @@ uniform sampler2D sNormal; gl_Position = vec4(vNewPos.xy + refOld.xy / refOld.z, 0.0, 1.0); #else vOldPos = vNewPos = vec4(0.0); - gl_Position = vec4(aCoord.xyz, 1.0); + gl_Position = vec4(coord.xyz, 1.0); #endif #endif vViewVec = uViewPos - vCoord.xyz; diff --git a/src/texture.h b/src/texture.h index a515eaa..4772ec5 100644 --- a/src/texture.h +++ b/src/texture.h @@ -70,6 +70,11 @@ struct Texture { void bind(uint16 tile, uint16 clut) { #ifdef _PSP + int swizzle = GU_FALSE; + #ifdef TEX_SWIZZLE + swizzle = GU_TRUE; + #endif + sceGuTexMode(GU_PSM_T4, 0, 0, swizzle); sceGuClutLoad(1, cluts + clut); sceGuTexImage(0, width, height, width, tiles + tile); #else @@ -79,6 +84,8 @@ struct Texture { #endif Texture(int width, int height, Format format, uint32 opt = 0, void *data = NULL) : opt(opt) { + LOG("create texture %d x %d (%d)\n", width, height, format); + #ifndef _PSP #ifdef SPLIT_BY_TILE memset(this->tiles, 0, sizeof(tiles)); @@ -126,8 +133,15 @@ struct Texture { this->format = format; #ifdef _PSP - memory = new uint8[width * height * 4]; - memcpy(memory, data, width * height * 4); + if (data) { + memory = new uint8[width * height * 4]; + #ifdef TEX_SWIZZLE + swizzle(memory, (uint8*)data, width * 4, height); + #else + memcpy(memory, data, width * height * 4); + #endif + } else + memory = NULL; #else glGenTextures(1, &ID); bind(0); @@ -268,10 +282,8 @@ struct Texture { #ifdef TEX_SWIZZLE swizzle = GU_TRUE; #endif - - sceGuTexMode(GU_PSM_8888, 0, 0, GU_FALSE); + sceGuTexMode(GU_PSM_8888, 0, 0, swizzle); sceGuTexImage(0, width, height, width, memory); - sceGuTexMode(GU_PSM_T4, 0, 0, swizzle); } #else #ifdef SPLIT_BY_TILE