add affine texture mapping and vertex jiggling, fix r_fullbright not using shader pipeline

master
an 2019-12-12 01:51:08 -05:00
parent f0e0176aa8
commit 51c33e86ee
2 changed files with 123 additions and 110 deletions

View File

@ -80,6 +80,7 @@ static GLuint fullbrightTexLoc;
static GLuint useFullbrightTexLoc; static GLuint useFullbrightTexLoc;
static GLuint useOverbrightLoc; static GLuint useOverbrightLoc;
static GLuint useAlphaTestLoc; static GLuint useAlphaTestLoc;
static GLuint useRFullbrightLoc;
#define pose1VertexAttrIndex 0 #define pose1VertexAttrIndex 0
#define pose1NormalAttrIndex 1 #define pose1NormalAttrIndex 1
@ -131,68 +132,78 @@ void GLAlias_CreateShaders(void)
{ "Pose2Normal", pose2NormalAttrIndex } { "Pose2Normal", pose2NormalAttrIndex }
}; };
const GLchar *vertSource = \ const GLchar *vertSource =
"#version 110\n" "#version 130\n"
"\n" "\n"
"uniform float Blend;\n" "uniform float Blend;\n"
"uniform vec3 ShadeVector;\n" "uniform vec3 ShadeVector;\n"
"uniform vec4 LightColor;\n" "uniform vec4 LightColor;\n"
"attribute vec4 TexCoords; // only xy are used \n" "attribute vec4 TexCoords; // only xy are used \n"
"attribute vec4 Pose1Vert;\n" "attribute vec4 Pose1Vert;\n"
"attribute vec3 Pose1Normal;\n" "attribute vec3 Pose1Normal;\n"
"attribute vec4 Pose2Vert;\n" "attribute vec4 Pose2Vert;\n"
"attribute vec3 Pose2Normal;\n" "attribute vec3 Pose2Normal;\n"
"\n" "\n"
"varying float FogFragCoord;\n" "varying float FogFragCoord;\n"
"\n" "\n"
"float r_avertexnormal_dot(vec3 vertexnormal) // from MH \n" "float r_avertexnormal_dot(vec3 vertexnormal) // from MH \n"
"{\n" "{\n"
" float dot = dot(vertexnormal, ShadeVector);\n" " float dot = dot(vertexnormal, ShadeVector);\n"
" // wtf - this reproduces anorm_dots within as reasonable a degree of tolerance as the >= 0 case\n" " // wtf - this reproduces anorm_dots within as reasonable a degree of tolerance as the >= 0 case\n"
" if (dot < 0.0)\n" " if(dot < 0.0)\n"
" return 1.0 + dot * (13.0 / 44.0);\n" " return 1.0 + dot * (13.0 / 44.0);\n"
" else\n" " else\n"
" return 1.0 + dot;\n" " return 1.0 + dot;\n"
"}\n" "}\n"
"void main()\n" "\n"
"{\n" "void main()\n"
" gl_TexCoord[0] = TexCoords;\n" "{\n"
" vec4 lerpedVert = mix(vec4(Pose1Vert.xyz, 1.0), vec4(Pose2Vert.xyz, 1.0), Blend);\n" " gl_TexCoord[0] = TexCoords;\n"
" gl_Position = gl_ModelViewProjectionMatrix * lerpedVert;\n" " vec4 lerpedVert = mix(vec4(Pose1Vert.xyz, 1.0), vec4(Pose2Vert.xyz, 1.0), Blend);\n"
" FogFragCoord = gl_Position.w;\n" " gl_Position = gl_ModelViewProjectionMatrix * lerpedVert;\n"
" float dot1 = r_avertexnormal_dot(Pose1Normal);\n" " gl_Position = vec4(floor(gl_Position.xyz * 10.0) / 10.0, gl_Position.w);"
" float dot2 = r_avertexnormal_dot(Pose2Normal);\n" " gl_Position /= abs(gl_Position.w);\n"
" gl_FrontColor = LightColor * vec4(vec3(mix(dot1, dot2, Blend)), 1.0);\n" " FogFragCoord = gl_Position.w;\n"
"}\n"; " float dot1 = r_avertexnormal_dot(Pose1Normal);\n"
" float dot2 = r_avertexnormal_dot(Pose2Normal);\n"
" gl_FrontColor = LightColor * vec4(vec3(mix(dot1, dot2, Blend)), 1.0);\n"
"}\n";
const GLchar *fragSource = \ const GLchar *fragSource = \
"#version 110\n" "#version 130\n"
"\n" "\n"
"uniform sampler2D Tex;\n" "uniform sampler2D Tex;\n"
"uniform sampler2D FullbrightTex;\n" "uniform sampler2D FullbrightTex;\n"
"uniform bool UseFullbrightTex;\n" "uniform bool UseFullbrightTex;\n"
"uniform bool UseOverbright;\n" "uniform bool UseOverbright;\n"
"uniform bool UseAlphaTest;\n" "uniform bool UseAlphaTest;\n"
"\n" "uniform bool UseRFullbright;\n"
"varying float FogFragCoord;\n" "\n"
"\n" "varying float FogFragCoord;\n"
"void main()\n" "\n"
"{\n" "void main()\n"
" vec4 result = texture2D(Tex, gl_TexCoord[0].xy);\n" "{\n"
" if (UseAlphaTest && (result.a < 0.666))\n" " vec4 result = texture2D(Tex, gl_TexCoord[0].xy);\n"
" discard;\n" " if(UseAlphaTest && result.a < 0.666)\n"
" result *= gl_Color;\n" " discard;\n"
" if (UseOverbright)\n" " if(!UseRFullbright)\n"
" result.rgb *= 2.0;\n" " {\n"
" if (UseFullbrightTex)\n" " result *= gl_Color;\n"
" result += texture2D(FullbrightTex, gl_TexCoord[0].xy);\n" " if(UseOverbright)\n"
" result = clamp(result, 0.0, 1.0);\n" " result.rgb *= 2.0;\n"
" float fog = exp(-gl_Fog.density * gl_Fog.density * FogFragCoord * FogFragCoord);\n" " }\n"
" fog = clamp(fog, 0.0, 1.0);\n" " if(UseFullbrightTex)\n"
" result = mix(gl_Fog.color, result, fog);\n" " result += texture2D(FullbrightTex, gl_TexCoord[0].xy);\n"
" result.a = gl_Color.a;\n" // FIXME: This will make almost transparent things cut holes though heavy fog " result = clamp(result, 0.0, 1.0);\n"
" gl_FragColor = result;\n" " if(!UseRFullbright)\n"
"}\n"; " {\n"
" float fog = exp(-gl_Fog.density * gl_Fog.density * FogFragCoord * FogFragCoord);\n"
" fog = clamp(fog, 0.0, 1.0);\n"
" result = mix(gl_Fog.color, result, fog);\n"
" result.a = gl_Color.a;\n" // FIXME: This will make almost transparent things cut holes though heavy fog
" }\n"
" gl_FragColor = result;\n"
"}\n";
if(!gl_glsl_alias_able) if(!gl_glsl_alias_able)
return; return;
@ -210,6 +221,7 @@ void GLAlias_CreateShaders(void)
useFullbrightTexLoc = GL_GetUniformLocation(&r_alias_program, "UseFullbrightTex"); useFullbrightTexLoc = GL_GetUniformLocation(&r_alias_program, "UseFullbrightTex");
useOverbrightLoc = GL_GetUniformLocation(&r_alias_program, "UseOverbright"); useOverbrightLoc = GL_GetUniformLocation(&r_alias_program, "UseOverbright");
useAlphaTestLoc = GL_GetUniformLocation(&r_alias_program, "UseAlphaTest"); useAlphaTestLoc = GL_GetUniformLocation(&r_alias_program, "UseAlphaTest");
useRFullbrightLoc = GL_GetUniformLocation(&r_alias_program, "UseRFullbright");
} }
} }
@ -267,6 +279,7 @@ void GL_DrawAliasFrame_GLSL(aliashdr_t *paliashdr, lerpdata_t lerpdata, gltextur
GL_Uniform1iFunc(useFullbrightTexLoc, (fb != NULL) ? 1 : 0); GL_Uniform1iFunc(useFullbrightTexLoc, (fb != NULL) ? 1 : 0);
GL_Uniform1fFunc(useOverbrightLoc, overbright ? 1 : 0); GL_Uniform1fFunc(useOverbrightLoc, overbright ? 1 : 0);
GL_Uniform1iFunc(useAlphaTestLoc, (currententity->model->flags & MF_HOLEY) ? 1 : 0); GL_Uniform1iFunc(useAlphaTestLoc, (currententity->model->flags & MF_HOLEY) ? 1 : 0);
GL_Uniform1iFunc(useRFullbrightLoc, r_fullbright_cheatsafe);
// set textures // set textures
GL_SelectTexture(GL_TEXTURE0); GL_SelectTexture(GL_TEXTURE0);
@ -714,6 +727,8 @@ void R_DrawAliasModel(entity_t *e)
// //
// draw it // draw it
// //
// call fast path if possible. if the shader compliation failed for some reason,
// r_alias_program will be 0.
if(r_drawflat_cheatsafe) if(r_drawflat_cheatsafe)
{ {
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
@ -721,6 +736,10 @@ void R_DrawAliasModel(entity_t *e)
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
srand((int32_t)(cl.time * 1000)); //restore randomness srand((int32_t)(cl.time * 1000)); //restore randomness
} }
else if(r_alias_program != 0)
{
GL_DrawAliasFrame_GLSL(paliashdr, lerpdata, tx, fb);
}
else if(r_fullbright_cheatsafe) else if(r_fullbright_cheatsafe)
{ {
GL_Bind(tx); GL_Bind(tx);
@ -751,12 +770,6 @@ void R_DrawAliasModel(entity_t *e)
GL_DrawAliasFrame(paliashdr, lerpdata); GL_DrawAliasFrame(paliashdr, lerpdata);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
} }
// call fast path if possible. if the shader compliation failed for some reason,
// r_alias_program will be 0.
else if(r_alias_program != 0)
{
GL_DrawAliasFrame_GLSL(paliashdr, lerpdata, tx, fb);
}
else if(overbright) else if(overbright)
{ {
if(gl_texture_env_combine && gl_mtexable && gl_texture_env_add && fb) //case 1: everything in one pass if(gl_texture_env_combine && gl_mtexable && gl_texture_env_add && fb) //case 1: everything in one pass

View File

@ -815,52 +815,52 @@ void GLWorld_CreateShaders(void)
}; };
const GLchar *vertSource = \ const GLchar *vertSource = \
"#version 110\n" "#version 130\n"
"\n" "\n"
"attribute vec3 Vert;\n" "attribute vec3 Vert;\n"
"attribute vec2 TexCoords;\n" "attribute vec2 TexCoords;\n"
"attribute vec2 LMCoords;\n" "attribute vec2 LMCoords;\n"
"\n" "\n"
"varying float FogFragCoord;\n" "varying float FogFragCoord;\n"
"\n" "\n"
"void main()\n" "void main()\n"
"{\n" "{\n"
" gl_TexCoord[0] = vec4(TexCoords, 0.0, 0.0);\n" " gl_TexCoord[0] = vec4(TexCoords, 0.0, 0.0);\n"
" gl_TexCoord[1] = vec4(LMCoords, 0.0, 0.0);\n" " gl_TexCoord[1] = vec4(LMCoords, 0.0, 0.0);\n"
" gl_Position = gl_ModelViewProjectionMatrix * vec4(Vert, 1.0);\n" " gl_Position = gl_ModelViewProjectionMatrix * vec4(Vert, 1.0);\n"
" FogFragCoord = gl_Position.w;\n" " FogFragCoord = gl_Position.w;\n"
"}\n"; "}\n";
const GLchar *fragSource = \ const GLchar *fragSource = \
"#version 110\n" "#version 130\n"
"\n" "\n"
"uniform sampler2D Tex;\n" "uniform sampler2D Tex;\n"
"uniform sampler2D LMTex;\n" "uniform sampler2D LMTex;\n"
"uniform sampler2D FullbrightTex;\n" "uniform sampler2D FullbrightTex;\n"
"uniform bool UseFullbrightTex;\n" "uniform bool UseFullbrightTex;\n"
"uniform bool UseOverbright;\n" "uniform bool UseOverbright;\n"
"uniform bool UseAlphaTest;\n" "uniform bool UseAlphaTest;\n"
"uniform float Alpha;\n" "uniform float Alpha;\n"
"\n" "\n"
"varying float FogFragCoord;\n" "varying float FogFragCoord;\n"
"\n" "\n"
"void main()\n" "void main()\n"
"{\n" "{\n"
" vec4 result = texture2D(Tex, gl_TexCoord[0].xy);\n" " vec4 result = texture2D(Tex, gl_TexCoord[0].xy);\n"
" if (UseAlphaTest && (result.a < 0.666))\n" " if (UseAlphaTest && (result.a < 0.666))\n"
" discard;\n" " discard;\n"
" result *= texture2D(LMTex, gl_TexCoord[1].xy);\n" " result *= texture2D(LMTex, gl_TexCoord[1].xy);\n"
" if (UseOverbright)\n" " if (UseOverbright)\n"
" result.rgb *= 2.0;\n" " result.rgb *= 2.0;\n"
" if (UseFullbrightTex)\n" " if (UseFullbrightTex)\n"
" result += texture2D(FullbrightTex, gl_TexCoord[0].xy);\n" " result += texture2D(FullbrightTex, gl_TexCoord[0].xy);\n"
" result = clamp(result, 0.0, 1.0);\n" " result = clamp(result, 0.0, 1.0);\n"
" float fog = exp(-gl_Fog.density * gl_Fog.density * FogFragCoord * FogFragCoord);\n" " float fog = exp(-gl_Fog.density * gl_Fog.density * FogFragCoord * FogFragCoord);\n"
" fog = clamp(fog, 0.0, 1.0);\n" " fog = clamp(fog, 0.0, 1.0);\n"
" result = mix(gl_Fog.color, result, fog);\n" " result = mix(gl_Fog.color, result, fog);\n"
" result.a = Alpha;\n" // FIXME: This will make almost transparent things cut holes though heavy fog " result.a = Alpha;\n" // FIXME: This will make almost transparent things cut holes though heavy fog
" gl_FragColor = result;\n" " gl_FragColor = result;\n"
"}\n"; "}\n";
if(!gl_glsl_alias_able) if(!gl_glsl_alias_able)
return; return;