mirror of
https://github.com/libretro/pcsx2.git
synced 2024-11-28 11:50:46 +00:00
GSdx:
Added loading of external shaders, coded by KrossX (thanks again :p ). Right now it looks for a file called "shader.fx" in PCSX2's main directory. If it finds one, the PageUp key activates the external shader (instead of the built-in FXAA). We have a forum thread for some nice shaders to try out here: http://forums.pcsx2.net/Thread-Custom-Shaders-for-GSdx git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5390 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
parent
801867ab95
commit
fb851cfdfc
@ -271,7 +271,12 @@ bool GSDevice11::Create(GSWnd* wnd)
|
||||
|
||||
hr = m_dev->CreateBuffer(&bd, NULL, &m_fxaa.cb);
|
||||
|
||||
CompileShader(IDR_FXAA_FX, "ps_main", NULL, &m_fxaa.ps);
|
||||
try {
|
||||
CompileShader("shader.fx", "ps_main", NULL, &m_fxaa.ps);
|
||||
}
|
||||
catch (GSDXRecoverableError) {
|
||||
CompileShader(IDR_FXAA_FX, "ps_main", NULL, &m_fxaa.ps);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@ -1368,6 +1373,72 @@ void GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO*
|
||||
}
|
||||
}
|
||||
|
||||
void GSDevice11::CompileShader(const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11VertexShader** vs, D3D11_INPUT_ELEMENT_DESC* layout, int count, ID3D11InputLayout** il)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
vector<D3D11_SHADER_MACRO> m;
|
||||
|
||||
PrepareShaderMacro(m, macro);
|
||||
|
||||
CComPtr<ID3D11Blob> shader, error;
|
||||
|
||||
hr = D3DX11CompileFromFile(fn, &m[0], NULL, entry, m_shader.vs.c_str(), 0, 0, NULL, &shader, &error, NULL);
|
||||
|
||||
if(error)
|
||||
{
|
||||
printf("%s\n", (const char*)error->GetBufferPointer());
|
||||
}
|
||||
|
||||
if(FAILED(hr))
|
||||
{
|
||||
throw GSDXRecoverableError();
|
||||
}
|
||||
|
||||
hr = m_dev->CreateVertexShader((void*)shader->GetBufferPointer(), shader->GetBufferSize(), NULL, vs);
|
||||
|
||||
if(FAILED(hr))
|
||||
{
|
||||
throw GSDXRecoverableError();
|
||||
}
|
||||
|
||||
hr = m_dev->CreateInputLayout(layout, count, shader->GetBufferPointer(), shader->GetBufferSize(), il);
|
||||
|
||||
if(FAILED(hr))
|
||||
{
|
||||
throw GSDXRecoverableError();
|
||||
}
|
||||
}
|
||||
|
||||
void GSDevice11::CompileShader(const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11PixelShader** ps)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
vector<D3D11_SHADER_MACRO> m;
|
||||
|
||||
PrepareShaderMacro(m, macro);
|
||||
|
||||
CComPtr<ID3D11Blob> shader, error;
|
||||
|
||||
hr = D3DX11CompileFromFile(fn, &m[0], NULL, entry, m_shader.ps.c_str(), 0, 0, NULL, &shader, &error, NULL);
|
||||
|
||||
if(error)
|
||||
{
|
||||
printf("%s\n", (const char*)error->GetBufferPointer());
|
||||
}
|
||||
|
||||
if(FAILED(hr))
|
||||
{
|
||||
throw GSDXRecoverableError();
|
||||
}
|
||||
|
||||
hr = m_dev->CreatePixelShader((void*)shader->GetBufferPointer(), shader->GetBufferSize(),NULL, ps);
|
||||
|
||||
if(FAILED(hr))
|
||||
{
|
||||
throw GSDXRecoverableError();
|
||||
}
|
||||
}
|
||||
void GSDevice11::CompileShader(const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11ComputeShader** cs)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
@ -219,5 +219,7 @@ public:
|
||||
void CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11PixelShader** ps);
|
||||
void CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11ComputeShader** cs);
|
||||
void CompileShader(const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11ComputeShader** cs);
|
||||
void CompileShader(const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11VertexShader** vs, D3D11_INPUT_ELEMENT_DESC* layout, int count, ID3D11InputLayout** il);
|
||||
void CompileShader(const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11PixelShader** ps);
|
||||
};
|
||||
|
||||
|
@ -360,7 +360,12 @@ bool GSDevice9::Create(GSWnd* wnd)
|
||||
|
||||
// fxaa
|
||||
|
||||
CompileShader(IDR_FXAA_FX, "ps_main", NULL, &m_fxaa.ps);
|
||||
try {
|
||||
CompileShader("shader.fx", "ps_main", NULL, &m_fxaa.ps);
|
||||
}
|
||||
catch (GSDXRecoverableError) {
|
||||
CompileShader(IDR_FXAA_FX, "ps_main", NULL, &m_fxaa.ps);
|
||||
}
|
||||
|
||||
// create shader layout
|
||||
|
||||
@ -1342,6 +1347,83 @@ void GSDevice9::OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4
|
||||
}
|
||||
}
|
||||
|
||||
void GSDevice9::CompileShader(const char* fn, const string& entry, const D3DXMACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il)
|
||||
{
|
||||
vector<D3DXMACRO> m;
|
||||
|
||||
PrepareShaderMacro(m, macro);
|
||||
|
||||
HRESULT hr;
|
||||
|
||||
CComPtr<ID3DXBuffer> shader, error;
|
||||
|
||||
hr = D3DXCompileShaderFromFile(fn, &m[0], NULL, entry.c_str(), m_shader.vs.c_str(), 0, &shader, &error, NULL);
|
||||
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
hr = m_dev->CreateVertexShader((DWORD*)shader->GetBufferPointer(), vs);
|
||||
}
|
||||
else if(error)
|
||||
{
|
||||
printf("%s\n", (const char*)error->GetBufferPointer());
|
||||
}
|
||||
|
||||
ASSERT(SUCCEEDED(hr));
|
||||
|
||||
if(FAILED(hr))
|
||||
{
|
||||
throw GSDXRecoverableError();
|
||||
}
|
||||
|
||||
hr = m_dev->CreateVertexDeclaration(layout, il);
|
||||
|
||||
if(FAILED(hr))
|
||||
{
|
||||
throw GSDXRecoverableError();
|
||||
}
|
||||
}
|
||||
|
||||
void GSDevice9::CompileShader(const char* fn, const string& entry, const D3DXMACRO* macro, IDirect3DPixelShader9** ps)
|
||||
{
|
||||
uint32 flags = 0;
|
||||
|
||||
if(m_shader.level >= D3D_FEATURE_LEVEL_9_3)
|
||||
{
|
||||
flags |= D3DXSHADER_AVOID_FLOW_CONTROL;
|
||||
}
|
||||
else
|
||||
{
|
||||
flags |= D3DXSHADER_SKIPVALIDATION;
|
||||
}
|
||||
|
||||
vector<D3DXMACRO> m;
|
||||
|
||||
PrepareShaderMacro(m, macro);
|
||||
|
||||
HRESULT hr;
|
||||
|
||||
CComPtr<ID3DXBuffer> shader, error;
|
||||
|
||||
hr = D3DXCompileShaderFromFile(fn, &m[0], NULL, entry.c_str(), m_shader.ps.c_str(), flags, &shader, &error, NULL);
|
||||
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
hr = m_dev->CreatePixelShader((DWORD*)shader->GetBufferPointer(), ps);
|
||||
}
|
||||
else if(error)
|
||||
{
|
||||
printf("%s\n", (const char*)error->GetBufferPointer());
|
||||
}
|
||||
|
||||
ASSERT(SUCCEEDED(hr));
|
||||
|
||||
if(FAILED(hr))
|
||||
{
|
||||
throw GSDXRecoverableError();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GSDevice9::CompileShader(uint32 id, const string& entry, const D3DXMACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il)
|
||||
{
|
||||
vector<D3DXMACRO> m;
|
||||
|
@ -224,6 +224,9 @@ public:
|
||||
void CompileShader(uint32 id, const string& entry, const D3DXMACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il);
|
||||
void CompileShader(uint32 id, const string& entry, const D3DXMACRO* macro, IDirect3DPixelShader9** ps);
|
||||
|
||||
void CompileShader(const char* fn, const string& entry, const D3DXMACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il);
|
||||
void CompileShader(const char* fn, const string& entry, const D3DXMACRO* macro, IDirect3DPixelShader9** ps);
|
||||
|
||||
void SetupVS(VSSelector sel, const VSConstantBuffer* cb);
|
||||
void SetupGS(GSSelector sel) {}
|
||||
void SetupPS(PSSelector sel, const PSConstantBuffer* cb, PSSamplerSelector ssel);
|
||||
|
@ -554,7 +554,7 @@ void GSRenderer::KeyEvent(GSKeyEventData* e)
|
||||
return;
|
||||
case VK_PRIOR:
|
||||
m_fxaa = !m_fxaa;
|
||||
printf("GSdx: fxaa is now %s.\n", m_fxaa ? "enabled" : "disabled");
|
||||
printf("GSdx: Post-processing shader is now %s.\n", m_fxaa ? "enabled" : "disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user