mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Massive style & comment cleanup of (mostly) GL plugin - also split some large files. A minor speedup for BP writes - merged the two switch()-es.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@899 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -40,17 +40,17 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
|
||||
_assert_( bpmem.genMode.numcolchans == xfregs.nNumChans);
|
||||
|
||||
u32 lightMask = 0;
|
||||
if( xfregs.nNumChans > 0 )
|
||||
lightMask |= xfregs.colChans[0].color.GetFullLightMask() | xfregs.colChans[0].alpha.GetFullLightMask();
|
||||
if( xfregs.nNumChans > 1 )
|
||||
if (xfregs.nNumChans > 0)
|
||||
lightMask |= xfregs.colChans[0].color.GetFullLightMask() | xfregs.colChans[0].alpha.GetFullLightMask();
|
||||
if (xfregs.nNumChans > 1)
|
||||
lightMask |= xfregs.colChans[1].color.GetFullLightMask() | xfregs.colChans[1].alpha.GetFullLightMask();
|
||||
|
||||
bool bOutputZ = bpmem.ztex2.op==ZTEXTURE_ADD || has_zbuffer_target;
|
||||
int ztexcoord = -1;
|
||||
|
||||
char *p = text;
|
||||
WRITE(p,"//Vertex Shader: comp:%x, \n", components);
|
||||
WRITE(p,"typedef struct {\n"
|
||||
WRITE(p, "//Vertex Shader: comp:%x, \n", components);
|
||||
WRITE(p, "typedef struct {\n"
|
||||
" float4 T0, T1, T2;\n"
|
||||
" float4 N0, N1, N2;\n"
|
||||
"} s_"I_POSNORMALMATRIX";\n\n"
|
||||
@ -89,25 +89,25 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
|
||||
" float4 params;\n" // a, b, c, b_shift
|
||||
"} s_"I_FOGPARAMS";\n\n");
|
||||
|
||||
WRITE(p,"struct VS_OUTPUT {\n");
|
||||
WRITE(p," float4 pos : POSITION;\n");
|
||||
WRITE(p," float4 colors[2] : COLOR0;\n");
|
||||
WRITE(p, "struct VS_OUTPUT {\n");
|
||||
WRITE(p, " float4 pos : POSITION;\n");
|
||||
WRITE(p, " float4 colors[2] : COLOR0;\n");
|
||||
|
||||
// if outputting Z, embed the Z coordinate in the w component of a texture coordinate
|
||||
// if number of tex gens occupies all the texture coordinates, use the last tex coord
|
||||
// otherwise use the next available tex coord
|
||||
for (int i = 0; i < xfregs.numTexGens; ++i) {
|
||||
WRITE(p," float%d tex%d : TEXCOORD%d;\n", (i==(xfregs.numTexGens-1)&&bOutputZ)?4:3, i, i);
|
||||
WRITE(p, " float%d tex%d : TEXCOORD%d;\n", (i==(xfregs.numTexGens-1)&&bOutputZ)?4:3, i, i);
|
||||
}
|
||||
if (bOutputZ && xfregs.numTexGens == 0) {
|
||||
ztexcoord = 0;
|
||||
WRITE(p," float4 tex%d : TEXCOORD%d;\n", ztexcoord, ztexcoord);
|
||||
WRITE(p, " float4 tex%d : TEXCOORD%d;\n", ztexcoord, ztexcoord);
|
||||
}
|
||||
else if (bOutputZ)
|
||||
ztexcoord = xfregs.numTexGens - 1;
|
||||
|
||||
WRITE(p,"};\n");
|
||||
WRITE(p,"\n");
|
||||
WRITE(p, "};\n");
|
||||
WRITE(p, "\n");
|
||||
|
||||
// uniforms
|
||||
|
||||
@ -123,152 +123,152 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
|
||||
WRITE(p, "uniform s_"I_PROJECTION" "I_PROJECTION" : register(c%d);\n", C_PROJECTION);
|
||||
WRITE(p, "uniform s_"I_FOGPARAMS" "I_FOGPARAMS" : register(c%d);\n", C_FOGPARAMS);
|
||||
|
||||
WRITE(p,"VS_OUTPUT main(\n");
|
||||
WRITE(p, "VS_OUTPUT main(\n");
|
||||
|
||||
// inputs
|
||||
if (components & VertexLoader::VB_HAS_NRM0)
|
||||
WRITE(p," float3 rawnorm0 : NORMAL,\n");
|
||||
WRITE(p, " float3 rawnorm0 : NORMAL,\n");
|
||||
if (components & VertexLoader::VB_HAS_NRM1)
|
||||
WRITE(p," float3 rawnorm1 : ATTR%d,\n", SHADER_NORM1_ATTRIB);
|
||||
WRITE(p, " float3 rawnorm1 : ATTR%d,\n", SHADER_NORM1_ATTRIB);
|
||||
if (components & VertexLoader::VB_HAS_NRM2)
|
||||
WRITE(p," float3 rawnorm2 : ATTR%d,\n", SHADER_NORM2_ATTRIB);
|
||||
WRITE(p, " float3 rawnorm2 : ATTR%d,\n", SHADER_NORM2_ATTRIB);
|
||||
if (components & VertexLoader::VB_HAS_COL0)
|
||||
WRITE(p," float4 color0 : COLOR0,\n");
|
||||
WRITE(p, " float4 color0 : COLOR0,\n");
|
||||
if (components & VertexLoader::VB_HAS_COL1)
|
||||
WRITE(p," float4 color1 : COLOR1,\n");
|
||||
WRITE(p, " float4 color1 : COLOR1,\n");
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
u32 hastexmtx = (components & (VertexLoader::VB_HAS_TEXMTXIDX0<<i));
|
||||
if ( (components & (VertexLoader::VB_HAS_UV0<<i)) || hastexmtx )
|
||||
WRITE(p," float%d tex%d : TEXCOORD%d,\n", hastexmtx ? 3 : 2, i,i);
|
||||
if ((components & (VertexLoader::VB_HAS_UV0<<i)) || hastexmtx )
|
||||
WRITE(p, " float%d tex%d : TEXCOORD%d,\n", hastexmtx ? 3 : 2, i,i);
|
||||
}
|
||||
if (components & VertexLoader::VB_HAS_POSMTXIDX)
|
||||
WRITE(p, " half posmtx : ATTR%d,\n", SHADER_POSMTX_ATTRIB);
|
||||
|
||||
WRITE(p," float4 rawpos : POSITION) {\n");
|
||||
WRITE(p, " float4 rawpos : POSITION) {\n");
|
||||
WRITE(p, "VS_OUTPUT o;\n");
|
||||
|
||||
// transforms
|
||||
if ( components & VertexLoader::VB_HAS_POSMTXIDX) {
|
||||
if (components & VertexLoader::VB_HAS_POSMTXIDX) {
|
||||
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 & VertexLoader::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");
|
||||
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");
|
||||
}
|
||||
|
||||
if (components & VertexLoader::VB_HAS_NRM0)
|
||||
WRITE(p,"half3 _norm0 = half3(dot(N0, rawnorm0), dot(N1, rawnorm0), dot(N2, rawnorm0));\n"
|
||||
"half3 norm0 = normalize(_norm0);\n");
|
||||
WRITE(p, "half3 _norm0 = half3(dot(N0, rawnorm0), dot(N1, rawnorm0), dot(N2, rawnorm0));\n"
|
||||
"half3 norm0 = normalize(_norm0);\n");
|
||||
if (components & VertexLoader::VB_HAS_NRM1)
|
||||
WRITE(p,"half3 _norm1 = half3(dot(N0, rawnorm1), dot(N1, rawnorm1), dot(N2, rawnorm1));\n");
|
||||
WRITE(p, "half3 _norm1 = half3(dot(N0, rawnorm1), dot(N1, rawnorm1), dot(N2, rawnorm1));\n");
|
||||
//"half3 norm1 = normalize(_norm1);\n");
|
||||
if (components & VertexLoader::VB_HAS_NRM2)
|
||||
WRITE(p,"half3 _norm2 = half3(dot(N0, rawnorm2), dot(N1, rawnorm2), dot(N2, rawnorm2));\n");
|
||||
WRITE(p, "half3 _norm2 = half3(dot(N0, rawnorm2), dot(N1, rawnorm2), dot(N2, rawnorm2));\n");
|
||||
//"half3 norm2 = normalize(_norm2);\n");
|
||||
}
|
||||
else {
|
||||
WRITE(p, "float4 pos = float4(dot("I_POSNORMALMATRIX".T0, rawpos), dot("I_POSNORMALMATRIX".T1, rawpos), dot("I_POSNORMALMATRIX".T2, rawpos), 1);\n");
|
||||
if (components & VertexLoader::VB_HAS_NRM0)
|
||||
WRITE(p,"half3 _norm0 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm0));\n"
|
||||
"half3 norm0 = normalize(_norm0);\n");
|
||||
WRITE(p, "half3 _norm0 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm0), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm0));\n"
|
||||
"half3 norm0 = normalize(_norm0);\n");
|
||||
if (components & VertexLoader::VB_HAS_NRM1)
|
||||
WRITE(p,"half3 _norm1 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm1));\n");
|
||||
WRITE(p, "half3 _norm1 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm1), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm1));\n");
|
||||
//"half3 norm1 = normalize(_norm1);\n");
|
||||
if (components & VertexLoader::VB_HAS_NRM2)
|
||||
WRITE(p,"half3 _norm2 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm2));\n");
|
||||
WRITE(p, "half3 _norm2 = half3(dot("I_POSNORMALMATRIX".N0.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N1.xyz, rawnorm2), dot("I_POSNORMALMATRIX".N2.xyz, rawnorm2));\n");
|
||||
//"half3 norm2 = normalize(_norm2);\n");
|
||||
}
|
||||
|
||||
if (!(components & VertexLoader::VB_HAS_NRM0))
|
||||
WRITE(p,"half3 _norm0 = half3(0,0,0), norm0= half3(0,0,0);\n");
|
||||
WRITE(p, "half3 _norm0 = half3(0,0,0), norm0= half3(0,0,0);\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, "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, "half4 mat, lacc;\n"
|
||||
"half3 ldir, h;\n"
|
||||
"half dist, dist2, attn;\n");
|
||||
|
||||
// lights/colors
|
||||
for (int j=0; j<xfregs.nNumChans; j++) {
|
||||
for (int j = 0; j < xfregs.nNumChans; j++) {
|
||||
|
||||
// bool bColorAlphaSame = xfregs.colChans[j].color.hex == xfregs.colChans[j].alpha.hex; unused
|
||||
const LitChannel& color = xfregs.colChans[j].color;
|
||||
const LitChannel& alpha = xfregs.colChans[j].alpha;
|
||||
|
||||
WRITE(p,"{\n");
|
||||
WRITE(p, "{\n");
|
||||
|
||||
if (color.matsource) {// from vertex
|
||||
if (components & (VertexLoader::VB_HAS_COL0<<j) )
|
||||
WRITE(p,"mat = color%d;\n", j);
|
||||
else WRITE(p,"mat = half4(1,1,1,1);\n");
|
||||
WRITE(p, "mat = color%d;\n", j);
|
||||
else WRITE(p, "mat = half4(1,1,1,1);\n");
|
||||
}
|
||||
else // from color
|
||||
WRITE(p,"mat = "I_MATERIALS".C%d;\n", j+2);
|
||||
WRITE(p, "mat = "I_MATERIALS".C%d;\n", j+2);
|
||||
|
||||
if( color.enablelighting ) {
|
||||
if (color.enablelighting) {
|
||||
if (color.ambsource) {// from vertex
|
||||
if (components & (VertexLoader::VB_HAS_COL0<<j) )
|
||||
WRITE(p,"lacc = color%d;\n", j);
|
||||
else WRITE(p,"lacc = half4(0.0f,0.0f,0.0f,0.0f);\n");
|
||||
WRITE(p, "lacc = color%d;\n", j);
|
||||
else WRITE(p, "lacc = half4(0.0f,0.0f,0.0f,0.0f);\n");
|
||||
}
|
||||
else // from color
|
||||
WRITE(p,"lacc = "I_MATERIALS".C%d;\n", j);
|
||||
WRITE(p, "lacc = "I_MATERIALS".C%d;\n", j);
|
||||
}
|
||||
|
||||
// check if alpha is different
|
||||
if (alpha.matsource != color.matsource) {
|
||||
if (alpha.matsource ) {// from vertex
|
||||
if (alpha.matsource) {// from vertex
|
||||
if (components & (VertexLoader::VB_HAS_COL0<<j) )
|
||||
WRITE(p,"mat.w = color%d.w;\n", j);
|
||||
else WRITE(p,"mat.w = 1;\n");
|
||||
WRITE(p, "mat.w = color%d.w;\n", j);
|
||||
else WRITE(p, "mat.w = 1;\n");
|
||||
}
|
||||
else // from color
|
||||
WRITE(p,"mat.w = "I_MATERIALS".C%d.w;\n", j+2);
|
||||
WRITE(p, "mat.w = "I_MATERIALS".C%d.w;\n", j+2);
|
||||
}
|
||||
|
||||
if (alpha.enablelighting && alpha.ambsource != color.ambsource) {
|
||||
if (alpha.ambsource) {// from vertex
|
||||
if (components & (VertexLoader::VB_HAS_COL0<<j) )
|
||||
WRITE(p,"lacc.w = color%d.w;\n", j);
|
||||
else WRITE(p,"lacc.w = 0;\n");
|
||||
WRITE(p, "lacc.w = color%d.w;\n", j);
|
||||
else WRITE(p, "lacc.w = 0;\n");
|
||||
}
|
||||
else // from color
|
||||
WRITE(p,"lacc.w = "I_MATERIALS".C%d.w;\n", j);
|
||||
WRITE(p, "lacc.w = "I_MATERIALS".C%d.w;\n", j);
|
||||
}
|
||||
|
||||
if( color.enablelighting && alpha.enablelighting && (color.GetFullLightMask() != alpha.GetFullLightMask() || color.lightparams != alpha.lightparams) ) {
|
||||
if (color.enablelighting && alpha.enablelighting && (color.GetFullLightMask() != alpha.GetFullLightMask() || color.lightparams != alpha.lightparams)) {
|
||||
|
||||
// both have lighting, except not using the same lights
|
||||
int mask = 0; // holds already computed lights
|
||||
|
||||
if( color.lightparams == alpha.lightparams && (color.GetFullLightMask() & alpha.GetFullLightMask()) ) {
|
||||
if (color.lightparams == alpha.lightparams && (color.GetFullLightMask() & alpha.GetFullLightMask())) {
|
||||
// if lights are shared, compute those first
|
||||
mask = color.GetFullLightMask() & alpha.GetFullLightMask();
|
||||
for(int i = 0; i < 8; ++i) {
|
||||
if( mask&(1<<i))
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if (mask&(1<<i))
|
||||
p = GenerateLightShader(p, i, color, "lacc", 3);
|
||||
}
|
||||
}
|
||||
|
||||
// no shared lights
|
||||
for(int i = 0; i < 8; ++i) {
|
||||
if( !(mask&(1<<i)) && (color.GetFullLightMask() & (1<<i)) )
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if (!(mask&(1<<i)) && (color.GetFullLightMask() & (1<<i)) )
|
||||
p = GenerateLightShader(p, i, color, "lacc", 1);
|
||||
if( !(mask&(1<<i)) && (alpha.GetFullLightMask() & (1<<i)) )
|
||||
if (!(mask&(1<<i)) && (alpha.GetFullLightMask() & (1<<i)) )
|
||||
p = GenerateLightShader(p, i, alpha, "lacc", 2);
|
||||
}
|
||||
}
|
||||
else if( color.enablelighting || alpha.enablelighting) {
|
||||
else if (color.enablelighting || alpha.enablelighting) {
|
||||
// either one is enabled
|
||||
int coloralpha = (int)color.enablelighting|((int)alpha.enablelighting<<1);
|
||||
for(int i = 0; i < 8; ++i) {
|
||||
if( color.GetFullLightMask() & (1<<i) )
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if (color.GetFullLightMask() & (1<<i) )
|
||||
p = GenerateLightShader(p, i, color.enablelighting?color:alpha, "lacc", coloralpha);
|
||||
}
|
||||
}
|
||||
|
||||
if (color.enablelighting != alpha.enablelighting) {
|
||||
if( color.enablelighting )
|
||||
if (color.enablelighting )
|
||||
WRITE(p, "o.colors[%d].xyz = mat.xyz * clamp(lacc.xyz,float3(0.0f,0.0f,0.0f),float3(1.0f,1.0f,1.0f));\n"
|
||||
"o.colors[%d].w = mat.w;\n", j, j);
|
||||
else
|
||||
@ -276,7 +276,7 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
|
||||
"o.colors[%d].w = mat.w * clamp(lacc.w,0.0f,1.0f);\n", j, j);
|
||||
}
|
||||
else {
|
||||
if( alpha.enablelighting )
|
||||
if (alpha.enablelighting )
|
||||
WRITE(p, "o.colors[%d] = mat * clamp(lacc,float4(0.0f,0.0f,0.0f,0.0f), float4(1.0f,1.0f,1.0f,1.0f));\n", j);
|
||||
else WRITE(p, "o.colors[%d] = mat;\n", j);
|
||||
}
|
||||
@ -284,15 +284,15 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
|
||||
}
|
||||
|
||||
// zero left over channels
|
||||
for(int i = xfregs.nNumChans; i < 2; ++i) WRITE(p, "o.colors[%d] = 0;\n", i);
|
||||
for (int i = xfregs.nNumChans; i < 2; ++i)
|
||||
WRITE(p, "o.colors[%d] = 0;\n", i);
|
||||
|
||||
// transform texcoords
|
||||
for(int i = 0; i < xfregs.numTexGens; ++i) {
|
||||
|
||||
for (int i = 0; i < xfregs.numTexGens; ++i) {
|
||||
TexMtxInfo& texinfo = xfregs.texcoords[i].texmtxinfo;
|
||||
|
||||
WRITE(p, "{\n");
|
||||
switch(texinfo.sourcerow) {
|
||||
switch (texinfo.sourcerow) {
|
||||
case XF_SRCGEOM_INROW:
|
||||
_assert_( texinfo.inputform == XF_TEXINPUT_ABC1 );
|
||||
WRITE(p, "float4 coord = rawpos;\n"); // pos.w is 1
|
||||
@ -323,7 +323,7 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
|
||||
break;
|
||||
default:
|
||||
_assert_(texinfo.sourcerow <= XF_SRCTEX7_INROW);
|
||||
if ( components & (VertexLoader::VB_HAS_UV0<<(texinfo.sourcerow - XF_SRCTEX0_INROW)) )
|
||||
if (components & (VertexLoader::VB_HAS_UV0<<(texinfo.sourcerow - XF_SRCTEX0_INROW)) )
|
||||
WRITE(p, "float4 coord = float4(tex%d.x, tex%d.y, 1.0f, 1.0f);\n", texinfo.sourcerow - XF_SRCTEX0_INROW, texinfo.sourcerow - XF_SRCTEX0_INROW);
|
||||
else
|
||||
WRITE(p, "float4 coord = float4(0.0f, 0.0f, 1.0f, 1.0f);\n");
|
||||
@ -331,9 +331,9 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
|
||||
}
|
||||
|
||||
// firs transformation
|
||||
switch(texinfo.texgentype) {
|
||||
switch (texinfo.texgentype) {
|
||||
case XF_TEXGEN_REGULAR:
|
||||
if( components & (VertexLoader::VB_HAS_TEXMTXIDX0<<i) ) {
|
||||
if (components & (VertexLoader::VB_HAS_TEXMTXIDX0<<i)) {
|
||||
if (texinfo.projection == XF_TEXPROJ_STQ )
|
||||
WRITE(p, "o.tex%d.xyz = float3(dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z].t), dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z+1].t), dot(coord, "I_TRANSFORMMATRICES".T[tex%d.z+2].t));\n", i, i, i, i);
|
||||
else {
|
||||
@ -349,7 +349,7 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
|
||||
break;
|
||||
case XF_TEXGEN_EMBOSS_MAP: // calculate tex coords into bump map
|
||||
|
||||
if( components & (VertexLoader::VB_HAS_NRM1|VertexLoader::VB_HAS_NRM2) ) {
|
||||
if (components & (VertexLoader::VB_HAS_NRM1|VertexLoader::VB_HAS_NRM2)) {
|
||||
// transform the light dir into tangent space
|
||||
WRITE(p, "ldir = normalize("I_LIGHTS".lights[%d].pos.xyz - pos.xyz);\n", texinfo.embosslightshift);
|
||||
WRITE(p, "o.tex%d.xyz = o.tex%d.xyz + float3(dot(ldir, _norm1), dot(ldir, _norm2), 0.0f);\n", i, texinfo.embosssourceshift);
|
||||
@ -367,7 +367,7 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
|
||||
break;
|
||||
}
|
||||
|
||||
if(xfregs.bEnableDualTexTransform && texinfo.texgentype == XF_TEXGEN_REGULAR ) { // only works for regular tex gen types?
|
||||
if(xfregs.bEnableDualTexTransform && texinfo.texgentype == XF_TEXGEN_REGULAR) { // only works for regular tex gen types?
|
||||
if (xfregs.texcoords[i].postmtxinfo.normalize)
|
||||
WRITE(p, "o.tex%d.xyz = normalize(o.tex%d.xyz);\n", i, i);
|
||||
|
||||
@ -383,11 +383,11 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
|
||||
WRITE(p, "}\n");
|
||||
}
|
||||
|
||||
if( ztexcoord >= 0 )
|
||||
if (ztexcoord >= 0 )
|
||||
WRITE(p, "o.tex%d.w = o.pos.z/o.pos.w;\n", ztexcoord);
|
||||
|
||||
// if( bpmem.fog.c_proj_fsel.fsel != 0 ) {
|
||||
// switch(bpmem.fog.c_proj_fsel.fsel) {
|
||||
// if (bpmem.fog.c_proj_fsel.fsel != 0) {
|
||||
// switch (bpmem.fog.c_proj_fsel.fsel) {
|
||||
// case 1: // linear
|
||||
// break;
|
||||
// case 4: // exp
|
||||
@ -403,7 +403,7 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
|
||||
// WRITE(p, "o.fog = o.pos.z/o.pos.w;\n");
|
||||
// }
|
||||
|
||||
WRITE(p,"return o;\n}\n");
|
||||
WRITE(p, "return o;\n}\n");
|
||||
|
||||
return text;
|
||||
}
|
||||
@ -412,12 +412,12 @@ char *GenerateVertexShader(u32 components, bool has_zbuffer_target)
|
||||
char* GenerateLightShader(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 (coloralpha == 1 ) swizzle = "xyz";
|
||||
else if (coloralpha == 2 ) swizzle = "w";
|
||||
|
||||
if( !(chan.attnfunc&1) ) {
|
||||
if (!(chan.attnfunc&1)) {
|
||||
// atten disabled
|
||||
switch(chan.diffusefunc) {
|
||||
switch (chan.diffusefunc) {
|
||||
case LIGHTDIF_NONE:
|
||||
WRITE(p, "%s.%s += "I_LIGHTS".lights[%d].col.%s;\n", dest, swizzle, index, swizzle);
|
||||
break;
|
||||
@ -433,20 +433,20 @@ char* GenerateLightShader(char* p, int index, const LitChannel& chan, const char
|
||||
else { // spec and spot
|
||||
WRITE(p, "ldir = "I_LIGHTS".lights[%d].pos.xyz - pos.xyz;\n", index);
|
||||
|
||||
if( chan.attnfunc == 3 ) { // spot
|
||||
if (chan.attnfunc == 3) { // spot
|
||||
WRITE(p, "dist2 = dot(ldir, ldir);\n"
|
||||
"dist = sqrt(dist2);\n"
|
||||
"ldir = ldir / dist;\n"
|
||||
"attn = max(0.0f, dot(ldir, "I_LIGHTS".lights[%d].dir.xyz));\n",index);
|
||||
WRITE(p, "attn = max(0.0f, dot("I_LIGHTS".lights[%d].cosatt.xyz, half3(1, attn, attn*attn))) / dot("I_LIGHTS".lights[%d].distatt.xyz, half3(1,dist,dist2));\n", index, index);
|
||||
}
|
||||
else if( chan.attnfunc == 1) { // specular
|
||||
else if (chan.attnfunc == 1) { // specular
|
||||
WRITE(p, "attn = dot(norm0, "I_LIGHTS".lights[%d].pos.xyz) > 0 ? max(0.0f, dot(norm0, "I_LIGHTS".lights[%d].dir.xyz)) : 0;\n", index, index);
|
||||
WRITE(p, "ldir = half3(1,attn,attn*attn);\n");
|
||||
WRITE(p, "attn = max(0.0f, dot("I_LIGHTS".lights[%d].cosatt.xyz, ldir)) / dot("I_LIGHTS".lights[%d].distatt.xyz, ldir);\n", index, index);
|
||||
}
|
||||
|
||||
switch(chan.diffusefunc) {
|
||||
switch (chan.diffusefunc) {
|
||||
case LIGHTDIF_NONE:
|
||||
WRITE(p, "%s.%s += attn * "I_LIGHTS".lights[%d].col.%s;\n", dest, swizzle, index, swizzle);
|
||||
break;
|
||||
|
Reference in New Issue
Block a user