- use default fragment shader for burn and stencil shader, with the time consuming parts disabled by a #define, to avoid code duplication.

This commit is contained in:
Christoph Oelckers 2014-07-10 10:33:07 +02:00
parent 92185f96eb
commit a936629cec
4 changed files with 38 additions and 29 deletions

View File

@ -212,6 +212,27 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
int texture_index = glGetUniformLocation(hShader, "texture2");
if (texture_index > 0) glUniform1i(texture_index, 1);
GLint binaryLength;
void* binary;
FILE* outfile;
GLenum binaryFormat;
//
// Retrieve the binary from the program object
//
glGetProgramiv(hShader, GL_PROGRAM_BINARY_LENGTH, &binaryLength);
binary = (void*)malloc(binaryLength);
glGetProgramBinary(hShader, binaryLength, NULL, &binaryFormat, binary);
//
// Cache the program binary for future runs
//
outfile = fopen(name, "wb");
fwrite(binary, binaryLength, 1, outfile);
fclose(outfile);
free(binary);
glUseProgram(0);
return !!linked;
}
@ -316,8 +337,8 @@ static const FEffectShader effectshaders[]=
{
{ "fogboundary", "shaders/glsl/main.vp", "shaders/glsl/fogboundary.fp", NULL, "" },
{ "spheremap", "shaders/glsl/main.vp", "shaders/glsl/main.fp", "shaders/glsl/func_normal.fp", "#define SPHEREMAP\n" },
{ "burn", "shaders/glsl/burn.vp", "shaders/glsl/burn.fp", NULL, "" },
{ "stencil", "shaders/glsl/stencil.vp", "shaders/glsl/stencil.fp", NULL, "" },
{ "burn", "shaders/glsl/main.vp", "shaders/glsl/burn.fp", NULL, "#define SIMPLE\n" },
{ "stencil", "shaders/glsl/main.vp", "shaders/glsl/stencil.fp", NULL, "#define SIMPLE\n" },
};

View File

@ -1,7 +0,0 @@
void main()
{
gl_FrontColor = gl_Color;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ProjectionMatrix * gl_Vertex;
}

View File

@ -1,7 +1,9 @@
#ifndef SIMPLE // we do not need these for simple shaders
in vec4 aVertex2;
out vec4 pixelpos;
out vec2 glowdist;
#endif
#ifdef UNIFORM_VB
uniform float fakeVB[100];
@ -30,16 +32,23 @@ void main()
#define tc gl_MultiTexCoord0
#endif
vec4 worldcoord = ModelMatrix * mix(vert, aVertex2, uInterpolationFactor);
#ifndef SIMPLE
vec4 worldcoord = ModelMatrix * mix(vert, aVertex2, uInterpolationFactor);
#else
vec4 worldcoord = ModelMatrix * vert;
#endif
vec4 eyeCoordPos = ViewMatrix * worldcoord;
gl_FrontColor = gl_Color;
pixelpos.xyz = worldcoord.xyz;
pixelpos.w = -eyeCoordPos.z/eyeCoordPos.w;
glowdist.x = -((uGlowTopPlane.w + uGlowTopPlane.x * worldcoord.x + uGlowTopPlane.y * worldcoord.z) * uGlowTopPlane.z) - worldcoord.y;
glowdist.y = worldcoord.y + ((uGlowBottomPlane.w + uGlowBottomPlane.x * worldcoord.x + uGlowBottomPlane.y * worldcoord.z) * uGlowBottomPlane.z);
#ifndef SIMPLE
pixelpos.xyz = worldcoord.xyz;
pixelpos.w = -eyeCoordPos.z/eyeCoordPos.w;
glowdist.x = -((uGlowTopPlane.w + uGlowTopPlane.x * worldcoord.x + uGlowTopPlane.y * worldcoord.z) * uGlowTopPlane.z) - worldcoord.y;
glowdist.y = worldcoord.y + ((uGlowBottomPlane.w + uGlowBottomPlane.x * worldcoord.x + uGlowBottomPlane.y * worldcoord.z) * uGlowBottomPlane.z);
#endif
#ifdef SPHEREMAP
vec3 u = normalize(eyeCoordPos.xyz);

View File

@ -1,14 +0,0 @@
out vec4 pixelpos;
void main()
{
// perform exactly the same relevant steps as in the main shader to ensure matching results (that also means including the model matrix here!)
vec4 worldcoord = ModelMatrix * gl_Vertex;
vec4 eyeCoordPos = ViewMatrix * worldcoord;
pixelpos.xyz = worldcoord.xyz;
pixelpos.w = -eyeCoordPos.z/eyeCoordPos.w;
gl_Position = ProjectionMatrix * eyeCoordPos;
}