i know still a lot to fix and much work to do but sometimes experiments are fun :)

for all the plugins implemented per pixel lighting, this will make games that uses lighting  a lot nice. (just look at mario sunshine and compare :))
for dx9: implemented temporal anaglyph stereo: just grab your red-cyan glasses  and enjoy.
stereo calibration: use stereo separation ( distance of the point from you are looking) and Focal Angle: the angle necessary to focus in one particular object.
this settings are different in every games as they use different depth ranges.
please for any regression and bug introduced by this commit.
if you ask why i did not implement stereo in dx11 and opengl the reason is one: they don't work right when i have more time will try to find a way to make them work.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6224 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Rodolfo Osvaldo Bogado
2010-09-23 02:17:48 +00:00
parent 5e806eb7b2
commit e641323de2
30 changed files with 558 additions and 79 deletions

View File

@ -22,7 +22,7 @@ static const char ID[4] = {'D', 'C', 'A', 'C'};
// Update this to the current SVN revision every time you change shader generation code.
// We don't automatically get this from SVN_REV because that would mean regenerating the
// shader cache for every revision, graphics-related or not, which is simply annoying.
const int version = 6148;
const int version = 6223;
LinearDiskCache::LinearDiskCache()
: file_(NULL), num_entries_(0) {

View File

@ -24,6 +24,8 @@
#include "PixelShaderGen.h"
#include "XFMemory.h" // for texture projection mode
#include "BPMemory.h"
#include "VideoConfig.h"
#include "NativeVertexFormat.h"
PIXELSHADERUID last_pixel_shader_uid;
@ -57,15 +59,26 @@ void GetPixelShaderId(PIXELSHADERUID *uid, u32 dstAlphaEnable)
for (int i = 0; i < 8; i += 2)
((u8*)&uid->values[1])[i / 2] = (bpmem.tevksel[i].hex & 0xf) | ((bpmem.tevksel[i + 1].hex & 0xf) << 4);
uid->values[2] = 0;
u32 enableZTexture = (!bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable)?1:0;
uid->values[3] = (u32)bpmem.fog.c_proj_fsel.fsel |
uid->values[2] = (u32)bpmem.fog.c_proj_fsel.fsel |
((u32)bpmem.fog.c_proj_fsel.proj << 3) |
((u32)enableZTexture << 4);
int hdr = 4;
if(g_ActiveConfig.bEnablePixelLigting)
{
for (int i = 0; i < 2; ++i) {
uid->values[3 + i] = xfregs.colChans[i].color.enablelighting ?
(u32)xfregs.colChans[i].color.hex :
(u32)xfregs.colChans[i].color.matsource;
uid->values[3 + i] |= (xfregs.colChans[i].alpha.enablelighting ?
(u32)xfregs.colChans[i].alpha.hex :
(u32)xfregs.colChans[i].alpha.matsource) << 15;
}
}
uid->values[4] |= g_ActiveConfig.bEnablePixelLigting << 31;
int hdr = 5;
u32 *pcurvalue = &uid->values[hdr];
for (u32 i = 0; i < numstages; ++i)
{
@ -135,7 +148,8 @@ void GetPixelShaderId(PIXELSHADERUID *uid, u32 dstAlphaEnable)
}
// yeah, well ....
uid->indstages = (u32)(pcurvalue - &uid->values[0] - (hdr - 1) - uid->tevstages);
uid->indstages = (u32)(pcurvalue - &uid->values[0] - (hdr - 1) - uid->tevstages);
}
// old tev->pixelshader notes
@ -366,7 +380,69 @@ static void BuildSwapModeTable()
}
}
const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType)
char *GeneratePixelLightShader(char *p, int index, const LitChannel& chan, const char *dest, int coloralpha)
{
const char* swizzle = "xyzw";
if (coloralpha == 1 ) swizzle = "xyz";
else if (coloralpha == 2 ) swizzle = "w";
if (!(chan.attnfunc & 1)) {
// atten disabled
switch (chan.diffusefunc) {
case LIGHTDIF_NONE:
WRITE(p, "%s.%s += "I_PLIGHTS".lights[%d].col.%s;\n", dest, swizzle, index, swizzle);
break;
case LIGHTDIF_SIGN:
case LIGHTDIF_CLAMP:
WRITE(p, "ldir = normalize("I_PLIGHTS".lights[%d].pos.xyz - pos.xyz);\n", index);
WRITE(p, "%s.%s += %sdot(ldir, _norm0)) * "I_PLIGHTS".lights[%d].col.%s;\n",
dest, swizzle, chan.diffusefunc != LIGHTDIF_SIGN ? "max(0.0f," :"(", index, swizzle);
break;
default: _assert_(0);
}
}
else { // spec and spot
if (chan.attnfunc == 3)
{ // spot
WRITE(p, "ldir = "I_PLIGHTS".lights[%d].pos.xyz - pos.xyz;\n", index);
WRITE(p, "dist2 = dot(ldir, ldir);\n"
"dist = sqrt(dist2);\n"
"ldir = ldir / dist;\n"
"attn = max(0.0f, dot(ldir, "I_PLIGHTS".lights[%d].dir.xyz));\n",index);
WRITE(p, "attn = max(0.0f, dot("I_PLIGHTS".lights[%d].cosatt.xyz, float3(1.0f, attn, attn*attn))) / dot("I_PLIGHTS".lights[%d].distatt.xyz, float3(1.0f,dist,dist2));\n", index, index);
}
else if (chan.attnfunc == 1)
{ // specular
WRITE(p, "ldir = normalize("I_PLIGHTS".lights[%d].pos.xyz);\n",index);
WRITE(p, "attn = (dot(_norm0,ldir) > 0.0f) ? max(0.0f, dot(_norm0, "I_PLIGHTS".lights[%d].dir.xyz)) : 0.0f;\n", index);
WRITE(p, "attn = max(0.0f, dot("I_PLIGHTS".lights[%d].cosatt.xyz, float3(1,attn,attn*attn))) / dot("I_PLIGHTS".lights[%d].distatt.xyz, float3(1,attn,attn*attn));\n", index, index);
}
switch (chan.diffusefunc)
{
case LIGHTDIF_NONE:
WRITE(p, "%s.%s += attn * "I_PLIGHTS".lights[%d].col.%s;\n", dest, swizzle, index, swizzle);
break;
case LIGHTDIF_SIGN:
case LIGHTDIF_CLAMP:
WRITE(p, "%s.%s += attn * %sdot(ldir, _norm0)) * "I_PLIGHTS".lights[%d].col.%s;\n",
dest,
swizzle,
chan.diffusefunc != LIGHTDIF_SIGN ? "max(0.0f," :"(",
index,
swizzle);
break;
default: _assert_(0);
}
}
WRITE(p, "\n");
return p;
}
const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType,u32 components)
{
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
text[sizeof(text) - 1] = 0x7C; // canary
@ -431,10 +507,18 @@ const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType)
WRITE(p, "uniform float4 "I_INDTEXSCALE"[2] : register(c%d);\n", C_INDTEXSCALE);
WRITE(p, "uniform float4 "I_INDTEXMTX"[6] : register(c%d);\n", C_INDTEXMTX);
WRITE(p, "uniform float4 "I_FOG"[2] : register(c%d);\n", C_FOG);
if(g_ActiveConfig.bEnablePixelLigting)
{
WRITE(p,"typedef struct { float4 col; float4 cosatt; float4 distatt; float4 pos; float4 dir; } Light;\n");
WRITE(p,"typedef struct { Light lights[8]; } s_"I_PLIGHTS";\n");
WRITE(p, "uniform s_"I_PLIGHTS" "I_PLIGHTS" : register(c%d);\n", C_PLIGHTS);
WRITE(p, "typedef struct { float4 C0, C1, C2, C3; } s_"I_PMATERIALS";\n");
WRITE(p, "uniform s_"I_PMATERIALS" "I_PMATERIALS" : register(c%d);\n", C_PMATERIALS);
}
WRITE(p, "void main(\n");
if(ApiType != API_D3D11)
WRITE(p, " out float4 ocol0 : COLOR0,%s\n in float4 rawpos : POSITION,\n",DepthTextureEnable ? "\n out float depth : DEPTH," : "");
WRITE(p, " out float4 ocol0 : COLOR0,%s\n in float4 rawpos : %s,\n",DepthTextureEnable ? "\n out float depth : DEPTH," : "", ApiType == API_OPENGL ? "WPOS" : "POSITION");
else
WRITE(p, " out float4 ocol0 : SV_Target,%s\n in float4 rawpos : SV_Position,\n",DepthTextureEnable ? "\n out float depth : SV_Depth," : "");
@ -446,14 +530,14 @@ const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType)
{
for (int i = 0; i < numTexgen; ++i)
WRITE(p, ",\n in float3 uv%d : TEXCOORD%d", i, i);
WRITE(p, ",\n in float4 clipPos : TEXCOORD%d", numTexgen);
WRITE(p, ",\n in float4 Normal : TEXCOORD%d", numTexgen + 1);
}
else
{
// wpos is in w of first 4 texcoords
for (int i = 0; i < numTexgen; ++i)
WRITE(p, ",\n in float%d uv%d : TEXCOORD%d", i<4?4:3, i, i);
for (int i = 0; i < 8; ++i)
WRITE(p, ",\n in float4 uv%d : TEXCOORD%d", i, i);
}
WRITE(p, " ) {\n");
@ -466,7 +550,138 @@ const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType)
" float3 tevcoord;\n"
" float2 wrappedcoord, tempcoord;\n"
" float4 cc0, cc1, cc2, cprev,crastemp,ckonsttemp;\n\n");
if(g_ActiveConfig.bEnablePixelLigting)
{
if (xfregs.numTexGens < 7)
{
WRITE(p,"float3 _norm0 = normalize(Normal.xyz);\n\n");
WRITE(p,"float3 pos = float3(clipPos.x,clipPos.y,Normal.w);\n");
}
else
{
WRITE(p," float3 _norm0 = normalize(float3(uv4.w,uv5.w,uv6.w));\n\n");
WRITE(p,"float3 pos = float3(uv0.w,uv1.w,uv7.w);\n");
}
WRITE(p, "float4 mat, lacc;\n"
"float3 ldir, h;\n"
"float dist, dist2, attn;\n");
// lights/colors
for (int j = 0; j < xfregs.nNumChans; j++)
{
const LitChannel& color = xfregs.colChans[j].color;
const LitChannel& alpha = xfregs.colChans[j].alpha;
WRITE(p, "{\n");
if (color.matsource) {// from vertex
if (components & (VB_HAS_COL0 << j))
WRITE(p, "mat = colors_%d;\n", j);
else if (components & VB_HAS_COL0)
WRITE(p, "mat = colors_0;\n");
else
WRITE(p, "mat = float4(1.0f, 1.0f, 1.0f, 1.0f);\n");
}
else // from color
WRITE(p, "mat = "I_PMATERIALS".C%d;\n", j+2);
if (color.enablelighting) {
if (color.ambsource) { // from vertex
if (components & (VB_HAS_COL0<<j) )
WRITE(p, "lacc = colors_%d;\n", j);
else if (components & VB_HAS_COL0 )
WRITE(p, "lacc = colors_0;\n");
else
WRITE(p, "lacc = float4(0.0f, 0.0f, 0.0f, 0.0f);\n");
}
else // from color
WRITE(p, "lacc = "I_PMATERIALS".C%d;\n", j);
}
else
{
WRITE(p, "lacc = float4(1.0f, 1.0f, 1.0f, 1.0f);\n");
}
// check if alpha is different
if (alpha.matsource != color.matsource) {
if (alpha.matsource) {// from vertex
if (components & (VB_HAS_COL0<<j))
WRITE(p, "mat.w = colors_%d.w;\n", j);
else if (components & VB_HAS_COL0)
WRITE(p, "mat.w = colors_0.w;\n");
else WRITE(p, "mat.w = 1.0f;\n");
}
else // from color
WRITE(p, "mat.w = "I_PMATERIALS".C%d.w;\n", j+2);
}
if (alpha.enablelighting)
{
if (alpha.ambsource) {// from vertex
if (components & (VB_HAS_COL0<<j) )
WRITE(p, "lacc.w = colors_%d.w;\n", j);
else if (components & VB_HAS_COL0 )
WRITE(p, "lacc.w = colors_0.w;\n");
else
WRITE(p, "lacc.w = 0.0f;\n");
}
else // from color
WRITE(p, "lacc.w = "I_PMATERIALS".C%d.w;\n", j);
}
else
{
WRITE(p, "lacc.w = 1.0f;\n");
}
if(color.enablelighting && alpha.enablelighting)
{
// both have lighting, test if they use the same lights
int mask = 0;
if(color.lightparams == alpha.lightparams)
{
mask = color.GetFullLightMask() & alpha.GetFullLightMask();
if(mask)
{
for (int i = 0; i < 8; ++i)
{
if (mask & (1<<i))
p = GeneratePixelLightShader(p, i, color, "lacc", 3);
}
}
}
// no shared lights
for (int i = 0; i < 8; ++i)
{
if (!(mask&(1<<i)) && (color.GetFullLightMask() & (1<<i)))
p = GeneratePixelLightShader(p, i, color, "lacc", 1);
if (!(mask&(1<<i)) && (alpha.GetFullLightMask() & (1<<i)))
p = GeneratePixelLightShader(p, i, alpha, "lacc", 2);
}
}
else if (color.enablelighting || alpha.enablelighting)
{
// lights are disabled on one channel so process only the active ones
LitChannel workingchannel = color.enablelighting ? color : alpha;
int coloralpha = color.enablelighting ? 1 : 2;
for (int i = 0; i < 8; ++i)
{
if (workingchannel.GetFullLightMask() & (1<<i))
p = GeneratePixelLightShader(p, i, workingchannel, "lacc", coloralpha);
}
}
WRITE(p, "colors_%d = mat * saturate(lacc);\n", j);
WRITE(p, "}\n");
}
}
if (numTexgen < 7)
WRITE(p, "clipPos = float4(rawpos.x, rawpos.y, clipPos.z, clipPos.w);\n");
else
WRITE(p, "float4 clipPos = float4(rawpos.x, rawpos.y, uv2.w, uv3.w);\n");
// HACK to handle cases where the tex gen is not enabled
if (numTexgen == 0)
{
@ -479,8 +694,7 @@ const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType)
// optional perspective divides
if (xfregs.texcoords[i].texmtxinfo.projection == XF_TEXPROJ_STQ)
WRITE(p, "uv%d.xy = uv%d.xy/uv%d.z;\n", i, i, i);
// scale texture coordinates
WRITE(p, "uv%d.xy = uv%d.xy * "I_TEXDIMS"[%d].zw;\n", i, i, i);
}
}
@ -552,8 +766,7 @@ const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType)
{
if((bpmem.fog.c_proj_fsel.fsel != 0) || DepthTextureEnable)
{
if (numTexgen >= 7)
WRITE(p, "float4 clipPos = float4(uv0.w, uv1.w, uv2.w, uv3.w);\n");
// the screen space depth value = far z + (clip z / clip w) * z range
WRITE(p, "float zCoord = "I_ZBIAS"[1].x + (clipPos.z / clipPos.w) * "I_ZBIAS"[1].y;\n");
}
@ -579,7 +792,7 @@ const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType)
{
WriteFog(p);
WRITE(p, " ocol0 = prev;\n");
}
}
}
WRITE(p, "}\n");
if (text[sizeof(text) - 1] != 0x7C)

View File

@ -28,18 +28,22 @@
#define I_INDTEXSCALE "cindscale"
#define I_INDTEXMTX "cindmtx"
#define I_FOG "cfog"
#define I_PLIGHTS "cLights"
#define I_PMATERIALS "cmtrl"
#define C_COLORS 0
#define C_KCOLORS (C_COLORS + 4)
#define C_ALPHA (C_KCOLORS + 4)
#define C_TEXDIMS (C_ALPHA + 1)
#define C_ZBIAS (C_TEXDIMS + 8)
#define C_INDTEXSCALE (C_ZBIAS + 2)
#define C_INDTEXMTX (C_INDTEXSCALE + 2)
#define C_FOG (C_INDTEXMTX + 6)
#define C_COLORMATRIX (C_FOG + 2)
#define C_PENVCONST_END (C_COLORMATRIX + 16)
#define PIXELSHADERUID_MAX_VALUES (5 + 32 + 6 + 11)
#define C_COLORS 0
#define C_KCOLORS (C_COLORS + 4)
#define C_ALPHA (C_KCOLORS + 4)
#define C_TEXDIMS (C_ALPHA + 1)
#define C_ZBIAS (C_TEXDIMS + 8)
#define C_INDTEXSCALE (C_ZBIAS + 2)
#define C_INDTEXMTX (C_INDTEXSCALE + 2)
#define C_FOG (C_INDTEXMTX + 6)
#define C_COLORMATRIX (C_FOG + 2)
#define C_PLIGHTS (C_COLORMATRIX + 4)
#define C_PMATERIALS (C_PLIGHTS + 40)
#define C_PENVCONST_END (C_PMATERIALS + 4)
#define PIXELSHADERUID_MAX_VALUES (5 + 32 + 6 + 11 + 2)
// DO NOT make anything in this class virtual.
class PIXELSHADERUID
@ -100,7 +104,7 @@ public:
}
};
const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType);
const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType,u32 components);
void GetPixelShaderId(PIXELSHADERUID *uid, u32 dstAlphaEnable);
extern PIXELSHADERUID last_pixel_shader_uid;

View File

@ -23,7 +23,7 @@
#include "PixelShaderManager.h"
#include "VideoCommon.h"
#include "VideoConfig.h"
static float GC_ALIGNED16(s_fMaterials[16]);
static int s_nColorsChanged[2]; // 0 - regular colors, 1 - k colors
static int s_nIndTexMtxChanged;
static bool s_bAlphaChanged;
@ -32,6 +32,7 @@ static bool s_bZTextureTypeChanged;
static bool s_bDepthRangeChanged;
static bool s_bFogColorChanged;
static bool s_bFogParamChanged;
static int nLightsChanged[2]; // min,max
static float lastDepthRange[2]; // 0 = far z, 1 = far - near
static float lastRGBAfull[2][4][4];
static u8 s_nTexDimsChanged;
@ -39,6 +40,7 @@ static u8 s_nIndTexScaleChanged;
static u32 lastAlpha;
static u32 lastTexDims[8]; // width | height << 16 | wrap_s << 28 | wrap_t << 30
static u32 lastZBias;
static int nMaterialsChanged;
void PixelShaderManager::Init()
{
@ -57,6 +59,8 @@ void PixelShaderManager::Dirty()
s_nIndTexMtxChanged = 15;
s_bAlphaChanged = s_bZBiasChanged = s_bZTextureTypeChanged = s_bDepthRangeChanged = true;
s_bFogColorChanged = s_bFogParamChanged = true;
nLightsChanged[0] = 0; nLightsChanged[1] = 0x80;
nMaterialsChanged = 15;
}
void PixelShaderManager::Shutdown()
@ -207,6 +211,50 @@ void PixelShaderManager::SetConstants()
}
s_bFogParamChanged = false;
}
if (nLightsChanged[0] >= 0)
{
// lights don't have a 1 to 1 mapping, the color component needs to be converted to 4 floats
int istart = nLightsChanged[0] / 0x10;
int iend = (nLightsChanged[1] + 15) / 0x10;
const float* xfmemptr = (const float*)&xfmem[0x10 * istart + XFMEM_LIGHTS];
for (int i = istart; i < iend; ++i)
{
u32 color = *(const u32*)(xfmemptr + 3);
float NormalizationCoef = 1 / 255.0f;
SetPSConstant4f(C_PLIGHTS + 5 * i,
((color >> 24) & 0xFF) * NormalizationCoef,
((color >> 16) & 0xFF) * NormalizationCoef,
((color >> 8) & 0xFF) * NormalizationCoef,
((color) & 0xFF) * NormalizationCoef);
xfmemptr += 4;
for (int j = 0; j < 4; ++j, xfmemptr += 3)
{
if (j == 1 &&
fabs(xfmemptr[0]) < 0.00001f &&
fabs(xfmemptr[1]) < 0.00001f &&
fabs(xfmemptr[2]) < 0.00001f)
{
// dist attenuation, make sure not equal to 0!!!
SetPSConstant4f(C_PLIGHTS+5*i+j+1, 0.00001f, xfmemptr[1], xfmemptr[2], 0);
}
else
SetPSConstant4fv(C_PLIGHTS+5*i+j+1, xfmemptr);
}
}
nLightsChanged[0] = nLightsChanged[1] = -1;
}
if (nMaterialsChanged)
{
for (int i = 0; i < 4; ++i)
if (nMaterialsChanged & (1 << i))
SetPSConstant4fv(C_PMATERIALS + i, &s_fMaterials[4 * i]);
nMaterialsChanged = 0;
}
}
void PixelShaderManager::SetPSTextureDims(int texid)
@ -349,3 +397,35 @@ void PixelShaderManager::SetColorMatrix(const float* pmatrix, const float* pfCon
SetMultiPSConstant4fv(C_COLORMATRIX,4,pmatrix);
SetPSConstant4fv(C_COLORMATRIX+4, pfConstAdd);
}
void PixelShaderManager::InvalidateXFRange(int start, int end)
{
if (start < XFMEM_LIGHTS_END && end > XFMEM_LIGHTS)
{
int _start = start < XFMEM_LIGHTS ? XFMEM_LIGHTS : start-XFMEM_LIGHTS;
int _end = end < XFMEM_LIGHTS_END ? end-XFMEM_LIGHTS : XFMEM_LIGHTS_END-XFMEM_LIGHTS;
if (nLightsChanged[0] == -1 )
{
nLightsChanged[0] = _start;
nLightsChanged[1] = _end;
}
else
{
if (nLightsChanged[0] > _start) nLightsChanged[0] = _start;
if (nLightsChanged[1] < _end) nLightsChanged[1] = _end;
}
}
}
void PixelShaderManager::SetMaterialColor(int index, u32 data)
{
int ind = index * 4;
nMaterialsChanged |= (1 << index);
float NormalizationCoef = 1 / 255.0f;
s_fMaterials[ind++] = ((data >> 24) & 0xFF) * NormalizationCoef;
s_fMaterials[ind++] = ((data >> 16) & 0xFF) * NormalizationCoef;
s_fMaterials[ind++] = ((data >> 8) & 0xFF) * NormalizationCoef;
s_fMaterials[ind] = ( data & 0xFF) * NormalizationCoef;
}

View File

@ -19,6 +19,7 @@
#define _PIXELSHADERMANAGER_H
#include "BPMemory.h"
#include "XFMemory.h"
#include "PixelShaderGen.h"
void SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4);
@ -51,6 +52,8 @@ public:
static void SetFogColorChanged();
static void SetFogParamChanged();
static void SetColorMatrix(const float* pmatrix, const float* pfConstAdd);
static void InvalidateXFRange(int start, int end);
static void SetMaterialColor(int index, u32 data);
};

View File

@ -24,6 +24,7 @@
#include "BPMemory.h"
#include "CPMemory.h"
#include "VertexShaderGen.h"
#include "VideoConfig.h"
VERTEXSHADERUID last_vertex_shader_uid;
@ -44,7 +45,7 @@ void GetVertexShaderId(VERTEXSHADERUID *uid, u32 components)
(u32)xfregs.colChans[i].alpha.hex :
(u32)xfregs.colChans[i].alpha.matsource) << 15;
}
uid->values[2] |= g_ActiveConfig.bEnablePixelLigting << 31;
u32 *pcurvalue = &uid->values[3];
for (int i = 0; i < xfregs.numTexGens; ++i) {
TexMtxInfo tinfo = xfregs.texcoords[i].texmtxinfo;
@ -115,11 +116,21 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
for (int i = 0; i < xfregs.numTexGens; ++i)
WRITE(p, " float3 tex%d : TEXCOORD%d;\n", i, i);
WRITE(p, " float4 clipPos : TEXCOORD%d;\n", xfregs.numTexGens);
if(g_ActiveConfig.bEnablePixelLigting)
WRITE(p, " float4 Normal : TEXCOORD%d;\n", xfregs.numTexGens + 1);
} else {
// clip position is in w of first 4 texcoords
for (int i = 0; i < xfregs.numTexGens; ++i)
WRITE(p, " float%d tex%d : TEXCOORD%d;\n", i<4?4:3, i, i);
}
if(g_ActiveConfig.bEnablePixelLigting)
{
for (int i = 0; i < 8; ++i)
WRITE(p, " float4 tex%d : TEXCOORD%d;\n", i, i);
}
else
{
for (int i = 0; i < xfregs.numTexGens; ++i)
WRITE(p, " float%d tex%d : TEXCOORD%d;\n", i < 4 ? 4 : 3 , i, i);
}
}
WRITE(p, "};\n");
// uniforms
@ -134,7 +145,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
WRITE(p, "uniform s_"I_PROJECTION" "I_PROJECTION" : register(c%d);\n", C_PROJECTION);
WRITE(p, "uniform float4 "I_DEPTHPARAMS" : register(c%d);\n", C_DEPTHPARAMS);
WRITE(p, "VS_OUTPUT main(\n");
WRITE(p, "VS_OUTPUT main(\n");
// inputs
if (components & VB_HAS_NRM0)
@ -169,8 +180,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
WRITE(p, " float fposmtx : ATTR%d,\n", SHADER_POSMTX_ATTRIB);
}
WRITE(p, " float4 rawpos : POSITION) {\n");
WRITE(p, "VS_OUTPUT o;\n");
WRITE(p, "VS_OUTPUT o;\n");
// transforms
if (components & VB_HAS_POSMTXIDX) {
if (api_type == API_D3D9)
@ -187,8 +197,8 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
WRITE(p, "int posmtx = fposmtx;\n");
}
WRITE(p, "float4 pos = float4(dot("I_TRANSFORMMATRICES".T[posmtx].t, rawpos), dot("I_TRANSFORMMATRICES".T[posmtx+1].t, rawpos), dot("I_TRANSFORMMATRICES".T[posmtx+2].t, rawpos), 1);\n");
WRITE(p, "float4 pos = float4(dot("I_TRANSFORMMATRICES".T[posmtx].t, rawpos), dot("I_TRANSFORMMATRICES".T[posmtx+1].t, rawpos), dot("I_TRANSFORMMATRICES".T[posmtx+2].t, rawpos), 1);\n");
if (components & VB_HAS_NRMALL) {
WRITE(p, "int normidx = posmtx >= 32 ? (posmtx-32) : posmtx;\n");
WRITE(p, "float3 N0 = "I_NORMALMATRICES".T[normidx].t.xyz, N1 = "I_NORMALMATRICES".T[normidx+1].t.xyz, N2 = "I_NORMALMATRICES".T[normidx+2].t.xyz;\n");
@ -215,9 +225,11 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
if (!(components & VB_HAS_NRM0))
WRITE(p, "float3 _norm0 = float3(0.0f, 0.0f, 0.0f);\n");
WRITE(p, "o.pos = float4(dot("I_PROJECTION".T0, pos), dot("I_PROJECTION".T1, pos), dot("I_PROJECTION".T2, pos), dot("I_PROJECTION".T3, pos));\n");
WRITE(p, "float4 mat, lacc;\n" // = half4(1, 1, 1, 1), lacc = half4(0, 0, 0, 0);\n"
WRITE(p, "float4 mat, lacc;\n"
"float3 ldir, h;\n"
"float dist, dist2, attn;\n");
@ -226,7 +238,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
if (components & VB_HAS_COL0)
WRITE(p, "o.colors_0 = color0;\n");
else
WRITE(p, "o.colors_0 = float4(1.0f, 1.0f, 1.0f, 1.0f);\n");
WRITE(p, "o.colors_0 = float4(1.0f, 1.0f, 1.0f, 1.0f);\n");
}
// lights/colors
for (int j = 0; j < xfregs.nNumChans; j++)
@ -293,8 +305,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
else
{
WRITE(p, "lacc.w = 1.0f;\n");
}
}
if(color.enablelighting && alpha.enablelighting)
{
@ -341,7 +352,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
if (components & VB_HAS_COL1)
WRITE(p, "o.colors_1 = color1;\n");
else
WRITE(p, "o.colors_1 = o.colors_0;\n");
WRITE(p, "o.colors_1 = o.colors_0;\n");
}
// special case if only pos and tex coord 0 and tex coord input is AB11
// donko - this has caused problems in some games. removed for now.
@ -460,14 +471,34 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
// clipPos/w needs to be done in pixel shader, not here
if (xfregs.numTexGens < 7) {
WRITE(p, "o.clipPos = o.pos;\n");
WRITE(p, "o.clipPos = float4(pos.x,pos.y,o.pos.z,o.pos.w);\n");
} else {
WRITE(p, "o.tex0.w = o.pos.x;\n");
WRITE(p, "o.tex1.w = o.pos.y;\n");
WRITE(p, "o.tex0.w = pos.x;\n");
WRITE(p, "o.tex1.w = pos.y;\n");
WRITE(p, "o.tex2.w = o.pos.z;\n");
WRITE(p, "o.tex3.w = o.pos.w;\n");
}
if(g_ActiveConfig.bEnablePixelLigting)
{
if (xfregs.numTexGens < 7) {
WRITE(p, "o.Normal = float4(_norm0.x,_norm0.y,_norm0.z,pos.z);\n");
} else {
WRITE(p, "o.tex4.w = _norm0.x;\n");
WRITE(p, "o.tex5.w = _norm0.y;\n");
WRITE(p, "o.tex6.w = _norm0.z;\n");
if (xfregs.numTexGens < 8)
WRITE(p, "o.tex7 = pos.xyzz;\n");
else
WRITE(p, "o.tex7.w = pos.z;\n");
}
if (components & VB_HAS_COL0)
WRITE(p, "o.colors_0 = color0;\n");
if (components & VB_HAS_COL1)
WRITE(p, "o.colors_1 = color1;\n");
}
//write the true depth value, if the game uses depth textures pixel shaders will override with the correct values
//if not early z culling will improve speed
if (is_d3d) {

View File

@ -379,7 +379,7 @@ void VertexShaderManager::SetConstants()
PRIM_LOG("Projection: %f %f %f %f %f %f\n", xfregs.rawProjection[0], xfregs.rawProjection[1], xfregs.rawProjection[2], xfregs.rawProjection[3], xfregs.rawProjection[4], xfregs.rawProjection[5]);
if (g_ActiveConfig.bFreeLook)
if ((g_ActiveConfig.bFreeLook || g_ActiveConfig.bAnaglyphStereo ) && xfregs.rawProjection[6] == 0)
{
Matrix44 mtxA;
Matrix44 mtxB;

View File

@ -72,6 +72,11 @@ void VideoConfig::Load(const char *ini_file)
iniFile.Get("Settings", "DumpEFBTarget", &bDumpEFBTarget, 0);
iniFile.Get("Settings", "DumpFrames", &bDumpFrames, 0);
iniFile.Get("Settings", "FreeLook", &bFreeLook, 0);
iniFile.Get("Settings", "AnaglyphStereo", &bAnaglyphStereo, false);
iniFile.Get("Settings", "AnaglyphStereoSeparation", &iAnaglyphStereoSeparation, 200);
iniFile.Get("Settings", "AnaglyphFocalAngle", &iAnaglyphFocalAngle, 0);
iniFile.Get("Settings", "EnablePixelLigting", &bEnablePixelLigting, 0);
iniFile.Get("Settings", "ShowShaderErrors", &bShowShaderErrors, 0);
iniFile.Get("Settings", "MSAA", &iMultisampleMode, 0);
iniFile.Get("Settings", "EFBScale", &iEFBScale, 0);
@ -184,6 +189,11 @@ void VideoConfig::Save(const char *ini_file)
iniFile.Set("Settings", "DumpEFBTarget", bDumpEFBTarget);
iniFile.Set("Settings", "DumpFrames", bDumpFrames);
iniFile.Set("Settings", "FreeLook", bFreeLook);
iniFile.Set("Settings", "AnaglyphStereo", bAnaglyphStereo);
iniFile.Set("Settings", "AnaglyphStereoSeparation", iAnaglyphStereoSeparation);
iniFile.Set("Settings", "AnaglyphFocalAngle", iAnaglyphFocalAngle);
iniFile.Set("Settings", "EnablePixelLigting", bEnablePixelLigting);
iniFile.Set("Settings", "ShowEFBCopyRegions", bShowEFBCopyRegions);
iniFile.Set("Settings", "ShowShaderErrors", bShowShaderErrors);
iniFile.Set("Settings", "MSAA", iMultisampleMode);

View File

@ -109,6 +109,9 @@ struct VideoConfig
bool bDumpEFBTarget;
bool bDumpFrames;
bool bFreeLook;
bool bAnaglyphStereo;
int iAnaglyphStereoSeparation;
int iAnaglyphFocalAngle;
// Hacks
bool bEFBAccessEnable;
@ -127,6 +130,7 @@ struct VideoConfig
bool bProjHack1;
float fAspectRatioHackW, fAspectRatioHackH;
bool bZTPSpeedHack; // The Legend of Zelda: Twilight Princess
bool bEnablePixelLigting;
int iLog; // CONF_ bits
int iSaveTargetId;

View File

@ -36,6 +36,7 @@ void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
{
VertexManager::Flush();
VertexShaderManager::InvalidateXFRange(address, address + transferSize);
PixelShaderManager::InvalidateXFRange(address, address + transferSize);
//PRIM_LOG("xfmem write: 0x%x-0x%x\n", address, address+transferSize);
memcpy_gc((u32*)&xfmem[address], &pData[i], transferSize*4);
@ -111,6 +112,7 @@ void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
VertexManager::Flush();
xfregs.colChans[chan].ambColor = data;
VertexShaderManager::SetMaterialColor(chan, data);
PixelShaderManager::SetMaterialColor(chan, data);
}
break;
}
@ -124,6 +126,7 @@ void LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
VertexManager::Flush();
xfregs.colChans[chan].matColor = data;
VertexShaderManager::SetMaterialColor(address - XFMEM_SETCHAN0_AMBCOLOR, data);
PixelShaderManager::SetMaterialColor(address - XFMEM_SETCHAN0_AMBCOLOR, data);
}
break;
}
@ -217,6 +220,7 @@ void LoadIndexedXF(u32 val, int array)
VertexManager::Flush();
VertexShaderManager::InvalidateXFRange(address, address+size);
PixelShaderManager::InvalidateXFRange(address, address+size);
//PRIM_LOG("xfmem iwrite: 0x%x-0x%x\n", address, address+size);
for (int i = 0; i < size; i++)