1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-03-14 08:09:40 +01:00

fix D3D11 version

add glext.h for Windows build
This commit is contained in:
XProger 2020-03-14 13:58:47 +03:00
parent 0c751bedce
commit 59abd003a1
25 changed files with 12888 additions and 278 deletions

View File

@ -8,7 +8,7 @@
#define NO_WATER_HEIGHT 1000000.0f
#if defined(_OS_IOS) || defined(_GAPI_D3D9) || defined(_GAPI_GXM)
#if defined(_OS_IOS) || defined(_GAPI_D3D9) || defined(_GAPI_D3D11) || defined(_GAPI_GXM)
#define USE_SCREEN_TEX
#endif
@ -292,6 +292,7 @@ struct AmbientCache {
Texture *src = textures[j * 4 + i - 1];
Texture *dst = textures[j * 4 + i];
Core::setTarget(dst, NULL, RT_STORE_COLOR);
Core::validateRenderState();
src->bind(sDiffuse);
game->getMesh()->renderQuad();
}
@ -680,10 +681,12 @@ struct WaterCache {
Core::active.shader->setParam(uParam, vec4(p.x, p.z, drop.radius * DETAIL, -drop.strength));
item.data[0]->bind(sNormal);
Core::setTarget(item.data[1], NULL, RT_STORE_COLOR);
Core::setViewport(0, 0, int(s.x + 0.5f), int(s.y + 0.5f));
Core::validateRenderState();
item.data[0]->bind(sNormal);
game->getMesh()->renderQuad();
item.data[0]->unbind(sNormal);
swap(item.data[0], item.data[1]);
}
}
@ -700,10 +703,12 @@ struct WaterCache {
while (item.timer >= SIMULATE_TIMESTEP) {
// water step
item.data[0]->bind(sNormal);
Core::setTarget(item.data[1], NULL, RT_STORE_COLOR);
Core::setViewport(0, 0, int(s.x + 0.5f), int(s.y + 0.5f));
Core::validateRenderState();
item.data[0]->bind(sNormal);
game->getMesh()->renderQuad();
item.data[0]->unbind(sNormal);
swap(item.data[0], item.data[1]);
item.timer -= SIMULATE_TIMESTEP;
}
@ -721,12 +726,14 @@ struct WaterCache {
Core::active.shader->setParam(uTexParam, vec4(1.0f / item.data[0]->width, 1.0f / item.data[0]->height, sx, sz));
Core::whiteTex->bind(sReflect);
item.data[0]->bind(sNormal);
item.caustics->unbind(sReflect);
Core::setTarget(item.caustics, NULL, RT_CLEAR_COLOR | RT_STORE_COLOR);
Core::validateRenderState(); // force clear color for borders
Core::setViewport(1, 1, item.caustics->width - 1, item.caustics->width - 1); // leave 2px for black border
Core::whiteTex->bind(sReflect);
item.data[0]->bind(sNormal);
game->getMesh()->renderPlane();
item.data[0]->unbind(sNormal);
}
void renderRays() {
@ -822,12 +829,14 @@ struct WaterCache {
if (screen) {
Core::setTarget(refract, NULL, RT_LOAD_DEPTH | RT_STORE_COLOR | RT_STORE_DEPTH);
Core::validateRenderState();
bool flip = false;
#if defined(_GAPI_D3D9) || defined(_GAPI_GXM)
#if defined(_GAPI_D3D9) || defined(_GAPI_D3D11) || defined(_GAPI_GXM)
flip = true;
#endif
blitTexture(screen, flip);
Core::setTarget(screen, NULL, RT_LOAD_COLOR | RT_LOAD_DEPTH | RT_STORE_COLOR);
Core::validateRenderState();
} else {
Core::copyTarget(refract, 0, 0, x, y, Core::viewportDef.z, Core::viewportDef.w); // copy framebuffer into refraction texture
}
@ -971,7 +980,7 @@ struct WaterCache {
Core::active.shader->setParam(uViewProj, mProj);
Core::active.shader->setParam(uMaterial, vec4(1.0f));
tex->bind(0);
tex->bind(sDiffuse);
int w = tex->width;
int h = tex->height;
@ -986,7 +995,7 @@ struct WaterCache {
vertices[2].light =
vertices[3].light = ubyte4(255, 255, 255, 255);
#if defined(_GAPI_D3D9) || defined(_GAPI_GXM)
#if defined(_GAPI_D3D9) || defined(_GAPI_D3D11) || defined(_GAPI_GXM)
flip = !flip;
#endif
@ -1008,6 +1017,8 @@ struct WaterCache {
game->getMesh()->renderBuffer(indices, COUNT(indices), vertices, COUNT(vertices));
Core::setDepthTest(true);
tex->unbind(sDiffuse);
}
#undef MAX_SURFACES

View File

@ -165,6 +165,8 @@
#define SHADOW_TEX_SIZE 512
#elif defined(_OS_GCW0)
#define SHADOW_TEX_SIZE 256
#elif defined(_OS_PSV)
#define SHADOW_TEX_SIZE 1024
#else
#define SHADOW_TEX_SIZE 2048
#endif

View File

@ -6,54 +6,39 @@
#define SAFE_RELEASE(P) if(P){P->Release(); P = NULL;}
#define PROFILE_MARKER(title)
#define PROFILE_LABEL(id, name, label)
#define PROFILE_TIMING(time)
#if defined(_DEBUG) || defined(PROFILE)
#include <d3d9.h>
struct Marker {
Marker(const char *title) {
wchar_t ws[128];
swprintf(ws, sizeof(ws), L"%hs", title);
D3DPERF_BeginEvent(0xFFFFFFFF, ws);
}
~Marker() {
D3DPERF_EndEvent();
}
static void setLabel(ID3D11DeviceChild *child, const char *label) {
// TODO: use Windows 10 SDK
//child->SetPrivateData(WKPDID_D3DDebugObjectName, strlen(label), label);
}
};
#define PROFILE_MARKER(title) Marker marker(title)
#define PROFILE_LABEL(id, child, label) Marker::setLabel(child, label)
#define PROFILE_TIMING(time)
#else
#define PROFILE_MARKER(title)
#define PROFILE_LABEL(id, child, label)
#define PROFILE_TIMING(time)
#endif
extern ID3D11Device *device;
extern ID3D11DeviceContext *deviceContext;
extern IDXGISwapChain *swapChain;
#ifdef _DEBUG
void D3DCHECK(HRESULT res) {
if (res == S_OK) return;
/*
LOG("! ");
switch (res) {
case D3DERR_WRONGTEXTUREFORMAT : LOG("D3DERR_WRONGTEXTUREFORMAT"); break;
case D3DERR_UNSUPPORTEDCOLOROPERATION : LOG("D3DERR_UNSUPPORTEDCOLOROPERATION"); break;
case D3DERR_UNSUPPORTEDCOLORARG : LOG("D3DERR_UNSUPPORTEDCOLORARG"); break;
case D3DERR_UNSUPPORTEDALPHAOPERATION : LOG("D3DERR_UNSUPPORTEDALPHAOPERATION"); break;
case D3DERR_UNSUPPORTEDALPHAARG : LOG("D3DERR_UNSUPPORTEDALPHAARG"); break;
case D3DERR_TOOMANYOPERATIONS : LOG("D3DERR_TOOMANYOPERATIONS"); break;
case D3DERR_CONFLICTINGTEXTUREFILTER : LOG("D3DERR_CONFLICTINGTEXTUREFILTER"); break;
case D3DERR_UNSUPPORTEDFACTORVALUE : LOG("D3DERR_UNSUPPORTEDFACTORVALUE"); break;
case D3DERR_CONFLICTINGRENDERSTATE : LOG("D3DERR_CONFLICTINGRENDERSTATE"); break;
case D3DERR_UNSUPPORTEDTEXTUREFILTER : LOG("D3DERR_UNSUPPORTEDTEXTUREFILTER"); break;
case D3DERR_CONFLICTINGTEXTUREPALETTE : LOG("D3DERR_CONFLICTINGTEXTUREPALETTE"); break;
case D3DERR_DRIVERINTERNALERROR : LOG("D3DERR_DRIVERINTERNALERROR"); break;
case D3DERR_NOTFOUND : LOG("D3DERR_NOTFOUND"); break;
case D3DERR_MOREDATA : LOG("D3DERR_MOREDATA"); break;
case D3DERR_DEVICELOST : LOG("D3DERR_DEVICELOST"); break;
case D3DERR_DEVICENOTRESET : LOG("D3DERR_DEVICENOTRESET"); break;
case D3DERR_NOTAVAILABLE : LOG("D3DERR_NOTAVAILABLE"); break;
case D3DERR_OUTOFVIDEOMEMORY : LOG("D3DERR_OUTOFVIDEOMEMORY"); break;
case D3DERR_INVALIDDEVICE : LOG("D3DERR_INVALIDDEVICE"); break;
case D3DERR_INVALIDCALL : LOG("D3DERR_INVALIDCALL"); break;
case D3DERR_DRIVERINVALIDCALL : LOG("D3DERR_DRIVERINVALIDCALL"); break;
case D3DERR_WASSTILLDRAWING : LOG("D3DERR_WASSTILLDRAWING"); break;
default : LOG("D3DERR_UNKNOWN"); break;
}
LOG("\n");
*/
ASSERT(false);
}
#else
#define D3DCHECK(res) res
#endif
#define MAX_SAMPLERS 5
namespace GAPI {
using namespace Core;
@ -75,7 +60,19 @@ namespace GAPI {
ID3D11RasterizerState *RS[cmMAX]; // [cullMode]
ID3D11DepthStencilState *DS[2][2]; // [depthTest][depthWrite]
ID3D11SamplerState *samplers[MAX_SAMPLERS];
enum {
smpDefault,
smpPoint,
smpPointWrap,
smpLinear,
smpLinearWrap,
smpCmp,
smpMAX
};
ID3D11SamplerState *samplers[smpMAX];
ID3D11Texture2D *stagingPixel;
// Shader
#include "shaders/d3d11/shaders.h"
@ -182,7 +179,7 @@ namespace GAPI {
case 1 : SHADER ( filter_downsample, v ); SHADER ( filter_downsample, f ); break;
case 3 : SHADER ( filter_grayscale, v ); SHADER ( filter_grayscale, f ); break;
case 4 : SHADER ( filter_blur, v ); SHADER ( filter_blur, f ); break;
case 5 : SHADER ( filter_blur, v ); SHADER ( filter_blur, f ); break; // TODO anaglyph
case 5 : SHADER ( filter_anaglyph, v ); SHADER ( filter_anaglyph, f ); break; // TODO anaglyph
default : ASSERT(false);
}
break;
@ -267,17 +264,22 @@ namespace GAPI {
// Texture
struct Texture {
ID3D11Texture2D *tex2D;
ID3D11Texture3D *tex3D;
union {
ID3D11Resource *ID;
ID3D11Texture2D *tex2D;
ID3D11Texture3D *tex3D;
};
ID3D11ShaderResourceView *SRV;
ID3D11RenderTargetView *RTV;
ID3D11RenderTargetView *RTV[6];
ID3D11DepthStencilView *DSV;
int width, height, depth, origWidth, origHeight, origDepth;
TexFormat fmt;
uint32 opt;
Texture(int width, int height, int depth, uint32 opt) : tex2D(NULL), tex3D(NULL), SRV(NULL), RTV(NULL), DSV(NULL), width(width), height(height), depth(depth), origWidth(width), origHeight(height), origDepth(depth), fmt(FMT_RGBA), opt(opt) {}
Texture(int width, int height, int depth, uint32 opt) : tex2D(NULL), tex3D(NULL), SRV(NULL), DSV(NULL), width(width), height(height), depth(depth), origWidth(width), origHeight(height), origDepth(depth), fmt(FMT_RGBA), opt(opt) {
memset(RTV, 0, sizeof(RTV));
}
void init(void *data) {
ASSERT((opt & OPT_PROXY) == 0);
@ -378,8 +380,18 @@ namespace GAPI {
device->CreateDepthStencilView(tex2D, &descDSV, &DSV);
ASSERT(DSV);
} else {
device->CreateRenderTargetView(tex2D, NULL, &RTV);
ASSERT(RTV);
D3D11_RENDER_TARGET_VIEW_DESC descRTV;
memset(&descRTV, 0, sizeof(descRTV));
descRTV.Format = desc.Format;
descRTV.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
descRTV.Texture2DArray.ArraySize = 1;
for (int i = 0; i < 6; i++) {
descRTV.Texture2DArray.FirstArraySlice = i;
device->CreateRenderTargetView(tex2D, &descRTV, &RTV[i]);
ASSERT(RTV[i]);
if (!isCube) break;
}
}
}
@ -394,7 +406,9 @@ namespace GAPI {
SAFE_RELEASE(tex2D);
SAFE_RELEASE(tex3D);
SAFE_RELEASE(SRV);
SAFE_RELEASE(RTV);
for (int i = 0; i < 6; i++) {
SAFE_RELEASE(RTV[i]);
}
SAFE_RELEASE(DSV);
}
@ -407,7 +421,7 @@ namespace GAPI {
ASSERT(tex2D);
ASSERT(opt & OPT_DYNAMIC);
D3D11_MAPPED_SUBRESOURCE mapped;
D3DCHECK(deviceContext->Map(tex2D, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped));
deviceContext->Map(tex2D, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
memcpy(mapped.pData, data, mapped.RowPitch * height);
deviceContext->Unmap(tex2D, 0);
}
@ -429,6 +443,13 @@ namespace GAPI {
void unbind(int sampler) {
if (Core::active.textures[sampler]) {
Core::active.textures[sampler] = NULL;
ID3D11ShaderResourceView *none = NULL;
if (opt & OPT_VERTEX) {
deviceContext->VSSetShaderResources(sampler, 1, &none);
}
deviceContext->PSSetShaderResources(sampler, 1, &none);
}
}
@ -437,13 +458,15 @@ namespace GAPI {
// Mesh
struct Mesh {
ID3D11Buffer *IB, *VB;
ID3D11Buffer *ID[2];
int iCount;
int vCount;
bool dynamic;
Mesh(bool dynamic) : IB(NULL), VB(NULL), dynamic(dynamic) {}
Mesh(bool dynamic) : dynamic(dynamic) {
ID[0] = ID[1] = NULL;
}
void init(Index *indices, int iCount, ::Vertex *vertices, int vCount, int aCount) {
this->iCount = iCount;
@ -461,17 +484,17 @@ namespace GAPI {
desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
desc.ByteWidth = iCount * sizeof(Index);
initData.pSysMem = indices;
D3DCHECK(device->CreateBuffer(&desc, dynamic ? NULL : &initData, &IB));
device->CreateBuffer(&desc, dynamic ? NULL : &initData, &ID[0]);
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
desc.ByteWidth = vCount * sizeof(Vertex);
initData.pSysMem = vertices;
D3DCHECK(device->CreateBuffer(&desc, dynamic ? NULL : &initData, &VB));
device->CreateBuffer(&desc, dynamic ? NULL : &initData, &ID[1]);
}
void deinit() {
SAFE_RELEASE(IB);
SAFE_RELEASE(VB);
SAFE_RELEASE(ID[0]);
SAFE_RELEASE(ID[1]);
}
void update(Index *indices, int iCount, ::Vertex *vertices, int vCount) {
@ -480,23 +503,23 @@ namespace GAPI {
D3D11_MAPPED_SUBRESOURCE mapped;
if (indices && iCount) {
deviceContext->Map(IB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
deviceContext->Map(ID[0], 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
memcpy(mapped.pData, indices, iCount * sizeof(indices[0]));
deviceContext->Unmap(IB, 0);
deviceContext->Unmap(ID[0], 0);
}
if (vertices && vCount) {
deviceContext->Map(VB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
deviceContext->Map(ID[1], 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
memcpy(mapped.pData, vertices, vCount * sizeof(vertices[0]));
deviceContext->Unmap(VB, 0);
deviceContext->Unmap(ID[1], 0);
}
}
void bind(const MeshRange &range) const {
UINT stride = sizeof(Vertex);
UINT offset = 0;//range.vStart * stride;
deviceContext->IASetIndexBuffer(IB, sizeof(Index) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0);
deviceContext->IASetVertexBuffers(0, 1, &VB, &stride, &offset);
deviceContext->IASetIndexBuffer(ID[0], sizeof(Index) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0);
deviceContext->IASetVertexBuffers(0, 1, &ID[1], &stride, &offset);
}
void initNextRange(MeshRange &range, int &aIndex) const {
@ -542,15 +565,19 @@ namespace GAPI {
}
if (cmp) {
desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT;
desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
desc.ComparisonFunc = D3D11_COMPARISON_LESS;
desc.BorderColor[0] =
desc.BorderColor[1] =
desc.BorderColor[2] =
desc.BorderColor[3] = 1.0f;
} else {
desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
}
desc.AddressU =
desc.AddressV =
desc.AddressW = wrap ? D3D11_TEXTURE_ADDRESS_WRAP : D3D11_TEXTURE_ADDRESS_CLAMP;
desc.AddressW = cmp ? D3D11_TEXTURE_ADDRESS_BORDER : (wrap ? D3D11_TEXTURE_ADDRESS_WRAP : D3D11_TEXTURE_ADDRESS_CLAMP);
desc.MinLOD = 0;
desc.MaxLOD = D3D11_FLOAT32_MAX;
@ -561,18 +588,12 @@ namespace GAPI {
void initSamplers() {
deinitSamplers();
/*
0 - smpDefault
1 - smpPoint
2 - smpPointWrap
3 - smpLinear
4 - smpCmp
*/
samplers[0] = initSampler(true, true, false, false); // TODO settings dependent
samplers[1] = initSampler(false, false, false, false);
samplers[2] = initSampler(false, false, true, false);
samplers[3] = initSampler(true, false, false, false);
samplers[4] = initSampler(true, false, false, true);
samplers[smpDefault] = initSampler(true, true, false, false); // TODO settings dependent
samplers[smpPoint] = initSampler(false, false, false, false);
samplers[smpPointWrap] = initSampler(false, false, true, false);
samplers[smpLinear] = initSampler(true, false, false, false);
samplers[smpLinearWrap] = initSampler(true, false, true, false);
samplers[smpCmp] = initSampler(true, false, false, true);
}
void init() {
@ -646,6 +667,7 @@ namespace GAPI {
memset(&desc, 0, sizeof(desc));
desc.ScissorEnable = TRUE;
desc.FrontCounterClockwise = TRUE;
desc.DepthClipEnable = TRUE;
desc.FillMode = D3D11_FILL_SOLID;
desc.CullMode = D3D11_CULL_NONE;
device->CreateRasterizerState(&desc, &RS[cmNone]);
@ -675,6 +697,20 @@ namespace GAPI {
// init samplers
memset(samplers, 0, sizeof(samplers));
initSamplers();
// init staging texture for copyPixel
D3D11_TEXTURE2D_DESC desc;
memset(&desc, 0, sizeof(desc));
desc.Width = 1;
desc.Height = 1;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.Usage = D3D11_USAGE_STAGING;
desc.MiscFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
device->CreateTexture2D(&desc, NULL, &stagingPixel);
}
void resetDevice() {
@ -686,15 +722,16 @@ namespace GAPI {
SAFE_RELEASE(rtCache.items[i].DSV);
}
deinitSamplers();
rtCache.count = 0;
}
void deinit() {
resetDevice();
deinitSamplers();
SAFE_RELEASE(stagingPixel);
for (int i = 0; i < COUNT(RS); i++) {
SAFE_RELEASE(RS[i]);
}
@ -705,7 +742,6 @@ namespace GAPI {
}
}
for (int j = 0; j < COUNT(BS); j++) {
for (int i = 0; i < COUNT(BS[0]); i++) {
SAFE_RELEASE(BS[j][i]);
@ -732,8 +768,8 @@ namespace GAPI {
bool beginFrame() {
if (!defRTV) {
ID3D11Texture2D *pBackBuffer = NULL;
D3DCHECK(swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer));
D3DCHECK(device->CreateRenderTargetView(pBackBuffer, NULL, &defRTV));
swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);
device->CreateRenderTargetView(pBackBuffer, NULL, &defRTV);
SAFE_RELEASE(pBackBuffer);
}
@ -750,14 +786,14 @@ namespace GAPI {
desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
ID3D11Texture2D *dsTex;
D3DCHECK(device->CreateTexture2D(&desc, NULL, &dsTex));
device->CreateTexture2D(&desc, NULL, &dsTex);
D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
memset(&descDSV, 0, sizeof(descDSV));
memset(&descDSV, 0, sizeof(descDSV));
descDSV.Format = desc.Format;
descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
descDSV.Texture2D.MipSlice = 0;
D3DCHECK(device->CreateDepthStencilView(dsTex, &descDSV, &defDSV));
device->CreateDepthStencilView(dsTex, &descDSV, &defDSV);
SAFE_RELEASE(dsTex);
}
@ -777,8 +813,8 @@ namespace GAPI {
depthTest = depthWrite = dirtyDepthState = true;
colorWrite = dirtyBlendState = true;
deviceContext->VSGetSamplers(0, COUNT(samplers), samplers);
deviceContext->PSGetSamplers(0, COUNT(samplers), samplers);
deviceContext->VSSetSamplers(0, COUNT(samplers), samplers);
deviceContext->PSSetSamplers(0, COUNT(samplers), samplers);
}
void cacheRenderTarget(ID3D11RenderTargetView **RTV, ID3D11DepthStencilView **DSV, int width, int height) {
@ -856,8 +892,8 @@ namespace GAPI {
if (target) {
ASSERT(target->opt & OPT_TARGET);
if (target->RTV) {
RTV = target->RTV;
if (target->RTV[face]) {
RTV = target->RTV[face];
cacheRenderTarget(NULL, &DSV, target->width, target->height);
} else if (target->DSV) {
DSV = target->DSV;
@ -923,10 +959,10 @@ namespace GAPI {
void setViewport(const short4 &v) {
D3D11_VIEWPORT viewport;
viewport.TopLeftX = (FLOAT)x;
viewport.TopLeftY = (FLOAT)y;
viewport.Width = (FLOAT)width;
viewport.Height = (FLOAT)height;
viewport.TopLeftX = (FLOAT)v.x;
viewport.TopLeftY = (FLOAT)v.y;
viewport.Width = (FLOAT)v.z;
viewport.Height = (FLOAT)v.w;
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
@ -1008,27 +1044,24 @@ namespace GAPI {
}
vec4 copyPixel(int x, int y) {
/* TODO
GAPI::Texture *t = Core::active.target;
ASSERT(t && t->tex2D);
D3D11_BOX srcBox;
srcBox.left = x;
srcBox.top = y;
srcBox.right = x + 1;
srcBox.bottom = y + 1;
srcBox.front = 0;
srcBox.back = 1;
LPDIRECT3DSURFACE9 surface, texSurface;
D3DCHECK(t->tex2D->GetSurfaceLevel(0, &texSurface));
D3DCHECK(device->CreateOffscreenPlainSurface(t->width, t->height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, NULL));
D3DCHECK(device->GetRenderTargetData(texSurface, surface));
ASSERT(Core::active.target);
deviceContext->CopySubresourceRegion(stagingPixel, 0, 0, 0, 0, Core::active.target->tex2D, 0, &srcBox);
RECT r = { x, y, x + 1, y + 1 };
D3DLOCKED_RECT rect;
surface->LockRect(&rect, &r, D3DLOCK_READONLY);
ubyte4 c = *((ubyte4*)rect.pBits);
surface->UnlockRect();
D3D11_MAPPED_SUBRESOURCE res;
deviceContext->Map(stagingPixel, 0, D3D11_MAP_READ, 0, &res);
ASSERT(res.pData);
Color32 c = *((Color32*)res.pData);
deviceContext->Unmap(stagingPixel, 0);
texSurface->Release();
surface->Release();
return vec4(float(c.z), float(c.y), float(c.x), float(c.w)) * (1.0f / 255.0f);
*/
return vec4(0.0f);
return vec4(float(c.r), float(c.g), float(c.b), float(c.a)) * (1.0f / 255.0f);
}
}

View File

@ -1422,15 +1422,18 @@ struct Inventory {
return; // TODO
#endif
game->setShader(Core::passFilter, Shader::FILTER_BLUR, false, false);
float s = 1.0f / INV_BG_SIZE;
// vertical
Core::setTarget(tmp, NULL, RT_STORE_COLOR);
Core::active.shader->setParam(uParam, vec4(0, 1.0f / INV_BG_SIZE, 0, 0));
Core::validateRenderState();
Core::active.shader->setParam(uParam, vec4(0, s, 0, s));
texInOut->bind(sDiffuse);
game->getMesh()->renderQuad();
// horizontal
Core::setTarget(texInOut, NULL, RT_STORE_COLOR);
Core::validateRenderState();
game->setShader(Core::passFilter, Shader::FILTER_BLUR, false, false);
Core::active.shader->setParam(uParam, vec4(1.0f / INV_BG_SIZE, 0, 0, 0));
Core::active.shader->setParam(uParam, vec4(s, 0, 0, s));
tmp->bind(sDiffuse);
game->getMesh()->renderQuad();
}
@ -1439,9 +1442,11 @@ struct Inventory {
#ifdef FFP
return; // TODO
#endif
float s = 1.0f / INV_BG_SIZE;
game->setShader(Core::passFilter, Shader::FILTER_GRAYSCALE, false, false);
Core::setTarget(texOut, NULL, RT_STORE_COLOR);
Core::active.shader->setParam(uParam, vec4(0.75f, 0.75f, 1.0f, 1.0f));
Core::validateRenderState();
Core::active.shader->setParam(uParam, vec4(0.75f, 0.75f, 1.0f, s));
texIn->bind(sDiffuse);
game->getMesh()->renderQuad();
}
@ -1837,7 +1842,7 @@ struct Inventory {
Core::setViewProj(mView, mProj);
game->setShader(Core::passFilter, Shader::FILTER_UPSCALE, false, false);
Core::active.shader->setParam(uParam, vec4(float(Core::active.textures[sDiffuse]->width), float(Core::active.textures[sDiffuse]->height), Core::getTime() * 0.001f, 0.0f));
Core::active.shader->setParam(uParam, vec4(float(Core::active.textures[sDiffuse]->width), float(Core::active.textures[sDiffuse]->height), 0.0f, 0.0f));
game->getMesh()->renderBuffer(indices, COUNT(indices), vertices, COUNT(vertices));
}

View File

@ -395,7 +395,7 @@ struct Level : IGame {
Stream::cacheWrite("settings", (char*)&settings, sizeof(settings));
if (rebuildShaders) {
#if !defined(_GAPI_D3D9) && !defined(_GAPI_GXM)
#if !defined(_GAPI_D3D9) && !defined(_GAPI_D3D11) && !defined(_GAPI_GXM)
delete shaderCache;
shaderCache = new ShaderCache();
#endif
@ -598,8 +598,10 @@ struct Level : IGame {
Core::whiteTex->bind(sReflect);
Core::whiteCube->bind(sEnvironment);
Texture *shadowMap = shadow[player ? player->camera->cameraIndex : 0];
if (shadowMap) shadowMap->bind(sShadow);
if (Core::pass != Core::passShadow) {
Texture *shadowMap = shadow[player ? player->camera->cameraIndex : 0];
if (shadowMap) shadowMap->bind(sShadow);
}
Core::basis.identity();
}
@ -627,8 +629,11 @@ struct Level : IGame {
for (int i = 0; i < 6; i++) {
setupCubeCamera(pos, i);
Core::pass = pass;
Texture *target = (targets[0]->opt & OPT_CUBEMAP) ? targets[0] : targets[i * stride];
Core::setTarget(target, NULL, RT_CLEAR_COLOR | RT_CLEAR_DEPTH | RT_STORE_COLOR, i);
if (targets[0]->opt & OPT_CUBEMAP) {
Core::setTarget(targets[0], NULL, RT_CLEAR_COLOR | RT_CLEAR_DEPTH | RT_STORE_COLOR, i);
} else {
Core::setTarget(targets[i * stride], NULL, RT_CLEAR_COLOR | RT_CLEAR_DEPTH | RT_STORE_COLOR);
}
renderView(rIndex, false, false);
}
@ -1773,6 +1778,9 @@ struct Level : IGame {
}
void renderSky() {
#ifndef _GAPI_GL
return;
#endif
ASSERT(mesh->transparent == 0);
Shader::Type type;
@ -2557,6 +2565,7 @@ struct Level : IGame {
if (water) {
screen = (waterCache && waterCache->visible) ? waterCache->getScreenTex() : NULL;
Core::setTarget(screen, NULL, RT_CLEAR_COLOR | RT_CLEAR_DEPTH | RT_STORE_COLOR | (screen ? RT_STORE_DEPTH : 0)); // render to screen texture (FUCK YOU iOS!) or back buffer
Core::validateRenderState();
setupBinding();
}
@ -2593,6 +2602,7 @@ struct Level : IGame {
if (water && waterCache && waterCache->visible && screen) {
Core::setTarget(NULL, NULL, RT_STORE_COLOR);
Core::validateRenderState();
waterCache->blitTexture(screen);
}
@ -2638,11 +2648,23 @@ struct Level : IGame {
m = Core::mProj * Core::mView;
mat4 bias;
bias.identity();
bias.e03 = bias.e13 = bias.e23 = bias.e00 = bias.e11 = bias.e22 = 0.5f;
#if defined(_GAPI_D3D9) || defined(_GAPI_GXM)
bias.e11 = -bias.e11;
#endif
if (GAPI::getProjRange() == mat4::PROJ_ZERO_POS)
bias = mat4(
0.5f, 0.0f, 0.0f, 0.0f,
0.0f,-0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.0f, 1.0f
);
else {
bias = mat4(
0.5f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 0.5f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f
);
}
m = bias * m;
Core::mLightProj = m;
@ -2793,6 +2815,11 @@ struct Level : IGame {
if (colorShadow)
Core::setClearColor(vec4(0.0f));
#ifdef _GAPI_D3D11 // TODO render pass
Core::setTarget(NULL, NULL, RT_CLEAR_DEPTH | RT_CLEAR_COLOR | RT_STORE_COLOR | RT_STORE_DEPTH);
Core::validateRenderState();
#endif
Core::eye = oldEye;
}
@ -3221,6 +3248,7 @@ struct Level : IGame {
Core::setDepthWrite(false);
Core::setTarget(NULL, NULL, RT_STORE_COLOR);
Core::validateRenderState();
setShader(Core::passFilter, Shader::FILTER_ANAGLYPH, false, false);
Core::eyeTex[0]->bind(sDiffuse);
Core::eyeTex[1]->bind(sNormal);

12537
src/libs/gl/glext.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -268,7 +268,9 @@ BOOL (WINAPI *RegisterTouchWindowX)(HWND, ULONG);
BOOL (WINAPI *GetTouchInputInfoX)(HTOUCHINPUT, UINT, PTOUCHINPUT, int);
BOOL (WINAPI *CloseTouchInputHandleX)(HTOUCHINPUT);
#define MAX_TOUCH_COUNT 6
#ifndef MAX_TOUCH_COUNT
#define MAX_TOUCH_COUNT 6
#endif
void touchInit(HWND hWnd) {
int value = GetSystemMetrics(SM_DIGITIZER);

View File

@ -14,7 +14,7 @@ VS_OUTPUT main(VS_INPUT In) {
float4 rBasisRot = uBasis[0];
float4 rBasisPos = uBasis[1];
Out.texCoord = In.aTexCoord * (1.0 / 32767.0);
Out.texCoord = In.aTexCoord * INV_SHORT_HALF;
float3 coord;
@ -25,7 +25,7 @@ VS_OUTPUT main(VS_INPUT In) {
Out.diffuse *= uMaterial.w;
Out.pos = mul(uViewProj, float4(coord, rBasisPos.w));
Out.pos = mul(uViewProj, float4(coord, 1.0));
return Out;
}

View File

@ -14,7 +14,7 @@ VS_OUTPUT main(VS_INPUT In) {
float4 rBasisRot = uBasis[0];
float4 rBasisPos = uBasis[1];
Out.texCoord = In.aTexCoord * (1.0 / 32767.0);
Out.texCoord = In.aTexCoord * INV_SHORT_HALF;
float3 coord;
@ -27,7 +27,7 @@ VS_OUTPUT main(VS_INPUT In) {
Out.diffuse *= In.aLight.a;
Out.pos = mul(uViewProj, float4(coord, rBasisPos.w));
Out.pos = mul(uViewProj, float4(coord, 1.0));
return Out;
}

View File

@ -2,26 +2,30 @@
#pragma pack_matrix( column_major )
#endif
#define ALPHA_REF 0.5
#define ALPHA_REF 0.5
#define MAX_LIGHTS 4
#define MAX_CONTACTS 15
#define WATER_FOG_DIST (1.0 / (6.0 * 1024.0))
#define WATER_COLOR_DIST (1.0 / (2.0 * 1024.0))
#define UNDERWATER_COLOR float3(0.6, 0.9, 0.9)
#define UNDERWATER_COLOR_H half3(0.6, 0.9, 0.9)
#define SHADOW_NORMAL_BIAS 16.0
#define SHADOW_NORMAL_BIAS 1.0
#define SHADOW_CONST_BIAS 0.05
#define SHADOW_SIZE 1024
#ifdef _GAPI_GXM
#define SHADOW_SIZE 1024.0
#else
#define SHADOW_SIZE 2048.0
#endif
#define SHADOW_TEXEL (1.0 / SHADOW_SIZE)
#define PI 3.141592653589793
static const float3 SHADOW_TEXEL = float3(1.0 / SHADOW_SIZE, 1.0 / SHADOW_SIZE, 0.0);
#define INV_SHORT_HALF (1.0 / 32767.0)
#ifdef _GAPI_D3D9
#define FLAGS_REG b0
#define FLAGS_TYPE bool4
#else
#define FLAGS_REG c94
#define FLAGS_TYPE float4
#if defined(_GAPI_D3D11) || defined(_GAPI_GXM)
#define SHADOW_DEPTH
#endif
struct VS_INPUT {
@ -33,11 +37,12 @@ struct VS_INPUT {
};
#ifdef _GAPI_D3D11
SamplerState smpDefault : register(s0);
SamplerState smpPoint : register(s1);
SamplerState smpPointWrap : register(s2);
SamplerState smpLinear : register(s3);
SamplerComparisonState smpCmp : register(s4);
SamplerState smpDefault : register(s0);
SamplerState smpPoint : register(s1);
SamplerState smpPointWrap : register(s2);
SamplerState smpLinear : register(s3);
SamplerState smpLinearWrap : register(s4);
SamplerComparisonState smpCmp : register(s5);
Texture2D sDiffuse : register(t0);
#ifdef NORMAL_AS_3D
@ -50,14 +55,15 @@ struct VS_INPUT {
TextureCube sEnvironment : register(t4);
Texture2D sMask : register(t5);
#define SAMPLE_2D(T,uv) T.Sample(smpDefault, uv)
#define SAMPLE_2D_POINT(T,uv) T.Sample(smpPoint, uv)
#define SAMPLE_2D_POINT_WRAP(T,uv) T.Sample(smpPointWrap, uv)
#define SAMPLE_2D_LINEAR(T,uv) T.Sample(smpLinear, uv)
#define SAMPLE_2D_CMP(T,uv) T.SampleCmp(smpCmp, uv.xy, uv.z)
#define SAMPLE_2D_LOD0(T,uv) T.SampleLevel(smpLinear, uv, 0)
#define SAMPLE_3D(T,uv) T.Sample(smpLinear, uv)
#define SAMPLE_CUBE(T,uv) T.Sample(smpLinear, uv)
#define SAMPLE_2D(T,uv) T.Sample(smpDefault, uv)
#define SAMPLE_2D_POINT(T,uv) T.Sample(smpPoint, uv)
#define SAMPLE_2D_POINT_WRAP(T,uv) T.Sample(smpPointWrap, uv)
#define SAMPLE_2D_LINEAR(T,uv) T.Sample(smpLinear, uv)
#define SAMPLE_2D_LINEAR_WRAP(T,uv) T.Sample(smpLinearWrap, uv)
#define SAMPLE_2D_CMP(T,uv) T.SampleCmp(smpCmp, uv.xy, uv.z)
#define SAMPLE_2D_LOD0(T,uv) T.SampleLevel(smpLinear, uv, 0)
#define SAMPLE_3D(T,uv) T.Sample(smpLinear, uv)
#define SAMPLE_CUBE(T,uv) T.Sample(smpLinear, uv)
#else
sampler2D sDiffuse : register(s0);
sampler2D sNormal : register(s1);
@ -70,6 +76,7 @@ struct VS_INPUT {
#define SAMPLE_2D_POINT(T,uv) tex2D(T, uv)
#define SAMPLE_2D_POINT_WRAP(T,uv) tex2D(T, uv)
#define SAMPLE_2D_LINEAR(T,uv) tex2D(T, uv)
#define SAMPLE_2D_LINEAR_WRAP(T,uv) tex2D(T, uv)
#define SAMPLE_2D_LOD0(T,uv) tex2Dlod(T, float4(uv.xy, 0, 0))
#define SAMPLE_2D_CMP(T,uv) ((tex2D(T, uv.xy) => uv.z) ? 1 : 0)
#define SAMPLE_3D(T,uv) tex3D(T, uv)
@ -89,14 +96,13 @@ float4 uLightPos[MAX_LIGHTS] : register( c83 );
float4 uLightColor[MAX_LIGHTS] : register( c87 );
float4 uRoomSize : register( c91 );
float4 uPosScale[2] : register( c92 );
FLAGS_TYPE uFlags[4] : register( FLAGS_REG );
float4 uContacts[MAX_CONTACTS] : register( c98 );
// options for compose, shadow, ambient passes
#define OPT_AMBIENT uFlags[0].x
#define OPT_SHADOW uFlags[0].y
#define OPT_CONTACT uFlags[0].z
#define OPT_CAUSTICS uFlags[0].w
#define OPT_AMBIENT 1
#define OPT_SHADOW 1
#define OPT_CONTACT 1
#define OPT_CAUSTICS 1
float4 pack(float value) {
float4 v = frac(value * float4(1.0, 255.0, 65025.0, 16581375.0));
@ -173,16 +179,6 @@ void applyFog(inout float3 color, float fogFactor) {
color.xyz = lerp(uFogParams.xyz, color.xyz, fogFactor);
}
float SHADOW(float2 p) {
#ifdef SHADOW_SAMPLER
return SAMPLE_2D_POINT(sShadow, float4(p, 0, 0)).x;
#elif SHADOW_DEPTH
return SAMPLE_2D_POINT(sShadow, float4(p, 0, 0)).x;
#else
return unpack(SAMPLE_2D_POINT(sShadow, p));
#endif
}
float getShadowValue(float3 lightVec, float4 lightProj) {
/*
float sMin = min(lightProj.x, lightProj.y);
@ -195,40 +191,27 @@ float getShadowValue(float3 lightVec, float4 lightProj) {
*/
float factor = step(0.0, lightProj.w); //float((sMin > 0.0f) && (sMax < lightProj.w)); //
lightProj.xyz *= factor;
lightProj.xyz /= lightProj.w;
lightProj.z -= SHADOW_CONST_BIAS * SHADOW_TEXEL;
#ifdef _GAPI_GXM
lightProj.z += SHADOW_CONST_BIAS * SHADOW_TEXEL.x * lightProj.w;
float rShadow = f1tex2Dproj(sShadow, lightProj);
#elif _GAPI_D3D11
float rShadow = sShadow.SampleCmpLevelZero(smpCmp, lightProj.xy, lightProj.z);
#else
float3 p = lightProj.xyz / lightProj.w;
p.z -= SHADOW_CONST_BIAS * SHADOW_TEXEL.x;
p.z = saturate(p.z);
float4 samples = float4(
SHADOW(p.xy ),
SHADOW(p.xy + SHADOW_TEXEL.xz),
SHADOW(p.xy + SHADOW_TEXEL.zy),
SHADOW(p.xy + SHADOW_TEXEL.xy)
);
samples = step(p.zzzz, samples);
float2 f = frac(p.xy / SHADOW_TEXEL.xy);
samples.xy = lerp(samples.xz, samples.yw, f.xx);
float rShadow = lerp(samples.x, samples.y, f.y);
float rShadow = 1.0;
#endif
//rShadow = lerp(1.0, rShadow, factor);
float fade = saturate(dot(lightVec, lightVec));
return rShadow + (1.0 - rShadow) * fade;
}
float getShadow(float3 lightVec, float3 normal, float4 lightProj) {
float factor = clamp(1.0 - dot(normalize(lightVec), normal), 0.0, 1.0);
factor *= SHADOW_NORMAL_BIAS;
return getShadowValue(lightVec, lightProj /*mul(uLightProj, float4(coord + normal * factor, 1.0)) */ );
return getShadowValue(lightVec, lightProj);
}
float4 calcLightProj(float3 coord, float3 lightVec, float3 normal) {
return mul(uLightProj, float4(coord, 1.0));
}
float getContactAO(float3 p, float3 n) {

View File

@ -23,6 +23,7 @@ call :compile filter _upscale "/DUPSCALE"
call :compile filter _downsample "/DDOWNSAMPLE"
call :compile filter _grayscale "/DGRAYSCALE"
call :compile filter _blur "/DBLUR"
call :compile filter _anaglyph "/DANAGLYPH"
call :compile gui

View File

@ -23,6 +23,7 @@ call :compile filter _upscale "/DUPSCALE"
call :compile filter _downsample "/DDOWNSAMPLE"
call :compile filter _grayscale "/DGRAYSCALE"
call :compile filter _blur "/DBLUR"
call :compile filter _anaglyph "/DANAGLYPH"
call :compile gui

View File

@ -23,7 +23,7 @@ VS_OUTPUT main(VS_INPUT In) {
float4 rBasisRot = uBasis[index];
float4 rBasisPos = uBasis[index + 1];
Out.texCoord = In.aTexCoord * (1.0 / 32767.0);
Out.texCoord = In.aTexCoord * INV_SHORT_HALF;
Out.coord = mulBasis(rBasisRot, rBasisPos.xyz, In.aCoord.xyz);
Out.texCoord.xy *= Out.texCoord.zw;
@ -71,7 +71,7 @@ VS_OUTPUT main(VS_INPUT In) {
Out.diffuse *= uMaterial.w;
Out.pos = mul(uViewProj, float4(Out.coord, rBasisPos.w));
Out.lightProj = mul(uLightProj, float4(Out.coord, 1.0));
Out.lightProj = calcLightProj(Out.coord, normalize(uLightPos[0].xyz - Out.coord), Out.normal.xyz);
return Out;
}
@ -106,10 +106,6 @@ float4 main(VS_OUTPUT In) : COLOR0 {
light += calcCaustics(In.coord, normal);
}
if (OPT_CONTACT) {
light *= getContactAO(In.coord, normal) * 0.5 + 0.5;
}
color.xyz *= light;
float specular = calcSpecular(normal, In.viewVec.xyz, lightVec, rSpecular);

View File

@ -17,9 +17,9 @@ VS_OUTPUT main(VS_INPUT In) {
float3 coord = mulBasis(rBasisRot, rBasisPos.xyz, In.aCoord.xyz);
Out.pos = mul(uViewProj, float4(coord, rBasisPos.w));
Out.pos = mul(uViewProj, float4(coord, 1.0));
Out.diffuse = In.aColor.rgb * (uMaterial.x * 1.8) + uMaterial.w;
Out.texCoord = In.aTexCoord * (1.0 / 32767.0);
Out.texCoord = In.aTexCoord * INV_SHORT_HALF;
Out.texCoord.xy *= Out.texCoord.zw;
return Out;

View File

@ -21,7 +21,7 @@ VS_OUTPUT main(VS_INPUT In) {
float4 rBasisRot = uBasis[0];
float4 rBasisPos = uBasis[1];
Out.texCoord = In.aTexCoord * (1.0 / 32767.0);
Out.texCoord = In.aTexCoord * INV_SHORT_HALF;
Out.coord = mulBasis(rBasisRot, rBasisPos.xyz, In.aCoord.xyz);
Out.texCoord.xy *= Out.texCoord.zw;
@ -65,9 +65,9 @@ VS_OUTPUT main(VS_INPUT In) {
Out.diffuse = float4(In.aColor.rgb * (uMaterial.x * 1.8), 1.0);
Out.diffuse *= uMaterial.w;
Out.pos = mul(uViewProj, float4(Out.coord, rBasisPos.w));
Out.lightProj = mul(uLightProj, float4(Out.coord, 1.0));
Out.pos = mul(uViewProj, float4(Out.coord, 1.0));
Out.lightProj = calcLightProj(Out.coord, normalize(uLightPos[0].xyz - Out.coord), Out.normal.xyz);
return Out;
}

View File

@ -19,7 +19,7 @@ VS_OUTPUT main(VS_INPUT In) {
float4 rBasisRot = uBasis[0];
float4 rBasisPos = uBasis[1];
Out.texCoord = In.aTexCoord * (1.0 / 32767.0);
Out.texCoord = In.aTexCoord * INV_SHORT_HALF;
Out.coord = mulBasis(rBasisRot, rBasisPos.xyz + In.aCoord.xyz, float3(In.aTexCoord.z, In.aTexCoord.w, 0.0));
@ -57,7 +57,7 @@ VS_OUTPUT main(VS_INPUT In) {
Out.diffuse *= uMaterial.w;
Out.diffuse *= In.aLight.a;
Out.pos = mul(uViewProj, float4(Out.coord, rBasisPos.w));
Out.pos = mul(uViewProj, float4(Out.coord, 1.0));
return Out;
}
@ -77,10 +77,6 @@ float4 main(VS_OUTPUT In) : COLOR0 {
float3 light = In.light.xyz;
if (OPT_CAUSTICS) {
light += calcCaustics(In.coord, normal);
}
color.xyz *= light;
#ifdef UNDERWATER

View File

@ -19,7 +19,7 @@ uniform mat4 uViewProj;
uniform sampler2D sNormal;
#ifdef FILTER_DOWNSAMPLE
vec4 downsample() { // uParam (textureSize, unused, unused, unused)
vec4 downsample() { // uParam (texelSize, unused, unused, unused)
vec4 color = vec4(0.0);
for (float y = -1.5; y < 2.0; y++)
for (float x = -1.5; x < 2.0; x++) {
@ -48,15 +48,15 @@ uniform mat4 uViewProj;
#endif
#ifdef FILTER_GRAYSCALE
vec4 grayscale() { // uParam (factor, unused, unused, unused)
vec4 grayscale() { // uParam (tint.rgb, texelSize)
vec4 color = texture2D(sDiffuse, vTexCoord);
vec3 gray = vec3(dot(color, vec4(0.299, 0.587, 0.114, 0.0)));
return vec4(mix(color.xyz, gray, uParam.w) * uParam.xyz, color.w);
return vec4(gray * uParam.xyz, color.w);
}
#endif
#ifdef FILTER_BLUR
vec4 blur() { // uParam (dirX, dirY, 1 / textureSize, unused)
vec4 blur() { // uParam (dirX, dirY, unused, texelSize)
const vec3 offset = vec3(0.0, 1.3846153846, 3.2307692308);
const vec3 weight = vec3(0.2270270270, 0.3162162162, 0.0702702703);

View File

@ -11,26 +11,28 @@ struct VS_OUTPUT {
#ifdef VERTEX
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);
Out.pos = mul(uViewProj, float4(In.aCoord.xy, 0.0, 1.0));
Out.texCoord = In.aTexCoord.xy * INV_SHORT_HALF;
#ifdef UPSCALE
Out.diffuse = In.aLight;
#endif
#ifndef _GAPI_GXM
#ifdef DOWNSAMPLE
Out.texCoord += float2(2.0, -2.0) * uParam.x;
#elif BLUR
Out.texCoord += float2(1.0, -1.0) * uParam.z;
#endif
#endif
#ifdef _GAPI_D3D9
#if defined(DOWNSAMPLE)
Out.texCoord += float2(2.0, -2.0) * uParam.x; // ???
#elif defined(BLUR) || defined(GRAYSCALE)
Out.texCoord += float2(0.5, 0.5) * uParam.w;
#elif defined(UPSCALE)
Out.texCoord += float2(0.5, 0.5) / uParam.xy;
#endif
#endif
return Out;
}
#else // PIXEL
float4 downsample(float2 uv) { // uParam (1 / textureSize, unused, unused, unused)
float4 downsample(float2 uv) { // uParam (texelSize, unused, unused, unused)
float4 color = 0.0;
for (float y = -1.5; y < 2.0; y++) {
@ -46,13 +48,13 @@ float4 downsample(float2 uv) { // uParam (1 / textureSize, unused, unused, unuse
return float4(color.xyz / color.w, 1.0);
}
float4 grayscale(float2 uv) { // uParam (factor, unused, unused, unused)
float4 grayscale(float2 uv) { // uParam (tint.rgb, texelSize)
float4 color = SAMPLE_2D_POINT(sDiffuse, uv);
float3 gray = dot(color, float4(0.299, 0.587, 0.114, 0.0));
return float4(lerp(color.xyz, gray, uParam.w) * uParam.xyz, color.w);
return float4(gray * uParam.xyz, color.w);
}
float4 blur(float2 uv) { // uParam (dirX, dirY, 1 / textureSize, unused)
float4 blur(float2 uv) { // uParam (dirX, dirY, unused, texelSize)
const float3 offset = float3( 0.0, 1.3846153846, 3.2307692308);
const float3 weight = float3(0.2270270270, 0.3162162162, 0.0702702703);
@ -65,13 +67,19 @@ float4 blur(float2 uv) { // uParam (dirX, dirY, 1 / textureSize, unused)
return color;
}
float4 upscale(float2 uv) { // uParam (1 / textureWidth, 1 / textureHeight, unused, unused)
uv *= uParam.xy + 0.5;
float2 iuv = floor(uv);
float2 fuv = frac(uv);
uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv);
uv = (uv - 0.5) / uParam.xy;
return SAMPLE_2D_LINEAR(sDiffuse, uv);
float4 upscale(float2 uv) { // uParam (textureWidth, textureHeight, unused, unused)
uv = uv * uParam.xy + 0.5;
float2 iuv = floor(uv);
float2 fuv = frac(uv);
uv = iuv + fuv * fuv * (3.0 - 2.0 * fuv);
uv = (uv - 0.5) / uParam.xy;
return SAMPLE_2D_LINEAR(sDiffuse, uv);
}
float4 anaglyph(float2 uv) {
float3 eyeL = SAMPLE_2D_POINT(sDiffuse, float2(uv.x, 1.0 - uv.y)).rgb;
float3 eyeR = SAMPLE_2D_POINT(sNormal, float2(uv.x, 1.0 - uv.y)).rgb;
return float4(eyeL.r, eyeR.g, eyeR.b, 1.0);
}
float4 main(VS_OUTPUT In) : COLOR0 {
@ -83,6 +91,8 @@ float4 main(VS_OUTPUT In) : COLOR0 {
return blur(In.texCoord.xy);
#elif UPSCALE
return upscale(In.texCoord.xy) * In.diffuse;
#elif ANAGLYPH
return anaglyph(In.texCoord.xy);
#else
#error unsupported filter type
#endif

View File

@ -10,7 +10,7 @@ struct VS_OUTPUT {
VS_OUTPUT main(VS_INPUT In) {
VS_OUTPUT Out;
Out.pos = mul(uViewProj, float4(In.aCoord.xy, 0.0, 1.0));
Out.texCoord = In.aTexCoord.xy * (1.0 / 32767.0);
Out.texCoord = In.aTexCoord.xy * INV_SHORT_HALF;
Out.diffuse = In.aLight * uMaterial;
return Out;
}

View File

@ -1,9 +1,11 @@
#include "common.hlsl"
struct VS_OUTPUT {
float4 pos : POSITION;
float4 texCoord : TEXCOORD0;
float4 hpos : TEXCOORD1;
float4 pos : POSITION;
float4 texCoord : TEXCOORD0;
#ifndef SHADOW_DEPTH
float4 hpos : TEXCOORD1;
#endif
};
#ifdef VERTEX
@ -11,32 +13,32 @@ struct VS_OUTPUT {
VS_OUTPUT main(VS_INPUT In) {
VS_OUTPUT Out;
int index = int(In.aCoord.w * 2.0);
int index = int(In.aCoord.w);
float4 rBasisRot = uBasis[index];
float4 rBasisPos = uBasis[index + 1];
float3 coord = mulBasis(rBasisRot, rBasisPos.xyz, In.aCoord.xyz);
Out.texCoord = In.aTexCoord * (1.0 / 32767.0);
float3 cpos = In.aCoord.xyz - normalize(In.aNormal.xyz) * SHADOW_NORMAL_BIAS;
float3 coord = mulBasis(rBasisRot, rBasisPos.xyz, cpos);
Out.texCoord = In.aTexCoord * INV_SHORT_HALF;
Out.pos = mul(uViewProj, float4(coord, rBasisPos.w));
#ifndef SHADOW_DEPTH
Out.hpos = Out.pos;
#endif
return Out;
}
#else // PIXEL
float4 main(VS_OUTPUT In) : COLOR0 {
#ifdef ALPHA_TEST
clip(SAMPLE_2D_LINEAR(sDiffuse, In.texCoord.xy).a - ALPHA_REF);
#endif
#ifdef ALPHA_TEST
clip(SAMPLE_2D_LINEAR(sDiffuse, In.texCoord.xy).a - ALPHA_REF);
#endif
#ifdef _GAPI_GXM
return 0.0;
#ifdef SHADOW_DEPTH
return 0.0;
#else
#ifdef SHADOW_DEPTH
return 0.0;
#else // SHADOW_COLOR
return pack(In.hpos.z / In.hpos.w);
#endif
return pack(In.hpos.z / In.hpos.w);
#endif
}

View File

@ -8,9 +8,11 @@ struct VS_OUTPUT {
float2 getInvUV(float2 uv, float4 param) {
float2 p = (float2(uv.x, -uv.y) * 0.5 + 0.5) * param.zw;
#ifndef _GAPI_GXM
#ifdef _GAPI_D3D9
p.xy += 0.5 * param.xy;
#endif
return p;
}
@ -22,7 +24,7 @@ float2 getUV(float2 uv, float4 param) {
VS_OUTPUT main(VS_INPUT In) {
VS_OUTPUT Out;
float3 coord = In.aCoord.xyz * (1.0 / 32767.0);
float3 coord = In.aCoord.xyz * INV_SHORT_HALF;
float3 rCoord = float3(coord.x, coord.y, 0.0) * uPosScale[1].xzy;

View File

@ -15,14 +15,15 @@ struct VS_OUTPUT {
VS_OUTPUT main(VS_INPUT In) {
VS_OUTPUT Out;
float3 coord = In.aCoord.xyz * (1.0 / 32767.0);
float3 coord = In.aCoord.xyz * INV_SHORT_HALF;
float4 uv = float4(coord.x, coord.y, coord.x, -coord.y) * 0.5 + 0.5;
Out.maskCoord = uv.xy * uRoomSize.zw;
Out.texCoord = uv.zw * uTexParam.zw;
#ifdef _GAPI_D3D9
Out.texCoord += 0.5 * uTexParam.xy;
#endif
#ifdef _GAPI_D3D9
Out.texCoord += 0.5 * uTexParam.xy;
#endif
coord = float3(coord.x, 0.0, coord.y) * uPosScale[1].xyz + uPosScale[0].xyz;
@ -64,7 +65,7 @@ half4 main(VS_OUTPUT In) : COLOR0 {
half fresnel = calcFresnel(max(0.0, dot(normal, viewVec)), 0.12);
half mask = SAMPLE_2D_POINT(sMask, In.maskCoord).a;
half mask = SAMPLE_2D_POINT(sMask, In.maskCoord).r;
half4 color = half4(lerp(refr, refl, fresnel), mask);
color.xyz += spec * 1.5;

View File

@ -8,7 +8,7 @@ struct VS_OUTPUT {
float2 getInvUV(float2 uv, float4 param) {
float2 p = (float2(uv.x, -uv.y) * 0.5 + 0.5) * param.zw;
#ifndef _GAPI_GXM
#ifdef _GAPI_D3D9
p.xy += 0.5 * param.xy;
#endif
return p;
@ -24,7 +24,7 @@ float2 getUV(float2 uv, float4 param) {
VS_OUTPUT main(VS_INPUT In) {
VS_OUTPUT Out;
float3 coord = In.aCoord.xyz * (1.0 / 32767.0);
float3 coord = In.aCoord.xyz * INV_SHORT_HALF;
Out.pos = float4(coord.xyz, 1.0);
Out.texCoord = getInvUV(coord.xy, uTexParam);

View File

@ -3,7 +3,7 @@
#ifdef VERTEX
float4 main(VS_INPUT In) : POSITION {
float3 coord = In.aCoord.xyz * (1.0 / 32767.0);
float3 coord = In.aCoord.xyz * INV_SHORT_HALF;
coord = float3(coord.x, 0.0, coord.y) * uPosScale[1].xyz + uPosScale[0].xyz;
return mul(uViewProj, float4(coord, 1.0));
}

View File

@ -15,14 +15,14 @@ struct VS_OUTPUT {
VS_OUTPUT main(VS_INPUT In) {
VS_OUTPUT Out;
float3 coord = In.aCoord.xyz * (1.0 / 32767.0);
float3 coord = In.aCoord.xyz * INV_SHORT_HALF;
float4 uv = float4(coord.x, coord.y, coord.x, -coord.y) * 0.5 + 0.5;
Out.pos = float4(coord.xyz, 1.0);
Out.maskCoord = uv.xy * uRoomSize.zw;
Out.texCoord = uv.zw * uTexParam.zw;
#ifndef _GAPI_GXM
#ifdef _GAPI_D3D9
Out.texCoord += 0.5 * uTexParam.xy;
#endif
@ -54,9 +54,9 @@ half4 main(VS_OUTPUT In) : COLOR0 {
v.y += (average - v.x) * WATER_VEL;
v.y *= WATER_VIS;
v.x += v.y;
v.x += (SAMPLE_2D_LINEAR(sDiffuse, In.noiseCoord).x * 2.0 - 1.0) * 0.00025;
v.x += (SAMPLE_2D_LINEAR_WRAP(sDiffuse, In.noiseCoord).x * 2.0 - 1.0) * 0.00025;
v *= SAMPLE_2D_POINT(sMask, In.maskCoord).a;
v *= SAMPLE_2D_POINT(sMask, In.maskCoord).r;
return v;
}