Revert dd9f77b4ab0b4c66fe7a2a717ed4b8cc1835e343: no gl_FragDepth in GLES 2 :(

This commit is contained in:
Flyinghead 2018-05-12 14:39:06 +02:00
parent dd9f77b4ab
commit 50a2e7e842
4 changed files with 58 additions and 15 deletions

View File

@ -99,6 +99,9 @@ struct rend_context
u8* proc_start;
u8* proc_end;
f32 fZ_min;
f32 fZ_max;
bool Overrun;
bool isRTT;
bool isAutoSort;
@ -130,6 +133,8 @@ struct rend_context
render_passes.Clear();
Overrun=false;
fZ_min= 1000000.0f;
fZ_max= 1.0f;
}
};

View File

@ -908,6 +908,12 @@ public:
static inline void update_fz(float z)
{
if ((s32&)vdrc.fZ_max<(s32&)z && (s32&)z<0x49800000)
vdrc.fZ_max=z;
}
//Poly Vertex handlers
//Append vertex base
template<class T>
@ -919,6 +925,7 @@ public:
cv->x=vtx->xyz[0];
cv->y=vtx->xyz[1];
cv->z=invW;
update_fz(invW);
return cv;
}
@ -1226,7 +1233,8 @@ public:
#define append_sprite_yz(indx,set,st2) \
cv[indx].y=sv->y##set; \
cv[indx].z=sv->z##st2;
cv[indx].z=sv->z##st2; \
update_fz(sv->z##st2);
#define sprite_uv(indx,u_name,v_name) \
cv[indx].u = f16(sv->u_name);\
@ -1259,10 +1267,12 @@ public:
cv[2].x=sv->x0;
cv[2].y=sv->y0;
cv[2].z=sv->z0;
update_fz(sv->z0);
cv[3].x=sv->x1;
cv[3].y=sv->y1;
cv[3].z=sv->z1;
update_fz(sv->z1);
cv[1].x=sv->x2;
}
@ -1322,6 +1332,7 @@ public:
cv[1].y=sv->y2;
cv[1].z=sv->z2;
update_fz(sv->z2);
cv[0].x=sv->x3;
cv[0].y=sv->y3;
@ -1334,6 +1345,8 @@ public:
CaclulateSpritePlane(cv);
update_fz(cv[0].z);
/*
if (CurrentPP->count)
{
@ -1377,10 +1390,12 @@ public:
lmr->x0=mvv->x0;
lmr->y0=mvv->y0;
lmr->z0=mvv->z0;
//update_fz(mvv->z0);
lmr->x1=mvv->x1;
lmr->y1=mvv->y1;
lmr->z1=mvv->z1;
//update_fz(mvv->z1);
lmr->x2=mvv->x2;
}
@ -1392,6 +1407,7 @@ public:
return;
lmr->y2=mvv->y2;
lmr->z2=mvv->z2;
//update_fz(mvv->z2);
}
static void VDECInit()

View File

@ -79,6 +79,7 @@ const char* VertexShaderSource =
"\
/* Vertex constants*/ \n\
uniform highp vec4 scale; \n\
uniform highp vec4 depth_scale; \n\
uniform highp float sp_FOG_DENSITY; \n\
/* Vertex input */ \n\
" attr " highp vec4 in_pos; \n\
@ -99,13 +100,9 @@ void main() \n\
vtx_xyz.xy = vpos.xy; \n\
vtx_xyz.z = vpos.z*sp_FOG_DENSITY; \n\
vpos.w=1.0/vpos.z; \n\
if (vpos.w < 0.0) { \n\
gl_Position = vec4(0.0, 0.0, 0.0, vpos.w); \n\
return; \n\
} \n\
vpos.xy=vpos.xy*scale.xy-scale.zw; \n\
vpos.xy*=vpos.w; \n\
vpos.z = vpos.w; \n\
vpos.z=depth_scale.x+depth_scale.y*vpos.w; \n\
gl_Position = vpos; \n\
}";
@ -331,8 +328,6 @@ void main() \n\
#if cp_AlphaTest == 1 \n\
color.a=1.0; \n\
#endif \n\
highp float w = gl_FragCoord.w * 100.0; \n\
gl_FragDepth = log2(1.0 + w) / 24.0; \n\
//color.rgb=vec3(vtx_xyz.z/255.0);\n\
" FRAGCOL "=color; \n\
}";
@ -347,8 +342,6 @@ uniform lowp float sp_ShaderColor; \n\
/* Vertex input*/ \n\
void main() \n\
{ \n\
highp float w = gl_FragCoord.w * 100.0; \n\
gl_FragDepth = log2(1.0 + w) / 24.0; \n\
" FRAGCOL "=vec4(0.0, 0.0, 0.0, sp_ShaderColor); \n\
}";
@ -683,6 +676,7 @@ struct ShaderUniforms_t
{
float PT_ALPHA;
float scale_coefs[4];
float depth_coefs[4];
float fog_den_float;
float ps_FOG_COL_RAM[3];
float ps_FOG_COL_VERT[3];
@ -696,6 +690,9 @@ struct ShaderUniforms_t
if (s->scale!=-1)
glUniform4fv( s->scale, 1, scale_coefs);
if (s->depth_scale!=-1)
glUniform4fv( s->depth_scale, 1, depth_coefs);
if (s->sp_FOG_DENSITY!=-1)
glUniform1f( s->sp_FOG_DENSITY,fog_den_float);
@ -829,6 +826,7 @@ bool CompilePipelineShader( PipelineShader* s)
//get the uniform locations
s->scale = glGetUniformLocation(s->program, "scale");
s->depth_scale = glGetUniformLocation(s->program, "depth_scale");
s->pp_ClipTest = glGetUniformLocation(s->program, "pp_ClipTest");
@ -927,11 +925,13 @@ bool gl_create_resources()
gl.modvol_shader.program=gl_CompileAndLink(VertexShaderSource,ModifierVolumeShader);
gl.modvol_shader.scale = glGetUniformLocation(gl.modvol_shader.program, "scale");
gl.modvol_shader.sp_ShaderColor = glGetUniformLocation(gl.modvol_shader.program, "sp_ShaderColor");
gl.modvol_shader.depth_scale = glGetUniformLocation(gl.modvol_shader.program, "depth_scale");
gl.OSD_SHADER.program=gl_CompileAndLink(VertexShaderSource,OSD_Shader);
printf("OSD: %d\n",gl.OSD_SHADER.program);
gl.OSD_SHADER.scale=glGetUniformLocation(gl.OSD_SHADER.program, "scale");
gl.OSD_SHADER.depth_scale=glGetUniformLocation(gl.OSD_SHADER.program, "depth_scale");
glUniform1i(glGetUniformLocation(gl.OSD_SHADER.program, "tex"),0); //bind osd texture to slot 0
//#define PRECOMPILE_SHADERS
@ -1452,13 +1452,26 @@ bool RenderFrame()
bool is_rtt=pvrrc.isRTT;
if (!is_rtt)
OSD_HOOK();
OSD_HOOK();
//if (FrameCount&7) return;
//Setup the matrix
//TODO: Make this dynamic
float vtx_min_fZ=0.f; //pvrrc.fZ_min;
float vtx_max_fZ=pvrrc.fZ_max;
//sanitise the values, now with NaN detection (for omap)
//0x49800000 is 1024*1024. Using integer math to avoid issues w/ infs and nans
if ((s32&)vtx_max_fZ<0 || (u32&)vtx_max_fZ>0x49800000)
vtx_max_fZ=10*1024;
//add some extra range to avoid clipping border cases
vtx_min_fZ*=0.98f;
vtx_max_fZ*=1.001f;
//calculate a projection so that it matches the pvr x,y setup, and
//a) Z is linearly scaled between 0 ... 1
@ -1614,6 +1627,11 @@ bool RenderFrame()
ShaderUniforms.scale_coefs[3]=(is_rtt?1:-1);
ShaderUniforms.depth_coefs[0]=2/(vtx_max_fZ-vtx_min_fZ);
ShaderUniforms.depth_coefs[1]=-vtx_min_fZ-1;
ShaderUniforms.depth_coefs[2]=0;
ShaderUniforms.depth_coefs[3]=0;
//printf("scale: %f, %f, %f, %f\n",ShaderUniforms.scale_coefs[0],ShaderUniforms.scale_coefs[1],ShaderUniforms.scale_coefs[2],ShaderUniforms.scale_coefs[3]);
@ -1654,9 +1672,14 @@ bool RenderFrame()
glUseProgram(gl.modvol_shader.program);
glUniform4fv( gl.modvol_shader.scale, 1, ShaderUniforms.scale_coefs);
glUniform4fv( gl.modvol_shader.depth_scale, 1, ShaderUniforms.depth_coefs);
GLfloat td[4]={0.5,0,0,0};
glUseProgram(gl.OSD_SHADER.program);
glUniform4fv( gl.OSD_SHADER.scale, 1, ShaderUniforms.scale_coefs);
glUniform4fv( gl.OSD_SHADER.depth_scale, 1, td);
ShaderUniforms.PT_ALPHA=(PT_ALPHA_REF&0xFF)/255.0f;

View File

@ -79,7 +79,7 @@ struct gl_ctx
{
GLuint program;
GLuint scale;
GLuint scale,depth_scale;
GLuint sp_ShaderColor;
} modvol_shader;
@ -87,8 +87,7 @@ struct gl_ctx
PipelineShader pogram_table[768*2];
struct
{
GLuint program;
GLuint scale;
GLuint program,scale,depth_scale;
} OSD_SHADER;
struct