mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-10 15:14:28 +02:00
#15 PSV split ambient shaders; generate shader cache for underwater, alphatest flags; fix fragment/vertex shader depended textures; fix dynamic mesh update;
This commit is contained in:
78
src/cache.h
78
src/cache.h
@@ -7,7 +7,6 @@
|
||||
#include "camera.h"
|
||||
|
||||
#define NO_CLIP_PLANE 1000000.0f
|
||||
//#define LOG_SHADERS
|
||||
|
||||
#if defined(_OS_IOS) || defined(_GAPI_D3D9) || defined(_GAPI_GXM)
|
||||
#define USE_SCREEN_TEX
|
||||
@@ -167,48 +166,6 @@ struct ShaderCache {
|
||||
|
||||
#undef SD_ADD
|
||||
|
||||
#ifdef LOG_SHADERS
|
||||
{
|
||||
static const char *DefineName[SD_MAX] = { SHADER_DEFINES(DECL_STR) };
|
||||
|
||||
int id = 0;
|
||||
/*
|
||||
id |= flags[ 5];
|
||||
id |= flags[ 6];
|
||||
id |= flags[ 7];
|
||||
id |= flags[ 8];
|
||||
id |= flags[ 9];
|
||||
id |= flags[10];
|
||||
id |= flags[11];
|
||||
*/
|
||||
char defines[1024];
|
||||
defines[0] = 0;
|
||||
|
||||
for (int i = 0; i < defCount; i++) { // base shader defines
|
||||
strcat(defines, " /D");
|
||||
strcat(defines, DefineName[def[i]]);
|
||||
strcat(defines, "=1");
|
||||
}
|
||||
|
||||
const char *name = NULL;
|
||||
|
||||
switch (pass) {
|
||||
case passCompose : name = "compose"; break;
|
||||
case passShadow : name = "shadow"; break;
|
||||
case passAmbient : name = "ambient"; break;
|
||||
case passWater : name = "water" ; break;
|
||||
case passFilter : name = "filter"; break;
|
||||
case passGUI : name = "gui"; break;
|
||||
}
|
||||
|
||||
char buf[256];
|
||||
sprintf(buf, "%s_%d_%02X", name, type, id);
|
||||
LOG("fxc /nologo /T vs_3_0 /O3 /Gec /Vn %s_vs /Fh d3d9/%s_vs.h %s.hlsl /DVERTEX%s\n", buf, buf, name, defines);
|
||||
LOG("fxc /nologo /T vs_3_0 /O3 /Gec /Vn %s_ps /Fh d3d9/%s_ps.h %s.hlsl /DPIXEL%s\n", buf, buf, name, defines);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
return shaders[pass][type][fx] = new Shader(pass, type, def, defCount);
|
||||
#else
|
||||
return NULL;
|
||||
@@ -232,8 +189,9 @@ struct ShaderCache {
|
||||
fx &= ~ShaderCache::FX_CLIP_PLANE;
|
||||
|
||||
Shader *shader = getShader(pass, type, fx);
|
||||
if (shader)
|
||||
if (shader) {
|
||||
shader->setup();
|
||||
}
|
||||
|
||||
Core::setAlphaTest((fx & FX_ALPHA_TEST) != 0);
|
||||
}
|
||||
@@ -457,7 +415,8 @@ struct WaterCache {
|
||||
#define MAX_SURFACES 16
|
||||
#define MAX_INVISIBLE_TIME 5.0f
|
||||
#define SIMULATE_TIMESTEP (1.0f / 40.0f)
|
||||
#define DETAIL (64.0f / 1024.0f)
|
||||
#define WATER_TILE_SIZE 64
|
||||
#define DETAIL (WATER_TILE_SIZE / 1024.0f)
|
||||
#define MAX_DROPS 32
|
||||
|
||||
IGame *game;
|
||||
@@ -554,13 +513,13 @@ struct WaterCache {
|
||||
size = vec3(float((maxX - minX) * 512), 1.0f, float((maxZ - minZ) * 512)); // half size
|
||||
pos = vec3(r.info.x + minX * 1024 + size.x, float(posY), r.info.z + minZ * 1024 + size.z);
|
||||
|
||||
int *mf = new int[4 * w * 64 * h * 64];
|
||||
memset(mf, 0, sizeof(int) * 4 * w * 64 * h * 64);
|
||||
data[0] = new Texture(w * 64, h * 64, FMT_RG_HALF, OPT_TARGET | OPT_VERTEX, mf);
|
||||
data[1] = new Texture(w * 64, h * 64, FMT_RG_HALF, OPT_TARGET | OPT_VERTEX);
|
||||
int *mf = new int[4 * w * h * SQR(WATER_TILE_SIZE)];
|
||||
memset(mf, 0, sizeof(int) * 4 * w * h * SQR(WATER_TILE_SIZE));
|
||||
data[0] = new Texture(w * WATER_TILE_SIZE, h * WATER_TILE_SIZE, FMT_RG_HALF, OPT_TARGET | OPT_VERTEX, mf);
|
||||
data[1] = new Texture(w * WATER_TILE_SIZE, h * WATER_TILE_SIZE, FMT_RG_HALF, OPT_TARGET | OPT_VERTEX);
|
||||
delete[] mf;
|
||||
|
||||
caustics = Core::settings.detail.water > Core::Settings::MEDIUM ? new Texture(512, 512, FMT_RGBA, OPT_TARGET) : NULL;
|
||||
caustics = Core::settings.detail.water > Core::Settings::MEDIUM ? new Texture(512, 512, FMT_RGBA, OPT_TARGET | OPT_DEPEND) : NULL;
|
||||
#ifdef BLUR_CAUSTICS
|
||||
caustics_tmp = Core::settings.detail.water > Core::Settings::MEDIUM ? new Texture(512, 512, Texture::RGBA) : NULL;
|
||||
#endif
|
||||
@@ -766,7 +725,8 @@ struct WaterCache {
|
||||
Core::whiteTex->bind(sReflect);
|
||||
item.data[0]->bind(sNormal);
|
||||
Core::setTarget(item.caustics, NULL, RT_CLEAR_COLOR | RT_STORE_COLOR);
|
||||
Core::setViewport(1, 1, item.caustics->width - 2, item.caustics->width - 2); // leave 1px for black border
|
||||
Core::validateRenderState(); // force clear color for borders
|
||||
Core::setViewport(1, 1, item.caustics->width - 1, item.caustics->width - 1); // leave 2px for black border
|
||||
game->getMesh()->renderPlane();
|
||||
#ifdef BLUR_CAUSTICS
|
||||
// v blur
|
||||
@@ -871,16 +831,18 @@ struct WaterCache {
|
||||
if (!screen) {
|
||||
x = Core::viewportDef.x;
|
||||
y = Core::viewportDef.y;
|
||||
} else
|
||||
} else {
|
||||
x = y = 0;
|
||||
}
|
||||
|
||||
if (screen) { // only for iOS devices
|
||||
if (screen) {
|
||||
Core::setTarget(refract, NULL, RT_LOAD_DEPTH | RT_STORE_COLOR | RT_STORE_DEPTH);
|
||||
blitTexture(screen);
|
||||
Core::setTarget(screen, NULL, RT_LOAD_COLOR | RT_LOAD_DEPTH | RT_STORE_COLOR);
|
||||
} else
|
||||
} else {
|
||||
Core::copyTarget(refract, 0, 0, x, y, Core::viewportDef.width, Core::viewportDef.height); // copy framebuffer into refraction texture
|
||||
}
|
||||
}
|
||||
|
||||
void simulate() {
|
||||
PROFILE_MARKER("WATER_SIMULATE");
|
||||
@@ -998,7 +960,7 @@ struct WaterCache {
|
||||
item.mask->bind(sMask);
|
||||
item.data[0]->bind(sNormal);
|
||||
Core::setCullMode(cmNone);
|
||||
Core::setBlendMode(bmAlpha);
|
||||
Core::setBlendMode(bmNone);
|
||||
#ifdef WATER_USE_GRID
|
||||
vec4 rPosScale[2] = { vec4(item.pos, 0.0f), vec4(item.size * vec3(1.0f / PLANE_DETAIL, 512.0f, 1.0f / PLANE_DETAIL), 1.0f) };
|
||||
Core::active.shader->setParam(uPosScale, rPosScale[0], 2);
|
||||
@@ -1059,9 +1021,9 @@ struct WaterCache {
|
||||
Core::setDepthTest(true);
|
||||
}
|
||||
|
||||
#undef MAX_WATER_SURFACES
|
||||
#undef MAX_WATER_INVISIBLE_TIME
|
||||
#undef WATER_SIMULATE_TIMESTEP
|
||||
#undef MAX_SURFACES
|
||||
#undef MAX_INVISIBLE_TIME
|
||||
#undef SIMULATE_TIMESTEP
|
||||
#undef DETAIL
|
||||
};
|
||||
|
||||
|
15
src/core.h
15
src/core.h
@@ -348,13 +348,14 @@ enum TexFormat {
|
||||
|
||||
// Texture options
|
||||
enum TexOption {
|
||||
OPT_REPEAT = 1,
|
||||
OPT_CUBEMAP = 2,
|
||||
OPT_MIPMAPS = 4,
|
||||
OPT_NEAREST = 8,
|
||||
OPT_TARGET = 16,
|
||||
OPT_VERTEX = 32,
|
||||
OPT_PROXY = 64,
|
||||
OPT_REPEAT = 0x01,
|
||||
OPT_CUBEMAP = 0x02,
|
||||
OPT_MIPMAPS = 0x04,
|
||||
OPT_NEAREST = 0x08,
|
||||
OPT_TARGET = 0x10,
|
||||
OPT_VERTEX = 0x20,
|
||||
OPT_DEPEND = 0x40,
|
||||
OPT_PROXY = 0x80,
|
||||
};
|
||||
|
||||
// Pipeline State Object
|
||||
|
146
src/gapi_d3d9.h
146
src/gapi_d3d9.h
@@ -50,37 +50,6 @@ void D3DCHECK(HRESULT res) {
|
||||
#endif
|
||||
|
||||
namespace GAPI {
|
||||
#include "shaders/d3d9/compose_sprite_vs.h"
|
||||
#include "shaders/d3d9/compose_sprite_ps.h"
|
||||
#include "shaders/d3d9/compose_flash_vs.h"
|
||||
#include "shaders/d3d9/compose_flash_ps.h"
|
||||
#include "shaders/d3d9/compose_room_vs.h"
|
||||
#include "shaders/d3d9/compose_room_ps.h"
|
||||
#include "shaders/d3d9/compose_entity_vs.h"
|
||||
#include "shaders/d3d9/compose_entity_ps.h"
|
||||
#include "shaders/d3d9/compose_mirror_vs.h"
|
||||
#include "shaders/d3d9/compose_mirror_ps.h"
|
||||
#include "shaders/d3d9/shadow_vs.h"
|
||||
#include "shaders/d3d9/shadow_ps.h"
|
||||
#include "shaders/d3d9/ambient_vs.h"
|
||||
#include "shaders/d3d9/ambient_ps.h"
|
||||
#include "shaders/d3d9/water_drop_vs.h"
|
||||
#include "shaders/d3d9/water_drop_ps.h"
|
||||
#include "shaders/d3d9/water_simulate_vs.h"
|
||||
#include "shaders/d3d9/water_simulate_ps.h"
|
||||
#include "shaders/d3d9/water_caustics_vs.h"
|
||||
#include "shaders/d3d9/water_caustics_ps.h"
|
||||
#include "shaders/d3d9/water_rays_vs.h"
|
||||
#include "shaders/d3d9/water_rays_ps.h"
|
||||
#include "shaders/d3d9/water_mask_vs.h"
|
||||
#include "shaders/d3d9/water_mask_ps.h"
|
||||
#include "shaders/d3d9/water_compose_vs.h"
|
||||
#include "shaders/d3d9/water_compose_ps.h"
|
||||
#include "shaders/d3d9/filter_vs.h"
|
||||
#include "shaders/d3d9/filter_ps.h"
|
||||
#include "shaders/d3d9/gui_vs.h"
|
||||
#include "shaders/d3d9/gui_ps.h"
|
||||
|
||||
using namespace Core;
|
||||
|
||||
typedef ::Vertex Vertex;
|
||||
@@ -122,6 +91,8 @@ namespace GAPI {
|
||||
}
|
||||
|
||||
// Shader
|
||||
#include "shaders/d3d9/shaders.h"
|
||||
|
||||
enum {
|
||||
USAGE_VS,
|
||||
USAGE_PS,
|
||||
@@ -157,53 +128,84 @@ namespace GAPI {
|
||||
Shader() : VS(NULL), PS(NULL) {}
|
||||
|
||||
void init(Core::Pass pass, int type, int *def, int defCount) {
|
||||
const BYTE *vSrc, *pSrc;
|
||||
switch (pass) {
|
||||
case Core::passCompose :
|
||||
switch (type) {
|
||||
case 0 : vSrc = COMPOSE_SPRITE_VS; pSrc = COMPOSE_SPRITE_PS; break;
|
||||
case 1 : vSrc = COMPOSE_FLASH_VS; pSrc = COMPOSE_FLASH_PS; break;
|
||||
case 2 : vSrc = COMPOSE_ROOM_VS; pSrc = COMPOSE_ROOM_PS; break;
|
||||
case 3 : vSrc = COMPOSE_ENTITY_VS; pSrc = COMPOSE_ENTITY_PS; break;
|
||||
case 4 : vSrc = COMPOSE_MIRROR_VS; pSrc = COMPOSE_MIRROR_PS; break;
|
||||
default : ASSERT(false);
|
||||
}
|
||||
break;
|
||||
case Core::passShadow : vSrc = SHADOW_VS; pSrc = SHADOW_PS; break;
|
||||
case Core::passAmbient : vSrc = AMBIENT_VS; pSrc = AMBIENT_PS; break;
|
||||
case Core::passWater :
|
||||
switch (type) {
|
||||
case 0 : vSrc = WATER_DROP_VS; pSrc = WATER_DROP_PS; break;
|
||||
case 1 : vSrc = WATER_SIMULATE_VS; pSrc = WATER_SIMULATE_PS; break;
|
||||
case 2 : vSrc = WATER_CAUSTICS_VS; pSrc = WATER_CAUSTICS_PS; break;
|
||||
case 3 : vSrc = WATER_RAYS_VS; pSrc = WATER_RAYS_PS; break;
|
||||
case 4 : vSrc = WATER_MASK_VS; pSrc = WATER_MASK_PS; break;
|
||||
case 5 : vSrc = WATER_COMPOSE_VS; pSrc = WATER_COMPOSE_PS; break;
|
||||
default : ASSERT(false);
|
||||
}
|
||||
break;
|
||||
case Core::passFilter : vSrc = FILTER_VS; pSrc = FILTER_PS; break;
|
||||
case Core::passGUI : vSrc = GUI_VS; pSrc = GUI_PS; break;
|
||||
default : ASSERT(false); LOG("! wrong pass id\n"); return;
|
||||
}
|
||||
|
||||
memset(flags, 0, sizeof(flags));
|
||||
flags[type] = TRUE;
|
||||
|
||||
bool underwater = false;
|
||||
bool alphatest = false;
|
||||
|
||||
for (int i = 0; i < defCount; i++) {
|
||||
switch (def[i]) {
|
||||
case SD_UNDERWATER : flags[ 5] = TRUE; break;
|
||||
case SD_ALPHA_TEST : flags[ 6] = TRUE; break;
|
||||
case SD_CLIP_PLANE : flags[ 7] = TRUE; break;
|
||||
case SD_OPT_AMBIENT : flags[ 8] = TRUE; break;
|
||||
case SD_OPT_SHADOW : flags[ 9] = TRUE; break;
|
||||
case SD_OPT_CONTACT : flags[10] = TRUE; break;
|
||||
case SD_OPT_CAUSTICS : flags[11] = TRUE; break;
|
||||
case SD_UNDERWATER : underwater = true; break;
|
||||
case SD_ALPHA_TEST : alphatest = true; break;
|
||||
case SD_OPT_AMBIENT : flags[0] = TRUE; break;
|
||||
case SD_OPT_SHADOW : flags[1] = TRUE; break;
|
||||
case SD_OPT_CONTACT : flags[2] = TRUE; break;
|
||||
case SD_OPT_CAUSTICS : flags[3] = TRUE; break;
|
||||
}
|
||||
}
|
||||
|
||||
#define SHADER(S,P) S##_##P
|
||||
#define SHADER_A(S,P) (alphatest ? SHADER(S##_a,P) : SHADER(S,P))
|
||||
#define SHADER_U(S,P) (underwater ? SHADER(S##_u,P) : SHADER(S,P))
|
||||
#define SHADER_AU(S,P) ((underwater && alphatest) ? SHADER(S##_au,P) : (alphatest ? SHADER(S##_a,P) : SHADER_U(S,P)))
|
||||
|
||||
const uint8 *vSrc, *fSrc;
|
||||
switch (pass) {
|
||||
case passCompose :
|
||||
switch (type) {
|
||||
case 0 : vSrc = SHADER_U ( compose_sprite, v ); fSrc = SHADER_AU ( compose_sprite, f ); break;
|
||||
case 1 : vSrc = SHADER ( compose_flash, v ); fSrc = SHADER ( compose_flash, f ); break;
|
||||
case 2 : vSrc = SHADER_U ( compose_room, v ); fSrc = SHADER_AU ( compose_room, f ); break;
|
||||
case 3 : vSrc = SHADER_U ( compose_entity, v ); fSrc = SHADER_AU ( compose_entity, f ); break;
|
||||
case 4 : vSrc = SHADER ( compose_mirror, v ); fSrc = SHADER ( compose_mirror, f ); break;
|
||||
default : ASSERT(false);
|
||||
}
|
||||
break;
|
||||
case passShadow :
|
||||
switch (type) {
|
||||
case 3 : vSrc = SHADER ( shadow_entity, v ); fSrc = SHADER ( shadow_entity, f ); break;
|
||||
default : ASSERT(false);
|
||||
}
|
||||
break;
|
||||
case passAmbient :
|
||||
switch (type) {
|
||||
case 0 : vSrc = SHADER ( ambient_sprite, v ); fSrc = SHADER_A ( ambient_sprite, f ); break;
|
||||
case 1 : vSrc = SHADER ( ambient_room, v ); fSrc = SHADER ( ambient_room, f ); break; // TYPE_FLASH (sky)
|
||||
case 2 : vSrc = SHADER ( ambient_room, v ); fSrc = SHADER_A ( ambient_room, f ); break;
|
||||
default : ASSERT(false);
|
||||
}
|
||||
break;
|
||||
case passWater :
|
||||
switch (type) {
|
||||
case 0 : vSrc = SHADER ( water_drop, v ); fSrc = SHADER ( water_drop, f ); break;
|
||||
case 1 : vSrc = SHADER ( water_simulate, v ); fSrc = SHADER ( water_simulate, f ); break;
|
||||
case 2 : vSrc = SHADER ( water_caustics, v ); fSrc = SHADER ( water_caustics, f ); break;
|
||||
case 3 : vSrc = SHADER ( water_rays, v ); fSrc = SHADER ( water_rays, f ); break;
|
||||
case 4 : vSrc = SHADER ( water_mask, v ); fSrc = SHADER ( water_mask, f ); break;
|
||||
case 5 : vSrc = SHADER ( water_compose, v ); fSrc = SHADER ( water_compose, f ); break;
|
||||
default : ASSERT(false);
|
||||
}
|
||||
break;
|
||||
case passFilter :
|
||||
switch (type) {
|
||||
case 0 : vSrc = SHADER ( filter_upscale, v ); fSrc = SHADER ( filter_upscale, f ); break;
|
||||
case 1 : vSrc = SHADER ( filter_downsample, v ); fSrc = SHADER ( filter_downsample, f ); break;
|
||||
case 3 : vSrc = SHADER ( filter_grayscale, v ); fSrc = SHADER ( filter_grayscale, f ); break;
|
||||
case 4 : vSrc = SHADER ( filter_blur, v ); fSrc = SHADER ( filter_blur, f ); break;
|
||||
default : ASSERT(false);
|
||||
}
|
||||
break;
|
||||
case passGUI : vSrc = SHADER ( gui, v ); fSrc = SHADER ( gui, f ); break;
|
||||
default : ASSERT(false); LOG("! wrong pass id\n"); return;
|
||||
}
|
||||
|
||||
#undef SHADER_A
|
||||
#undef SHADER_U
|
||||
#undef SHADER_AU
|
||||
|
||||
device->CreateVertexShader ((DWORD*)vSrc, &VS);
|
||||
device->CreatePixelShader ((DWORD*)pSrc, &PS);
|
||||
device->CreatePixelShader ((DWORD*)fSrc, &PS);
|
||||
}
|
||||
|
||||
void deinit() {
|
||||
@@ -339,8 +341,9 @@ namespace GAPI {
|
||||
if (opt & OPT_VERTEX) {
|
||||
device->SetTexture(D3DVERTEXTEXTURESAMPLER0 + sampler, tex2D);
|
||||
}
|
||||
} else if (texCube)
|
||||
} else if (texCube) {
|
||||
device->SetTexture(sampler, texCube);
|
||||
}
|
||||
|
||||
bool filter = (Core::settings.detail.filter > Core::Settings::LOW) && !(opt & OPT_NEAREST);
|
||||
bool mipmaps = (Core::settings.detail.filter > Core::Settings::MEDIUM) && (opt & OPT_MIPMAPS);
|
||||
@@ -472,7 +475,7 @@ namespace GAPI {
|
||||
support.texFloat = true;
|
||||
support.texHalfLinear = true;
|
||||
support.texHalf = true;
|
||||
support.clipDist = false;
|
||||
support.clipDist = true;
|
||||
|
||||
#ifdef PROFILE
|
||||
support.profMarker = false;
|
||||
@@ -525,7 +528,6 @@ namespace GAPI {
|
||||
if (defDS) defDS->Release();
|
||||
|
||||
D3DCHECK(device->Reset(&d3dpp));
|
||||
|
||||
device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &defRT);
|
||||
device->GetDepthStencilSurface(&defDS);
|
||||
|
||||
|
217
src/gapi_gxm.h
217
src/gapi_gxm.h
@@ -19,39 +19,6 @@
|
||||
#define DISPLAY_PIXEL_FORMAT SCE_DISPLAY_PIXELFORMAT_A8B8G8R8
|
||||
|
||||
namespace GAPI {
|
||||
#include "shaders/gxm/compose_sprite_vp.h"
|
||||
#include "shaders/gxm/compose_sprite_fp.h"
|
||||
#include "shaders/gxm/compose_flash_vp.h"
|
||||
#include "shaders/gxm/compose_flash_fp.h"
|
||||
#include "shaders/gxm/compose_room_vp.h"
|
||||
#include "shaders/gxm/compose_room_fp.h"
|
||||
#include "shaders/gxm/compose_entity_vp.h"
|
||||
#include "shaders/gxm/compose_entity_fp.h"
|
||||
#include "shaders/gxm/compose_mirror_vp.h"
|
||||
#include "shaders/gxm/compose_mirror_fp.h"
|
||||
#include "shaders/gxm/shadow_vp.h"
|
||||
#include "shaders/gxm/shadow_fp.h"
|
||||
#include "shaders/gxm/ambient_vp.h"
|
||||
#include "shaders/gxm/ambient_fp.h"
|
||||
#include "shaders/gxm/water_drop_vp.h"
|
||||
#include "shaders/gxm/water_drop_fp.h"
|
||||
#include "shaders/gxm/water_simulate_vp.h"
|
||||
#include "shaders/gxm/water_simulate_fp.h"
|
||||
#include "shaders/gxm/water_caustics_vp.h"
|
||||
#include "shaders/gxm/water_caustics_fp.h"
|
||||
#include "shaders/gxm/water_rays_vp.h"
|
||||
#include "shaders/gxm/water_rays_fp.h"
|
||||
#include "shaders/gxm/water_mask_vp.h"
|
||||
#include "shaders/gxm/water_mask_fp.h"
|
||||
#include "shaders/gxm/water_compose_vp.h"
|
||||
#include "shaders/gxm/water_compose_fp.h"
|
||||
#include "shaders/gxm/filter_vp.h"
|
||||
#include "shaders/gxm/filter_fp.h"
|
||||
#include "shaders/gxm/gui_vp.h"
|
||||
#include "shaders/gxm/gui_fp.h"
|
||||
#include "shaders/gxm/clear_vp.h"
|
||||
#include "shaders/gxm/clear_fp.h"
|
||||
|
||||
#define SHADER_BUFF_SIZE (64 * 1024)
|
||||
#define SHADER_VERT_SIZE (64 * 1024)
|
||||
#define SHADER_FRAG_SIZE (64 * 1024)
|
||||
@@ -281,12 +248,13 @@ namespace GAPI {
|
||||
void checkPendings() {
|
||||
int i = 0;
|
||||
while (i < pendings.length) {
|
||||
if (pendings[i].frameIndex + DISPLAY_BUFFER_COUNT <= Core::stats.frameIndex)
|
||||
if (pendings[i].frameIndex + DISPLAY_BUFFER_COUNT <= Core::stats.frameIndex) {
|
||||
pendings.removeFast(i);
|
||||
else
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void swizzleTiles(T *dst, T *src, int width, int tilesX, int tilesY) {
|
||||
@@ -461,6 +429,8 @@ namespace GAPI {
|
||||
};
|
||||
|
||||
// Shader
|
||||
#include "shaders/gxm/shaders.h"
|
||||
|
||||
static const int bindings[uMAX] = {
|
||||
94, // uFlags
|
||||
0, // uParam
|
||||
@@ -507,54 +477,88 @@ namespace GAPI {
|
||||
|
||||
outputFmt = SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4;
|
||||
|
||||
const uint8 *vpSrc, *fpSrc;
|
||||
switch (pass) {
|
||||
case passCompose :
|
||||
switch (type) {
|
||||
case 0 : vpSrc = COMPOSE_SPRITE_VP; fpSrc = COMPOSE_SPRITE_FP; break;
|
||||
case 1 : vpSrc = COMPOSE_FLASH_VP; fpSrc = COMPOSE_FLASH_FP; break;
|
||||
case 2 : vpSrc = COMPOSE_ROOM_VP; fpSrc = COMPOSE_ROOM_FP; break;
|
||||
case 3 : vpSrc = COMPOSE_ENTITY_VP; fpSrc = COMPOSE_ENTITY_FP; break;
|
||||
case 4 : vpSrc = COMPOSE_MIRROR_VP; fpSrc = COMPOSE_MIRROR_FP; break;
|
||||
default : ASSERT(false);
|
||||
}
|
||||
break;
|
||||
case passShadow : vpSrc = SHADOW_VP; fpSrc = SHADOW_FP; break;
|
||||
case passAmbient : vpSrc = AMBIENT_VP; fpSrc = AMBIENT_FP; break;
|
||||
case passWater :
|
||||
switch (type) {
|
||||
case 0 : vpSrc = WATER_DROP_VP; fpSrc = WATER_DROP_FP; outputFmt = SCE_GXM_OUTPUT_REGISTER_FORMAT_HALF2; break;
|
||||
case 1 : vpSrc = WATER_SIMULATE_VP; fpSrc = WATER_SIMULATE_FP; outputFmt = SCE_GXM_OUTPUT_REGISTER_FORMAT_HALF2; break;
|
||||
case 2 : vpSrc = WATER_CAUSTICS_VP; fpSrc = WATER_CAUSTICS_FP; break;
|
||||
case 3 : vpSrc = WATER_RAYS_VP; fpSrc = WATER_RAYS_FP; break;
|
||||
case 4 : vpSrc = WATER_MASK_VP; fpSrc = WATER_MASK_FP; break;
|
||||
case 5 : vpSrc = WATER_COMPOSE_VP; fpSrc = WATER_COMPOSE_FP; break;
|
||||
default : ASSERT(false);
|
||||
}
|
||||
break;
|
||||
case passFilter : vpSrc = FILTER_VP; fpSrc = FILTER_FP; break;
|
||||
case passGUI : vpSrc = GUI_VP; fpSrc = GUI_FP; break;
|
||||
case PASS_CLEAR : vpSrc = CLEAR_VP; fpSrc = CLEAR_FP; break;
|
||||
default : ASSERT(false); LOG("! wrong pass id\n"); return;
|
||||
}
|
||||
|
||||
float *flags = (float*)(cbMem + bindings[uFlags]);
|
||||
flags[type] = 1.0f;
|
||||
|
||||
bool underwater = false;
|
||||
bool alphatest = false;
|
||||
|
||||
for (int i = 0; i < defCount; i++) {
|
||||
switch (def[i]) {
|
||||
case SD_UNDERWATER : flags[ 5] = 1.0f; break;
|
||||
case SD_ALPHA_TEST : flags[ 6] = 1.0f; break;
|
||||
case SD_CLIP_PLANE : flags[ 7] = 1.0f; break;
|
||||
case SD_OPT_AMBIENT : flags[ 8] = 1.0f; break;
|
||||
case SD_OPT_SHADOW : flags[ 9] = 1.0f; break;
|
||||
case SD_OPT_CONTACT : flags[10] = 1.0f; break;
|
||||
case SD_OPT_CAUSTICS : flags[11] = 1.0f; break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
vpPtr = (SceGxmProgram*)vpSrc;
|
||||
fpPtr = (SceGxmProgram*)fpSrc;
|
||||
#define SHADER(S,P) S##_##P
|
||||
#define SHADER_A(S,P) (alphatest ? SHADER(S##_a,P) : SHADER(S,P))
|
||||
#define SHADER_U(S,P) (underwater ? SHADER(S##_u,P) : SHADER(S,P))
|
||||
#define SHADER_AU(S,P) ((underwater && alphatest) ? SHADER(S##_au,P) : (alphatest ? SHADER(S##_a,P) : SHADER_U(S,P)))
|
||||
|
||||
const uint8 *vSrc, *fSrc;
|
||||
switch (pass) {
|
||||
case passCompose :
|
||||
switch (type) {
|
||||
case 0 : vSrc = SHADER_U ( compose_sprite, v ); fSrc = SHADER_AU ( compose_sprite, f ); break;
|
||||
case 1 : vSrc = SHADER ( compose_flash, v ); fSrc = SHADER ( compose_flash, f ); break;
|
||||
case 2 : vSrc = SHADER_U ( compose_room, v ); fSrc = SHADER_AU ( compose_room, f ); break;
|
||||
case 3 : vSrc = SHADER_U ( compose_entity, v ); fSrc = SHADER_AU ( compose_entity, f ); break;
|
||||
case 4 : vSrc = SHADER ( compose_mirror, v ); fSrc = SHADER ( compose_mirror, f ); break;
|
||||
default : ASSERT(false);
|
||||
}
|
||||
break;
|
||||
case passShadow :
|
||||
switch (type) {
|
||||
case 3 : vSrc = SHADER ( shadow_entity, v ); fSrc = SHADER ( shadow_entity, f ); break;
|
||||
default : ASSERT(false);
|
||||
}
|
||||
break;
|
||||
case passAmbient :
|
||||
switch (type) {
|
||||
case 0 : vSrc = SHADER ( ambient_sprite, v ); fSrc = SHADER_A ( ambient_sprite, f ); break;
|
||||
case 1 : vSrc = SHADER ( ambient_room, v ); fSrc = SHADER ( ambient_room, f ); break; // TYPE_FLASH (sky)
|
||||
case 2 : vSrc = SHADER ( ambient_room, v ); fSrc = SHADER_A ( ambient_room, f ); break;
|
||||
default : ASSERT(false);
|
||||
}
|
||||
break;
|
||||
case passWater :
|
||||
switch (type) {
|
||||
case 0 : vSrc = SHADER ( water_drop, v ); fSrc = SHADER ( water_drop, f ); break;
|
||||
case 1 : vSrc = SHADER ( water_simulate, v ); fSrc = SHADER ( water_simulate, f ); break;
|
||||
case 2 : vSrc = SHADER ( water_caustics, v ); fSrc = SHADER ( water_caustics, f ); break;
|
||||
case 3 : vSrc = SHADER ( water_rays, v ); fSrc = SHADER ( water_rays, f ); break;
|
||||
case 4 : vSrc = SHADER ( water_mask, v ); fSrc = SHADER ( water_mask, f ); break;
|
||||
case 5 : vSrc = SHADER ( water_compose, v ); fSrc = SHADER ( water_compose, f ); break;
|
||||
default : ASSERT(false);
|
||||
}
|
||||
break;
|
||||
case passFilter :
|
||||
switch (type) {
|
||||
case 0 : vSrc = SHADER ( filter_upscale, v ); fSrc = SHADER ( filter_upscale, f ); break;
|
||||
case 1 : vSrc = SHADER ( filter_downsample, v ); fSrc = SHADER ( filter_downsample, f ); break;
|
||||
case 3 : vSrc = SHADER ( filter_grayscale, v ); fSrc = SHADER ( filter_grayscale, f ); break;
|
||||
case 4 : vSrc = SHADER ( filter_blur, v ); fSrc = SHADER ( filter_blur, f ); break;
|
||||
default : ASSERT(false);
|
||||
}
|
||||
break;
|
||||
case passGUI : vSrc = SHADER ( gui, v ); fSrc = SHADER ( gui, f ); break;
|
||||
case PASS_CLEAR : vSrc = SHADER ( clear, v ); fSrc = SHADER ( clear, f ); break;
|
||||
default : ASSERT(false); LOG("! wrong pass id\n"); return;
|
||||
}
|
||||
|
||||
#undef SHADER_A
|
||||
#undef SHADER_U
|
||||
#undef SHADER_AU
|
||||
|
||||
if (pass == passWater && (type == 0 || type == 1)) { // water_simulate & water_drop use half2 render target
|
||||
outputFmt = SCE_GXM_OUTPUT_REGISTER_FORMAT_HALF2;
|
||||
}
|
||||
|
||||
vpPtr = (SceGxmProgram*)vSrc;
|
||||
fpPtr = (SceGxmProgram*)fSrc;
|
||||
|
||||
sceGxmShaderPatcherRegisterProgram(shaderPatcher, vpPtr, &vpUID);
|
||||
|
||||
@@ -771,8 +775,8 @@ namespace GAPI {
|
||||
bool isCube = (opt & OPT_CUBEMAP) != 0;
|
||||
bool isTarget = (opt & OPT_TARGET) != 0;
|
||||
bool isShadow = fmt == FMT_SHADOW;
|
||||
bool isTiled = isTarget || fmt == FMT_DEPTH || fmt == FMT_SHADOW;
|
||||
bool isSwizzled = false;//!isTiled;
|
||||
bool isTiled = isTarget;
|
||||
bool isSwizzled = !isTiled;
|
||||
|
||||
FormatDesc desc = formats[fmt];
|
||||
|
||||
@@ -968,31 +972,39 @@ namespace GAPI {
|
||||
SceUID iBufferUID;
|
||||
SceUID vBufferUID;
|
||||
|
||||
int iCount;
|
||||
int vCount;
|
||||
|
||||
bool dynamic;
|
||||
|
||||
struct Chunk {
|
||||
int frameIndex;
|
||||
int iStart, iCount;
|
||||
int vStart, vCount;
|
||||
int iBase, iStart, iCount;
|
||||
int vBase, vStart, vCount;
|
||||
} chunks[DISPLAY_BUFFER_COUNT];
|
||||
|
||||
Mesh(bool dynamic) : iBuffer(NULL), vBuffer(NULL), dynamic(dynamic) {}
|
||||
|
||||
void init(Index *indices, int iCount, ::Vertex *vertices, int vCount, int aCount) {
|
||||
ASSERT(sizeof(GAPI::Vertex) == sizeof(::Vertex));
|
||||
|
||||
memset(chunks, 0, sizeof(chunks));
|
||||
|
||||
this->iCount = iCount;
|
||||
this->vCount = vCount;
|
||||
for (int i = 0; i < COUNT(chunks); i++) {
|
||||
chunks[i].frameIndex = -1;
|
||||
chunks[i].iBase = i * iCount;
|
||||
chunks[i].vBase = i * vCount;
|
||||
}
|
||||
|
||||
if (dynamic) {
|
||||
iCount *= COUNT(chunks);
|
||||
vCount *= COUNT(chunks);
|
||||
}
|
||||
|
||||
iBuffer = (Index*) Context::allocGPU(SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, iCount * sizeof(Index), SCE_GXM_MEMORY_ATTRIB_READ, &iBufferUID);
|
||||
vBuffer = (Vertex*) Context::allocGPU(SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, vCount * sizeof(Vertex), SCE_GXM_MEMORY_ATTRIB_READ, &vBufferUID);
|
||||
|
||||
if (!dynamic) {
|
||||
update(indices, iCount, vertices, vCount);
|
||||
}
|
||||
}
|
||||
|
||||
void deinit() {
|
||||
Context::freeGPU(iBufferUID, true);
|
||||
@@ -1007,8 +1019,8 @@ namespace GAPI {
|
||||
Chunk &chunk = getChunk();
|
||||
if (chunk.frameIndex != Core::stats.frameIndex) {
|
||||
chunk.frameIndex = Core::stats.frameIndex;
|
||||
chunk.iStart = chunk.iCount = 0;
|
||||
chunk.vStart = chunk.vCount = 0;
|
||||
chunk.iStart = chunk.iCount = chunk.iBase;
|
||||
chunk.vStart = chunk.vCount = chunk.vBase;
|
||||
}
|
||||
|
||||
if (indices && iCount) {
|
||||
@@ -1117,7 +1129,7 @@ namespace GAPI {
|
||||
vertices[2].coord = short4{-1, 3, 1, 1};
|
||||
clearMesh.init(indices, 3, vertices, 3, 0);
|
||||
|
||||
clearColor = vec4(1.0f, 1.0f, 0.0f, 1.0f);
|
||||
clearColor = vec4(0.0f);
|
||||
|
||||
colorMask = SCE_GXM_COLOR_MASK_ALL;
|
||||
blendMode = 0;
|
||||
@@ -1197,6 +1209,10 @@ namespace GAPI {
|
||||
} else {
|
||||
ASSERT(target->opt & OPT_TARGET);
|
||||
|
||||
uint32 flags = 0;
|
||||
if (target->opt & OPT_VERTEX) flags |= SCE_GXM_SCENE_FRAGMENT_SET_DEPENDENCY;
|
||||
if (target->opt & OPT_DEPEND) flags |= SCE_GXM_SCENE_VERTEX_WAIT_FOR_DEPENDENCY;
|
||||
|
||||
SceGxmColorSurface *colorSurface = (target->fmt == FMT_DEPTH || target->fmt == FMT_SHADOW) ? NULL : &target->colorSurface;
|
||||
|
||||
bool loadDepth = (Core::reqTarget.op & RT_LOAD_DEPTH);
|
||||
@@ -1205,30 +1221,7 @@ namespace GAPI {
|
||||
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);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
bool depth = target->fmt == FMT_DEPTH || target->fmt == FMT_SHADOW;
|
||||
|
||||
if (target->tex2D) {
|
||||
D3DCHECK(target->tex2D->GetSurfaceLevel(0, &surface));
|
||||
} else if (target->texCube)
|
||||
D3DCHECK(target->texCube->GetCubeMapSurface(D3DCUBEMAP_FACES(D3DCUBEMAP_FACE_POSITIVE_X + face), 0, &surface));
|
||||
|
||||
int rtIndex = cacheRenderTarget(!depth, target->width, target->height);
|
||||
|
||||
if (depth) {
|
||||
D3DCHECK(device->SetRenderTarget(0, rtCache[false].items[rtIndex].surface));
|
||||
D3DCHECK(device->SetDepthStencilSurface(surface));
|
||||
} else {
|
||||
D3DCHECK(device->SetRenderTarget(0, surface));
|
||||
D3DCHECK(device->SetDepthStencilSurface(rtCache[true].items[rtIndex].surface));
|
||||
}
|
||||
|
||||
surface->Release();
|
||||
*/
|
||||
sceGxmBeginScene(Context::gxmContext, flags, target->renderTarget, NULL, NULL, NULL, colorSurface, &target->depthSurface);
|
||||
}
|
||||
active.viewport = Viewport(0, 0, 0, 0); // forcing viewport reset
|
||||
}
|
||||
|
@@ -174,7 +174,7 @@ struct MeshBuilder {
|
||||
};
|
||||
|
||||
MeshBuilder(TR::Level *level, Texture *atlas) : atlas(atlas), level(level) {
|
||||
dynMesh = new Mesh(NULL, DYN_MESH_FACES * 3, NULL, DYN_MESH_FACES * 3, 1, true);
|
||||
dynMesh = new Mesh(NULL, COUNT(dynIndices), NULL, COUNT(dynVertices), 1, true);
|
||||
dynRange.vStart = 0;
|
||||
dynRange.iStart = 0;
|
||||
dynMesh->initRange(dynRange);
|
||||
@@ -1320,12 +1320,13 @@ struct MeshBuilder {
|
||||
}
|
||||
|
||||
void dynEnd() {
|
||||
if (dynICount)
|
||||
if (dynICount) {
|
||||
renderBuffer(dynIndices, dynICount, dynVertices, dynVCount);
|
||||
}
|
||||
}
|
||||
|
||||
void dynCheck(int freeIndicesCount) {
|
||||
if (dynICount + freeIndicesCount > DYN_MESH_FACES * 3) {
|
||||
if (dynICount + freeIndicesCount > COUNT(dynIndices)) {
|
||||
dynEnd();
|
||||
dynBegin();
|
||||
}
|
||||
|
@@ -1,54 +0,0 @@
|
||||
#include "common.hlsl"
|
||||
|
||||
struct VS_OUTPUT {
|
||||
float4 pos : POSITION;
|
||||
float4 texCoord : TEXCOORD0;
|
||||
float4 diffuse : TEXCOORD1;
|
||||
};
|
||||
|
||||
#ifdef VERTEX
|
||||
VS_OUTPUT main(VS_INPUT In) {
|
||||
VS_OUTPUT Out;
|
||||
|
||||
float4 rBasisRot = uBasis[0];
|
||||
float4 rBasisPos = uBasis[0 + 1];
|
||||
|
||||
Out.texCoord = In.aTexCoord * (1.0 / 32767.0);
|
||||
|
||||
float3 coord;
|
||||
|
||||
if (TYPE_SPRITE) {
|
||||
coord = mulBasis(rBasisRot, rBasisPos.xyz + In.aCoord.xyz, float3(In.aTexCoord.z, In.aTexCoord.w, 0.0));
|
||||
} else {
|
||||
coord = mulBasis(rBasisRot, rBasisPos.xyz, In.aCoord.xyz);
|
||||
}
|
||||
|
||||
Out.diffuse = float4(RGB(In.aColor) * (uMaterial.x * 1.8), 1.0);
|
||||
Out.diffuse.xyz *= RGB(In.aLight);
|
||||
|
||||
Out.diffuse *= uMaterial.w;
|
||||
|
||||
if (TYPE_SPRITE) {
|
||||
Out.diffuse *= RGBA(In.aLight).a;
|
||||
}
|
||||
|
||||
Out.pos = mul(uViewProj, float4(coord, rBasisPos.w));
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
#else // PIXEL
|
||||
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
float4 color = tex2D(sDiffuse, In.texCoord.xy).bgra;
|
||||
|
||||
if (ALPHA_TEST) {
|
||||
if (color.w <= 0.5)
|
||||
discard;
|
||||
}
|
||||
|
||||
color *= In.diffuse;
|
||||
|
||||
return color;
|
||||
}
|
||||
#endif
|
47
src/shaders/ambient_room.hlsl
Normal file
47
src/shaders/ambient_room.hlsl
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "common.hlsl"
|
||||
|
||||
struct VS_OUTPUT {
|
||||
float4 pos : POSITION;
|
||||
float4 texCoord : TEXCOORD0;
|
||||
float4 diffuse : COLOR0;
|
||||
};
|
||||
|
||||
#ifdef VERTEX
|
||||
|
||||
VS_OUTPUT main(VS_INPUT In) {
|
||||
VS_OUTPUT Out;
|
||||
|
||||
float4 rBasisRot = uBasis[0];
|
||||
float4 rBasisPos = uBasis[1];
|
||||
|
||||
Out.texCoord = In.aTexCoord * (1.0 / 32767.0);
|
||||
|
||||
float3 coord;
|
||||
|
||||
coord = mulBasis(rBasisRot, rBasisPos.xyz, In.aCoord.xyz);
|
||||
|
||||
Out.diffuse = float4(In.aColor.rgb * (uMaterial.x * 1.8), 1.0);
|
||||
Out.diffuse.xyz *= In.aLight.rgb;
|
||||
|
||||
Out.diffuse *= uMaterial.w;
|
||||
|
||||
Out.pos = mul(uViewProj, float4(coord, rBasisPos.w));
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
#else // PIXEL
|
||||
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
float4 color = tex2D(sDiffuse, In.texCoord.xy);
|
||||
|
||||
#ifdef ALPHA_TEST
|
||||
clip(color.w - ALPHA_REF);
|
||||
#endif
|
||||
|
||||
color *= In.diffuse;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
#endif
|
49
src/shaders/ambient_sprite.hlsl
Normal file
49
src/shaders/ambient_sprite.hlsl
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "common.hlsl"
|
||||
|
||||
struct VS_OUTPUT {
|
||||
float4 pos : POSITION;
|
||||
float4 texCoord : TEXCOORD0;
|
||||
float4 diffuse : COLOR0;
|
||||
};
|
||||
|
||||
#ifdef VERTEX
|
||||
|
||||
VS_OUTPUT main(VS_INPUT In) {
|
||||
VS_OUTPUT Out;
|
||||
|
||||
float4 rBasisRot = uBasis[0];
|
||||
float4 rBasisPos = uBasis[1];
|
||||
|
||||
Out.texCoord = In.aTexCoord * (1.0 / 32767.0);
|
||||
|
||||
float3 coord;
|
||||
|
||||
coord = mulBasis(rBasisRot, rBasisPos.xyz + In.aCoord.xyz, float3(In.aTexCoord.z, In.aTexCoord.w, 0.0));
|
||||
|
||||
Out.diffuse = float4(In.aColor.rgb * (uMaterial.x * 1.8), 1.0);
|
||||
Out.diffuse.xyz *= In.aLight.rgb;
|
||||
|
||||
Out.diffuse *= uMaterial.w;
|
||||
|
||||
Out.diffuse *= In.aLight.a;
|
||||
|
||||
Out.pos = mul(uViewProj, float4(coord, rBasisPos.w));
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
#else // PIXEL
|
||||
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
float4 color = tex2D(sDiffuse, In.texCoord.xy);
|
||||
|
||||
#ifdef ALPHA_TEST
|
||||
clip(color.w - ALPHA_REF);
|
||||
#endif
|
||||
|
||||
color *= In.diffuse;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
#endif
|
@@ -21,13 +21,12 @@ static const float3 SHADOW_TEXEL = float3(1.0 / SHADOW_SIZE, 1.0 / SHADOW_SIZE,
|
||||
#define FLAGS_TYPE float4
|
||||
#define RGBA(c) (c).rgba
|
||||
#define RGB(c) (c).rgb
|
||||
#define F2_TEX2D(s,uv) h2tex2Dlod(s, float4(uv, 0, 0))
|
||||
#else
|
||||
#define FLAGS_REG b0
|
||||
#define FLAGS_TYPE bool4
|
||||
#define RGBA(c) (c).rgba
|
||||
#define RGB(c) (c).rgb
|
||||
#define F2_TEX2D(s,uv) tex2Dlod(s, float4(uv, 0, 0)).xy
|
||||
#define CLIP_PLANE
|
||||
#endif
|
||||
|
||||
struct VS_INPUT {
|
||||
@@ -61,27 +60,11 @@ float4 uPosScale[2] : register( c92 );
|
||||
FLAGS_TYPE uFlags[4] : register( FLAGS_REG );
|
||||
float4 uContacts[MAX_CONTACTS] : register( c98 );
|
||||
|
||||
#define FILTER_DEFAULT uFlags[0].x
|
||||
#define FILTER_DOWNSAMPLE uFlags[0].y
|
||||
#define FILTER_DOWNSAMPLE_DEPTH uFlags[0].z
|
||||
#define FILTER_GRAYSCALE uFlags[0].w
|
||||
#define FILTER_BLUR uFlags[1].x
|
||||
#define FILTER_EQUIRECTANGULAR uFlags[1].y
|
||||
|
||||
// options for compose, shadow, ambient passes
|
||||
#define TYPE_SPRITE uFlags[0].x
|
||||
#define TYPE_FLASH uFlags[0].y
|
||||
#define TYPE_ROOM uFlags[0].z
|
||||
#define TYPE_ENTITY uFlags[0].w
|
||||
#define TYPE_MIRROR uFlags[1].x
|
||||
|
||||
#define UNDERWATER uFlags[1].y
|
||||
#define ALPHA_TEST uFlags[1].z
|
||||
#define CLIP_PLANE uFlags[1].w
|
||||
#define OPT_AMBIENT uFlags[2].x
|
||||
#define OPT_SHADOW uFlags[2].y
|
||||
#define OPT_CONTACT uFlags[2].z
|
||||
#define OPT_CAUSTICS uFlags[2].w
|
||||
#define OPT_AMBIENT uFlags[0].x
|
||||
#define OPT_SHADOW uFlags[0].y
|
||||
#define OPT_CONTACT uFlags[0].z
|
||||
#define OPT_CAUSTICS uFlags[0].w
|
||||
|
||||
float4 pack(float value) {
|
||||
float4 v = frac(value * float4(1.0, 255.0, 65025.0, 16581375.0));
|
||||
@@ -120,10 +103,10 @@ float calcCaustics(float3 coord, float3 n) {
|
||||
return tex2Dlod(sReflect, float4(cc.x, 1.0 - cc.y, 0, 0)).x * max(0.0, -n.y);
|
||||
}
|
||||
|
||||
float3 calcNormal(float2 tc, float base) {
|
||||
float dx = F2_TEX2D(sNormal, float2(tc.x + uTexParam.x, tc.y)).x - base;
|
||||
float dz = F2_TEX2D(sNormal, float2(tc.x, tc.y + uTexParam.y)).x - base;
|
||||
return normalize( float3(dx, 64.0 / (1024.0 * 8.0), dz) );
|
||||
half3 calcNormal(float2 tc, half base) {
|
||||
half dx = (half)tex2Dlod(sNormal, float4(tc.x + uTexParam.x, tc.y, 0, 0)).x - base;
|
||||
half dz = (half)tex2Dlod(sNormal, float4(tc.x, tc.y + uTexParam.y, 0, 0)).x - base;
|
||||
return normalize( half3(dx, 64.0 / (1024.0 * 8.0), dz) );
|
||||
}
|
||||
|
||||
void applyFogUW(inout float3 color, float3 coord, float waterFogDist) {
|
||||
@@ -200,7 +183,11 @@ float getShadow(float3 lightVec, float3 normal, float4 lightProj) {
|
||||
|
||||
float getContactAO(float3 p, float3 n) {
|
||||
float res = 1.0;
|
||||
#ifdef _GAPI_GXM
|
||||
#pragma loop (unroll: always)
|
||||
#else
|
||||
[unroll]
|
||||
#endif
|
||||
for (int i = 0; i < MAX_CONTACTS; i++) {
|
||||
float3 v = uContacts[i].xyz - p;
|
||||
float a = uContacts[i].w;
|
||||
|
@@ -1,36 +1,55 @@
|
||||
@echo off
|
||||
rd /S /Q d3d9
|
||||
mkdir d3d9
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn COMPOSE_SPRITE_VS /Fh d3d9/compose_sprite_vs.h compose_sprite.hlsl /DVERTEX
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn COMPOSE_SPRITE_PS /Fh d3d9/compose_sprite_ps.h compose_sprite.hlsl /DPIXEL
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn COMPOSE_FLASH_VS /Fh d3d9/compose_flash_vs.h compose_flash.hlsl /DVERTEX
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn COMPOSE_FLASH_PS /Fh d3d9/compose_flash_ps.h compose_flash.hlsl /DPIXEL
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn COMPOSE_ROOM_VS /Fh d3d9/compose_room_vs.h compose_room.hlsl /DVERTEX
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn COMPOSE_ROOM_PS /Fh d3d9/compose_room_ps.h compose_room.hlsl /DPIXEL
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn COMPOSE_ENTITY_VS /Fh d3d9/compose_entity_vs.h compose_entity.hlsl /DVERTEX
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn COMPOSE_ENTITY_PS /Fh d3d9/compose_entity_ps.h compose_entity.hlsl /DPIXEL
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn COMPOSE_MIRROR_VS /Fh d3d9/compose_mirror_vs.h compose_mirror.hlsl /DVERTEX
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn COMPOSE_MIRROR_PS /Fh d3d9/compose_mirror_ps.h compose_mirror.hlsl /DPIXEL
|
||||
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn SHADOW_VS /Fh d3d9/shadow_vs.h shadow.hlsl /DVERTEX
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn SHADOW_PS /Fh d3d9/shadow_ps.h shadow.hlsl /DPIXEL
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn AMBIENT_VS /Fh d3d9/ambient_vs.h ambient.hlsl /DVERTEX
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn AMBIENT_PS /Fh d3d9/ambient_ps.h ambient.hlsl /DPIXEL
|
||||
call :compile_au compose_sprite
|
||||
call :compile_au compose_room
|
||||
call :compile_au compose_entity
|
||||
call :compile compose_mirror
|
||||
call :compile compose_flash
|
||||
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn WATER_DROP_VS /Fh d3d9/water_drop_vs.h water_drop.hlsl /DVERTEX
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn WATER_DROP_PS /Fh d3d9/water_drop_ps.h water_drop.hlsl /DPIXEL
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn WATER_SIMULATE_VS /Fh d3d9/water_simulate_vs.h water_simulate.hlsl /DVERTEX
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn WATER_SIMULATE_PS /Fh d3d9/water_simulate_ps.h water_simulate.hlsl /DPIXEL
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn WATER_CAUSTICS_VS /Fh d3d9/water_caustics_vs.h water_caustics.hlsl /DVERTEX
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn WATER_CAUSTICS_PS /Fh d3d9/water_caustics_ps.h water_caustics.hlsl /DPIXEL
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn WATER_RAYS_VS /Fh d3d9/water_rays_vs.h water_rays.hlsl /DVERTEX
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn WATER_RAYS_PS /Fh d3d9/water_rays_ps.h water_rays.hlsl /DPIXEL
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn WATER_MASK_VS /Fh d3d9/water_mask_vs.h water_mask.hlsl /DVERTEX
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn WATER_MASK_PS /Fh d3d9/water_mask_ps.h water_mask.hlsl /DPIXEL
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn WATER_COMPOSE_VS /Fh d3d9/water_compose_vs.h water_compose.hlsl /DVERTEX
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn WATER_COMPOSE_PS /Fh d3d9/water_compose_ps.h water_compose.hlsl /DPIXEL
|
||||
call :compile_a shadow_entity
|
||||
call :compile_a ambient_room
|
||||
call :compile_a ambient_sprite
|
||||
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn FILTER_VS /Fh d3d9/filter_vs.h filter.hlsl /DVERTEX
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn FILTER_PS /Fh d3d9/filter_ps.h filter.hlsl /DPIXEL
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn GUI_VS /Fh d3d9/gui_vs.h gui.hlsl /DVERTEX
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn GUI_PS /Fh d3d9/gui_ps.h gui.hlsl /DPIXEL
|
||||
call :compile water_drop
|
||||
call :compile water_simulate
|
||||
call :compile water_caustics
|
||||
call :compile water_rays
|
||||
call :compile water_mask
|
||||
call :compile water_compose
|
||||
|
||||
call :compile filter _upscale "/DUPSCALE"
|
||||
call :compile filter _downsample "/DDOWNSAMPLE"
|
||||
call :compile filter _grayscale "/DGRAYSCALE"
|
||||
call :compile filter _blur "/DBLUR"
|
||||
|
||||
call :compile gui
|
||||
|
||||
|
||||
EXIT /B %ERRORLEVEL%
|
||||
|
||||
:compile
|
||||
SETLOCAL
|
||||
echo compile d3d9/%~1%~2 %~3
|
||||
echo #include "%~1%~2_v.h" >> d3d9/shaders.h
|
||||
echo #include "%~1%~2_f.h" >> d3d9/shaders.h
|
||||
fxc /nologo /T vs_3_0 /O3 /Gec /Vn %~1%~2_v /Fh d3d9/%~1%~2_v.h %~1.hlsl /DVERTEX %~3
|
||||
fxc /nologo /T ps_3_0 /O3 /Gec /Vn %~1%~2_f /Fh d3d9/%~1%~2_f.h %~1.hlsl /DPIXEL %~3
|
||||
ENDLOCAL
|
||||
EXIT /B 0
|
||||
|
||||
:compile_a
|
||||
SETLOCAL
|
||||
call :compile %~1
|
||||
call :compile %~1 _a "/DALPHA_TEST"
|
||||
ENDLOCAL
|
||||
EXIT /B 0
|
||||
|
||||
:compile_au
|
||||
SETLOCAL
|
||||
call :compile_a %~1
|
||||
call :compile %~1 _u "/DUNDERWATER"
|
||||
call :compile %~1 _au "/DALPHA_TEST /DUNDERWATER"
|
||||
ENDLOCAL
|
||||
EXIT /B 0
|
||||
|
@@ -2,79 +2,65 @@
|
||||
rd /S /Q gxm
|
||||
mkdir gxm
|
||||
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/compose_sprite_vp.gxp compose_sprite.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/compose_sprite_fp.gxp compose_sprite.hlsl -DPIXEL
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/compose_flash_vp.gxp compose_flash.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/compose_flash_fp.gxp compose_flash.hlsl -DPIXEL
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/compose_room_vp.gxp compose_room.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/compose_room_fp.gxp compose_room.hlsl -DPIXEL
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/compose_entity_vp.gxp compose_entity.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/compose_entity_fp.gxp compose_entity.hlsl -DPIXEL
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/compose_mirror_vp.gxp compose_mirror.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/compose_mirror_fp.gxp compose_mirror.hlsl -DPIXEL
|
||||
call :compile_au compose_sprite
|
||||
call :compile_au compose_room
|
||||
call :compile_au compose_entity
|
||||
call :compile compose_mirror
|
||||
call :compile compose_flash
|
||||
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/shadow_vp.gxp shadow.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/shadow_fp.gxp shadow.hlsl -DPIXEL
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/ambient_vp.gxp ambient.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/ambient_fp.gxp ambient.hlsl -DPIXEL
|
||||
call :compile_a shadow_entity
|
||||
call :compile_a ambient_room
|
||||
call :compile_a ambient_sprite
|
||||
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/water_drop_vp.gxp water_drop.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/water_drop_fp.gxp water_drop.hlsl -DPIXE
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/water_simulate_vp.gxp water_simulate.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/water_simulate_fp.gxp water_simulate.hlsl -DPIXEL
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/water_caustics_vp.gxp water_caustics.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/water_caustics_fp.gxp water_caustics.hlsl -DPIXEL
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/water_rays_vp.gxp water_rays.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/water_rays_fp.gxp water_rays.hlsl -DPIXEL
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/water_mask_vp.gxp water_mask.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/water_mask_fp.gxp water_mask.hlsl -DPIXEL
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/water_compose_vp.gxp water_compose.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/water_compose_fp.gxp water_compose.hlsl -DPIXEL
|
||||
call :compile water_drop
|
||||
call :compile water_simulate
|
||||
call :compile water_caustics
|
||||
call :compile water_rays
|
||||
call :compile water_mask
|
||||
call :compile water_compose
|
||||
|
||||
call :compile filter _upscale "-DUPSCALE"
|
||||
call :compile filter _downsample "-DDOWNSAMPLE"
|
||||
call :compile filter _grayscale "-DGRAYSCALE"
|
||||
call :compile filter _blur "-DBLUR"
|
||||
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/filter_vp.gxp filter.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/filter_fp.gxp filter.hlsl -DPIXEL
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/gui_vp.gxp gui.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/gui_fp.gxp gui.hlsl -DPIXEL
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic -o gxm/clear_vp.gxp clear.hlsl -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic -o gxm/clear_fp.gxp clear.hlsl -DPIXEL
|
||||
call :compile gui
|
||||
|
||||
call :compile clear
|
||||
|
||||
cd gxm
|
||||
..\bin2c.exe compose_sprite_vp.gxp compose_sprite_vp.h COMPOSE_SPRITE_VP
|
||||
..\bin2c.exe compose_sprite_fp.gxp compose_sprite_fp.h COMPOSE_SPRITE_FP
|
||||
..\bin2c.exe compose_flash_vp.gxp compose_flash_vp.h COMPOSE_FLASH_VP
|
||||
..\bin2c.exe compose_flash_fp.gxp compose_flash_fp.h COMPOSE_FLASH_FP
|
||||
..\bin2c.exe compose_room_vp.gxp compose_room_vp.h COMPOSE_ROOM_VP
|
||||
..\bin2c.exe compose_room_fp.gxp compose_room_fp.h COMPOSE_ROOM_FP
|
||||
..\bin2c.exe compose_entity_vp.gxp compose_entity_vp.h COMPOSE_ENTITY_VP
|
||||
..\bin2c.exe compose_entity_fp.gxp compose_entity_fp.h COMPOSE_ENTITY_FP
|
||||
..\bin2c.exe compose_mirror_vp.gxp compose_mirror_vp.h COMPOSE_MIRROR_VP
|
||||
..\bin2c.exe compose_mirror_fp.gxp compose_mirror_fp.h COMPOSE_MIRROR_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_drop_vp.gxp water_drop_vp.h WATER_DROP_VP
|
||||
..\bin2c.exe water_drop_fp.gxp water_drop_fp.h WATER_DROP_FP
|
||||
..\bin2c.exe water_simulate_vp.gxp water_simulate_vp.h WATER_SIMULATE_VP
|
||||
..\bin2c.exe water_simulate_fp.gxp water_simulate_fp.h WATER_SIMULATE_FP
|
||||
..\bin2c.exe water_caustics_vp.gxp water_caustics_vp.h WATER_CAUSTICS_VP
|
||||
..\bin2c.exe water_caustics_fp.gxp water_caustics_fp.h WATER_CAUSTICS_FP
|
||||
..\bin2c.exe water_rays_vp.gxp water_rays_vp.h WATER_RAYS_VP
|
||||
..\bin2c.exe water_rays_fp.gxp water_rays_fp.h WATER_RAYS_FP
|
||||
..\bin2c.exe water_mask_vp.gxp water_mask_vp.h WATER_MASK_VP
|
||||
..\bin2c.exe water_mask_fp.gxp water_mask_fp.h WATER_MASK_FP
|
||||
..\bin2c.exe water_compose_vp.gxp water_compose_vp.h WATER_COMPOSE_VP
|
||||
..\bin2c.exe water_compose_fp.gxp water_compose_fp.h WATER_COMPOSE_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
|
||||
set CONV_CMD=..\bin2c.exe
|
||||
|
||||
for /r . %%i in (*.gxp) do (
|
||||
:: ..\psp2gxpstrip -o %%i %%i
|
||||
..\bin2c.exe %%i %%~ni.h %%~ni
|
||||
)
|
||||
|
||||
cd ..
|
||||
|
||||
EXIT /B %ERRORLEVEL%
|
||||
|
||||
:compile
|
||||
SETLOCAL
|
||||
echo compile gxm/%~1%~2 %~3
|
||||
echo #include "%~1%~2_v.h" >> gxm/shaders.h
|
||||
echo #include "%~1%~2_f.h" >> gxm/shaders.h
|
||||
psp2cgc -profile sce_vp_psp2 -W4 -Wperf -pedantic %~1.hlsl -o gxm/%~1%~2_v.gxp %~3 -DVERTEX
|
||||
psp2cgc -profile sce_fp_psp2 -W4 -Wperf -pedantic %~1.hlsl -o gxm/%~1%~2_f.gxp %~3 -DPIXEL
|
||||
ENDLOCAL
|
||||
EXIT /B 0
|
||||
|
||||
:compile_a
|
||||
SETLOCAL
|
||||
call :compile %~1
|
||||
call :compile %~1 _a "-DALPHA_TEST"
|
||||
ENDLOCAL
|
||||
EXIT /B 0
|
||||
|
||||
:compile_au
|
||||
SETLOCAL
|
||||
call :compile_a %~1
|
||||
call :compile %~1 _u "-DUNDERWATER"
|
||||
call :compile %~1 _au "-DALPHA_TEST -DUNDERWATER"
|
||||
ENDLOCAL
|
||||
EXIT /B 0
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include "common.hlsl"
|
||||
|
||||
// UNDERWATER, ALPHA_TEST, CLIP_PLANE (D3D9 only), OPT_SHADOW, OPT_CAUSTICS, OPT_AMBIENT
|
||||
// ALPHA_TEST, UNDERWATER, CLIP_PLANE (D3D9 only), OPT_SHADOW, OPT_CAUSTICS, OPT_AMBIENT
|
||||
|
||||
struct VS_OUTPUT {
|
||||
float4 pos : POSITION;
|
||||
@@ -18,9 +18,9 @@ struct VS_OUTPUT {
|
||||
};
|
||||
|
||||
#ifdef VERTEX
|
||||
|
||||
VS_OUTPUT main(VS_INPUT In) {
|
||||
VS_OUTPUT Out;
|
||||
Out.ambient = 0.0;
|
||||
|
||||
int index = int(In.aCoord.w * 2.0);
|
||||
float4 rBasisRot = uBasis[index];
|
||||
@@ -53,12 +53,12 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
lum.w = dot(Out.normal.xyz, normalize(lv3)); att.w = dot(lv3, lv3);
|
||||
light = max((float4)0.0, lum) * max((float4)0.0, (float4)1.0 - att);
|
||||
|
||||
if (UNDERWATER) {
|
||||
#ifdef UNDERWATER
|
||||
light.x *= abs(sin(dot(Out.coord.xyz, 1.0 / 512.0) + uParam.x)) * 1.5 + 0.5;
|
||||
Out.normal.w = 0.0;
|
||||
} else {
|
||||
#else
|
||||
Out.normal.w = saturate(1.0 / exp(length(Out.viewVec.xyz)));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (OPT_SHADOW) {
|
||||
Out.light = light;
|
||||
@@ -88,14 +88,12 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
float4 color = tex2D(sDiffuse, In.texCoord.xy / In.texCoord.zw);
|
||||
|
||||
if (ALPHA_TEST) {
|
||||
#ifdef ALPHA_TEST
|
||||
clip(color.w - ALPHA_REF);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef _GAPI_GXM
|
||||
if (CLIP_PLANE) {
|
||||
#ifdef CLIP_PLANE
|
||||
clip(In.viewVec.w);
|
||||
}
|
||||
#endif
|
||||
|
||||
color *= In.diffuse;
|
||||
@@ -127,16 +125,16 @@ float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
|
||||
float specular = calcSpecular(normal, In.viewVec.xyz, lightVec, rSpecular);
|
||||
|
||||
if (UNDERWATER) {
|
||||
#ifdef UNDERWATER
|
||||
float uwSign = step(uParam.y, In.coord.y);
|
||||
specular *= (1.0 - uwSign);
|
||||
color.xyz += specular;
|
||||
|
||||
applyFogUW(color.xyz, In.coord, WATER_FOG_DIST * uwSign);
|
||||
} else {
|
||||
#else
|
||||
color.xyz += specular;
|
||||
applyFog(color.xyz, In.normal.w);
|
||||
}
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@ struct VS_OUTPUT {
|
||||
};
|
||||
|
||||
#ifdef VERTEX
|
||||
|
||||
VS_OUTPUT main(VS_INPUT In) {
|
||||
VS_OUTPUT Out;
|
||||
|
||||
@@ -38,10 +39,8 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
float4 color = tex2D(sDiffuse, In.texCoord.xy / In.texCoord.zw);
|
||||
|
||||
#ifndef _GAPI_GXM
|
||||
if (CLIP_PLANE) {
|
||||
#ifdef CLIP_PLANE
|
||||
clip(In.clipDist);
|
||||
}
|
||||
#endif
|
||||
|
||||
color.xyz *= In.diffuse.xyz;
|
||||
|
@@ -12,6 +12,7 @@ struct VS_OUTPUT {
|
||||
};
|
||||
|
||||
#ifdef VERTEX
|
||||
|
||||
VS_OUTPUT main(VS_INPUT In) {
|
||||
VS_OUTPUT Out;
|
||||
|
||||
@@ -41,10 +42,8 @@ float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
float3 rv = reflect(-In.viewVec.xyz, In.normal.xyz);
|
||||
float4 color = texCUBE(sEnvironment, normalize(rv));
|
||||
|
||||
#ifndef _GAPI_GXM
|
||||
if (CLIP_PLANE) {
|
||||
#ifdef CLIP_PLANE
|
||||
clip(In.viewVec.w);
|
||||
}
|
||||
#endif
|
||||
|
||||
color *= uMaterial;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include "common.hlsl"
|
||||
|
||||
// UNDERWATER, ALPHA_TEST, CLIP_PLANE (D3D9 only), OPT_SHADOW, OPT_CAUSTICS, OPT_CONTACT
|
||||
// ALPHA_TEST, UNDERWATER, CLIP_PLANE (D3D9 only), OPT_SHADOW, OPT_CAUSTICS, OPT_CONTACT
|
||||
|
||||
struct VS_OUTPUT {
|
||||
float4 pos : POSITION;
|
||||
@@ -31,8 +31,6 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
Out.coord = mulBasis(rBasisRot, rBasisPos.xyz, In.aCoord.xyz);
|
||||
Out.texCoord.xy *= Out.texCoord.zw;
|
||||
|
||||
float3 viewVec = (uViewPos.xyz - Out.coord) * uFogParams.w;
|
||||
|
||||
Out.normal.xyz = mulQuat(rBasisRot, normalize(In.aNormal.xyz));
|
||||
|
||||
float3 lv1 = (uLightPos[1].xyz - Out.coord) * uLightColor[1].w;
|
||||
@@ -51,12 +49,13 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
lum.w = dot(Out.normal.xyz, normalize(lv3)); att.w = dot(lv3, lv3);
|
||||
light = max((float4)0.0, lum) * max((float4)0.0, (float4)1.0 - att);
|
||||
|
||||
if (UNDERWATER) {
|
||||
#ifdef UNDERWATER
|
||||
light.x *= abs(sin(dot(Out.coord.xyz, 1.0 / 512.0) + uParam.x)) * 1.5 + 0.5;
|
||||
Out.normal.w = 0.0;
|
||||
} else {
|
||||
#else
|
||||
float3 viewVec = (uViewPos.xyz - Out.coord) * uFogParams.w;
|
||||
Out.normal.w = saturate(1.0 / exp(length(viewVec.xyz)));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (OPT_SHADOW) {
|
||||
Out.light = light;
|
||||
@@ -85,14 +84,12 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
float4 color = tex2D(sDiffuse, In.texCoord.xy / In.texCoord.zw);
|
||||
|
||||
if (ALPHA_TEST) {
|
||||
#ifdef ALPHA_TEST
|
||||
clip(color.w - ALPHA_REF);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef _GAPI_GXM
|
||||
if (CLIP_PLANE) {
|
||||
#ifdef CLIP_PLANE
|
||||
clip(In.clipDist);
|
||||
}
|
||||
#endif
|
||||
|
||||
color *= In.diffuse;
|
||||
@@ -119,11 +116,11 @@ float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
|
||||
color.xyz *= light;
|
||||
|
||||
if (UNDERWATER) {
|
||||
#ifdef UNDERWATER
|
||||
applyFogUW(color.xyz, In.coord, WATER_FOG_DIST);
|
||||
} else {
|
||||
#else
|
||||
applyFog(color.xyz, In.normal.w);
|
||||
}
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include "common.hlsl"
|
||||
|
||||
// UNDERWATER, OPT_CAUSTICS, CLIP_PLANE (D3D9 only), ALPHA_TEST
|
||||
// ALPHA_TEST, UNDERWATER, OPT_CAUSTICS, CLIP_PLANE (D3D9 only)
|
||||
|
||||
struct VS_OUTPUT {
|
||||
float4 pos : POSITION;
|
||||
@@ -17,6 +17,7 @@ struct VS_OUTPUT {
|
||||
};
|
||||
|
||||
#ifdef VERTEX
|
||||
|
||||
VS_OUTPUT main(VS_INPUT In) {
|
||||
VS_OUTPUT Out;
|
||||
|
||||
@@ -45,11 +46,11 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
lum.w = dot(Out.normal.xyz, normalize(lv3)); att.w = dot(lv3, lv3);
|
||||
light = max((float4)0.0, lum) * max((float4)0.0, (float4)1.0 - att);
|
||||
|
||||
if (UNDERWATER) {
|
||||
#ifdef UNDERWATER
|
||||
Out.normal.w = 0.0;
|
||||
} else {
|
||||
#else
|
||||
Out.normal.w = saturate(1.0 / exp(length(viewVec.xyz)));
|
||||
}
|
||||
#endif
|
||||
|
||||
Out.light.xyz = uLightColor[1].xyz * light.y + uLightColor[2].xyz * light.z + uLightColor[3].xyz * light.w;
|
||||
Out.light.w = 0.0;
|
||||
@@ -73,14 +74,12 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
float4 color = tex2D(sDiffuse, In.texCoord.xy);
|
||||
|
||||
if (ALPHA_TEST) {
|
||||
#ifdef ALPHA_TEST
|
||||
clip(color.w - ALPHA_REF);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef _GAPI_GXM
|
||||
if (CLIP_PLANE) {
|
||||
#ifdef CLIP_PLANE
|
||||
clip(In.clipDist);
|
||||
}
|
||||
#endif
|
||||
|
||||
color *= In.diffuse;
|
||||
@@ -95,11 +94,11 @@ float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
|
||||
color.xyz *= light;
|
||||
|
||||
if (UNDERWATER) {
|
||||
#ifdef UNDERWATER
|
||||
applyFogUW(color.xyz, In.coord, WATER_FOG_DIST);
|
||||
} else {
|
||||
#else
|
||||
applyFog(color.xyz, In.normal.w);
|
||||
}
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
|
@@ -3,7 +3,9 @@
|
||||
struct VS_OUTPUT {
|
||||
float4 pos : POSITION;
|
||||
float2 texCoord : TEXCOORD0;
|
||||
#ifdef UPSCALE
|
||||
float4 diffuse : COLOR0;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef VERTEX
|
||||
@@ -11,15 +13,16 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
VS_OUTPUT Out;
|
||||
Out.pos = float4(In.aCoord.xy * (1.0 / 32767.0), 0.0, 1.0);
|
||||
Out.texCoord = In.aTexCoord.xy * (1.0 / 32767.0);
|
||||
#ifdef UPSCALE
|
||||
Out.diffuse = RGBA(In.aLight);
|
||||
#endif
|
||||
|
||||
#ifndef _GAPI_GXM
|
||||
// D3D9 specific
|
||||
if (FILTER_DOWNSAMPLE) {
|
||||
#ifdef DOWNSAMPLE
|
||||
Out.texCoord += float2(2.0, -2.0) * uParam.x;
|
||||
} else if (FILTER_BLUR) {
|
||||
#elif BLUR
|
||||
Out.texCoord += float2(1.0, -1.0) * uParam.z;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return Out;
|
||||
@@ -62,7 +65,7 @@ float4 blur(float2 uv) { // uParam (dirX, dirY, 1 / textureSize, unused)
|
||||
return color;
|
||||
}
|
||||
|
||||
float4 upscale(float2 uv) {
|
||||
float4 upscale(float2 uv) { // uParam (1 / textureWidth, 1 / textureHeight, unused, unused)
|
||||
uv *= uParam.xy + 0.5;
|
||||
float2 iuv = floor(uv);
|
||||
float2 fuv = frac(uv);
|
||||
@@ -72,16 +75,16 @@ float4 upscale(float2 uv) {
|
||||
}
|
||||
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
|
||||
if (FILTER_DOWNSAMPLE)
|
||||
#ifdef DOWNSAMPLE
|
||||
return downsample(In.texCoord.xy);
|
||||
|
||||
if (FILTER_GRAYSCALE)
|
||||
#elif GRAYSCALE
|
||||
return grayscale(In.texCoord.xy);
|
||||
|
||||
if (FILTER_BLUR)
|
||||
#elif BLUR
|
||||
return blur(In.texCoord.xy);
|
||||
|
||||
#elif UPSCALE
|
||||
return upscale(In.texCoord.xy) * In.diffuse;
|
||||
#else
|
||||
#error unsupported filter type
|
||||
#endif
|
||||
}
|
||||
#endif
|
@@ -18,6 +18,6 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
#else // PIXEL
|
||||
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
return In.diffuse * tex2Dlod(sDiffuse, float4(In.texCoord, 0, 0));
|
||||
return In.diffuse * tex2D(sDiffuse, In.texCoord);
|
||||
}
|
||||
#endif
|
@@ -7,6 +7,7 @@ struct VS_OUTPUT {
|
||||
};
|
||||
|
||||
#ifdef VERTEX
|
||||
|
||||
VS_OUTPUT main(VS_INPUT In) {
|
||||
VS_OUTPUT Out;
|
||||
|
||||
@@ -24,10 +25,10 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
#else // PIXEL
|
||||
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
if (ALPHA_TEST) {
|
||||
if (tex2D(sDiffuse, In.texCoord.xy).a <= 0.5)
|
||||
discard;
|
||||
}
|
||||
#ifdef ALPHA_TEST
|
||||
clip(tex2D(sDiffuse, In.texCoord.xy).a - ALPHA_REF);
|
||||
#endif
|
||||
|
||||
#ifdef _GAPI_GXM
|
||||
return 0.0;
|
||||
#else
|
||||
@@ -38,4 +39,5 @@ float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
@@ -30,7 +30,7 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
float3 rCoord = float3(coord.x, coord.y, 0.0) * uPosScale[1].xzy;
|
||||
|
||||
float2 uv = getInvUV(rCoord.xy, uTexParam).xy;
|
||||
float2 info = F2_TEX2D(sNormal, uv).xy;
|
||||
float2 info = tex2Dlod(sNormal, float4(uv, 0, 0)).xy;
|
||||
float3 normal = calcNormal(uv, info.x).xzy;
|
||||
|
||||
float3 light = float3(0.0, 0.0, 1.0);
|
||||
|
@@ -53,7 +53,7 @@ float calcFresnel(float VoH, float f0) {
|
||||
float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
float3 viewVec = normalize(In.viewVec);
|
||||
|
||||
float2 value = F2_TEX2D(sNormal, In.texCoord).xy;
|
||||
float2 value = tex2D(sNormal, In.texCoord).xy;
|
||||
|
||||
float3 normal = calcNormal(In.texCoord, value.x);
|
||||
normal.y *= sign(viewVec.y);
|
||||
@@ -67,15 +67,15 @@ float4 main(VS_OUTPUT In) : COLOR0 {
|
||||
|
||||
float2 tc = In.hpos.xy / In.hpos.z * 0.5 + 0.5;
|
||||
|
||||
float4 refrA = tex2Dlod(sDiffuse, float4(uParam.xy * invUV(clamp(tc + dudv * uParam.z, 0.0, 0.999)), 0, 0) );
|
||||
float4 refrB = tex2Dlod(sDiffuse, float4(uParam.xy * invUV(tc), 0, 0) );
|
||||
float4 refrA = tex2D(sDiffuse, uParam.xy * invUV(clamp(tc + dudv * uParam.z, 0.0, 0.999)));
|
||||
float4 refrB = tex2D(sDiffuse, uParam.xy * invUV(tc));
|
||||
float4 refr = float4(lerp(refrA.xyz, refrB.xyz, refrA.w), 1.0);
|
||||
float4 refl = tex2Dlod(sReflect, float4(tc.xy + dudv * uParam.w, 0, 0));
|
||||
float4 refl = tex2D(sReflect, tc.xy + dudv * uParam.w);
|
||||
|
||||
float fresnel = calcFresnel(max(0.0, dot(normal, viewVec)), 0.12);
|
||||
|
||||
float4 color = lerp(refr, refl, fresnel) + spec * 1.5;
|
||||
color.w *= tex2Dlod(sMask, float4(In.maskCoord, 0, 0)).a;
|
||||
color.w *= tex2D(sMask, In.maskCoord).a;
|
||||
|
||||
float dist = In.viewVec.y / viewVec.y;
|
||||
dist *= step(In.coord.y, uViewPos.y);
|
||||
|
@@ -36,7 +36,7 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
#else // PIXEL
|
||||
|
||||
half4 main(VS_OUTPUT In) : COLOR0 {
|
||||
half2 v = (half2)tex2Dlod(sNormal, float4(In.texCoord.xy, 0, 0)).xy;
|
||||
half2 v = tex2D(sNormal, In.texCoord.xy).xy;
|
||||
|
||||
float value = max(0.0, 1.0 - length(uParam.xy - In.dropCoord / uTexParam.xy) / uParam.z);
|
||||
value = 0.5 - cos(value * PI) * 0.5;
|
||||
|
@@ -2,12 +2,12 @@
|
||||
|
||||
struct VS_OUTPUT {
|
||||
float4 pos : POSITION;
|
||||
half2 texCoord : TEXCOORD0;
|
||||
float2 texCoord : TEXCOORD0;
|
||||
half2 maskCoord : TEXCOORD1;
|
||||
half2 texCoordL : TEXCOORD2;
|
||||
half2 texCoordR : TEXCOORD3;
|
||||
half2 texCoordT : TEXCOORD4;
|
||||
half2 texCoordB : TEXCOORD5;
|
||||
float2 texCoordL : TEXCOORD2;
|
||||
float2 texCoordR : TEXCOORD3;
|
||||
float2 texCoordT : TEXCOORD4;
|
||||
float2 texCoordB : TEXCOORD5;
|
||||
half2 noiseCoord : TEXCOORD6;
|
||||
};
|
||||
|
||||
@@ -31,7 +31,7 @@ VS_OUTPUT main(VS_INPUT In) {
|
||||
Out.texCoordR = Out.texCoord + d.xz;
|
||||
Out.texCoordT = Out.texCoord - d.zy;
|
||||
Out.texCoordB = Out.texCoord + d.zy;
|
||||
Out.noiseCoord = Out.texCoord + uParam.zw;
|
||||
Out.noiseCoord = Out.maskCoord + uParam.zw;
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ half4 main(VS_OUTPUT In) : COLOR0 {
|
||||
v.y += (average - v.x) * WATER_VEL;
|
||||
v.y *= WATER_VIS;
|
||||
v.x += v.y;
|
||||
v.x += tex2D(sDiffuse, In.noiseCoord).x * 0.00025;
|
||||
v.x += (tex2D(sDiffuse, In.noiseCoord).x * 2.0 - 1.0) * 0.00025;
|
||||
|
||||
v *= tex2D(sMask, In.maskCoord).a;
|
||||
|
||||
|
Reference in New Issue
Block a user