wined3d: Use the ARB fog option in ARB_fragment_program shaders.

This is the "replacement" for the fog coord optimization removed in
the previous patch.
This commit is contained in:
Stefan Dösinger 2008-12-14 17:10:09 +01:00 committed by Alexandre Julliard
parent 7c21147dcd
commit e61aa24aa3
1 changed files with 25 additions and 38 deletions

View File

@ -1924,14 +1924,30 @@ static GLuint shader_arb_generate_pshader(IWineD3DPixelShader *iface, SHADER_BUF
const shader_reg_maps* reg_maps = &This->baseShader.reg_maps; const shader_reg_maps* reg_maps = &This->baseShader.reg_maps;
CONST DWORD *function = This->baseShader.function; CONST DWORD *function = This->baseShader.function;
DWORD shader_version = reg_maps->shader_version; DWORD shader_version = reg_maps->shader_version;
const char *fragcolor;
const WineD3D_GL_Info *gl_info = &((IWineD3DDeviceImpl *)This->baseShader.device)->adapter->gl_info; const WineD3D_GL_Info *gl_info = &((IWineD3DDeviceImpl *)This->baseShader.device)->adapter->gl_info;
const local_constant *lconst; const local_constant *lconst;
GLuint retval; GLuint retval;
const char *fragcolor;
/* Create the hw ARB shader */ /* Create the hw ARB shader */
shader_addline(buffer, "!!ARBfp1.0\n"); shader_addline(buffer, "!!ARBfp1.0\n");
if (shader_version < WINED3DPS_VERSION(3,0)) {
switch(args->fog) {
case FOG_OFF:
break;
case FOG_LINEAR:
shader_addline(buffer, "OPTION ARB_fog_linear;\n");
break;
case FOG_EXP:
shader_addline(buffer, "OPTION ARB_fog_exp;\n");
break;
case FOG_EXP2:
shader_addline(buffer, "OPTION ARB_fog_exp2;\n");
break;
}
}
shader_addline(buffer, "TEMP TMP;\n"); /* Used in matrix ops */ shader_addline(buffer, "TEMP TMP;\n"); /* Used in matrix ops */
shader_addline(buffer, "TEMP TMP2;\n"); /* Used in matrix ops */ shader_addline(buffer, "TEMP TMP2;\n"); /* Used in matrix ops */
shader_addline(buffer, "TEMP TA;\n"); /* Used for modifiers */ shader_addline(buffer, "TEMP TA;\n"); /* Used for modifiers */
@ -1941,52 +1957,23 @@ static GLuint shader_arb_generate_pshader(IWineD3DPixelShader *iface, SHADER_BUF
shader_addline(buffer, "PARAM coefmul = { 2, 4, 8, 16 };\n"); shader_addline(buffer, "PARAM coefmul = { 2, 4, 8, 16 };\n");
shader_addline(buffer, "PARAM one = { 1.0, 1.0, 1.0, 1.0 };\n"); shader_addline(buffer, "PARAM one = { 1.0, 1.0, 1.0, 1.0 };\n");
if (shader_version < WINED3DPS_VERSION(2,0)) {
fragcolor = "R0";
} else {
shader_addline(buffer, "TEMP TMP_COLOR;\n");
fragcolor = "TMP_COLOR";
}
/* Base Declarations */ /* Base Declarations */
shader_generate_arb_declarations( (IWineD3DBaseShader*) This, reg_maps, buffer, &GLINFO_LOCATION); shader_generate_arb_declarations( (IWineD3DBaseShader*) This, reg_maps, buffer, &GLINFO_LOCATION);
/* We need two variables for fog blending */
if(args->fog != FOG_OFF) shader_addline(buffer, "TEMP TMP_FOG;\n");
if (shader_version >= WINED3DPS_VERSION(2,0)) shader_addline(buffer, "TEMP TMP_COLOR;\n");
/* Base Shader Body */ /* Base Shader Body */
shader_generate_main( (IWineD3DBaseShader*) This, buffer, reg_maps, function); shader_generate_main( (IWineD3DBaseShader*) This, buffer, reg_maps, function);
if (shader_version < WINED3DPS_VERSION(2,0)) {
fragcolor = "R0";
} else {
fragcolor = "TMP_COLOR";
}
if(args->srgb_correction) { if(args->srgb_correction) {
arbfp_add_sRGB_correction(buffer, fragcolor, "TMP", "TMP2", "TA", "TB"); arbfp_add_sRGB_correction(buffer, fragcolor, "TMP", "TMP2", "TA", "TB");
} }
if (shader_version < WINED3DPS_VERSION(3,0)) { shader_addline(buffer, "MOV result.color, %s;\n", fragcolor);
/* calculate fog and blend it
* NOTE: state.fog.params.y and state.fog.params.z don't hold fog start s and end e but
* -1/(e-s) and e/(e-s) respectively.
*/
switch(args->fog) {
case FOG_OFF:
shader_addline(buffer, "MOV result.color, %s;\n", fragcolor);
break;
case FOG_LINEAR:
shader_addline(buffer, "SUB TMP_FOG.x, state.fog.params.z, state.fog.params.y;\n");
shader_addline(buffer, "RCP TMP_FOG, -TMP_FOG.x;\n");
shader_addline(buffer, "MUL TMP_FOG.y, -TMP_FOG.y, state.fog.params.z;\n");
shader_addline(buffer, "MAD_SAT TMP_FOG, fragment.fogcoord, TMP_FOG.x, TMP_FOG.y;\n");
shader_addline(buffer, "LRP result.color.rgb, TMP_FOG.x, %s, state.fog.color;\n", fragcolor);
shader_addline(buffer, "MOV result.color.a, %s.a;\n", fragcolor);
break;
case FOG_EXP:
FIXME("Implement EXP fog in ARB\n");
shader_addline(buffer, "MOV result.color, %s;\n", fragcolor);
break;
case FOG_EXP2:
FIXME("Implement EXP2 fog in ARB\n");
shader_addline(buffer, "MOV result.color, %s;\n", fragcolor);
break;
}
}
shader_addline(buffer, "END\n"); shader_addline(buffer, "END\n");
/* TODO: change to resource.glObjectHandle or something like that */ /* TODO: change to resource.glObjectHandle or something like that */