mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-03-12 22:03:49 +00:00
mdl normals preview
This commit is contained in:
parent
c02fd49811
commit
bd4ca17fb0
1 changed files with 2 additions and 68 deletions
|
@ -71,20 +71,13 @@ static GLuint r_alias_program;
|
|||
|
||||
// uniforms used in vert shader
|
||||
static GLuint blendLoc;
|
||||
static GLuint shadevectorLoc;
|
||||
static GLuint lightColorLoc;
|
||||
|
||||
// uniforms used in frag shader
|
||||
static GLuint texLoc;
|
||||
static GLuint fullbrightTexLoc;
|
||||
static GLuint useFullbrightTexLoc;
|
||||
static GLuint useOverbrightLoc;
|
||||
|
||||
static const GLint pose1VertexAttrIndex = 0;
|
||||
static const GLint pose1NormalAttrIndex = 1;
|
||||
static const GLint pose2VertexAttrIndex = 2;
|
||||
static const GLint pose2NormalAttrIndex = 3;
|
||||
static const GLint texCoordsAttrIndex = 4;
|
||||
|
||||
extern GLuint r_meshvbo;
|
||||
extern GLuint r_meshindexesvbo;
|
||||
|
@ -127,7 +120,6 @@ GLAlias_CreateShaders
|
|||
void GLAlias_CreateShaders (void)
|
||||
{
|
||||
const glsl_attrib_binding_t bindings[] = {
|
||||
{ "TexCoords", texCoordsAttrIndex },
|
||||
{ "Pose1Vert", pose1VertexAttrIndex },
|
||||
{ "Pose1Normal", pose1NormalAttrIndex },
|
||||
{ "Pose2Vert", pose2VertexAttrIndex },
|
||||
|
@ -138,56 +130,23 @@ void GLAlias_CreateShaders (void)
|
|||
"#version 110\n"
|
||||
"\n"
|
||||
"uniform float Blend;\n"
|
||||
"uniform vec3 ShadeVector;\n"
|
||||
"uniform vec4 LightColor;\n"
|
||||
"attribute vec4 TexCoords; // only xy are used \n"
|
||||
"attribute vec4 Pose1Vert;\n"
|
||||
"attribute vec3 Pose1Normal;\n"
|
||||
"attribute vec4 Pose2Vert;\n"
|
||||
"attribute vec3 Pose2Normal;\n"
|
||||
"float r_avertexnormal_dot(vec3 vertexnormal) // from MH \n"
|
||||
"{\n"
|
||||
" float dot = dot(vertexnormal, ShadeVector);\n"
|
||||
" // wtf - this reproduces anorm_dots within as reasonable a degree of tolerance as the >= 0 case\n"
|
||||
" if (dot < 0.0)\n"
|
||||
" return 1.0 + dot * (13.0 / 44.0);\n"
|
||||
" else\n"
|
||||
" return 1.0 + dot;\n"
|
||||
"}\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_TexCoord[0] = TexCoords;\n"
|
||||
" vec4 lerpedVert = mix(Pose1Vert, Pose2Vert, Blend);\n"
|
||||
" gl_Position = gl_ModelViewProjectionMatrix * lerpedVert;\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"
|
||||
" // fog\n"
|
||||
" vec3 ecPosition = vec3(gl_ModelViewMatrix * lerpedVert);\n"
|
||||
" gl_FogFragCoord = abs(ecPosition.z);\n"
|
||||
" gl_FrontColor = vec4(mix((Pose1Normal + 1.0) / 2.0, (Pose2Normal + 1.0) / 2.0, Blend), 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
const GLchar *fragSource = \
|
||||
"#version 110\n"
|
||||
"\n"
|
||||
"uniform sampler2D Tex;\n"
|
||||
"uniform sampler2D FullbrightTex;\n"
|
||||
"uniform bool UseFullbrightTex;\n"
|
||||
"uniform bool UseOverbright;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec4 result = texture2D(Tex, gl_TexCoord[0].xy);\n"
|
||||
" result *= gl_Color;\n"
|
||||
" if (UseOverbright)\n"
|
||||
" result.rgb *= 2.0;\n"
|
||||
" if (UseFullbrightTex)\n"
|
||||
" result += texture2D(FullbrightTex, gl_TexCoord[0].xy);\n"
|
||||
" result = clamp(result, 0.0, 1.0);\n"
|
||||
" // apply GL_EXP2 fog (from the orange book)\n"
|
||||
" float fog = exp(-gl_Fog.density * gl_Fog.density * gl_FogFragCoord * gl_FogFragCoord);\n"
|
||||
" fog = clamp(fog, 0.0, 1.0);\n"
|
||||
" result = vec4(mix(gl_Fog.color.rgb, result.rgb, fog), result.a);\n"
|
||||
" gl_FragColor = result;\n"
|
||||
" gl_FragColor = gl_Color;\n"
|
||||
"}\n";
|
||||
|
||||
if (!gl_glsl_alias_able)
|
||||
|
@ -199,12 +158,6 @@ void GLAlias_CreateShaders (void)
|
|||
{
|
||||
// get uniform locations
|
||||
blendLoc = GL_GetUniformLocation (&r_alias_program, "Blend");
|
||||
shadevectorLoc = GL_GetUniformLocation (&r_alias_program, "ShadeVector");
|
||||
lightColorLoc = GL_GetUniformLocation (&r_alias_program, "LightColor");
|
||||
texLoc = GL_GetUniformLocation (&r_alias_program, "Tex");
|
||||
fullbrightTexLoc = GL_GetUniformLocation (&r_alias_program, "FullbrightTex");
|
||||
useFullbrightTexLoc = GL_GetUniformLocation (&r_alias_program, "UseFullbrightTex");
|
||||
useOverbrightLoc = GL_GetUniformLocation (&r_alias_program, "UseOverbright");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,13 +193,11 @@ void GL_DrawAliasFrame_GLSL (aliashdr_t *paliashdr, lerpdata_t lerpdata, gltextu
|
|||
GL_BindBuffer (GL_ARRAY_BUFFER, r_meshvbo);
|
||||
GL_BindBuffer (GL_ELEMENT_ARRAY_BUFFER, r_meshindexesvbo);
|
||||
|
||||
GL_EnableVertexAttribArrayFunc (texCoordsAttrIndex);
|
||||
GL_EnableVertexAttribArrayFunc (pose1VertexAttrIndex);
|
||||
GL_EnableVertexAttribArrayFunc (pose2VertexAttrIndex);
|
||||
GL_EnableVertexAttribArrayFunc (pose1NormalAttrIndex);
|
||||
GL_EnableVertexAttribArrayFunc (pose2NormalAttrIndex);
|
||||
|
||||
GL_VertexAttribPointerFunc (texCoordsAttrIndex, 2, GL_FLOAT, GL_FALSE, 0, (void *)(intptr_t)currententity->model->vbostofs);
|
||||
GL_VertexAttribPointerFunc (pose1VertexAttrIndex, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof (meshxyz_t), GLARB_GetXYZOffset (paliashdr, lerpdata.pose1));
|
||||
GL_VertexAttribPointerFunc (pose2VertexAttrIndex, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof (meshxyz_t), GLARB_GetXYZOffset (paliashdr, lerpdata.pose2));
|
||||
// GL_TRUE to normalize the signed bytes to [-1 .. 1]
|
||||
|
@ -255,28 +206,11 @@ void GL_DrawAliasFrame_GLSL (aliashdr_t *paliashdr, lerpdata_t lerpdata, gltextu
|
|||
|
||||
// set uniforms
|
||||
GL_Uniform1fFunc (blendLoc, blend);
|
||||
GL_Uniform3fFunc (shadevectorLoc, shadevector[0], shadevector[1], shadevector[2]);
|
||||
GL_Uniform4fFunc (lightColorLoc, lightcolor[0], lightcolor[1], lightcolor[2], entalpha);
|
||||
GL_Uniform1iFunc (texLoc, 0);
|
||||
GL_Uniform1iFunc (fullbrightTexLoc, 1);
|
||||
GL_Uniform1iFunc (useFullbrightTexLoc, (fb != NULL) ? 1 : 0);
|
||||
GL_Uniform1fFunc (useOverbrightLoc, overbright ? 1 : 0);
|
||||
|
||||
// set textures
|
||||
GL_SelectTexture (GL_TEXTURE0);
|
||||
GL_Bind (tx);
|
||||
|
||||
if (fb)
|
||||
{
|
||||
GL_SelectTexture (GL_TEXTURE1);
|
||||
GL_Bind (fb);
|
||||
}
|
||||
|
||||
// draw
|
||||
glDrawElements (GL_TRIANGLES, paliashdr->numindexes, GL_UNSIGNED_SHORT, (void *)(intptr_t)currententity->model->vboindexofs);
|
||||
|
||||
// clean up
|
||||
GL_DisableVertexAttribArrayFunc (texCoordsAttrIndex);
|
||||
GL_DisableVertexAttribArrayFunc (pose1VertexAttrIndex);
|
||||
GL_DisableVertexAttribArrayFunc (pose2VertexAttrIndex);
|
||||
GL_DisableVertexAttribArrayFunc (pose1NormalAttrIndex);
|
||||
|
|
Loading…
Reference in a new issue