Skip to content

Commit

Permalink
Merge remote-tracking branch 'ioquake3/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
zturtleman committed May 9, 2016
2 parents 775ccff + d8afce6 commit 01cc677
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 147 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,13 @@ ifdef MINGW
endif

ifndef CC
CC=$(strip $(foreach MINGW_PREFIX, $(MINGW_PREFIXES), \
$(call bin_path, $(MINGW_PREFIX)-gcc)))
CC=$(firstword $(strip $(foreach MINGW_PREFIX, $(MINGW_PREFIXES), \
$(call bin_path, $(MINGW_PREFIX)-gcc))))
endif

ifndef WINDRES
WINDRES=$(strip $(foreach MINGW_PREFIX, $(MINGW_PREFIXES), \
$(call bin_path, $(MINGW_PREFIX)-windres)))
WINDRES=$(firstword $(strip $(foreach MINGW_PREFIX, $(MINGW_PREFIXES), \
$(call bin_path, $(MINGW_PREFIX)-windres))))
endif
else
# Some MinGW installations define CC to cc, but don't actually provide cc,
Expand Down
17 changes: 12 additions & 5 deletions code/renderergl2/glsl/depthblur_fp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ varying vec2 var_ScreenTex;
float gauss[4] = float[4](0.40, 0.24, 0.054, 0.0044);
//float gauss[3] = float[3](0.60, 0.19, 0.0066);
#define BLUR_SIZE 4

#if !defined(USE_DEPTH)
//#define USE_GAUSS
#endif

float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNear)
{
Expand All @@ -19,21 +22,21 @@ float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNea

vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFarDivZNear, float zFar, vec2 scale)
{
float depthCenter = getLinearDepth(depthMap, tex, zFarDivZNear);

// enable for less blurring for farther objects
#if defined(USE_DEPTH)
float depthCenter = getLinearDepth(depthMap, tex, zFarDivZNear);
vec2 slope = vec2(dFdx(depthCenter), dFdy(depthCenter)) / vec2(dFdx(tex.x), dFdy(tex.y));
scale /= clamp(zFarDivZNear * depthCenter / 32.0, 1.0, 2.0);
#endif

#if defined(USE_HORIZONTAL_BLUR)
vec2 direction = vec2(scale.x * 2.0, 0.0);
vec2 nudge = vec2(0.0, scale.y * 0.5);
#else // if defined(USE_VERTICAL_BLUR)
vec2 direction = vec2(0.0, scale.y * 2.0);
vec2 nudge = vec2(scale.x * 0.5, 0.0);
vec2 nudge = vec2(-scale.x * 0.5, 0.0);
#endif

vec2 slope = vec2(dFdx(depthCenter), dFdy(depthCenter)) / vec2(dFdx(tex.x), dFdy(tex.y));

#if defined(USE_GAUSS)
vec4 result = texture2D(imageMap, tex) * gauss[0];
float total = gauss[0];
Expand All @@ -49,9 +52,13 @@ vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFa
for (j = 1; j < BLUR_SIZE; j++)
{
vec2 offset = direction * (float(j) - 0.25) + nudge;
#if defined(USE_DEPTH)
float depthSample = getLinearDepth(depthMap, tex + offset, zFarDivZNear);
float depthExpected = depthCenter + dot(slope, offset);
float useSample = float(abs(depthSample - depthExpected) < zLimit);
#else
float useSample = 1.0;
#endif
#if defined(USE_GAUSS)
result += texture2D(imageMap, tex + offset) * (gauss[j] * useSample);
total += gauss[j] * useSample;
Expand Down
3 changes: 2 additions & 1 deletion code/renderergl2/glsl/depthblur_vp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ varying vec2 var_ScreenTex;
void main()
{
gl_Position = attr_Position;
var_ScreenTex = (floor(attr_TexCoord0.xy * (1.0 / u_ViewInfo.zw - vec2(1.0))) + vec2(0.5)) * u_ViewInfo.zw;
vec2 wh = vec2(1.0) / u_ViewInfo.zw - vec2(1.0);
var_ScreenTex = (floor(attr_TexCoord0.xy * wh) + vec2(0.5)) * u_ViewInfo.zw;

//vec2 screenCoords = gl_Position.xy / gl_Position.w;
//var_ScreenTex = screenCoords * 0.5 + 0.5;
Expand Down
71 changes: 68 additions & 3 deletions code/renderergl2/tr_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1280,11 +1280,11 @@ const void *RB_DrawSurfs( const void *data ) {
if (tr.hdrDepthFbo)
{
// need the depth in a texture we can do GL_LINEAR sampling on, so copy it to an HDR image
ivec4_t srcBox;
vec4_t srcTexCoords;

VectorSet4(srcBox, 0, tr.renderDepthImage->height, tr.renderDepthImage->width, -tr.renderDepthImage->height);
VectorSet4(srcTexCoords, 0.0f, 0.0f, 1.0f, 1.0f);

FBO_BlitFromTexture(tr.renderDepthImage, srcBox, NULL, tr.hdrDepthFbo, NULL, NULL, NULL, 0);
FBO_BlitFromTexture(tr.renderDepthImage, srcTexCoords, NULL, tr.hdrDepthFbo, NULL, NULL, NULL, 0);
}

if (r_sunlightMode->integer && backEnd.viewParms.flags & VPF_USESUNLIGHT)
Expand Down Expand Up @@ -1892,6 +1892,71 @@ const void *RB_PostProcess(const void *data)
else
RB_GaussianBlur(backEnd.refdef.blurFactor);

#if 0
if (0)
{
vec4_t quadVerts[4];
vec2_t texCoords[4];
ivec4_t iQtrBox;
vec4_t box;
vec4_t viewInfo;
static float scale = 5.0f;

scale -= 0.005f;
if (scale < 0.01f)
scale = 5.0f;

FBO_FastBlit(NULL, NULL, tr.quarterFbo[0], NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);

iQtrBox[0] = backEnd.viewParms.viewportX * tr.quarterImage[0]->width / (float)glConfig.vidWidth;
iQtrBox[1] = backEnd.viewParms.viewportY * tr.quarterImage[0]->height / (float)glConfig.vidHeight;
iQtrBox[2] = backEnd.viewParms.viewportWidth * tr.quarterImage[0]->width / (float)glConfig.vidWidth;
iQtrBox[3] = backEnd.viewParms.viewportHeight * tr.quarterImage[0]->height / (float)glConfig.vidHeight;

qglViewport(iQtrBox[0], iQtrBox[1], iQtrBox[2], iQtrBox[3]);
qglScissor(iQtrBox[0], iQtrBox[1], iQtrBox[2], iQtrBox[3]);

VectorSet4(box, 0.0f, 0.0f, 1.0f, 1.0f);

texCoords[0][0] = box[0]; texCoords[0][1] = box[3];
texCoords[1][0] = box[2]; texCoords[1][1] = box[3];
texCoords[2][0] = box[2]; texCoords[2][1] = box[1];
texCoords[3][0] = box[0]; texCoords[3][1] = box[1];

VectorSet4(box, -1.0f, -1.0f, 1.0f, 1.0f);

VectorSet4(quadVerts[0], box[0], box[3], 0, 1);
VectorSet4(quadVerts[1], box[2], box[3], 0, 1);
VectorSet4(quadVerts[2], box[2], box[1], 0, 1);
VectorSet4(quadVerts[3], box[0], box[1], 0, 1);

GL_State(GLS_DEPTHTEST_DISABLE);


VectorSet4(viewInfo, backEnd.viewParms.zFar / r_znear->value, backEnd.viewParms.zFar, 0.0, 0.0);

viewInfo[2] = scale / (float)(tr.quarterImage[0]->width);
viewInfo[3] = scale / (float)(tr.quarterImage[0]->height);

FBO_Bind(tr.quarterFbo[1]);
GLSL_BindProgram(&tr.depthBlurShader[2]);
GL_BindToTMU(tr.quarterImage[0], TB_COLORMAP);
GLSL_SetUniformVec4(&tr.depthBlurShader[2], UNIFORM_VIEWINFO, viewInfo);
RB_InstantQuad2(quadVerts, texCoords);

FBO_Bind(tr.quarterFbo[0]);
GLSL_BindProgram(&tr.depthBlurShader[3]);
GL_BindToTMU(tr.quarterImage[1], TB_COLORMAP);
GLSL_SetUniformVec4(&tr.depthBlurShader[3], UNIFORM_VIEWINFO, viewInfo);
RB_InstantQuad2(quadVerts, texCoords);

SetViewportAndScissor();

FBO_FastBlit(tr.quarterFbo[1], NULL, NULL, NULL, GL_COLOR_BUFFER_BIT, GL_LINEAR);
FBO_Bind(NULL);
}
#endif

if (0 && r_sunlightMode->integer)
{
ivec4_t dstBox;
Expand Down
120 changes: 43 additions & 77 deletions code/renderergl2/tr_fbo.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,9 @@ void R_FBOList_f(void)
ri.Printf(PRINT_ALL, " %i FBOs\n", tr.numFBOs);
}

void FBO_BlitFromTexture(struct image_s *src, ivec4_t inSrcBox, vec2_t inSrcTexScale, FBO_t *dst, ivec4_t inDstBox, struct shaderProgram_s *shaderProgram, vec4_t inColor, int blend)
void FBO_BlitFromTexture(struct image_s *src, vec4_t inSrcTexCorners, vec2_t inSrcTexScale, FBO_t *dst, ivec4_t inDstBox, struct shaderProgram_s *shaderProgram, vec4_t inColor, int blend)
{
ivec4_t dstBox, srcBox;
vec2_t srcTexScale;
ivec4_t dstBox;
vec4_t color;
vec4_t quadVerts[4];
vec2_t texCoords[4];
Expand All @@ -513,49 +512,44 @@ void FBO_BlitFromTexture(struct image_s *src, ivec4_t inSrcBox, vec2_t inSrcTexS
return;
}

if (inSrcBox)
width = dst ? dst->width : glConfig.vidWidth;
height = dst ? dst->height : glConfig.vidHeight;

if (inSrcTexCorners)
{
VectorSet4(srcBox, inSrcBox[0], inSrcBox[1], inSrcBox[0] + inSrcBox[2], inSrcBox[1] + inSrcBox[3]);
VectorSet2(texCoords[0], inSrcTexCorners[0], inSrcTexCorners[1]);
VectorSet2(texCoords[1], inSrcTexCorners[2], inSrcTexCorners[1]);
VectorSet2(texCoords[2], inSrcTexCorners[2], inSrcTexCorners[3]);
VectorSet2(texCoords[3], inSrcTexCorners[0], inSrcTexCorners[3]);
}
else
{
VectorSet4(srcBox, 0, 0, src->width, src->height);
VectorSet2(texCoords[0], 0.0f, 1.0f);
VectorSet2(texCoords[1], 1.0f, 1.0f);
VectorSet2(texCoords[2], 1.0f, 0.0f);
VectorSet2(texCoords[3], 0.0f, 0.0f);
}

// framebuffers are 0 bottom, Y up.
if (inDstBox)
{
if (dst)
{
dstBox[0] = inDstBox[0];
dstBox[1] = dst->height - inDstBox[1] - inDstBox[3];
dstBox[2] = inDstBox[0] + inDstBox[2];
dstBox[3] = dst->height - inDstBox[1];
}
else
{
dstBox[0] = inDstBox[0];
dstBox[1] = glConfig.vidHeight - inDstBox[1] - inDstBox[3];
dstBox[2] = inDstBox[0] + inDstBox[2];
dstBox[3] = glConfig.vidHeight - inDstBox[1];
}
}
else if (dst)
{
VectorSet4(dstBox, 0, dst->height, dst->width, 0);
dstBox[0] = inDstBox[0];
dstBox[1] = height - inDstBox[1] - inDstBox[3];
dstBox[2] = inDstBox[0] + inDstBox[2];
dstBox[3] = height - inDstBox[1];
}
else
{
VectorSet4(dstBox, 0, glConfig.vidHeight, glConfig.vidWidth, 0);
VectorSet4(dstBox, 0, height, width, 0);
}

if (inSrcTexScale)
{
VectorCopy2(inSrcTexScale, srcTexScale);
VectorCopy2(inSrcTexScale, invTexRes);
}
else
{
srcTexScale[0] = srcTexScale[1] = 1.0f;
VectorSet2(invTexRes, 1.0f, 1.0f);
}

if (inColor)
Expand All @@ -574,17 +568,6 @@ void FBO_BlitFromTexture(struct image_s *src, ivec4_t inSrcBox, vec2_t inSrcTexS

FBO_Bind(dst);

if (glState.currentFBO)
{
width = glState.currentFBO->width;
height = glState.currentFBO->height;
}
else
{
width = glConfig.vidWidth;
height = glConfig.vidHeight;
}

qglViewport( 0, 0, width, height );
qglScissor( 0, 0, width, height );

Expand All @@ -594,18 +577,13 @@ void FBO_BlitFromTexture(struct image_s *src, ivec4_t inSrcBox, vec2_t inSrcTexS

GL_BindToTMU(src, TB_COLORMAP);

VectorSet4(quadVerts[0], dstBox[0], dstBox[1], 0, 1);
VectorSet4(quadVerts[1], dstBox[2], dstBox[1], 0, 1);
VectorSet4(quadVerts[2], dstBox[2], dstBox[3], 0, 1);
VectorSet4(quadVerts[3], dstBox[0], dstBox[3], 0, 1);
VectorSet4(quadVerts[0], dstBox[0], dstBox[1], 0.0f, 1.0f);
VectorSet4(quadVerts[1], dstBox[2], dstBox[1], 0.0f, 1.0f);
VectorSet4(quadVerts[2], dstBox[2], dstBox[3], 0.0f, 1.0f);
VectorSet4(quadVerts[3], dstBox[0], dstBox[3], 0.0f, 1.0f);

texCoords[0][0] = srcBox[0] / (float)src->width; texCoords[0][1] = 1.0f - srcBox[1] / (float)src->height;
texCoords[1][0] = srcBox[2] / (float)src->width; texCoords[1][1] = 1.0f - srcBox[1] / (float)src->height;
texCoords[2][0] = srcBox[2] / (float)src->width; texCoords[2][1] = 1.0f - srcBox[3] / (float)src->height;
texCoords[3][0] = srcBox[0] / (float)src->width; texCoords[3][1] = 1.0f - srcBox[3] / (float)src->height;

invTexRes[0] = 1.0f / src->width * srcTexScale[0];
invTexRes[1] = 1.0f / src->height * srcTexScale[1];
invTexRes[0] /= src->width;
invTexRes[1] /= src->height;

GL_State( blend );

Expand All @@ -617,35 +595,34 @@ void FBO_BlitFromTexture(struct image_s *src, ivec4_t inSrcBox, vec2_t inSrcTexS
GLSL_SetUniformVec2(shaderProgram, UNIFORM_AUTOEXPOSUREMINMAX, tr.refdef.autoExposureMinMax);
GLSL_SetUniformVec3(shaderProgram, UNIFORM_TONEMINAVGMAXLINEAR, tr.refdef.toneMinAvgMaxLinear);

RB_InstantQuad2(quadVerts, texCoords); //, color, shaderProgram, invTexRes);
RB_InstantQuad2(quadVerts, texCoords);

FBO_Bind(oldFbo);
}

void FBO_Blit(FBO_t *src, ivec4_t inSrcBox, vec2_t srcTexScale, FBO_t *dst, ivec4_t dstBox, struct shaderProgram_s *shaderProgram, vec4_t color, int blend)
{
ivec4_t srcBox;
vec4_t srcTexCorners;

if (!src)
{
ri.Printf(PRINT_WARNING, "Tried to blit from a NULL FBO!\n");
return;
}

// framebuffers are 0 bottom, Y up.
if (inSrcBox)
{
srcBox[0] = inSrcBox[0];
srcBox[1] = src->height - inSrcBox[1] - inSrcBox[3];
srcBox[2] = inSrcBox[2];
srcBox[3] = inSrcBox[3];
srcTexCorners[0] = inSrcBox[0] / (float)src->width;
srcTexCorners[1] = (inSrcBox[1] + inSrcBox[3]) / (float)src->height;
srcTexCorners[2] = (inSrcBox[0] + inSrcBox[2]) / (float)src->width;
srcTexCorners[3] = inSrcBox[1] / (float)src->height;
}
else
{
VectorSet4(srcBox, 0, src->height, src->width, -src->height);
VectorSet4(srcTexCorners, 0.0f, 0.0f, 1.0f, 1.0f);
}

FBO_BlitFromTexture(src->colorImage[0], srcBox, srcTexScale, dst, dstBox, shaderProgram, color, blend | GLS_DEPTHTEST_DISABLE);
FBO_BlitFromTexture(src->colorImage[0], srcTexCorners, srcTexScale, dst, dstBox, shaderProgram, color, blend | GLS_DEPTHTEST_DISABLE);
}

void FBO_FastBlit(FBO_t *src, ivec4_t srcBox, FBO_t *dst, ivec4_t dstBox, int buffers, int filter)
Expand All @@ -659,22 +636,15 @@ void FBO_FastBlit(FBO_t *src, ivec4_t srcBox, FBO_t *dst, ivec4_t dstBox, int bu
return;
}

// get to a neutral state first
//FBO_Bind(NULL);

srcFb = src ? src->frameBuffer : 0;
dstFb = dst ? dst->frameBuffer : 0;

if (!srcBox)
{
if (src)
{
VectorSet4(srcBoxFinal, 0, 0, src->width, src->height);
}
else
{
VectorSet4(srcBoxFinal, 0, 0, glConfig.vidWidth, glConfig.vidHeight);
}
int width = src ? src->width : glConfig.vidWidth;
int height = src ? src->height : glConfig.vidHeight;

VectorSet4(srcBoxFinal, 0, 0, width, height);
}
else
{
Expand All @@ -683,14 +653,10 @@ void FBO_FastBlit(FBO_t *src, ivec4_t srcBox, FBO_t *dst, ivec4_t dstBox, int bu

if (!dstBox)
{
if (dst)
{
VectorSet4(dstBoxFinal, 0, 0, dst->width, dst->height);
}
else
{
VectorSet4(dstBoxFinal, 0, 0, glConfig.vidWidth, glConfig.vidHeight);
}
int width = dst ? dst->width : glConfig.vidWidth;
int height = dst ? dst->height : glConfig.vidHeight;

VectorSet4(dstBoxFinal, 0, 0, width, height);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion code/renderergl2/tr_fbo.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void FBO_Bind(FBO_t *fbo);
void FBO_Init(void);
void FBO_Shutdown(void);

void FBO_BlitFromTexture(struct image_s *src, ivec4_t srcBox, vec2_t srcTexScale, FBO_t *dst, ivec4_t dstBox, struct shaderProgram_s *shaderProgram, vec4_t color, int blend);
void FBO_BlitFromTexture(struct image_s *src, vec4_t inSrcTexCorners, vec2_t inSrcTexScale, FBO_t *dst, ivec4_t inDstBox, struct shaderProgram_s *shaderProgram, vec4_t inColor, int blend);
void FBO_Blit(FBO_t *src, ivec4_t srcBox, vec2_t srcTexScale, FBO_t *dst, ivec4_t dstBox, struct shaderProgram_s *shaderProgram, vec4_t color, int blend);
void FBO_FastBlit(FBO_t *src, ivec4_t srcBox, FBO_t *dst, ivec4_t dstBox, int buffers, int filter);

Expand Down
Loading

0 comments on commit 01cc677

Please sign in to comment.