Renderer, v29.

This commit is contained in:
James Canete 2012-03-21 10:29:55 +00:00
parent 89cb7951fa
commit 245e8532cb
18 changed files with 2166 additions and 1438 deletions

View file

@ -305,6 +305,31 @@ void (APIENTRY * qglRenderbufferStorageMultisampleEXT)(GLenum target, GLsizei sa
#define GL_MAX_SAMPLES_EXT 0x8D57
#endif
#ifndef GL_EXT_texture_sRGB
#define GL_EXT_texture_sRGB
#define GL_SRGB_EXT 0x8C40
#define GL_SRGB8_EXT 0x8C41
#define GL_SRGB_ALPHA_EXT 0x8C42
#define GL_SRGB8_ALPHA8_EXT 0x8C43
#define GL_SLUMINANCE_ALPHA_EXT 0x8C44
#define GL_SLUMINANCE8_ALPHA8_EXT 0x8C45
#define GL_SLUMINANCE_EXT 0x8C46
#define GL_SLUMINANCE8_EXT 0x8C47
#define GL_COMPRESSED_SRGB_EXT 0x8C48
#define GL_COMPRESSED_SRGB_ALPHA_EXT 0x8C49
#define GL_COMPRESSED_SLUMINANCE_EXT 0x8C4A
#define GL_COMPRESSED_SLUMINANCE_ALPHA_EXT 0x8C4B
#define GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C
#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D
#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E
#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F
#endif
#ifndef GL_EXT_framebuffer_sRGB
#define GL_EXT_framebuffer_sRGB
#define GL_FRAMEBUFFER_SRGB_EXT 0x8DB9
#endif
#if defined(WIN32)
// WGL_ARB_create_context
#ifndef WGL_ARB_create_context

View file

@ -575,10 +575,14 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
drawSurf_t *drawSurf;
int oldSort;
float originalTime;
float depth[2];
FBO_t* fbo = NULL;
qboolean inQuery = qfalse;
#ifdef REACTION
float depth[2];
#endif
// save original time for entity shader offsets
originalTime = backEnd.refdef.floatTime;
@ -598,8 +602,11 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
oldPshadowed = qfalse;
oldSort = -1;
depthRange = qfalse;
#ifdef REACTION
depth[0] = 0.f;
depth[1] = 1.f;
#endif
backEnd.pc.c_surfaces += numDrawSurfs;
@ -759,8 +766,10 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
if (!sunflare)
qglDepthRange (0, 1);
#ifdef REACTION
depth[0] = 0;
depth[1] = 1;
#endif
}
oldDepthRange = depthRange;
@ -1266,6 +1275,15 @@ const void *RB_ColorMask(const void *data)
{
const colorMaskCommand_t *cmd = data;
if (glRefConfig.framebufferObject)
{
// reverse color mask, so 0 0 0 0 is the default
backEnd.colorMask[0] = !cmd->rgba[0];
backEnd.colorMask[1] = !cmd->rgba[1];
backEnd.colorMask[2] = !cmd->rgba[2];
backEnd.colorMask[3] = !cmd->rgba[3];
}
qglColorMask(cmd->rgba[0], cmd->rgba[1], cmd->rgba[2], cmd->rgba[3]);
return (const void *)(cmd + 1);
@ -1337,42 +1355,66 @@ const void *RB_SwapBuffers( const void *data ) {
// copy final image to screen
vec2_t texScale;
vec4_t srcBox, dstBox, white;
FBO_t *srcFbo, *dstFbo;
texScale[0] =
texScale[1] = 1.0f;
white[0] =
white[1] =
white[2] = pow(2, tr.overbrightBits); //exp2(tr.overbrightBits);
white[2] =
white[3] = 1.0f;
VectorSet4(dstBox, 0, 0, glConfig.vidWidth, glConfig.vidHeight);
VectorSet4(dstBox, 0, 0, tr.screenScratchFbo->width, tr.screenScratchFbo->height);
if (backEnd.framePostProcessed)
{
// frame was postprocessed into screen fbo, copy from there
VectorSet4(srcBox, 0, 0, tr.screenScratchFbo->width, tr.screenScratchFbo->height);
FBO_Blit(tr.screenScratchFbo, srcBox, texScale, NULL, dstBox, &tr.textureColorShader, white, 0);
srcFbo = tr.screenScratchFbo;
}
else
else if (tr.msaaResolveFbo)
{
// frame still in render fbo, possibly resolve then copy from there
FBO_t *hdrFbo;
if (tr.msaaResolveFbo)
{
// Resolve the MSAA before anything else
// Resolve the MSAA before copying
FBO_ResolveMSAA(tr.renderFbo, tr.msaaResolveFbo);
hdrFbo = tr.msaaResolveFbo;
// need to copy from resolve to screenscratch to fix gamma
srcFbo = tr.msaaResolveFbo;
dstFbo = tr.screenScratchFbo;
VectorSet4(srcBox, 0, 0, srcFbo->width, srcFbo->height);
VectorSet4(dstBox, 0, 0, dstFbo->width, dstFbo->height);
FBO_Blit(srcFbo, srcBox, texScale, dstFbo, dstBox, &tr.textureColorShader, white, 0);
srcFbo = tr.screenScratchFbo;
}
else
hdrFbo = tr.renderFbo;
{
// need to copy from render to screenscratch to fix gamma
srcFbo = tr.renderFbo;
dstFbo = tr.screenScratchFbo;
VectorSet4(srcBox, 0, 0, hdrFbo->width, hdrFbo->height);
VectorSet4(srcBox, 0, 0, srcFbo->width, srcFbo->height);
VectorSet4(dstBox, 0, 0, dstFbo->width, dstFbo->height);
FBO_Blit(hdrFbo, srcBox, texScale, NULL, dstBox, &tr.textureColorShader, white, 0);
FBO_Blit(srcFbo, srcBox, texScale, dstFbo, dstBox, &tr.textureColorShader, white, 0);
srcFbo = tr.screenScratchFbo;
}
VectorSet4(srcBox, 0, 0, srcFbo->width, srcFbo->height);
VectorSet4(dstBox, 0, 0, glConfig.vidWidth, glConfig.vidHeight);
white[0] =
white[1] =
white[2] = pow(2, tr.overbrightBits); //exp2(tr.overbrightBits);
white[3] = 1.0f;
// turn off colormask when copying final image
qglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
FBO_Blit(srcFbo, srcBox, texScale, NULL, dstBox, &tr.textureColorShader, white, 0);
qglColorMask(!backEnd.colorMask[0], !backEnd.colorMask[1], !backEnd.colorMask[2], !backEnd.colorMask[3]);
}
if ( !glState.finishCalled ) {
@ -1405,12 +1447,12 @@ const void *RB_CapShadowMap(const void *data)
if (cmd->cubeSide != -1)
{
GL_BindCubemap(tr.shadowCubemaps[cmd->map]);
qglCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + cmd->cubeSide, 0, GL_RGBA8, backEnd.refdef.x, glConfig.vidHeight - ( backEnd.refdef.y + 256 ), 256, 256, 0);
qglCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + cmd->cubeSide, 0, GL_RGBA8, backEnd.refdef.x, glConfig.vidHeight - ( backEnd.refdef.y + PSHADOW_MAP_SIZE ), PSHADOW_MAP_SIZE, PSHADOW_MAP_SIZE, 0);
}
else
{
GL_Bind(tr.pshadowMaps[cmd->map]);
qglCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, backEnd.refdef.x, glConfig.vidHeight - ( backEnd.refdef.y + 256 ), 256, 256, 0);
qglCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, backEnd.refdef.x, glConfig.vidHeight - ( backEnd.refdef.y + PSHADOW_MAP_SIZE ), PSHADOW_MAP_SIZE, PSHADOW_MAP_SIZE, 0);
}
}
@ -1435,6 +1477,8 @@ const void *RB_PostProcess(const void *data)
texScale[0] =
texScale[1] = 1.0f;
if (glRefConfig.framebufferObject)
{
if (tr.msaaResolveFbo)
{
// Resolve the MSAA before anything else
@ -1443,8 +1487,9 @@ const void *RB_PostProcess(const void *data)
}
else
hdrFbo = tr.renderFbo;
}
if (!r_postProcess->integer)
if (!r_postProcess->integer || !glRefConfig.framebufferObject)
{
// if we have an FBO, just copy it out, otherwise, do nothing.
if (glRefConfig.framebufferObject)

View file

@ -408,7 +408,7 @@ static void R_LoadLightmaps( lump_t *l, lump_t *surfs ) {
// if under an arbitrary value (say 12) grey it out
// this prevents weird splotches in dimly lit areas
if (color[0] + color[1] + color[2] < 12)
if (color[0] + color[1] + color[2] < 12.0f)
{
float avg = (color[0] + color[1] + color[2]) * 0.3333f;
color[0] = avg;
@ -626,11 +626,11 @@ static shader_t *ShaderForShaderNum( int shaderNum, int lightmapNum ) {
shader_t *shader;
dshader_t *dsh;
shaderNum = LittleLong( shaderNum );
if ( shaderNum < 0 || shaderNum >= s_worldData.numShaders ) {
ri.Error( ERR_DROP, "ShaderForShaderNum: bad num %i", shaderNum );
int _shaderNum = LittleLong( shaderNum );
if ( _shaderNum < 0 || _shaderNum >= s_worldData.numShaders ) {
ri.Error( ERR_DROP, "ShaderForShaderNum: bad num %i", _shaderNum );
}
dsh = &s_worldData.shaders[ shaderNum ];
dsh = &s_worldData.shaders[ _shaderNum ];
if ( r_vertexLight->integer || glConfig.hardwareType == GLHW_PERMEDIA2 ) {
lightmapNum = LIGHTMAP_BY_VERTEX;

View file

@ -343,7 +343,8 @@ void RE_StretchPic ( float x, float y, float w, float h,
#define MODE_RED_CYAN 1
#define MODE_RED_BLUE 2
#define MODE_RED_GREEN 3
#define MODE_MAX MODE_RED_GREEN
#define MODE_GREEN_MAGENTA 4
#define MODE_MAX MODE_GREEN_MAGENTA
void R_SetColorMode(GLboolean *rgba, stereoFrame_t stereoFrame, int colormode)
{
@ -359,6 +360,15 @@ void R_SetColorMode(GLboolean *rgba, stereoFrame_t stereoFrame, int colormode)
colormode -= MODE_MAX;
}
if(colormode == MODE_GREEN_MAGENTA)
{
if(stereoFrame == STEREO_LEFT)
rgba[0] = rgba[2] = GL_FALSE;
else if(stereoFrame == STEREO_RIGHT)
rgba[1] = GL_FALSE;
}
else
{
if(stereoFrame == STEREO_LEFT)
rgba[1] = rgba[2] = GL_FALSE;
else if(stereoFrame == STEREO_RIGHT)
@ -371,6 +381,7 @@ void R_SetColorMode(GLboolean *rgba, stereoFrame_t stereoFrame, int colormode)
rgba[2] = GL_FALSE;
}
}
}
/*
@ -482,6 +493,10 @@ void RE_BeginFrame( stereoFrame_t stereoFrame ) {
{
// clear both, front and backbuffer.
qglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
backEnd.colorMask[0] = GL_FALSE;
backEnd.colorMask[1] = GL_FALSE;
backEnd.colorMask[2] = GL_FALSE;
backEnd.colorMask[3] = GL_FALSE;
qglClearColor(0.0f, 0.0f, 0.0f, 1.0f);
qglDrawBuffer(GL_FRONT);
@ -489,6 +504,42 @@ void RE_BeginFrame( stereoFrame_t stereoFrame ) {
qglDrawBuffer(GL_BACK);
qglClear(GL_COLOR_BUFFER_BIT);
if (glRefConfig.framebufferObject)
{
// clear all framebuffers
// FIXME: must be a better way to do this
int i;
for (i = 0; i < 3; i++)
{
if (i == 1 && !tr.msaaResolveFbo)
continue;
switch(i)
{
case 0:
FBO_Bind(tr.renderFbo);
break;
case 1:
FBO_Bind(tr.msaaResolveFbo);
break;
case 2:
FBO_Bind(tr.screenScratchFbo);
break;
}
qglDrawBuffer(GL_FRONT);
qglClear(GL_COLOR_BUFFER_BIT);
qglDrawBuffer(GL_BACK);
qglClear(GL_COLOR_BUFFER_BIT);
}
FBO_Bind(NULL);
}
r_anaglyphMode->modified = qfalse;
}
@ -534,6 +585,10 @@ void RE_BeginFrame( stereoFrame_t stereoFrame ) {
if(r_anaglyphMode->modified)
{
qglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
backEnd.colorMask[0] = 0;
backEnd.colorMask[1] = 0;
backEnd.colorMask[2] = 0;
backEnd.colorMask[3] = 0;
r_anaglyphMode->modified = qfalse;
}

View file

@ -185,40 +185,37 @@ static qboolean GLimp_HaveExtension(const char *ext)
void GLimp_InitExtraExtensions()
{
char *extension;
const char* action[2] = { "ignoring", "using" };
const char* result[3] = { "...ignoring %s\n", "...using %s\n", "...%s not found\n" };
// GL_EXT_multi_draw_arrays
extension = "GL_EXT_multi_draw_arrays";
glRefConfig.multiDrawArrays = qfalse;
qglMultiDrawArraysEXT = NULL;
qglMultiDrawElementsEXT = NULL;
if( GLimp_HaveExtension( "GL_EXT_multi_draw_arrays"))
if( GLimp_HaveExtension( extension ) )
{
qglMultiDrawArraysEXT = (PFNGLMULTIDRAWARRAYSEXTPROC) SDL_GL_GetProcAddress("glMultiDrawArraysEXT");
qglMultiDrawElementsEXT = (PFNGLMULTIDRAWELEMENTSEXTPROC) SDL_GL_GetProcAddress("glMultiDrawElementsEXT");
if ( r_ext_multi_draw_arrays->integer )
{
ri.Printf(PRINT_ALL, "...using GL_EXT_multi_draw_arrays\n");
glRefConfig.multiDrawArrays = qtrue;
ri.Printf(PRINT_ALL, result[glRefConfig.multiDrawArrays], extension);
}
else
{
ri.Printf(PRINT_ALL, "...ignoring GL_EXT_multi_draw_arrays\n");
}
}
else
{
ri.Printf(PRINT_ALL, "...GL_EXT_multi_draw_arrays not found\n");
ri.Printf(PRINT_ALL, result[2], extension);
}
// GL_ARB_vertex_program
//glRefConfig.vertexProgram = qfalse;
extension = "GL_ARB_vertex_program";
qglVertexAttrib4fARB = NULL;
qglVertexAttrib4fvARB = NULL;
qglVertexAttribPointerARB = NULL;
qglEnableVertexAttribArrayARB = NULL;
qglDisableVertexAttribArrayARB = NULL;
if( GLimp_HaveExtension( "GL_ARB_vertex_program"))
if( GLimp_HaveExtension( extension ) )
{
qglVertexAttrib4fARB = (PFNGLVERTEXATTRIB4FARBPROC) SDL_GL_GetProcAddress("glVertexAttrib4fARB");
qglVertexAttrib4fvARB = (PFNGLVERTEXATTRIB4FVARBPROC) SDL_GL_GetProcAddress("glVertexAttrib4fvARB");
@ -227,16 +224,18 @@ void GLimp_InitExtraExtensions()
(PFNGLENABLEVERTEXATTRIBARRAYARBPROC) SDL_GL_GetProcAddress("glEnableVertexAttribArrayARB");
qglDisableVertexAttribArrayARB =
(PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) SDL_GL_GetProcAddress("glDisableVertexAttribArrayARB");
ri.Printf(PRINT_ALL, "...using GL_ARB_vertex_program\n");
ri.Printf(PRINT_ALL, result[1], extension);
//glRefConfig.vertexProgram = qtrue;
}
else
{
ri.Error(ERR_FATAL, "...GL_ARB_vertex_program not found\n");
ri.Error(ERR_FATAL, result[2], extension);
}
// GL_ARB_vertex_buffer_object
//glRefConfig.vertexBufferObject = qfalse;
extension = "GL_ARB_vertex_buffer_object";
qglBindBufferARB = NULL;
qglDeleteBuffersARB = NULL;
qglGenBuffersARB = NULL;
@ -246,7 +245,7 @@ void GLimp_InitExtraExtensions()
qglGetBufferSubDataARB = NULL;
qglGetBufferParameterivARB = NULL;
qglGetBufferPointervARB = NULL;
if( GLimp_HaveExtension( "GL_ARB_vertex_buffer_object"))
if( GLimp_HaveExtension( extension ) )
{
qglBindBufferARB = (PFNGLBINDBUFFERARBPROC) SDL_GL_GetProcAddress("glBindBufferARB");
qglDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC) SDL_GL_GetProcAddress("glDeleteBuffersARB");
@ -257,15 +256,16 @@ void GLimp_InitExtraExtensions()
qglGetBufferSubDataARB = (PFNGLGETBUFFERSUBDATAARBPROC) SDL_GL_GetProcAddress("glGetBufferSubDataARB");
qglGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC) SDL_GL_GetProcAddress("glGetBufferParameterivARB");
qglGetBufferPointervARB = (PFNGLGETBUFFERPOINTERVARBPROC) SDL_GL_GetProcAddress("glGetBufferPointervARB");
ri.Printf(PRINT_ALL, "...using GL_ARB_vertex_buffer_object\n");
ri.Printf(PRINT_ALL, result[1], extension);
//glRefConfig.vertexBufferObject = qtrue;
}
else
{
ri.Error(ERR_FATAL, "...GL_ARB_vertex_buffer_object not found\n");
ri.Error(ERR_FATAL, result[2], extension);
}
// GL_ARB_shader_objects
extension = "GL_ARB_shader_objects";
//glRefConfig.shaderObjects = qfalse;
qglDeleteObjectARB = NULL;
qglGetHandleARB = NULL;
@ -305,7 +305,7 @@ void GLimp_InitExtraExtensions()
qglGetUniformfvARB = NULL;
qglGetUniformivARB = NULL;
qglGetShaderSourceARB = NULL;
if( GLimp_HaveExtension( "GL_ARB_shader_objects"))
if( GLimp_HaveExtension( extension ) )
{
qglDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) SDL_GL_GetProcAddress("glDeleteObjectARB");
qglGetHandleARB = (PFNGLGETHANDLEARBPROC) SDL_GL_GetProcAddress("glGetHandleARB");
@ -345,28 +345,29 @@ void GLimp_InitExtraExtensions()
qglGetUniformfvARB = (PFNGLGETUNIFORMFVARBPROC) SDL_GL_GetProcAddress("glGetUniformfvARB");
qglGetUniformivARB = (PFNGLGETUNIFORMIVARBPROC) SDL_GL_GetProcAddress("glGetUniformivARB");
qglGetShaderSourceARB = (PFNGLGETSHADERSOURCEARBPROC) SDL_GL_GetProcAddress("glGetShaderSourceARB");
ri.Printf(PRINT_ALL, "...using GL_ARB_shader_objects\n");
ri.Printf(PRINT_ALL, result[1], extension);
//glRefConfig.shaderObjects = qtrue;
}
else
{
ri.Error(ERR_FATAL, "...GL_ARB_shader_objects not found\n");
ri.Error(ERR_FATAL, result[2], extension);
}
// GL_ARB_vertex_shader
//glRefConfig.vertexShader = qfalse;
extension = "GL_ARB_vertex_shader";
qglBindAttribLocationARB = NULL;
qglGetActiveAttribARB = NULL;
qglGetAttribLocationARB = NULL;
if( GLimp_HaveExtension( "GL_ARB_vertex_shader"))
if( GLimp_HaveExtension( extension ) )
{
int reservedComponents;
//int reservedComponents;
//qglGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &glConfig.maxVertexUniforms);
//qglGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &glConfig.maxVaryingFloats);
//qglGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &glConfig.maxVertexAttribs);
reservedComponents = 16 * 10; // approximation how many uniforms we have besides the bone matrices
//reservedComponents = 16 * 10; // approximation how many uniforms we have besides the bone matrices
#if 0
if(glConfig.driverType == GLDRV_MESA)
@ -385,12 +386,12 @@ void GLimp_InitExtraExtensions()
qglBindAttribLocationARB = (PFNGLBINDATTRIBLOCATIONARBPROC) SDL_GL_GetProcAddress("glBindAttribLocationARB");
qglGetActiveAttribARB = (PFNGLGETACTIVEATTRIBARBPROC) SDL_GL_GetProcAddress("glGetActiveAttribARB");
qglGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC) SDL_GL_GetProcAddress("glGetAttribLocationARB");
ri.Printf(PRINT_ALL, "...using GL_ARB_vertex_shader\n");
ri.Printf(PRINT_ALL, result[1], extension);
//glRefConfig.vertexShader = qtrue;
}
else
{
ri.Error(ERR_FATAL, "...GL_ARB_vertex_shader not found\n");
ri.Error(ERR_FATAL, result[2], extension);
}
glRefConfig.memInfo = MI_NONE;
@ -404,65 +405,58 @@ void GLimp_InitExtraExtensions()
glRefConfig.memInfo = MI_ATI;
}
extension = "GL_ARB_texture_non_power_of_two";
glRefConfig.textureNonPowerOfTwo = qfalse;
if( GLimp_HaveExtension( "GL_ARB_texture_non_power_of_two" ))
if( GLimp_HaveExtension( extension ) )
{
if(1) //(r_ext_texture_non_power_of_two->integer)
{
glRefConfig.textureNonPowerOfTwo = qtrue;
ri.Printf(PRINT_ALL, "...using GL_ARB_texture_non_power_of_two\n");
}
ri.Printf(PRINT_ALL, result[glRefConfig.textureNonPowerOfTwo], extension);
}
else
{
ri.Printf(PRINT_ALL, "...ignoring GL_ARB_texture_non_power_of_two\n");
}
}
else
{
ri.Printf(PRINT_ALL, "...GL_ARB_texture_non_power_of_two not found\n");
ri.Printf(PRINT_ALL, result[2], extension);
}
// GL_ARB_texture_float
extension = "GL_ARB_texture_float";
glRefConfig.textureFloat = qfalse;
if( GLimp_HaveExtension( "GL_ARB_texture_float" ))
if( GLimp_HaveExtension( extension ) )
{
if( r_ext_texture_float->integer )
{
glRefConfig.textureFloat = qtrue;
ri.Printf(PRINT_ALL, "...using GL_ARB_texture_float\n");
}
ri.Printf(PRINT_ALL, result[glRefConfig.textureFloat], extension);
}
else
{
ri.Printf(PRINT_ALL, "...ignoring GL_ARB_texture_float\n");
}
}
else
{
ri.Printf(PRINT_ALL, "...GL_ARB_texture_float not found\n");
ri.Printf(PRINT_ALL, result[2], extension);
}
// GL_ARB_half_float_pixel
extension = "GL_ARB_texture_float";
glRefConfig.halfFloatPixel = qfalse;
if( GLimp_HaveExtension( "GL_ARB_half_float_pixel" ))
if( GLimp_HaveExtension( extension ) )
{
if( r_arb_half_float_pixel->integer )
{
glRefConfig.halfFloatPixel = qtrue;
ri.Printf(PRINT_ALL, "...using GL_ARB_half_float_pixel\n");
ri.Printf(PRINT_ALL, result[glRefConfig.halfFloatPixel], extension);
}
else
{
ri.Printf(PRINT_ALL, "...ignoring GL_ARB_half_float_pixel\n");
}
}
else
{
ri.Printf(PRINT_ALL, "...GL_ARB_half_float_pixel not found\n");
ri.Printf(PRINT_ALL, result[2], extension);
}
// GL_EXT_framebuffer_object
extension = "GL_EXT_framebuffer_object";
glRefConfig.framebufferObject = qfalse;
if( GLimp_HaveExtension( "GL_EXT_framebuffer_object" ))
if( GLimp_HaveExtension( extension ) )
{
glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE_EXT, &glRefConfig.maxRenderbufferSize);
glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &glRefConfig.maxColorAttachments);
@ -486,25 +480,26 @@ void GLimp_InitExtraExtensions()
qglGenerateMipmapEXT = (PFNGLGENERATEMIPMAPEXTPROC) SDL_GL_GetProcAddress("glGenerateMipmapEXT");
if(r_ext_framebuffer_object->value)
{
glRefConfig.framebufferObject = qtrue;
ri.Printf(PRINT_ALL, "...using GL_EXT_framebuffer_object\n");
ri.Printf(PRINT_ALL, result[glRefConfig.framebufferObject], extension);
}
else
{
ri.Printf(PRINT_ALL, "...ignoring GL_EXT_framebuffer_object\n");
}
}
else
{
ri.Printf(PRINT_ALL, "...GL_EXT_framebuffer_object not found\n");
ri.Printf(PRINT_ALL, result[2], extension);
}
// GL_EXT_packed_depth_stencil
extension = "GL_EXT_packed_depth_stencil";
glRefConfig.packedDepthStencil = qfalse;
if( GLimp_HaveExtension( "GL_EXT_packed_depth_stencil" ))
if( GLimp_HaveExtension(extension))
{
glRefConfig.packedDepthStencil = qtrue;
ri.Printf(PRINT_ALL, result[glRefConfig.packedDepthStencil], extension);
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
// GL_ARB_occlusion_query
@ -521,11 +516,11 @@ void GLimp_InitExtraExtensions()
qglGetQueryObjectivARB = (PFNGLGETQUERYOBJECTIVARBPROC) SDL_GL_GetProcAddress("glGetQueryObjectivARB");
qglGetQueryObjectuivARB = (PFNGLGETQUERYOBJECTUIVARBPROC) SDL_GL_GetProcAddress("glGetQueryObjectuivARB");
glRefConfig.occlusionQuery = qtrue;
ri.Printf(PRINT_ALL, "...%s %s\n", action[glRefConfig.occlusionQuery], extension);
ri.Printf(PRINT_ALL, result[glRefConfig.occlusionQuery], extension);
}
else
{
ri.Printf(PRINT_ALL, "...%s not found\n", extension);
ri.Printf(PRINT_ALL, result[2], extension);
}
// GL_EXT_framebuffer_blit
@ -535,11 +530,11 @@ void GLimp_InitExtraExtensions()
{
qglBlitFramebufferEXT = (void *)SDL_GL_GetProcAddress("glBlitFramebufferEXT");
glRefConfig.framebufferBlit = qtrue;
ri.Printf(PRINT_ALL, "...%s %s\n", action[glRefConfig.framebufferBlit], extension);
ri.Printf(PRINT_ALL, result[glRefConfig.framebufferBlit], extension);
}
else
{
ri.Printf(PRINT_ALL, "...%s not found\n", extension);
ri.Printf(PRINT_ALL, result[2], extension);
}
// GL_EXT_framebuffer_multisample
@ -549,11 +544,40 @@ void GLimp_InitExtraExtensions()
{
qglRenderbufferStorageMultisampleEXT = (void *)SDL_GL_GetProcAddress("glRenderbufferStorageMultisampleEXT");
glRefConfig.framebufferMultisample = qtrue;
ri.Printf(PRINT_ALL, "...%s %s\n", action[glRefConfig.framebufferMultisample], extension);
ri.Printf(PRINT_ALL, result[glRefConfig.framebufferMultisample], extension);
}
else
{
ri.Printf(PRINT_ALL, "...%s not found\n", extension);
ri.Printf(PRINT_ALL, result[2], extension);
}
// GL_EXT_texture_sRGB
extension = "GL_EXT_texture_sRGB";
glRefConfig.texture_srgb = qfalse;
if (GLimp_HaveExtension(extension))
{
if (r_srgb->integer)
glRefConfig.texture_srgb = qtrue;
ri.Printf(PRINT_ALL, result[glRefConfig.texture_srgb], extension);
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
// GL_EXT_framebuffer_sRGB
extension = "GL_EXT_framebuffer_sRGB";
glRefConfig.framebuffer_srgb = qfalse;
if (GLimp_HaveExtension(extension))
{
if (r_srgb->integer)
glRefConfig.framebuffer_srgb = qtrue;
ri.Printf(PRINT_ALL, result[glRefConfig.framebuffer_srgb], extension);
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
}

View file

@ -48,8 +48,12 @@ void Matrix16Ortho( float left, float right, float bottom, float top, float znea
#define VectorCopy5(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3],(b)[4]=(a)[4])
#define OffsetByteToFloat(a) ((float)(a) * 1.0f/127.5f - 1.0f)
#define ByteToFloat(a) ((float)(a) * 1.0f/255.0f)
#define FloatToOffsetByte(a) (byte)(((a) + 1.0f) * 127.5f)
#define ByteToFloat(a) ((float)(a) * 1.0f/255.0f)
#define FloatToByte(a) (byte)((a) * 255.0f)
#define RGBtosRGB(a) (((a) < 0.0031308f) ? (12.92f * (a)) : (1.055f * pow((a), 0.41666f) - 0.055f))
#define sRGBtoRGB(a) (((a) <= 0.04045f) ? ((a) / 12.92f) : (pow((((a) + 0.055f) / 1.055f), 2.4)) )
static ID_INLINE int VectorCompare4(const vec4_t v1, const vec4_t v2)
{

View file

@ -464,7 +464,7 @@ void FBO_Init(void)
FBO_AttachTextureImage(tr.pshadowMaps[i], 0);
FBO_CreateBuffer(tr.pshadowFbos[i], GL_DEPTH_COMPONENT24_ARB, 0, 0);
R_AttachFBOTextureDepth(tr.textureDepthImage->texnum);
//R_AttachFBOTextureDepth(tr.textureDepthImage->texnum);
R_CheckFBO(tr.pshadowFbos[i]);
}
@ -491,11 +491,18 @@ void FBO_Init(void)
}
{
int format;
if (glRefConfig.texture_srgb && glRefConfig.framebuffer_srgb)
format = GL_SRGB8_ALPHA8_EXT;
else
format = GL_RGBA8;
//tr.screenScratchFbo = FBO_Create("_screenscratch", width, height);
tr.screenScratchFbo = FBO_Create("_screenscratch", tr.screenScratchImage->width, tr.screenScratchImage->height);
FBO_Bind(tr.screenScratchFbo);
FBO_CreateBuffer(tr.screenScratchFbo, GL_RGBA8, 0, 0);
FBO_CreateBuffer(tr.screenScratchFbo, format, 0, 0);
FBO_AttachTextureImage(tr.screenScratchImage, 0);
// FIXME: hack: share zbuffer between render fbo and pre-screen fbo

View file

@ -115,15 +115,14 @@ static const char *fallbackGenericShader_fp =
"\n\r\nvarying vec2 var_DiffuseTex;\r\n\r\n#if defined(USE_LIGHTMAP)\r"
"\nvarying vec2 var_LightTex;\r\n#endif\r\n\r\nvarying vec4 var_Co"
"lor;\r\n\r\n\r\nvoid main()\r\n{\r\n\tvec4 color = texture2D(u_DiffuseMap,"
" var_DiffuseTex);\r\n\r\n#if defined(USE_LIGHTMAP)\r\n #if defined(RGBE_LI"
"GHTMAP)\r\n\tvec4 lightSample = texture2D(u_LightMap, var_LightTex).rgba;\r"
"\n\tvec3 directedLight = lightSample.rgb * (exp2(lightSample.a * 255.0 - 12"
"8.0));\r\n\tvec4 color2 = vec4(directedLight, 1.0);\r\n #else\r\n\tvec4 co"
"lor2 = texture2D(u_LightMap, var_LightTex);\r\n #endif\r\n\r\n\tif (u_Text"
"ure1Env == TEXENV_MODULATE)\r\n\t{\r\n\t\tcolor *= color2;\r\n\t}\r\n\telse"
" if (u_Texture1Env == TEXENV_ADD)\r\n\t{\r\n\t\tcolor += color2;\r\n\t}\r\n"
"\telse if (u_Texture1Env == TEXENV_REPLACE)\r\n\t{\r\n\t\tcolor = color2;\r"
"\n\t}\r\n#endif\r\n\r\n\tgl_FragColor = color * var_Color;\r\n}\r\n";
" var_DiffuseTex);\r\n#if defined(USE_LIGHTMAP)\r\n\tvec4 color2 = texture2D"
"(u_LightMap, var_LightTex);\r\n #if defined(RGBE_LIGHTMAP)\r\n\tcolor2.rgb"
" *= exp2(color2.a * 255.0 - 128.0);\r\n\tcolor2.a = 1.0;\r\n #endif\r\n\r"
"\n\tif (u_Texture1Env == TEXENV_MODULATE)\r\n\t{\r\n\t\tcolor *= color2;\r"
"\n\t}\r\n\telse if (u_Texture1Env == TEXENV_ADD)\r\n\t{\r\n\t\tcolor += col"
"or2;\r\n\t}\r\n\telse if (u_Texture1Env == TEXENV_REPLACE)\r\n\t{\r\n\t\tco"
"lor = color2;\r\n\t}\r\n#endif\r\n\r\n\tgl_FragColor = color * var_Color;\r"
"\n}\r\n";
static const char *fallbackTextureColorShader_vp =
"#version 120\r\n\r\nattribute vec4 attr_Position;\r\nattribute vec4 attr_Te"
@ -291,118 +290,116 @@ static const char *fallbackLightallShader_fp =
"ition;\r\n\r\n#if defined(USE_NORMALMAP)\r\nvarying vec3 var_Tangent;"
"\r\nvarying vec3 var_Bitangent;\r\n#endif\r\n\r\nvarying vec3 var"
"_Normal;\r\n\r\n#if defined(USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX)\r\nv"
"arying vec3 var_LightDirection;\r\n#endif\r\n\r\n#if defined(USE_PARAL"
"LAXMAP)\r\nfloat SampleHeight(sampler2D normalMap, vec2 t)\r\n{\r\n #if de"
"fined(SWIZZLE_NORMALMAP)\r\n\treturn texture2D(normalMap, t).r;\r\n #else"
"\r\n\treturn texture2D(normalMap, t).a;\r\n #endif\r\n}\r\n\r\nfloat RayIn"
"tersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap)\r\n{\r\n\tconst i"
"nt linearSearchSteps = 16;\r\n\tconst int binarySearchSteps = 6;\r\n\r\n\tf"
"loat depthStep = 1.0 / float(linearSearchSteps);\r\n\r\n\t// current size o"
"f search window\r\n\tfloat size = depthStep;\r\n\r\n\t// current depth posi"
"tion\r\n\tfloat depth = 0.0;\r\n\r\n\t// best match found (starts with last"
" position 1.0)\r\n\tfloat bestDepth = 1.0;\r\n\r\n\t// search front to back"
" for first point inside object\r\n\tfor(int i = 0; i < linearSearchSteps - "
"1; ++i)\r\n\t{\r\n\t\tdepth += size;\r\n\t\t\r\n\t\tfloat t = SampleHeight("
"normalMap, dp + ds * depth);\r\n\t\t\r\n\t\tif(bestDepth > 0.996)\t\t// if "
"no depth found yet\r\n\t\t\tif(depth >= t)\r\n\t\t\t\tbestDepth = depth;\t/"
"/ store best depth\r\n\t}\r\n\r\n\tdepth = bestDepth;\r\n\t\r\n\t// recurse"
" around first point (depth) for closest match\r\n\tfor(int i = 0; i < binar"
"ySearchSteps; ++i)\r\n\t{\r\n\t\tsize *= 0.5;\r\n\r\n\t\tfloat t = SampleHe"
"ight(normalMap, dp + ds * depth);\r\n\t\t\r\n\t\tif(depth >= t)\r\n\t\t{\r"
"\n\t\t\tbestDepth = depth;\r\n\t\t\tdepth -= 2.0 * size;\r\n\t\t}\r\n\r\n\t"
"\tdepth += size;\r\n\t}\r\n\r\n\treturn bestDepth;\r\n}\r\n#endif\r\n\r\n#i"
"f defined(USE_OREN_NAYAR)\r\nfloat OrenNayar(vec3 N, vec3 L, vec3 E, float "
"NE, float NL, float roughness)\r\n{\r\n\tfloat gamma = dot(E - N * NE, L - "
"N * NL);\r\n\tfloat r_sq = roughness * roughness;\r\n\r\n\tfloat A = 1.0 - "
"0.5 * (r_sq / (r_sq + 0.57));\r\n\tfloat B = 0.45 * (r_sq / (r_sq + 0.09));"
"\r\n\r\n\tfloat alpha = max(acos(NE), acos(NL));\r\n\tfloat beta = min(aco"
"s(NE), acos(NL));\r\n\r\n\tfloat C = sin(alpha) * tan(beta);\r\n\r\n\tretur"
"n (A + B * max(0.0, gamma) * C) * max(0.0, NL);\r\n}\r\n#endif\r\n\r\n#if d"
"efined(USE_COOK_TORRANCE)\r\nfloat CookTorrance(float NH, float NL, float N"
"E, float EH, float fzero, float roughness)\r\n{\r\n\tfloat geo = 2.0 * NH /"
" EH;\r\n\tgeo *= min(NE, NL);\r\n\tgeo = min(1, geo);\r\n\r\n\tfloat r_sq ="
" roughness * roughness;\r\n\tfloat NH_sq = NH * NH;\r\n\tfloat rough = exp("
"(NH_sq - 1.0) / (r_sq * NH_sq)) / (4.0 * r_sq * pow(NH, 4));\r\n\r\n\tfloat"
" fresnel = fzero + (1.0 - fzero) * pow(1.0 - EH, 5);\r\n\r\n\treturn fresne"
"l * geo * rough / NE;\r\n}\r\n#endif\r\n\r\n#if defined(USE_TRIACE)\r\nfloa"
"t TriAce(float NH, float NL, float NE, float EH, float fzero, float shinine"
"ss)\r\n{\t\r\n\tfloat factor = 0.1248582 * shininess + 0.2691817;\r\n\tfloa"
"t fresnel = fzero + (1.0 - fzero) * pow(1.0 - EH, 5);\r\n\r\n\treturn facto"
"r * fresnel * pow(NH, shininess) / max(NL, NE);\r\n}\r\n#endif\r\n\r\nvoid "
"main()\r\n{\r\n#if defined(USE_LIGHTMAP)\r\n #if defined(RGBE_LIGHTMAP)\r"
"\n\tvec4 lightSample = texture2D(u_LightMap, var_LightTex).rgba;\r\n\tvec3 "
"directedLight = lightSample.rgb * (exp2(lightSample.a * 255.0 - 128.0));\r"
"\n #else\r\n\tvec3 directedLight = texture2D(u_LightMap, var_LightTex).rgb"
";\r\n #endif\r\n #if defined(USE_DELUXEMAP)\r\n\tvec3 worldLight = 2.0 * "
"texture2D(u_DeluxeMap, var_LightTex).xyz - vec3(1.0);\r\n #else\r\n\tvec3 "
"worldLight = var_LightDirection;\r\n #endif\r\n#endif\r\n#if defined(USE_L"
"IGHT_VECTOR)\r\n\tvec3 worldLight = u_LightOrigin.xyz - (var_Position * u_L"
"ightOrigin.w);\t\r\n #if defined(USE_INVSQRLIGHT)\r\n\tfloat intensity = 1"
".0 / dot(worldLight, worldLight);\r\n #else\r\n\tfloat intensity = clamp(("
"1.0 - dot(worldLight, worldLight) / (u_LightRadius * u_LightRadius)) * 1.07"
", 0.0, 1.0);\r\n #endif\r\n #if defined(USE_SHADOWMAP)\r\n \tvec3 dist3 "
"= textureCube(u_ShadowMap, worldLight).rgb;\r\n\tfloat dist = dot(dist3, ve"
"c3(1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0)) * u_LightRadius;\r\n\r\n\tinte"
"nsity *= max(sign(dist - length(worldLight)), 0.0);\r\n #endif\r\n\tvec3 d"
"irectedLight = u_DirectedLight * intensity;\r\n\tvec3 ambientLight = u_Amb"
"ientLight;\r\n#endif\r\n#if defined(USE_LIGHT_VERTEX)\r\n\tvec3 directedLig"
"ht = var_Color.rgb;\r\n\tvec3 worldLight = var_LightDirection;\r\n#endif\r"
"\n\r\n#if !(defined(USE_LIGHTMAP) || defined(USE_LIGHT_VECTOR) || defined(U"
"SE_LIGHT_VERTEX))\r\n\tvec3 worldLight = var_Normal;\r\n#endif\r\n\r\n#if d"
"efined(USE_DELUXEMAP) \r\n\tworldLight += var_LightDirection * 0.01;\r\n#en"
"dif\r\n\r\n\tvec3 SampleToView = normalize(u_ViewOrigin - var_Position);\r"
"\n\tvec2 tex = var_DiffuseTex;\r\n\t\r\n\tfloat ambientDiff = 1.0;\r\n\r\n#"
"if defined(USE_NORMALMAP)\r\n\tmat3 tangentToWorld = mat3(var_Tangent.xyz, "
"var_Bitangent.xyz, var_Normal.xyz);\r\n\r\n #if defined(USE_PARALLAXMAP)\r"
"\n\tvec3 offsetDir = normalize(SampleToView * tangentToWorld);\r\n #if 0"
"\r\n float height = SampleHeight(u_NormalMap, tex);\r\n\tfloat dist "
"= 0.05 * height - (0.05 / 2.0);\r\n #else\r\n\toffsetDir.xy *= 0.02 / of"
"fsetDir.z;\r\n\tfloat dist = RayIntersectDisplaceMap(tex, offsetDir.xy, u_N"
"ormalMap);\r\n #endif\t\r\n\ttex += offsetDir.xy * dist;\r\n #endif\r\n"
" #if defined(SWIZZLE_NORMALMAP)\r\n\tvec3 normal;\r\n\tnormal.xy = 2.0 * t"
"exture2D(u_NormalMap, tex).ag - 1.0;\r\n\tnormal.z = sqrt(1.0 - dot(normal."
"xy, normal.xy));\r\n #else\r\n\tvec3 normal = 2.0 * texture2D(u_NormalMap,"
" tex).rgb - 1.0;\r\n #endif\r\n\tvec3 worldNormal = tangentToWorld * norma"
"l;\r\n #if defined(r_normalAmbient)\r\n\tambientDiff = 0.781341 * normal.z"
" + 0.218659;\r\n #endif\r\n#else\r\n\tvec3 worldNormal = var_Normal;\r\n#e"
"ndif\r\n\r\n\tvec4 diffuse = texture2D(u_DiffuseMap, tex);\r\n\t\r\n\tworld"
"Normal = normalize(worldNormal);\r\n\tworldLight = normalize(worldLight);\r"
"\n\r\n#if defined(USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX)\r\n\tdirectedL"
"ight /= max(dot(normalize(var_Normal), worldLight), 0.004);\r\n\r\n #if de"
"fined(r_normalAmbient)\r\n\tvec3 ambientLight = directedLight * r_normalAmb"
"ient;\r\n\tdirectedLight -= ambientLight;\r\n #else\r\n\tvec3 ambientLight"
" = vec3(0);\r\n #endif\r\n#endif\r\n\r\n#if (defined(USE_LIGHTMAP) || defi"
"ned(USE_LIGHT_VECTOR) || defined(USE_LIGHT_VERTEX))\r\n\tfloat NL = max(dot"
"(worldNormal, worldLight), 0.0);\r\n\tfloat NE = max(dot(worldNormal, S"
"ampleToView), 0.00001);\r\n #if defined(USE_OREN_NAYAR)\r\n\tfloat directe"
"dDiff = OrenNayar(worldNormal, worldLight, SampleToView, NE, NL, u_DiffuseR"
"oughness);\r\n #else\r\n\tfloat directedDiff = NL;\r\n #endif\r\n\tdiffus"
"e.rgb *= directedLight * directedDiff + ambientDiff * ambientLight;\r\n#end"
"if\r\n \r\n#if defined(USE_SPECULARMAP) && (defined(USE_LIGHTMAP) || defin"
"ed(USE_LIGHT_VECTOR) || defined(USE_LIGHT_VERTEX))\r\n\tvec4 specular = tex"
"ture2D(u_SpecularMap, tex);\r\n\tfloat shininess = specular.a * 255 + 1.0;"
"\r\n\tfloat fzero = u_SpecularReflectance;\r\n\r\n\tvec3 halfAngle = normal"
"ize(worldLight + SampleToView);\r\n\r\n\tfloat EH = max(dot(SampleToView, h"
"alfAngle), 0.0);\r\n\tfloat NH = max(dot(worldNormal, halfAngle), 0.00001)"
";\r\n\t\r\n #if defined(USE_COOK_TORRANCE)\r\n\tfloat roughness = specular"
".a * -0.99 + 1.0;\r\n\tfloat directedSpec = CookTorrance(NH, NL, NE, EH, fz"
"ero, roughness);\r\n #endif\r\n \r\n #if defined(USE_TRIACE)\r\n\tfloat "
"directedSpec = TriAce(NH, NL, NE, EH, fzero, shininess);\r\n #endif\r\n "
"\r\n #if defined(USE_BLINN)\t\r\n\tfloat directedSpec = pow(NH, shininess)"
";\r\n #endif\r\n \r\n #if defined(r_normalAmbient)\r\n\tvec3 ambientHalf"
" = normalize(var_Normal + SampleToView);\r\n\tfloat ambientSpec = max(dot(a"
"mbientHalf, worldNormal) + 0.5, 0.0);\r\n\tambientSpec *= ambientSpec * 0.4"
"4;\r\n\tambientSpec = pow(ambientSpec, shininess) * fzero;\r\n #if defin"
"ed(USE_TRIACE)\r\n\tambientSpec *= 0.1248582 * shininess + 0.2691817;\r\n "
" #endif \r\n\tspecular.rgb *= min(directedSpec * directedLight + ambien"
"tSpec * ambientLight, 1.0);\r\n #else\r\n\tspecular.rgb *= min(directedSpe"
"c * directedLight, 1.0);\r\n #endif\r\n#endif\r\n\r\n\tgl_FragColor = diff"
"use;\r\n\r\n#if defined(USE_SPECULARMAP) && (defined(USE_LIGHTMAP) || defin"
"ed(USE_LIGHT_VECTOR) || defined(USE_LIGHT_VERTEX))\r\n\tgl_FragColor.rgb +="
" specular.rgb;\r\n#endif\r\n\r\n#if !defined(USE_LIGHT_VERTEX)\r\n\tgl_Frag"
"Color *= var_Color;\r\n#endif\r\n\r\n#if (defined(USE_LIGHTMAP) || defined("
"USE_LIGHT_VECTOR) || defined(USE_LIGHT_VERTEX))\r\n\t//gl_FragColor.rgb = w"
"orldLight * 0.5 + 0.5;\r\n#endif\r\n}\r\n";
"arying vec3 var_LightDirection;\r\n#endif\r\n\r\n#define EPSILON 0.000"
"00001\r\n\r\n#if defined(USE_PARALLAXMAP)\r\nfloat SampleHeight(sampler2D n"
"ormalMap, vec2 t)\r\n{\r\n #if defined(SWIZZLE_NORMALMAP)\r\n\treturn text"
"ure2D(normalMap, t).r;\r\n #else\r\n\treturn texture2D(normalMap, t).a;\r"
"\n #endif\r\n}\r\n\r\nfloat RayIntersectDisplaceMap(vec2 dp, vec2 ds, samp"
"ler2D normalMap)\r\n{\r\n\tconst int linearSearchSteps = 16;\r\n\tconst int"
" binarySearchSteps = 6;\r\n\r\n\tfloat depthStep = 1.0 / float(linearSearch"
"Steps);\r\n\r\n\t// current size of search window\r\n\tfloat size = depthSt"
"ep;\r\n\r\n\t// current depth position\r\n\tfloat depth = 0.0;\r\n\r\n\t// "
"best match found (starts with last position 1.0)\r\n\tfloat bestDepth = 1.0"
";\r\n\r\n\t// search front to back for first point inside object\r\n\tfor(i"
"nt i = 0; i < linearSearchSteps - 1; ++i)\r\n\t{\r\n\t\tdepth += size;\r\n"
"\t\t\r\n\t\tfloat t = SampleHeight(normalMap, dp + ds * depth);\r\n\t\t\r\n"
"\t\tif(bestDepth > 0.996)\t\t// if no depth found yet\r\n\t\t\tif(depth >= "
"t)\r\n\t\t\t\tbestDepth = depth;\t// store best depth\r\n\t}\r\n\r\n\tdepth"
" = bestDepth;\r\n\t\r\n\t// recurse around first point (depth) for closest "
"match\r\n\tfor(int i = 0; i < binarySearchSteps; ++i)\r\n\t{\r\n\t\tsize *="
" 0.5;\r\n\r\n\t\tfloat t = SampleHeight(normalMap, dp + ds * depth);\r\n\t"
"\t\r\n\t\tif(depth >= t)\r\n\t\t{\r\n\t\t\tbestDepth = depth;\r\n\t\t\tdept"
"h -= 2.0 * size;\r\n\t\t}\r\n\r\n\t\tdepth += size;\r\n\t}\r\n\r\n\treturn "
"bestDepth;\r\n}\r\n#endif\r\n\r\n#if defined(USE_OREN_NAYAR)\r\nfloat OrenN"
"ayar(vec3 N, vec3 L, vec3 E, float NE, float NL, float roughness)\r\n{\r\n"
"\tfloat gamma = dot(E - N * NE, L - N * NL);\r\n\tfloat r_sq = roughness * "
"roughness;\r\n\r\n\tfloat A = 1.0 - 0.5 * (r_sq / (r_sq + 0.57));\r\n\tfloa"
"t B = 0.45 * (r_sq / (r_sq + 0.09));\r\n\r\n\tfloat alpha = max(acos(NE), a"
"cos(NL));\r\n\tfloat beta = min(acos(NE), acos(NL));\r\n\r\n\tfloat C = si"
"n(alpha) * tan(beta);\r\n\r\n\treturn (A + B * max(0.0, gamma) * C) * max(0"
".0, NL);\r\n}\r\n#endif\r\n\r\n#if defined(USE_SPECULARMAP)\r\nfloat CalcSp"
"ecular(float NH, float NL, float NE, float EH, float fzero, float shininess"
")\r\n{\r\n #if defined(USE_BLINN) || defined(USE_TRIACE) || defined(USE_TO"
"RRANCE_SPARROW)\r\n\tfloat blinn = pow(NH, shininess);\r\n #endif\r\n\r\n "
" #if defined(USE_BLINN)\r\n\treturn blinn;\r\n #endif\r\n\r\n #if defined"
"(USE_COOK_TORRANCE) || defined (USE_TRIACE) || defined (USE_TORRANCE_SPARRO"
"W)\r\n\tfloat fresnel = fzero + (1.0 - fzero) * pow(1.0 - EH, 5);\r\n #end"
"if\r\n\r\n #if defined(USE_COOK_TORRANCE)\r\n\tfloat roughness = shininess"
" * -0.99 + 1.0;\r\n\r\n\tfloat geo = 2.0 * NH / EH;\r\n\tgeo *= min(NE, NL)"
";\r\n\tgeo = min(1, geo);\r\n\r\n\tfloat r_sq = roughness * roughness;\r\n"
"\tfloat NH_sq = NH * NH;\r\n\tfloat rough = exp((NH_sq - 1.0) / (r_sq * NH_"
"sq)) / (4.0 * r_sq * pow(NH, 4));\r\n\r\n\treturn min(fresnel * geo * rough"
" / NE, 1.0);\r\n #endif\r\n\r\n #if defined(USE_TRIACE) || defined(USE_TO"
"RRANCE_SPARROW)\r\n #if defined(USE_TRIACE)\r\n\tfloat scale = 0.1248582"
" * shininess + 0.2691817;\r\n #else // elif defined(USE_TORRANCE_SPARROW"
")\r\n\tfloat scale = (0.5 * shininess + 1.0) * NH / max(EH, EPSILON);\r\n "
" #endif\r\n\r\n\treturn min(scale * fresnel * blinn / max(max(NL, NE), EPS"
"ILON), 1.0);\r\n #endif\r\n}\r\n#endif\r\n\r\nvoid main()\r\n{\r\n#if defi"
"ned(USE_LIGHTMAP)\r\n #if defined(RGBE_LIGHTMAP)\r\n\tvec4 lightSample = t"
"exture2D(u_LightMap, var_LightTex).rgba;\r\n\tvec3 directedLight = lightSam"
"ple.rgb * exp2(lightSample.a * 255.0 - 128.0);\r\n #else\r\n\tvec3 directe"
"dLight = texture2D(u_LightMap, var_LightTex).rgb;\r\n #endif\r\n #if defi"
"ned(USE_DELUXEMAP)\r\n\tvec3 worldLight = 2.0 * texture2D(u_DeluxeMap, var_"
"LightTex).xyz - vec3(1.0);\r\n #else\r\n\tvec3 worldLight = var_LightDirec"
"tion;\r\n #endif\r\n#endif\r\n#if defined(USE_LIGHT_VECTOR)\r\n\tvec3 worl"
"dLight = u_LightOrigin.xyz - (var_Position * u_LightOrigin.w);\t\r\n #if d"
"efined(USE_INVSQRLIGHT)\r\n\tfloat intensity = 1.0 / dot(worldLight, worldL"
"ight);\r\n #else\r\n\tfloat intensity = clamp((1.0 - dot(worldLight, world"
"Light) / (u_LightRadius * u_LightRadius)) * 1.07, 0.0, 1.0);\r\n #endif\r"
"\n #if defined(USE_SHADOWMAP)\r\n \tvec3 dist3 = textureCube(u_ShadowMap,"
" worldLight).rgb;\r\n\tfloat dist = dot(dist3, vec3(1.0 / (256.0 * 256.0), "
"1.0 / 256.0, 1.0)) * u_LightRadius;\r\n\r\n\tintensity *= max(sign(dist - l"
"ength(worldLight)), 0.0);\r\n #endif\r\n\tvec3 directedLight = u_DirectedL"
"ight * intensity;\r\n\tvec3 ambientLight = u_AmbientLight;\r\n#endif\r\n#i"
"f defined(USE_LIGHT_VERTEX)\r\n\tvec3 directedLight = var_Color.rgb;\r\n\tv"
"ec3 worldLight = var_LightDirection;\r\n#endif\r\n\r\n#if !(defined(USE_LIG"
"HT))\r\n\tvec3 worldLight = var_Normal;\r\n#endif\r\n\r\n#if defined(USE_DE"
"LUXEMAP) \r\n\tworldLight += var_LightDirection * 0.01;\r\n#endif\r\n\r\n\t"
"vec3 SampleToView = normalize(u_ViewOrigin - var_Position);\r\n\tvec2 tex ="
" var_DiffuseTex;\r\n\t\r\n\tfloat ambientDiff = 1.0;\r\n\r\n#if defined(USE"
"_NORMALMAP)\r\n\tmat3 tangentToWorld = mat3(var_Tangent.xyz, var_Bitangent."
"xyz, var_Normal.xyz);\r\n\r\n #if defined(USE_PARALLAXMAP)\r\n\tvec3 offse"
"tDir = normalize(SampleToView * tangentToWorld);\r\n #if 0\r\n float "
"height = SampleHeight(u_NormalMap, tex);\r\n\tfloat pdist = 0.05 * height -"
" (0.05 / 2.0);\r\n #else\r\n\toffsetDir.xy *= 0.02 / offsetDir.z;\r\n\tf"
"loat pdist = RayIntersectDisplaceMap(tex, offsetDir.xy, u_NormalMap);\r\n "
" #endif\t\r\n\ttex += offsetDir.xy * pdist;\r\n #endif\r\n #if defined(S"
"WIZZLE_NORMALMAP)\r\n\tvec3 normal = 2.0 * texture2D(u_NormalMap, tex).agb "
"- 1.0;\r\n #else\r\n\tvec3 normal = 2.0 * texture2D(u_NormalMap, tex).rgb "
"- 1.0;\r\n #endif\r\n\t//normal.z = sqrt(max(1.0 - dot(normal.xy, normal.x"
"y), 0.0));\r\n\tvec3 worldNormal = tangentToWorld * normal;\r\n #if define"
"d(r_normalAmbient)\r\n\tambientDiff = 0.781341 * normal.z + 0.218659;\r\n "
"#endif\r\n#else\r\n\tvec3 worldNormal = var_Normal;\r\n#endif\r\n\r\n\tvec4"
" diffuse = texture2D(u_DiffuseMap, tex);\r\n\t\r\n\tworldNormal = normalize"
"(worldNormal);\r\n\tworldLight = normalize(worldLight);\r\n\r\n#if defined("
"USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX)\r\n\tdirectedLight /= max(dot(no"
"rmalize(var_Normal), worldLight), 0.004);\r\n\r\n #if defined(r_normalAmbi"
"ent)\r\n\tvec3 ambientLight = directedLight * r_normalAmbient;\r\n\tdirecte"
"dLight -= ambientLight;\r\n #else\r\n\tvec3 ambientLight = vec3(0);\r\n #"
"endif\r\n#endif\r\n\r\n#if defined(USE_LIGHT)\r\n\tfloat NL = max(dot(world"
"Normal, worldLight), 0.0);\r\n\tfloat NE = max(dot(worldNormal, SampleT"
"oView), 0.0);\r\n #if defined(USE_OREN_NAYAR)\r\n\tfloat directedDiff = Or"
"enNayar(worldNormal, worldLight, SampleToView, NE, NL, u_DiffuseRoughness);"
"\r\n #else\r\n\tfloat directedDiff = NL;\r\n #endif\r\n\tdiffuse.rgb *= d"
"irectedLight * directedDiff + ambientDiff * ambientLight;\r\n#endif\r\n \r"
"\n#if defined(USE_SPECULARMAP) && defined(USE_LIGHT)\r\n\tvec4 specular = t"
"exture2D(u_SpecularMap, tex);\r\n\tspecular.rgb = min(specular.rgb, 1.0 - d"
"iffuse.rgb);\r\n\tfloat shininess = specular.a * 255 + 1.0;\r\n\tfloat fzer"
"o = u_SpecularReflectance;\r\n\r\n\tvec3 halfAngle = normalize(worldLight +"
" SampleToView);\r\n\r\n\tfloat EH = max(dot(SampleToView, halfAngle), 0.0);"
"\r\n\tfloat NH = max(dot(worldNormal, halfAngle), 0.0);\r\n\t\r\n\tfloat d"
"irectedSpec = CalcSpecular(NH, NL, NE, EH, fzero, shininess);\r\n \r\n #i"
"f defined(r_normalAmbient)\r\n\tvec3 ambientHalf = normalize(var_Normal + S"
"ampleToView);\r\n\tfloat ambientSpec = max(dot(ambientHalf, worldNormal) + "
"0.5, 0.0);\r\n\tambientSpec *= ambientSpec * 0.44;\r\n\tambientSpec = pow(a"
"mbientSpec, shininess) * fzero;\r\n #if defined(USE_TRIACE)\r\n\tambient"
"Spec *= 0.1248582 * shininess + 0.2691817;\r\n #endif \r\n\tspecular."
"rgb *= min(directedSpec * directedLight + ambientSpec * ambientLight, 1.0);"
"\r\n #else\r\n\tspecular.rgb *= min(directedSpec * directedLight, 1.0);\r"
"\n #endif\r\n#endif\r\n\r\n\tgl_FragColor = diffuse;\r\n\r\n#if defined(US"
"E_SPECULARMAP) && defined(USE_LIGHT)\r\n\tgl_FragColor.rgb += specular.rgb;"
"\r\n#endif\r\n\r\n#if !defined(USE_LIGHT_VERTEX)\r\n\tgl_FragColor *= var_C"
"olor;\r\n#endif\r\n}\r\n";
static const char *fallbackShadowfillShader_vp =
"attribute vec4 attr_Position;\r\nattribute vec3 attr_Normal;\r\nattribute"
@ -441,19 +438,20 @@ static const char *fallbackShadowfillShader_vp =
static const char *fallbackShadowfillShader_fp =
"uniform vec4 u_LightOrigin;\r\nuniform float u_LightRadius;\r\n\r\nvarying"
" vec3 var_Position;\r\n\r\nvoid main()\r\n{\r\n\tfloat depth = length(u_Li"
"ghtOrigin.xyz - var_Position) / u_LightRadius;\r\n#if 0\r\n\t// 32 bit prec"
"ision\r\n\tconst vec4 bitSh = vec4( 256 * 256 * 256, 256 * 256, 2"
"56, 1);\r\n\tconst vec4 bitMsk = vec4( 0, 1.0 / 256."
"0, 1.0 / 256.0, 1.0 / 256.0);\r\n\t\r\n\tvec4 comp;\r\n\tcomp = depth * bit"
"Sh;\r\n\tcomp.xyz = fract(comp.xyz);\r\n\tcomp -= comp.xxyz * bitMsk;\r\n\t"
"gl_FragColor = comp;\r\n#endif\r\n\r\n#if 1\r\n\t// 24 bit precision\r\n\tc"
"onst vec3 bitSh = vec3( 256 * 256, 256, 1);\r\n\tconst ve"
"c3 bitMsk = vec3( 0, 1.0 / 256.0, 1.0 / 256.0);\r\n\t\r\n\tvec3 comp"
";\r\n\tcomp = depth * bitSh;\r\n\tcomp.xy = fract(comp.xy);\r\n\tcomp -= co"
"mp.xxy * bitMsk;\r\n\tgl_FragColor = vec4(comp, 1.0);\r\n#endif\r\n\r\n#if "
"0\r\n\t// 8 bit precision\r\n\tgl_FragColor = vec4(depth, depth, depth, 1);"
"\r\n#endif\r\n}\r\n";
" vec3 var_Position;\r\n\r\nvoid main()\r\n{\r\n#if defined(USE_DEPTH)\r\n"
"\tfloat depth = length(u_LightOrigin.xyz - var_Position) / u_LightRadius;\r"
"\n #if 0\r\n\t// 32 bit precision\r\n\tconst vec4 bitSh = vec4( 256 * 256 *"
" 256, 256 * 256, 256, 1);\r\n\tconst vec4 bitMsk = vec4"
"( 0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);\r\n\t\r\n\tvec4 c"
"omp;\r\n\tcomp = depth * bitSh;\r\n\tcomp.xyz = fract(comp.xyz);\r\n\tcomp "
"-= comp.xxyz * bitMsk;\r\n\tgl_FragColor = comp;\r\n #endif\r\n\r\n #if 1\r"
"\n\t// 24 bit precision\r\n\tconst vec3 bitSh = vec3( 256 * 256, 25"
"6, 1);\r\n\tconst vec3 bitMsk = vec3( 0, 1.0 / 256.0, 1.0 "
"/ 256.0);\r\n\t\r\n\tvec3 comp;\r\n\tcomp = depth * bitSh;\r\n\tcomp.xy = f"
"ract(comp.xy);\r\n\tcomp -= comp.xxy * bitMsk;\r\n\tgl_FragColor = vec4(com"
"p, 1.0);\r\n #endif\r\n\r\n #if 0\r\n\t// 8 bit precision\r\n\tgl_FragColor"
" = vec4(depth, depth, depth, 1);\r\n #endif\r\n#else\r\n\tgl_FragColor = ve"
"c4(0, 0, 0, 1);\r\n#endif\r\n}\r\n";
static const char *fallbackPshadowShader_vp =
"attribute vec4 attr_Position;\r\nattribute vec3 attr_Normal;\r\n\r\nuniform"
@ -484,23 +482,22 @@ static const char *fallbackPshadowShader_fp =
"discard;\r\n\t}\r\n\r\n\tif (dot(var_Normal, lightToPos) > 0.0)\r\n\t{\r\n"
"\t\tdiscard;\r\n\t}\r\n#else\r\n\tintensity *= max(sign(dot(u_LightForward,"
" lightToPos)), 0.0);\r\n\tintensity *= max(sign(-dot(var_Normal, lightToPos"
")), 0.0);\r\n#endif\r\n\r\n\tintensity *= fade;\r\n\t\r\n#if defined(USE_PC"
"F)\r\n\tfloat part;\r\n\t\r\n\tdist = sampleDistMap(u_ShadowMap, st + vec2("
"-1.0/256.0, -1.0/256.0), u_LightRadius);\r\n\tpart = max(sign(lightDist - "
"dist), 0.0);\r\n\r\n\tdist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/256."
"0, -1.0/256.0), u_LightRadius);\r\n\tpart += max(sign(lightDist - dist), 0."
"0);\r\n\r\n\tdist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/256.0, 1.0/2"
"56.0), u_LightRadius);\r\n\tpart += max(sign(lightDist - dist), 0.0);\r\n\r"
"\n\tdist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/256.0, 1.0/256.0), u_"
"LightRadius);\r\n\tpart += max(sign(lightDist - dist), 0.0);\r\n\r\n #if de"
"fined(USE_DISCARD)\r\n\tif (part <= 0.0)\r\n\t{\r\n\t\tdiscard;\r\n\t}\r\n "
"#endif\r\n\r\n\tintensity *= part * 0.25;\r\n#else\r\n\tdist = sampleDistMa"
"p(u_ShadowMap, st, u_LightRadius);\r\n\r\n #if defined(USE_DISCARD)\r\n\tif"
" (lightDist - dist <= 0.0)\r\n\t{\r\n\t\tdiscard;\r\n\t}\r\n #endif\r\n\t\t"
"\t\r\n\t//intensity *= max(sign(254.0 / 255.0 - dist / u_LightRadius), 0.0)"
";\r\n\tintensity *= max(sign(lightDist - dist), 0.0);\r\n#endif\r\n\t\t\r\n"
"\tgl_FragColor.rgb = vec3(0);\r\n\tgl_FragColor.a = clamp(intensity, 0.0, 0"
".75);\r\n}\r\n";
")), 0.0);\r\n#endif\r\n\r\n\tintensity *= fade;\r\n#if defined(USE_PCF)\r\n"
"\tfloat part;\r\n\t\r\n\tdist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/5"
"12.0, -1.0/512.0), u_LightRadius);\r\n\tpart = max(sign(lightDist - dist),"
" 0.0);\r\n\r\n\tdist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/512.0, -1."
"0/512.0), u_LightRadius);\r\n\tpart += max(sign(lightDist - dist), 0.0);\r"
"\n\r\n\tdist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/512.0, 1.0/512.0)"
", u_LightRadius);\r\n\tpart += max(sign(lightDist - dist), 0.0);\r\n\r\n\td"
"ist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/512.0, 1.0/512.0), u_Light"
"Radius);\r\n\tpart += max(sign(lightDist - dist), 0.0);\r\n\r\n #if define"
"d(USE_DISCARD)\r\n\tif (part <= 0.0)\r\n\t{\r\n\t\tdiscard;\r\n\t}\r\n #en"
"dif\r\n\r\n\tintensity *= part * 0.25;\r\n#else\r\n\tdist = sampleDistMap(u"
"_ShadowMap, st, u_LightRadius);\r\n\r\n #if defined(USE_DISCARD)\r\n\tif ("
"lightDist - dist <= 0.0)\r\n\t{\r\n\t\tdiscard;\r\n\t}\r\n #endif\r\n\t\t"
"\t\r\n\tintensity *= max(sign(lightDist - dist), 0.0);\r\n#endif\r\n\t\t\r"
"\n\tgl_FragColor.rgb = vec3(0);\r\n\tgl_FragColor.a = clamp(intensity, 0.0,"
" 0.75);\r\n}\r\n";
static const char *fallbackDown4xShader_vp =
"attribute vec4 attr_Position;\r\nattribute vec4 attr_TexCoord0;\r\n\r\nunif"
@ -614,30 +611,23 @@ static const char *fallbackToneMapShader_fp =
"iform vec4 u_Color;\r\n\r\nuniform vec2 u_InvTexRes;\r\nuniform v"
"ec2 u_AutoExposureMinMax;\r\n\r\nvarying vec2 var_TexCoords;\r\n"
"\r\nconst vec3 LUMINANCE_VECTOR = vec3(0.2125, 0.7154, 0.0721); //vec3(0"
".299, 0.587, 0.114);\r\n\r\n#if 1\r\nvec3 RGB2Yxy(vec3 RGB)\r\n{\r\n\tconst"
" mat3 RGB2XYZ = mat3(\r\n\t\t0.4124564, 0.3575761, 0.1804375, \r\n\t\t0.2"
"126729, 0.7151522, 0.0721750, \r\n\t\t0.0193339, 0.1191920, 0.9503041);"
"\r\n\r\n\tvec3 XYZ = RGB2XYZ * RGB;\r\n\r\n\tfloat scale = 1.0f / (XYZ.r + "
"XYZ.g + XYZ.b);\r\n\r\n\treturn XYZ.grg * vec3(1.0, scale, scale);\r\n}\r\n"
"\r\nvec3 Yxy2RGB(vec3 Yxy)\r\n{\r\n\tconst mat3 XYZ2RGB = mat3(\r\n\t\t 3."
"2404542, -1.5371385, -0.4985314,\r\n\t\t-0.9692660, 1.8760108, 0.0415560,"
"\r\n\t\t 0.0556434, -0.2040259, 1.0572252);\r\n\r\n\tvec3 XYZ = Yxy.rrr;\r"
"\n\tfloat invy = 1.0 / Yxy.b;\r\n\tfloat xdivy = Yxy.g * invy;\r\n\t\r\n\tX"
"YZ *= vec3(xdivy, 1.0, invy - xdivy - 1.0);\r\n\t\t\r\n\treturn clamp(XYZ2R"
"GB * XYZ, 0.0, 1.0);\r\n}\r\n#endif\r\n\r\nvoid main()\r\n{\r\n\tvec4 color"
" = texture2D(u_TextureMap, var_TexCoords) * u_Color;\r\n\tvec3 minAvgMax = "
"texture2D(u_LevelsMap, var_TexCoords).rgb;\r\n\tvec3 logMinAvgMaxLum = clam"
"p(minAvgMax * 20.0 - 10.0, -u_AutoExposureMinMax.y, -u_AutoExposureMinMax.x"
");\r\n\t\t\r\n\tfloat avgLum = exp2(logMinAvgMaxLum.y) ;\r\n\tfloat maxLum "
"= exp2(logMinAvgMaxLum.z);\r\n\t\t\r\n\tvec3 Yxy = RGB2Yxy(color.rgb);\r\n"
"\tfloat lscale = 1000000000.0;\r\n\tfloat lkey = 1.03 - (2.0 / (2.0 + log(a"
"vgLum * lscale + 1.0) / log(10.0)));\r\n\tfloat lmax = 2.0;\r\n\t//float lu"
"mi = max(dot(LUMINANCE_VECTOR, color.rgb), 0.000001);\r\n\tfloat lumi = Yxy"
".r;\r\n\tfloat newLumi = lumi * lkey / avgLum;\r\n\tnewLumi = newLumi * (1."
"0 + newLumi / (lmax * lmax)) / (1.0 + newLumi);\r\n\t\r\n#if defined(r_obbc"
"orrect)\r\n\tnewLumi /= r_obbcorrect;\r\n#endif\r\n\r\n\tYxy.r = newLumi;\r"
"\n\tgl_FragColor.rgb = Yxy2RGB(Yxy);\r\n\t//gl_FragColor.rgb = color.rgb / "
"lumi * newLumi;\r\n\tgl_FragColor.a = color.a;\r\n}\r\n";
".299, 0.587, 0.114);\r\n\r\nfloat FilmicTonemap(float x)\r\n{\r\n\tfloat sh"
"oulderStrength = 0.22;\r\n\tfloat linearStrength = 0.30;\r\n\tfloat linearA"
"ngle = 0.10;\r\n\tfloat toeStrength = 0.20;\r\n\tfloat toeAngleNumerator = "
"0.01;\r\n\tfloat toeAngleDenominator = 0.30;\r\n float toeAngle = toeAng"
"leNumerator / toeAngleDenominator;\r\n\t\r\n\treturn ((x*(shoulderStrength*"
"x+linearAngle*linearStrength)+toeStrength*toeAngleNumerator)/\r\n\t(x*(shou"
"lderStrength*x+linearStrength)+toeStrength*toeAngleDenominator)) - toeAngle"
";\r\n}\r\n\r\nvoid main()\r\n{\r\n\tvec4 color = texture2D(u_TextureMap, va"
"r_TexCoords) * u_Color;\r\n\tvec3 minAvgMax = texture2D(u_LevelsMap, var_Te"
"xCoords).rgb;\r\n\tvec3 logMinAvgMaxLum = clamp(minAvgMax * 20.0 - 10.0, -u"
"_AutoExposureMinMax.y, -u_AutoExposureMinMax.x);\r\n\t\t\r\n\tfloat avgLum "
"= exp2(logMinAvgMaxLum.y) ;\r\n\tfloat maxLum = exp2(logMinAvgMaxLum.z);\r"
"\n\r\n\tfloat fWhite = 1.0 / FilmicTonemap(avgLum * 2);\r\n\tcolor.r = Film"
"icTonemap(color.r) * fWhite;\r\n\tcolor.g = FilmicTonemap(color.g) * fWhite"
";\r\n\tcolor.b = FilmicTonemap(color.b) * fWhite;\r\n\t\r\n#if defined(r_ob"
"bcorrect)\r\n\tcolor.rgb /= r_obbcorrect;\r\n#endif\r\n\t\r\n\tgl_FragColor"
" = color;\r\n}\r\n";
static const char *fallbackCalcLevels4xShader_vp =
"attribute vec4 attr_Position;\r\nattribute vec4 attr_TexCoord0;\r\n\r\nunif"
@ -1732,6 +1722,10 @@ void GLSL_InitGPUShaders(void)
if (r_hdr->integer && !(glRefConfig.textureFloat && glRefConfig.halfFloatPixel))
Q_strcat(extradefines, 1024, "#define RGBE_LIGHTMAP\n");
if (i & LIGHTDEF_LIGHTTYPE_MASK)
{
Q_strcat(extradefines, 1024, "#define USE_LIGHT\n");
switch (i & LIGHTDEF_LIGHTTYPE_MASK)
{
case LIGHTDEF_USE_LIGHTMAP:
@ -1748,8 +1742,9 @@ void GLSL_InitGPUShaders(void)
default:
break;
}
}
if (i & LIGHTDEF_USE_NORMALMAP && r_normalMapping->integer)
if ((i & LIGHTDEF_USE_NORMALMAP) && r_normalMapping->integer)
{
Q_strcat(extradefines, 1024, "#define USE_NORMALMAP\n");
@ -1759,7 +1754,7 @@ void GLSL_InitGPUShaders(void)
attribs |= ATTR_TANGENT | ATTR_BITANGENT;
}
if (i & LIGHTDEF_USE_SPECULARMAP && r_specularMapping->integer)
if ((i & LIGHTDEF_USE_SPECULARMAP) && r_specularMapping->integer)
{
Q_strcat(extradefines, 1024, "#define USE_SPECULARMAP\n");
@ -1777,13 +1772,17 @@ void GLSL_InitGPUShaders(void)
case 3:
Q_strcat(extradefines, 1024, "#define USE_COOK_TORRANCE\n");
break;
case 4:
Q_strcat(extradefines, 1024, "#define USE_TORRANCE_SPARROW\n");
break;
}
}
if (i & LIGHTDEF_USE_DELUXEMAP && r_deluxeMapping->integer)
if ((i & LIGHTDEF_USE_DELUXEMAP) && r_deluxeMapping->integer)
Q_strcat(extradefines, 1024, "#define USE_DELUXEMAP\n");
if (i & LIGHTDEF_USE_PARALLAXMAP && !(i & LIGHTDEF_ENTITY) && r_parallaxMapping->integer)
if ((i & LIGHTDEF_USE_PARALLAXMAP) && !(i & LIGHTDEF_ENTITY) && r_parallaxMapping->integer)
Q_strcat(extradefines, 1024, "#define USE_PARALLAXMAP\n");
if (i & LIGHTDEF_TCGEN_ENVIRONMENT)
@ -1847,12 +1846,13 @@ void GLSL_InitGPUShaders(void)
numLightShaders++;
}
attribs = ATTR_POSITION | ATTR_POSITION2 | ATTR_NORMAL | ATTR_NORMAL2 | ATTR_TEXCOORD;
if (!GLSL_InitGPUShader(&tr.shadowmapShader, "shadowfill", attribs, qtrue, NULL, qtrue, fallbackShadowfillShader_vp, fallbackShadowfillShader_fp, GENERIC_UNIFORM_COUNT))
extradefines[0] = '\0';
if (!GLSL_InitGPUShader(&tr.shadowmapShader, "shadowfill", attribs, qtrue, extradefines, qtrue, fallbackShadowfillShader_vp, fallbackShadowfillShader_fp, GENERIC_UNIFORM_COUNT))
{
ri.Error(ERR_FATAL, "Could not load depth shader!\n");
ri.Error(ERR_FATAL, "Could not load shadowfill shader!\n");
}
GLSL_AddUniform(&tr.shadowmapShader, GENERIC_UNIFORM_DEFORMGEN, "u_DeformGen", GLSL_INT);
@ -1870,7 +1870,6 @@ void GLSL_InitGPUShaders(void)
numEtcShaders++;
attribs = ATTR_POSITION | ATTR_NORMAL;
extradefines[0] = '\0';
@ -2071,27 +2070,21 @@ void GLSL_ShutdownGPUShaders(void)
GLSL_BindNullProgram();
for ( i = 0; i < GENERICDEF_COUNT; i++)
{
GLSL_DeleteGPUShader(&tr.genericShader[i]);
}
GLSL_DeleteGPUShader(&tr.textureColorShader);
GLSL_DeleteGPUShader(&tr.fogShader);
GLSL_DeleteGPUShader(&tr.dlightallShader);
for ( i = 0; i < LIGHTDEF_COUNT; i++)
{
GLSL_DeleteGPUShader(&tr.lightallShader[i]);
}
GLSL_DeleteGPUShader(&tr.shadowmapShader);
GLSL_DeleteGPUShader(&tr.pshadowShader);
GLSL_DeleteGPUShader(&tr.down4xShader);
for ( i = 0; i < 2; i++)
{
GLSL_DeleteGPUShader(&tr.calclevels4xShader[i]);
}
glState.currentProgram = 0;
qglUseProgramObjectARB(0);

File diff suppressed because it is too large Load diff

View file

@ -34,6 +34,10 @@ glstate_t glState;
static void GfxInfo_f( void );
static void GfxMemInfo_f( void );
#ifdef USE_RENDERER_DLOPEN
cvar_t *com_altivec;
#endif
cvar_t *r_flareSize;
cvar_t *r_flareFade;
cvar_t *r_flareCoeff;
@ -107,6 +111,8 @@ cvar_t *r_postProcess;
cvar_t *r_toneMap;
cvar_t *r_autoExposure;
cvar_t *r_srgb;
cvar_t *r_normalMapping;
cvar_t *r_specularMapping;
cvar_t *r_deluxeMapping;
@ -119,6 +125,7 @@ cvar_t *r_pshadowDist;
cvar_t *r_imageUpsample;
cvar_t *r_imageUpsampleMaxSize;
cvar_t *r_imageUpsampleType;
cvar_t *r_genNormalMaps;
cvar_t *r_ignoreGLErrors;
cvar_t *r_logFile;
@ -908,6 +915,11 @@ void GL_SetDefaultState( void )
glState.currentVBO = NULL;
glState.currentIBO = NULL;
if (glRefConfig.framebuffer_srgb)
{
qglEnable(GL_FRAMEBUFFER_SRGB_EXT);
}
qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
qglDepthMask( GL_TRUE );
qglDisable( GL_DEPTH_TEST );
@ -1067,6 +1079,10 @@ R_Register
*/
void R_Register( void )
{
#ifdef USE_RENDERER_DLOPEN
com_altivec = ri.Cvar_Get("com_altivec", "1", CVAR_ARCHIVE);
#endif
//
// latched and archived variables
//
@ -1120,6 +1136,8 @@ void R_Register( void )
r_autoExposure = ri.Cvar_Get( "r_autoExposure", "1", CVAR_ARCHIVE );
r_cameraExposure = ri.Cvar_Get( "r_cameraExposure", "0", CVAR_CHEAT );
r_srgb = ri.Cvar_Get( "r_srgb", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_normalMapping = ri.Cvar_Get( "r_normalMapping", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_specularMapping = ri.Cvar_Get( "r_specularMapping", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_deluxeMapping = ri.Cvar_Get( "r_deluxeMapping", "1", CVAR_ARCHIVE | CVAR_LATCH );
@ -1132,6 +1150,7 @@ void R_Register( void )
r_imageUpsample = ri.Cvar_Get( "r_imageUpsample", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_imageUpsampleMaxSize = ri.Cvar_Get( "r_imageUpsampleMaxSize", "1024", CVAR_ARCHIVE | CVAR_LATCH );
r_imageUpsampleType = ri.Cvar_Get( "r_imageUpsampleType", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_genNormalMaps = ri.Cvar_Get( "r_genNormalMaps", "0", CVAR_ARCHIVE | CVAR_LATCH );
//
// temporary latched variables that can only change over a restart

View file

@ -442,7 +442,7 @@ int R_LightDirForPoint( vec3_t point, vec3_t lightDir, vec3_t normal, world_t *w
VectorCopy( point, ent.e.origin );
R_SetupEntityLightingGrid( &ent, world );
if ((DotProduct(ent.lightDir, ent.lightDir) < 0.9f) || (DotProduct(ent.lightDir, normal) < 0.3f))
if ((DotProduct(ent.lightDir, ent.lightDir) < 0.9f) || (DotProduct(ent.lightDir, normal) < 0.1f))
{
VectorCopy(normal, lightDir);
}

View file

@ -66,6 +66,7 @@ typedef unsigned int glIndex_t;
#define MAX_CALC_PSHADOWS 64
#define MAX_DRAWN_PSHADOWS 16 // do not increase past 32, because bit flags are used on surfaces
#define PSHADOW_MAP_SIZE 512
typedef struct dlight_s {
vec3_t origin;
@ -116,6 +117,8 @@ typedef enum
IMGFLAG_NORMALIZED = 0x0020,
IMGFLAG_NOLIGHTSCALE = 0x0040,
IMGFLAG_CLAMPTOEDGE = 0x0080,
IMGFLAG_SRGB = 0x0100,
IMGFLAG_GENNORMALMAP = 0x0200,
} imgFlags_t;
typedef struct image_s {
@ -940,6 +943,7 @@ typedef struct {
qboolean isPortal; // true if this view is through a portal
qboolean isMirror; // the portal is a mirror, invert the face culling
qboolean isShadowmap;
qboolean isDepthShadow;
int frameSceneNum; // copied from tr.frameSceneNum
int frameCount; // copied from tr.frameCount
cplane_t portalPlane; // clip anything behind this if mirroring
@ -1527,7 +1531,7 @@ the bits are allocated as follows:
*/
#define QSORT_FOGNUM_SHIFT 2
#define QSORT_ENTITYNUM_SHIFT 7
#define QSORT_SHADERNUM_SHIFT (QSORT_ENTITYNUM_SHIFT+GENTITYNUM_BITS)
#define QSORT_SHADERNUM_SHIFT (QSORT_ENTITYNUM_SHIFT+ENTITYNUM_BITS)
#if (QSORT_SHADERNUM_SHIFT+SHADERNUM_BITS) > 32
#error "Need to update sorting, too many bits."
#endif
@ -1602,6 +1606,9 @@ typedef struct {
qboolean framebufferMultisample;
qboolean framebufferBlit;
qboolean texture_srgb;
qboolean framebuffer_srgb;
} glRefConfig_t;
@ -1660,6 +1667,7 @@ typedef struct {
trRefEntity_t entity2D; // currentEntity will point at this when doing 2D rendering
FBO_t *last2DFBO;
qboolean colorMask[4];
qboolean framePostProcessed;
} backEndState_t;
@ -1965,6 +1973,8 @@ extern cvar_t *r_toneMap;
extern cvar_t *r_autoExposure;
extern cvar_t *r_cameraExposure;
extern cvar_t *r_srgb;
extern cvar_t *r_normalMapping;
extern cvar_t *r_specularMapping;
extern cvar_t *r_deluxeMapping;
@ -1977,6 +1987,7 @@ extern cvar_t *r_mergeLightmaps;
extern cvar_t *r_imageUpsample;
extern cvar_t *r_imageUpsampleMaxSize;
extern cvar_t *r_imageUpsampleType;
extern cvar_t *r_genNormalMaps;
extern cvar_t *r_greyscale;
@ -2109,8 +2120,7 @@ qboolean R_GetEntityToken( char *buffer, int size );
model_t *R_AllocModel( void );
void R_Init( void );
image_t *R_FindImageFile( const char *name, qboolean mipmap, qboolean allowPicmip, int glWrapClampMode );
image_t *R_FindImageFile2( const char *name, imgFlags_t flags );
image_t *R_FindImageFile( const char *name, imgFlags_t flags );
image_t *R_CreateImage( const char *name, byte *pic, int width, int height, qboolean mipmap
, qboolean allowPicmip, int wrapClampMode );
image_t *R_CreateImage2( const char *name, byte *pic, int width, int height, imgFlags_t flags, int internalFormat );

View file

@ -2100,9 +2100,9 @@ void R_RenderDlightCubemaps(const refdef_t *fd)
Com_Memset( &shadowParms, 0, sizeof( shadowParms ) );
shadowParms.viewportX = tr.refdef.x;
shadowParms.viewportY = glConfig.vidHeight - ( tr.refdef.y + 256 );
shadowParms.viewportWidth = 256;
shadowParms.viewportHeight = 256;
shadowParms.viewportY = glConfig.vidHeight - ( tr.refdef.y + PSHADOW_MAP_SIZE );
shadowParms.viewportWidth = PSHADOW_MAP_SIZE;
shadowParms.viewportHeight = PSHADOW_MAP_SIZE;
shadowParms.isPortal = qfalse;
shadowParms.isMirror = qtrue; // because it is
@ -2110,6 +2110,7 @@ void R_RenderDlightCubemaps(const refdef_t *fd)
shadowParms.fovY = 90;
shadowParms.isShadowmap = qtrue;
shadowParms.isDepthShadow = qtrue;
shadowParms.zFar = tr.refdef.dlights[i].radius;
VectorCopy( tr.refdef.dlights[i].origin, shadowParms.or.origin );
@ -2402,10 +2403,10 @@ void R_RenderPshadowMaps(const refdef_t *fd)
else
{
shadowParms.viewportX = tr.refdef.x;
shadowParms.viewportY = glConfig.vidHeight - ( tr.refdef.y + 256 );
shadowParms.viewportY = glConfig.vidHeight - ( tr.refdef.y + PSHADOW_MAP_SIZE );
}
shadowParms.viewportWidth = 256;
shadowParms.viewportHeight = 256;
shadowParms.viewportWidth = PSHADOW_MAP_SIZE;
shadowParms.viewportHeight = PSHADOW_MAP_SIZE;
shadowParms.isPortal = qfalse;
shadowParms.isMirror = qfalse;
@ -2416,6 +2417,7 @@ void R_RenderPshadowMaps(const refdef_t *fd)
shadowParms.targetFbo = tr.pshadowFbos[i];
shadowParms.isShadowmap = qtrue;
shadowParms.isDepthShadow = qtrue;
shadowParms.zFar = shadow->lightRadius;

View file

@ -484,7 +484,7 @@ static void RB_VBlur(FBO_t *srcFbo, FBO_t *dstFbo, float strength)
void RB_GaussianBlur(float blur)
{
float mul = 1.f;
//float mul = 1.f;
float factor = Com_Clamp(0.f, 1.f, blur);
if (factor <= 0.f)

View file

@ -689,8 +689,8 @@ static void ComputeFogColorMask( shaderStage_t *pStage, vec4_t fogColorMask )
static void ForwardDlight( void ) {
int l;
vec3_t origin;
float scale;
//vec3_t origin;
//float scale;
float radius;
int deformGen;
@ -721,15 +721,15 @@ static void ForwardDlight( void ) {
}
dl = &backEnd.refdef.dlights[l];
VectorCopy( dl->transformed, origin );
//VectorCopy( dl->transformed, origin );
radius = dl->radius;
scale = 1.0f / radius;
//scale = 1.0f / radius;
//if (pStage->glslShaderGroup == tr.lightallShader)
{
int index = pStage->glslShaderIndex;
index &= ~(LIGHTDEF_USE_LIGHTMAP | LIGHTDEF_USE_DELUXEMAP);
index &= ~(LIGHTDEF_LIGHTTYPE_MASK | LIGHTDEF_USE_DELUXEMAP);
index |= LIGHTDEF_USE_LIGHT_VECTOR;
sp = &tr.lightallShader[index];
@ -1399,7 +1399,7 @@ void RB_StageIteratorGeneric( void )
if ( tess.dlightBits && tess.shader->sort <= SS_OPAQUE
&& !(tess.shader->surfaceFlags & (SURF_NODLIGHT | SURF_SKY) ) ) {
if (tess.shader->numUnfoggedPasses == 1 && tess.xstages[0]->glslShaderGroup == tr.lightallShader
&& r_dlightMode->integer)
&& (tess.xstages[0]->glslShaderIndex & LIGHTDEF_LIGHTTYPE_MASK) && r_dlightMode->integer)
{
ForwardDlight();
}

View file

@ -661,38 +661,25 @@ static qboolean ParseStage( shaderStage_t *stage, char **text )
flags |= IMGFLAG_PICMIP;
if (stage->type == ST_NORMALMAP || stage->type == ST_NORMALPARALLAXMAP)
{
flags |= IMGFLAG_SWIZZLE | IMGFLAG_NORMALIZED | IMGFLAG_NOLIGHTSCALE;
}
else
{
if (r_genNormalMaps->integer)
flags |= IMGFLAG_GENNORMALMAP;
stage->bundle[0].image[0] = R_FindImageFile2( token, flags );
if (r_srgb->integer)
flags |= IMGFLAG_SRGB;
}
stage->bundle[0].image[0] = R_FindImageFile( token, flags );
if ( !stage->bundle[0].image[0] )
{
ri.Printf( PRINT_WARNING, "WARNING: R_FindImageFile could not find '%s' in shader '%s'\n", token, shader.name );
return qfalse;
}
if (stage->type == ST_DIFFUSEMAP)
{
char filename[MAX_QPATH];
//if ( r_autoFindNormalMap->integer )
if ( r_normalMapping->integer )
{
COM_StripExtension(token, filename, sizeof(filename));
Q_strcat(filename, sizeof(filename), "_normal");
stage->bundle[TB_NORMALMAP].image[0] = R_FindImageFile2( filename, flags | IMGFLAG_SWIZZLE | IMGFLAG_NORMALIZED | IMGFLAG_NOLIGHTSCALE);
}
//if ( r_autoFindSpecularMap->integer )
if ( r_specularMapping->integer )
{
COM_StripExtension(token, filename, sizeof(filename));
Q_strcat(filename, sizeof(filename), "_specular");
stage->bundle[TB_SPECULARMAP].image[0] = R_FindImageFile2( filename, flags );
stage->specularReflectance = 0.04f;
}
}
}
}
//
@ -700,6 +687,8 @@ static qboolean ParseStage( shaderStage_t *stage, char **text )
//
else if ( !Q_stricmp( token, "clampmap" ) )
{
imgFlags_t flags = IMGFLAG_CLAMPTOEDGE | IMGFLAG_SRGB;
token = COM_ParseExt( text, qfalse );
if ( !token[0] )
{
@ -707,7 +696,27 @@ static qboolean ParseStage( shaderStage_t *stage, char **text )
return qfalse;
}
stage->bundle[0].image[0] = R_FindImageFile( token, !shader.noMipMaps, !shader.noPicMip, GL_CLAMP_TO_EDGE );
if (!shader.noMipMaps)
flags |= IMGFLAG_MIPMAP;
if (!shader.noPicMip)
flags |= IMGFLAG_PICMIP;
if (stage->type == ST_NORMALMAP || stage->type == ST_NORMALPARALLAXMAP)
{
flags |= IMGFLAG_SWIZZLE | IMGFLAG_NORMALIZED | IMGFLAG_NOLIGHTSCALE;
}
else
{
if (r_genNormalMaps->integer)
flags |= IMGFLAG_GENNORMALMAP;
if (r_srgb->integer)
flags |= IMGFLAG_SRGB;
}
stage->bundle[0].image[0] = R_FindImageFile( token, flags );
if ( !stage->bundle[0].image[0] )
{
ri.Printf( PRINT_WARNING, "WARNING: R_FindImageFile could not find '%s' in shader '%s'\n", token, shader.name );
@ -737,7 +746,15 @@ static qboolean ParseStage( shaderStage_t *stage, char **text )
}
num = stage->bundle[0].numImageAnimations;
if ( num < MAX_IMAGE_ANIMATIONS ) {
stage->bundle[0].image[num] = R_FindImageFile( token, !shader.noMipMaps, !shader.noPicMip, GL_REPEAT );
imgFlags_t flags = IMGFLAG_SRGB;
if (!shader.noMipMaps)
flags |= IMGFLAG_MIPMAP;
if (!shader.noPicMip)
flags |= IMGFLAG_PICMIP;
stage->bundle[0].image[num] = R_FindImageFile( token, flags );
if ( !stage->bundle[0].image[num] )
{
ri.Printf( PRINT_WARNING, "WARNING: R_FindImageFile could not find '%s' in shader '%s'\n", token, shader.name );
@ -1356,7 +1373,7 @@ static void ParseSkyParms( char **text ) {
for (i=0 ; i<6 ; i++) {
Com_sprintf( pathname, sizeof(pathname), "%s_%s.tga"
, token, suf[i] );
shader.sky.outerbox[i] = R_FindImageFile( ( char * ) pathname, qtrue, qtrue, GL_CLAMP_TO_EDGE );
shader.sky.outerbox[i] = R_FindImageFile( ( char * ) pathname, IMGFLAG_SRGB | IMGFLAG_MIPMAP | IMGFLAG_PICMIP | IMGFLAG_CLAMPTOEDGE );
if ( !shader.sky.outerbox[i] ) {
shader.sky.outerbox[i] = tr.defaultImage;
@ -1387,7 +1404,7 @@ static void ParseSkyParms( char **text ) {
for (i=0 ; i<6 ; i++) {
Com_sprintf( pathname, sizeof(pathname), "%s_%s.tga"
, token, suf[i] );
shader.sky.innerbox[i] = R_FindImageFile( ( char * ) pathname, qtrue, qtrue, GL_REPEAT );
shader.sky.innerbox[i] = R_FindImageFile( ( char * ) pathname, IMGFLAG_SRGB | IMGFLAG_MIPMAP | IMGFLAG_PICMIP );
if ( !shader.sky.innerbox[i] ) {
shader.sky.innerbox[i] = tr.defaultImage;
}
@ -2119,6 +2136,7 @@ static void CollapseStagesToLightall(shaderStage_t *diffuse,
if (r_normalMapping->integer)
{
image_t *diffuseImg;
if (normal)
{
//ri.Printf(PRINT_ALL, ", normalmap %s", normal->bundle[0].image[0]->imgName);
@ -2127,12 +2145,26 @@ static void CollapseStagesToLightall(shaderStage_t *diffuse,
if (parallax && r_parallaxMapping->integer)
defs |= LIGHTDEF_USE_PARALLAXMAP;
}
else if (diffuse->bundle[TB_NORMALMAP].image[0])
else if ((lightmap || useLightVector || useLightVertex) && (diffuseImg = diffuse->bundle[TB_DIFFUSEMAP].image[0]))
{
image_t *tmpImg = diffuse->bundle[TB_NORMALMAP].image[0];
diffuse->bundle[TB_NORMALMAP] = diffuse->bundle[TB_DIFFUSEMAP];
diffuse->bundle[TB_NORMALMAP].image[0] = tmpImg;
char normalName[MAX_QPATH];
image_t *normalImg;
imgFlags_t normalFlags = (diffuseImg->flags & ~(IMGFLAG_GENNORMALMAP | IMGFLAG_SRGB)) | IMGFLAG_SWIZZLE | IMGFLAG_NORMALIZED | IMGFLAG_NOLIGHTSCALE;
COM_StripExtension(diffuseImg->imgName, normalName, MAX_QPATH);
Q_strcat(normalName, MAX_QPATH, "_n");
normalImg = R_FindImageFile(normalName, normalFlags);
if (normalImg)
{
diffuse->bundle[TB_NORMALMAP] = diffuse->bundle[0];
diffuse->bundle[TB_NORMALMAP].image[0] = normalImg;
defs |= LIGHTDEF_USE_NORMALMAP;
if (parallax && r_parallaxMapping->integer)
defs |= LIGHTDEF_USE_PARALLAXMAP;
}
}
}
@ -2145,13 +2177,6 @@ static void CollapseStagesToLightall(shaderStage_t *diffuse,
diffuse->specularReflectance = specular->specularReflectance;
defs |= LIGHTDEF_USE_SPECULARMAP;
}
else if (diffuse->bundle[TB_SPECULARMAP].image[0])
{
image_t *tmpImg = diffuse->bundle[TB_SPECULARMAP].image[0];
diffuse->bundle[TB_SPECULARMAP] = diffuse->bundle[TB_DIFFUSEMAP];
diffuse->bundle[TB_SPECULARMAP].image[0] = tmpImg;
defs |= LIGHTDEF_USE_SPECULARMAP;
}
}
if (environment)
@ -3062,12 +3087,33 @@ shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImag
// if not defined in the in-memory shader descriptions,
// look for a single supported image file
//
image = R_FindImageFile( name, mipRawImage, mipRawImage, mipRawImage ? GL_REPEAT : GL_CLAMP_TO_EDGE );
{
imgFlags_t flags;
flags = IMGFLAG_NONE;
if (r_srgb->integer)
flags |= IMGFLAG_SRGB;
if (mipRawImage)
{
flags |= IMGFLAG_MIPMAP | IMGFLAG_PICMIP;
if (r_genNormalMaps->integer)
flags |= IMGFLAG_GENNORMALMAP;
}
else
{
flags |= IMGFLAG_CLAMPTOEDGE;
}
image = R_FindImageFile( name, flags );
if ( !image ) {
ri.Printf( PRINT_DEVELOPER, "Couldn't find image file for shader %s\n", name );
shader.defaultShader = qtrue;
return FinishShader();
}
}
//
// create the default shading commands

View file

@ -1599,8 +1599,8 @@ static void RB_SurfaceVBOMesh(srfVBOMesh_t * srf)
void RB_SurfaceVBOMDVMesh(srfVBOMDVMesh_t * surface)
{
mdvModel_t *mdvModel;
mdvSurface_t *mdvSurface;
//mdvModel_t *mdvModel;
//mdvSurface_t *mdvSurface;
refEntity_t *refEnt;
GLimp_LogComment("--- RB_SurfaceVBOMDVMesh ---\n");
@ -1620,8 +1620,8 @@ void RB_SurfaceVBOMDVMesh(srfVBOMDVMesh_t * surface)
tess.numIndexes += surface->numIndexes;
tess.numVertexes += surface->numVerts;
mdvModel = surface->mdvModel;
mdvSurface = surface->mdvSurface;
//mdvModel = surface->mdvModel;
//mdvSurface = surface->mdvSurface;
refEnt = &backEnd.currentEntity->e;