Faster normal mapping.

git-svn-id: https://svn.eduke32.com/eduke32@1283 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
plagman 2009-03-28 18:25:30 +00:00
parent 13243ffeae
commit 73149ef78b
2 changed files with 23 additions and 13 deletions

View file

@ -97,10 +97,11 @@ typedef struct s_prrograminfo {
GLint attrib_nextFrameNormal; GLint attrib_nextFrameNormal;
GLint uniform_frameProgress; GLint uniform_frameProgress;
// PR_BIT_NORMAL_MAP // PR_BIT_NORMAL_MAP
GLint uniform_normalMap;
GLint attrib_T; GLint attrib_T;
GLint attrib_B; GLint attrib_B;
GLint attrib_N; GLint attrib_N;
GLint uniform_eyePosition;
GLint uniform_normalMap;
// PR_BIT_DIFFUSE_MAP // PR_BIT_DIFFUSE_MAP
GLint uniform_diffuseMap; GLint uniform_diffuseMap;
GLint uniform_diffuseScale; GLint uniform_diffuseScale;
@ -219,7 +220,6 @@ typedef struct s_prwall {
char pal, xrepeat, yrepeat, xpanning, ypanning; char pal, xrepeat, yrepeat, xpanning, ypanning;
char nwallxpanning, nwallypanning; char nwallxpanning, nwallypanning;
char underover; char underover;
uint32_t invalidid; uint32_t invalidid;
char controlstate; char controlstate;

View file

@ -192,22 +192,21 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
"attribute vec3 T;\n" "attribute vec3 T;\n"
"attribute vec3 B;\n" "attribute vec3 B;\n"
"attribute vec3 N;\n" "attribute vec3 N;\n"
"varying mat3 matTBN;\n" "uniform vec3 eyePosition;\n"
"\n", "\n",
// vert_prog // vert_prog
" //TBN = mat3(gl_NormalMatrix * T, gl_NormalMatrix * B, gl_NormalMatrix * N);\n" " TBN = transpose(mat3(T, B, N));\n"
" matTBN = gl_NormalMatrix * mat3(T, B, N);\n" " eyePos = eyePosition;\n"
"\n" "\n"
" isNormalMapped = 1;\n" " isNormalMapped = 1;\n"
"\n", "\n",
// frag_def // frag_def
"uniform sampler2D normalMap;\n" "uniform sampler2D normalMap;\n"
"varying mat3 matTBN;\n"
"\n", "\n",
// frag_prog // frag_prog
" normalTexel = texture2D(normalMap, gl_TexCoord[0].st);\n" " normalTexel = texture2D(normalMap, gl_TexCoord[0].st);\n"
"\n"
" isNormalMapped = 1;\n" " isNormalMapped = 1;\n"
" TBN = matTBN;\n"
"\n", "\n",
}, },
{ {
@ -367,8 +366,10 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
" lightVector = gl_LightSource[0].ambient.rgb - vertexPos;\n" " lightVector = gl_LightSource[0].ambient.rgb - vertexPos;\n"
"\n" "\n"
" if (isNormalMapped == 1) {\n" " if (isNormalMapped == 1) {\n"
" //tangentSpaceLightVector = vec3(32376.0, -94.0, -32496.0) - vec3(curVertex);\n" " tangentSpaceLightVector = gl_LightSource[0].specular.rgb - vec3(curVertex);\n"
" //tangentSpaceLightVector = TBN * tangentSpaceLightVector;\n" " tangentSpaceLightVector = TBN * tangentSpaceLightVector;\n"
" eyeVector = eyePos - vec3(curVertex);\n"
" eyeVector = TBN * eyeVector;\n"
" } else\n" " } else\n"
" vertexNormal = normalize(gl_NormalMatrix * curNormal);\n" " vertexNormal = normalize(gl_NormalMatrix * curNormal);\n"
"\n", "\n",
@ -405,8 +406,8 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
" }\n" " }\n"
"\n" "\n"
" if (isNormalMapped == 1) {\n" " if (isNormalMapped == 1) {\n"
" N = 2.0 * (normalTexel.rgb - 0.5);\n" " N = normalize(2.0 * (normalTexel.rgb - 0.5));\n"
" N = normalize(TBN * N);\n" " L = normalize(tangentSpaceLightVector);\n"
" } else\n" " } else\n"
" N = normalize(vertexNormal);\n" " N = normalize(vertexNormal);\n"
" NdotL = max(dot(N, L), 0.0);\n" " NdotL = max(dot(N, L), 0.0);\n"
@ -431,6 +432,7 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
" vec4 curVertex = gl_Vertex;\n" " vec4 curVertex = gl_Vertex;\n"
" vec3 curNormal = gl_Normal;\n" " vec3 curNormal = gl_Normal;\n"
" int isNormalMapped = 0;\n" " int isNormalMapped = 0;\n"
" vec3 eyePos;\n"
" mat3 TBN;\n" " mat3 TBN;\n"
"\n" "\n"
" gl_TexCoord[0] = gl_MultiTexCoord0;\n" " gl_TexCoord[0] = gl_MultiTexCoord0;\n"
@ -448,7 +450,6 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
" vec4 normalTexel;\n" " vec4 normalTexel;\n"
" int isLightingPass = 0;\n" " int isLightingPass = 0;\n"
" int isNormalMapped = 0;\n" " int isNormalMapped = 0;\n"
" mat3 TBN;\n"
" int isSpotLight = 0;\n" " int isSpotLight = 0;\n"
" vec3 spotVector;\n" " vec3 spotVector;\n"
" vec2 spotCosRadius;\n" " vec2 spotCosRadius;\n"
@ -3288,9 +3289,16 @@ static int32_t polymer_bindmaterial(_prmaterial material, char* lights, int
// PR_BIT_NORMAL_MAP // PR_BIT_NORMAL_MAP
if (programbits & prprogrambits[PR_BIT_NORMAL_MAP].bit) if (programbits & prprogrambits[PR_BIT_NORMAL_MAP].bit)
{ {
float pos[3];
pos[0] = globalposy;
pos[1] = -(float)(globalposz) / 16.0f;
pos[2] = -globalposx;
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB); bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
bglBindTexture(GL_TEXTURE_2D, material.normalmap); bglBindTexture(GL_TEXTURE_2D, material.normalmap);
bglUniform3fvARB(prprograms[programbits].uniform_eyePosition, 1, pos);
bglUniform1iARB(prprograms[programbits].uniform_normalMap, texunit); bglUniform1iARB(prprograms[programbits].uniform_normalMap, texunit);
texunit++; texunit++;
@ -3443,6 +3451,7 @@ static int32_t polymer_bindmaterial(_prmaterial material, char* lights, int
bglLightfv(GL_LIGHT0, GL_AMBIENT, pos); bglLightfv(GL_LIGHT0, GL_AMBIENT, pos);
bglLightfv(GL_LIGHT0, GL_DIFFUSE, color); bglLightfv(GL_LIGHT0, GL_DIFFUSE, color);
bglLightfv(GL_LIGHT0, GL_SPECULAR, inpos);
bglLightfv(GL_LIGHT0, GL_CONSTANT_ATTENUATION, &range[0]); bglLightfv(GL_LIGHT0, GL_CONSTANT_ATTENUATION, &range[0]);
bglLightfv(GL_LIGHT0, GL_LINEAR_ATTENUATION, &range[1]); bglLightfv(GL_LIGHT0, GL_LINEAR_ATTENUATION, &range[1]);
} }
@ -3558,10 +3567,11 @@ static void polymer_compileprogram(int32_t programbits)
// PR_BIT_NORMAL_MAP // PR_BIT_NORMAL_MAP
if (programbits & prprogrambits[PR_BIT_NORMAL_MAP].bit) if (programbits & prprogrambits[PR_BIT_NORMAL_MAP].bit)
{ {
prprograms[programbits].uniform_normalMap = bglGetUniformLocationARB(program, "normalMap");
prprograms[programbits].attrib_T = bglGetAttribLocationARB(program, "T"); prprograms[programbits].attrib_T = bglGetAttribLocationARB(program, "T");
prprograms[programbits].attrib_B = bglGetAttribLocationARB(program, "B"); prprograms[programbits].attrib_B = bglGetAttribLocationARB(program, "B");
prprograms[programbits].attrib_N = bglGetAttribLocationARB(program, "N"); prprograms[programbits].attrib_N = bglGetAttribLocationARB(program, "N");
prprograms[programbits].uniform_eyePosition = bglGetUniformLocationARB(program, "eyePosition");
prprograms[programbits].uniform_normalMap = bglGetUniformLocationARB(program, "normalMap");
} }
// PR_BIT_DIFFUSE_MAP // PR_BIT_DIFFUSE_MAP