mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 03:00:46 +00:00
Light my fire.
git-svn-id: https://svn.eduke32.com/eduke32@1170 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
0c869a2254
commit
f062dafaed
4 changed files with 91 additions and 8 deletions
|
@ -103,6 +103,7 @@ extern void (APIENTRY * bglColor4ub)( GLubyte red, GLubyte green, GLubyte blue,
|
||||||
extern void (APIENTRY * bglTexCoord2d)( GLdouble s, GLdouble t );
|
extern void (APIENTRY * bglTexCoord2d)( GLdouble s, GLdouble t );
|
||||||
extern void (APIENTRY * bglTexCoord2f)( GLfloat s, GLfloat t );
|
extern void (APIENTRY * bglTexCoord2f)( GLfloat s, GLfloat t );
|
||||||
extern void (APIENTRY * bglTexCoord2i)( GLint s, GLint t );
|
extern void (APIENTRY * bglTexCoord2i)( GLint s, GLint t );
|
||||||
|
extern void (APIENTRY * bglNormal3f)( GLfloat x, GLfloat y, GLfloat z );
|
||||||
|
|
||||||
// Lighting
|
// Lighting
|
||||||
extern void (APIENTRY * bglShadeModel)( GLenum mode );
|
extern void (APIENTRY * bglShadeModel)( GLenum mode );
|
||||||
|
|
|
@ -48,6 +48,7 @@ typedef enum {
|
||||||
PR_BIT_DIFFUSE_MAP,
|
PR_BIT_DIFFUSE_MAP,
|
||||||
PR_BIT_DIFFUSE_DETAIL_MAP,
|
PR_BIT_DIFFUSE_DETAIL_MAP,
|
||||||
PR_BIT_DIFFUSE_MODULATION,
|
PR_BIT_DIFFUSE_MODULATION,
|
||||||
|
PR_BIT_POINT_LIGHT,
|
||||||
PR_BIT_DIFFUSE_GLOW_MAP,
|
PR_BIT_DIFFUSE_GLOW_MAP,
|
||||||
PR_BIT_DEFAULT, // must be just before last
|
PR_BIT_DEFAULT, // must be just before last
|
||||||
PR_BIT_COUNT // must be last
|
PR_BIT_COUNT // must be last
|
||||||
|
@ -81,11 +82,15 @@ typedef struct s_prrograminfo {
|
||||||
// PR_BIT_DIFFUSE_DETAIL_MAP
|
// PR_BIT_DIFFUSE_DETAIL_MAP
|
||||||
GLint uniform_detailMap;
|
GLint uniform_detailMap;
|
||||||
GLint uniform_detailScale;
|
GLint uniform_detailScale;
|
||||||
|
// PR_BIT_POINT_LIGHT
|
||||||
|
GLint uniform_pointLightPosition;
|
||||||
|
GLint uniform_pointLightColor;
|
||||||
|
GLint uniform_pointLightRange;
|
||||||
// PR_BIT_DIFFUSE_GLOW_MAP
|
// PR_BIT_DIFFUSE_GLOW_MAP
|
||||||
GLint uniform_glowMap;
|
GLint uniform_glowMap;
|
||||||
} _prprograminfo;
|
} _prprograminfo;
|
||||||
|
|
||||||
#define PR_INFO_LOG_BUFFER_SIZE 512
|
#define PR_INFO_LOG_BUFFER_SIZE 16384
|
||||||
|
|
||||||
typedef struct s_prprogrambit {
|
typedef struct s_prprogrambit {
|
||||||
int bit;
|
int bit;
|
||||||
|
@ -169,7 +174,7 @@ typedef enum {
|
||||||
} prlighttype;
|
} prlighttype;
|
||||||
|
|
||||||
typedef struct s_prlight {
|
typedef struct s_prlight {
|
||||||
int x, y, z, horiz, range, faderange;
|
int x, y, z, horiz, faderange, range;
|
||||||
short angle, sector;
|
short angle, sector;
|
||||||
prlighttype type;
|
prlighttype type;
|
||||||
} _prlight;
|
} _prlight;
|
||||||
|
|
|
@ -70,6 +70,7 @@ void (APIENTRY * bglColor4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte
|
||||||
void (APIENTRY * bglTexCoord2d)(GLdouble s, GLdouble t);
|
void (APIENTRY * bglTexCoord2d)(GLdouble s, GLdouble t);
|
||||||
void (APIENTRY * bglTexCoord2f)(GLfloat s, GLfloat t);
|
void (APIENTRY * bglTexCoord2f)(GLfloat s, GLfloat t);
|
||||||
void (APIENTRY * bglTexCoord2i)(GLint s, GLint t);
|
void (APIENTRY * bglTexCoord2i)(GLint s, GLint t);
|
||||||
|
void (APIENTRY * bglNormal3f)(GLfloat x, GLfloat y, GLfloat z);
|
||||||
|
|
||||||
// Lighting
|
// Lighting
|
||||||
void (APIENTRY * bglShadeModel)(GLenum mode);
|
void (APIENTRY * bglShadeModel)(GLenum mode);
|
||||||
|
@ -412,6 +413,7 @@ int loadgldriver(const char *driver)
|
||||||
bglTexCoord2d = GETPROC("glTexCoord2d");
|
bglTexCoord2d = GETPROC("glTexCoord2d");
|
||||||
bglTexCoord2f = GETPROC("glTexCoord2f");
|
bglTexCoord2f = GETPROC("glTexCoord2f");
|
||||||
bglTexCoord2i = GETPROC("glTexCoord2i");
|
bglTexCoord2i = GETPROC("glTexCoord2i");
|
||||||
|
bglNormal3f = GETPROC("glNormal3f");
|
||||||
|
|
||||||
// Lighting
|
// Lighting
|
||||||
bglShadeModel = GETPROC("glShadeModel");
|
bglShadeModel = GETPROC("glShadeModel");
|
||||||
|
@ -684,6 +686,7 @@ int unloadgldriver(void)
|
||||||
bglTexCoord2d = NULL;
|
bglTexCoord2d = NULL;
|
||||||
bglTexCoord2f = NULL;
|
bglTexCoord2f = NULL;
|
||||||
bglTexCoord2i = NULL;
|
bglTexCoord2i = NULL;
|
||||||
|
bglNormal3f = NULL;
|
||||||
|
|
||||||
// Lighting
|
// Lighting
|
||||||
bglShadeModel = NULL;
|
bglShadeModel = NULL;
|
||||||
|
|
|
@ -151,7 +151,7 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
|
||||||
"uniform vec2 diffuseScale;\n"
|
"uniform vec2 diffuseScale;\n"
|
||||||
"\n",
|
"\n",
|
||||||
// vert_prog
|
// vert_prog
|
||||||
"gl_TexCoord[0] = vec4(diffuseScale, 1.0, 1.0) * gl_MultiTexCoord0;\n"
|
" gl_TexCoord[0] = vec4(diffuseScale, 1.0, 1.0) * gl_MultiTexCoord0;\n"
|
||||||
"\n",
|
"\n",
|
||||||
// frag_def
|
// frag_def
|
||||||
"uniform sampler2D diffuseMap;\n"
|
"uniform sampler2D diffuseMap;\n"
|
||||||
|
@ -166,7 +166,7 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
|
||||||
"uniform vec2 detailScale;\n"
|
"uniform vec2 detailScale;\n"
|
||||||
"\n",
|
"\n",
|
||||||
// vert_prog
|
// vert_prog
|
||||||
"gl_TexCoord[1] = vec4(detailScale, 1.0, 1.0) * gl_MultiTexCoord0;\n"
|
" gl_TexCoord[1] = vec4(detailScale, 1.0, 1.0) * gl_MultiTexCoord0;\n"
|
||||||
"\n",
|
"\n",
|
||||||
// frag_def
|
// frag_def
|
||||||
"uniform sampler2D detailMap;\n"
|
"uniform sampler2D detailMap;\n"
|
||||||
|
@ -181,7 +181,7 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
|
||||||
// vert_def
|
// vert_def
|
||||||
"",
|
"",
|
||||||
// vert_prog
|
// vert_prog
|
||||||
"gl_FrontColor = gl_Color;\n"
|
" gl_FrontColor = gl_Color;\n"
|
||||||
"\n",
|
"\n",
|
||||||
// frag_def
|
// frag_def
|
||||||
"",
|
"",
|
||||||
|
@ -189,12 +189,63 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
|
||||||
" result *= vec4(gl_Color);\n"
|
" result *= vec4(gl_Color);\n"
|
||||||
"\n",
|
"\n",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
1 << PR_BIT_POINT_LIGHT,
|
||||||
|
// vert_def
|
||||||
|
"uniform vec3 pointLightPosition;\n"
|
||||||
|
"uniform vec2 pointLightRange;\n"
|
||||||
|
"varying vec3 vertexNormal;\n"
|
||||||
|
"varying vec3 lightVector;\n"
|
||||||
|
"varying vec2 eyeSpaceRange;\n"
|
||||||
|
"\n",
|
||||||
|
// vert_prog
|
||||||
|
" vec3 vertexPos;\n"
|
||||||
|
" vec3 lightPos;\n"
|
||||||
|
"\n"
|
||||||
|
" vertexNormal = normalize(gl_NormalMatrix * gl_Normal);\n"
|
||||||
|
" vertexPos = vec3(result);\n"
|
||||||
|
" lightPos = vec3(gl_ModelViewProjectionMatrix * vec4(pointLightPosition, 1.0));\n"
|
||||||
|
" lightVector = lightPos - vertexPos;\n"
|
||||||
|
" eyeSpaceRange.x = length(gl_ModelViewProjectionMatrix * vec4(pointLightRange.x, 0.0, 0.0, 0.0));\n"
|
||||||
|
" eyeSpaceRange.y = length(gl_ModelViewProjectionMatrix * vec4(pointLightRange.y, 0.0, 0.0, 0.0));\n"
|
||||||
|
" eyeSpaceRange.x = 0.5;\n"
|
||||||
|
" eyeSpaceRange.y = 1.0;\n"
|
||||||
|
/* " pointLightDirection = normalize(lightVector);\n"
|
||||||
|
" pointLightHalfVector = normalize(lightVector) + normalize(vec3(-result));\n"*/
|
||||||
|
"\n",
|
||||||
|
// frag_def
|
||||||
|
"uniform vec3 pointLightColor;\n"
|
||||||
|
"varying vec3 vertexNormal;\n"
|
||||||
|
"varying vec3 lightVector;\n"
|
||||||
|
"varying vec2 eyeSpaceRange;\n"
|
||||||
|
"\n",
|
||||||
|
// frag_prog
|
||||||
|
" vec3 fragmentNormal;\n"
|
||||||
|
" float dotNormalLightDir;\n"
|
||||||
|
" float lightAttenuation;\n"
|
||||||
|
" float pointLightDistance;\n"
|
||||||
|
"\n"
|
||||||
|
" fragmentNormal = normalize(vertexNormal);\n"
|
||||||
|
" pointLightDistance = length(lightVector);\n"
|
||||||
|
// " dotNormalLightDir = max(dot(fragmentNormal, normalize(pointLightDirection)), 0.0);\n"
|
||||||
|
" if (pointLightDistance < eyeSpaceRange.y)\n"
|
||||||
|
" {\n"
|
||||||
|
" if (pointLightDistance < eyeSpaceRange.x)\n"
|
||||||
|
" lightAttenuation = 1.0;\n"
|
||||||
|
" else {\n"
|
||||||
|
" lightAttenuation = 1.0 - (pointLightDistance - eyeSpaceRange.x) /\n"
|
||||||
|
" (eyeSpaceRange.y - eyeSpaceRange.x);\n"
|
||||||
|
" }\n"
|
||||||
|
" result += vec4(lightAttenuation * 1.0 * pointLightColor, 0.0);\n"
|
||||||
|
" }\n"
|
||||||
|
"\n",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
1 << PR_BIT_DIFFUSE_GLOW_MAP,
|
1 << PR_BIT_DIFFUSE_GLOW_MAP,
|
||||||
// vert_def
|
// vert_def
|
||||||
"",
|
"",
|
||||||
// vert_prog
|
// vert_prog
|
||||||
"gl_TexCoord[2] = gl_MultiTexCoord0;\n"
|
" gl_TexCoord[2] = gl_MultiTexCoord0;\n"
|
||||||
"\n",
|
"\n",
|
||||||
// frag_def
|
// frag_def
|
||||||
"uniform sampler2D glowMap;\n"
|
"uniform sampler2D glowMap;\n"
|
||||||
|
@ -326,7 +377,7 @@ void polymer_glinit(void)
|
||||||
|
|
||||||
bglMatrixMode(GL_PROJECTION);
|
bglMatrixMode(GL_PROJECTION);
|
||||||
bglLoadIdentity();
|
bglLoadIdentity();
|
||||||
bgluPerspective((float)(pr_fov) / (2048.0f / 360.0f), (float)xdim / (float)ydim, 0.01f, 100.0f);
|
bgluPerspective((float)(pr_fov) / (2048.0f / 360.0f), (float)xdim / (float)ydim, 0.1f, 100.0f);
|
||||||
|
|
||||||
// get the new projection matrix
|
// get the new projection matrix
|
||||||
bglGetDoublev(GL_PROJECTION_MATRIX, projectionmatrix);
|
bglGetDoublev(GL_PROJECTION_MATRIX, projectionmatrix);
|
||||||
|
@ -1043,6 +1094,8 @@ static void polymer_drawplane(short sectnum, short wallnum, _prplane* pl
|
||||||
|
|
||||||
// bglBindTexture(GL_TEXTURE_2D, plane->material.diffusemap);
|
// bglBindTexture(GL_TEXTURE_2D, plane->material.diffusemap);
|
||||||
|
|
||||||
|
bglNormal3f((float)(plane->plane[0]), (float)(plane->plane[1]), (float)(plane->plane[2]));
|
||||||
|
|
||||||
materialbits = polymer_bindmaterial(plane->material);
|
materialbits = polymer_bindmaterial(plane->material);
|
||||||
|
|
||||||
if (plane->vbo && (pr_vbos > 0))
|
if (plane->vbo && (pr_vbos > 0))
|
||||||
|
@ -2585,6 +2638,7 @@ static int polymer_bindmaterial(_prmaterial material)
|
||||||
(material.diffusemodulation[2] != 1.0f) || (material.diffusemodulation[3] != 1.0f))
|
(material.diffusemodulation[2] != 1.0f) || (material.diffusemodulation[3] != 1.0f))
|
||||||
programbits |= prprogrambits[PR_BIT_DIFFUSE_MODULATION].bit;
|
programbits |= prprogrambits[PR_BIT_DIFFUSE_MODULATION].bit;
|
||||||
|
|
||||||
|
programbits |= prprogrambits[PR_BIT_POINT_LIGHT].bit;
|
||||||
// PR_BIT_DIFFUSE_GLOW_MAP
|
// PR_BIT_DIFFUSE_GLOW_MAP
|
||||||
if (material.glowmap)
|
if (material.glowmap)
|
||||||
programbits |= prprogrambits[PR_BIT_DIFFUSE_GLOW_MAP].bit;
|
programbits |= prprogrambits[PR_BIT_DIFFUSE_GLOW_MAP].bit;
|
||||||
|
@ -2644,6 +2698,14 @@ static int polymer_bindmaterial(_prmaterial material)
|
||||||
material.diffusemodulation[3]);
|
material.diffusemodulation[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PR_BIT_POINT_LIGHT
|
||||||
|
if (programbits & prprogrambits[PR_BIT_POINT_LIGHT].bit)
|
||||||
|
{
|
||||||
|
bglUniform3fARB(prprograms[programbits].uniform_pointLightPosition, 62208, 36864 / 16.0, -6656);
|
||||||
|
bglUniform3fARB(prprograms[programbits].uniform_pointLightColor, 0.1f, 0.1f, 0.5f);
|
||||||
|
bglUniform2fARB(prprograms[programbits].uniform_pointLightRange, 1024.0f, 2048.0f);
|
||||||
|
}
|
||||||
|
|
||||||
// PR_BIT_DIFFUSE_GLOW_MAP
|
// PR_BIT_DIFFUSE_GLOW_MAP
|
||||||
if (programbits & prprogrambits[PR_BIT_DIFFUSE_GLOW_MAP].bit)
|
if (programbits & prprogrambits[PR_BIT_DIFFUSE_GLOW_MAP].bit)
|
||||||
{
|
{
|
||||||
|
@ -2735,8 +2797,13 @@ static void polymer_compileprogram(int programbits)
|
||||||
prprograms[programbits].handle = program;
|
prprograms[programbits].handle = program;
|
||||||
|
|
||||||
if (pr_verbosity >= 1) OSD_Printf("Compiling GPU program with bits %i...\n", programbits);
|
if (pr_verbosity >= 1) OSD_Printf("Compiling GPU program with bits %i...\n", programbits);
|
||||||
if (infobuffer[0])
|
if (infobuffer[0]) {
|
||||||
if (pr_verbosity >= 1) OSD_Printf("Info log:\n%s\n", infobuffer);
|
if (pr_verbosity >= 1) OSD_Printf("Info log:\n%s\n", infobuffer);
|
||||||
|
bglGetShaderSourceARB(vert, PR_INFO_LOG_BUFFER_SIZE, NULL, infobuffer);
|
||||||
|
if (pr_verbosity >= 1) OSD_Printf("Vertex source dump:\n%s\n", infobuffer);
|
||||||
|
bglGetShaderSourceARB(frag, PR_INFO_LOG_BUFFER_SIZE, NULL, infobuffer);
|
||||||
|
if (pr_verbosity >= 1) OSD_Printf("Shader source dump:\n%s\n", infobuffer);
|
||||||
|
}
|
||||||
|
|
||||||
// --------- ATTRIBUTE/UNIFORM LOCATIONS
|
// --------- ATTRIBUTE/UNIFORM LOCATIONS
|
||||||
|
|
||||||
|
@ -2760,6 +2827,13 @@ static void polymer_compileprogram(int programbits)
|
||||||
prprograms[programbits].uniform_detailMap = bglGetUniformLocationARB(program, "detailMap");
|
prprograms[programbits].uniform_detailMap = bglGetUniformLocationARB(program, "detailMap");
|
||||||
prprograms[programbits].uniform_detailScale = bglGetUniformLocationARB(program, "detailScale");
|
prprograms[programbits].uniform_detailScale = bglGetUniformLocationARB(program, "detailScale");
|
||||||
}
|
}
|
||||||
|
// PR_BIT_POINT_LIGHT
|
||||||
|
if (programbits & prprogrambits[PR_BIT_POINT_LIGHT].bit)
|
||||||
|
{
|
||||||
|
prprograms[programbits].uniform_pointLightPosition = bglGetUniformLocationARB(program, "pointLightPosition");
|
||||||
|
prprograms[programbits].uniform_pointLightColor = bglGetUniformLocationARB(program, "pointLightColor");
|
||||||
|
prprograms[programbits].uniform_pointLightRange = bglGetUniformLocationARB(program, "pointLightRange");
|
||||||
|
}
|
||||||
|
|
||||||
// PR_BIT_DIFFUSE_GLOW_MAP
|
// PR_BIT_DIFFUSE_GLOW_MAP
|
||||||
if (programbits & prprogrambits[PR_BIT_DIFFUSE_GLOW_MAP].bit)
|
if (programbits & prprogrambits[PR_BIT_DIFFUSE_GLOW_MAP].bit)
|
||||||
|
|
Loading…
Reference in a new issue