mirror of
https://github.com/ioquake/ioq3.git
synced 2024-11-10 07:11:46 +00:00
OpenGL2: More ssao/depth blur improvements.
This commit is contained in:
parent
87cb2167bf
commit
93e1feaaad
4 changed files with 21 additions and 12 deletions
|
@ -9,11 +9,11 @@ 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
|
||||
//#define USE_GAUSS
|
||||
|
||||
float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNear)
|
||||
{
|
||||
// depth is upside down?
|
||||
float sampleZDivW = texture2D(depthMap, vec2(tex.x, 1.0 - tex.y)).r;
|
||||
float sampleZDivW = texture2D(depthMap, tex).r;
|
||||
return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW);
|
||||
}
|
||||
|
||||
|
@ -22,12 +22,14 @@ vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFa
|
|||
float depthCenter = getLinearDepth(depthMap, tex, zFarDivZNear);
|
||||
|
||||
// enable for less blurring for farther objects
|
||||
//scale /= min(zFarDivZNear * depthCenter / 32.0, 2.0);
|
||||
scale /= clamp(zFarDivZNear * depthCenter / 32.0, 1.0, 2.0);
|
||||
|
||||
#if defined(USE_HORIZONTAL_BLUR)
|
||||
vec2 direction = vec2(scale.x, 0.0);
|
||||
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);
|
||||
vec2 direction = vec2(0.0, scale.y * 2.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));
|
||||
|
@ -46,7 +48,7 @@ vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFa
|
|||
{
|
||||
for (j = 1; j < BLUR_SIZE; j++)
|
||||
{
|
||||
vec2 offset = direction * j;
|
||||
vec2 offset = direction * (float(j) - 0.25) + nudge;
|
||||
float depthSample = getLinearDepth(depthMap, tex + offset, zFarDivZNear);
|
||||
float depthExpected = depthCenter + dot(slope, offset);
|
||||
float useSample = float(abs(depthSample - depthExpected) < zLimit);
|
||||
|
@ -57,9 +59,11 @@ vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFa
|
|||
result += texture2D(imageMap, tex + offset) * useSample;
|
||||
total += useSample;
|
||||
#endif
|
||||
nudge = -nudge;
|
||||
}
|
||||
|
||||
direction = -direction;
|
||||
nudge = -nudge;
|
||||
}
|
||||
|
||||
return result / total;
|
||||
|
@ -67,5 +71,5 @@ vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFa
|
|||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = depthGaussian1D(u_ScreenImageMap, u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x, u_ViewInfo.y, u_ViewInfo.wz);
|
||||
gl_FragColor = depthGaussian1D(u_ScreenImageMap, u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x, u_ViewInfo.y, u_ViewInfo.zw);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
uniform vec4 u_ViewInfo; // zfar / znear, zfar, 1/width, 1/height
|
||||
|
||||
varying vec2 var_ScreenTex;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = attr_Position;
|
||||
var_ScreenTex = attr_TexCoord0.xy;
|
||||
var_ScreenTex = (floor(attr_TexCoord0.xy * (1.0 / u_ViewInfo.zw - vec2(1.0))) + vec2(0.5)) * u_ViewInfo.zw;
|
||||
|
||||
//vec2 screenCoords = gl_Position.xy / gl_Position.w;
|
||||
//var_ScreenTex = screenCoords * 0.5 + 0.5;
|
||||
}
|
||||
|
|
|
@ -40,8 +40,7 @@ mat2 randomRotation( const vec2 p )
|
|||
|
||||
float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNear)
|
||||
{
|
||||
// depth is upside down?
|
||||
float sampleZDivW = texture2D(depthMap, vec2(tex.x, 1.0 - tex.y)).r;
|
||||
float sampleZDivW = texture2D(depthMap, tex).r;
|
||||
return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW);
|
||||
}
|
||||
|
||||
|
|
|
@ -980,7 +980,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
|
||||
FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, tr.hdrDepthFbo, NULL, NULL, NULL, 0);
|
||||
ivec4_t srcBox;
|
||||
|
||||
VectorSet4(srcBox, 0, tr.renderDepthImage->height, tr.renderDepthImage->width, -tr.renderDepthImage->height);
|
||||
|
||||
FBO_BlitFromTexture(tr.renderDepthImage, srcBox, NULL, tr.hdrDepthFbo, NULL, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
if (r_sunlightMode->integer && backEnd.viewParms.flags & VPF_USESUNLIGHT)
|
||||
|
@ -1540,7 +1544,6 @@ const void *RB_PostProcess(const void *data)
|
|||
srcBox[2] = backEnd.viewParms.viewportWidth * tr.screenSsaoImage->width / (float)glConfig.vidWidth;
|
||||
srcBox[3] = backEnd.viewParms.viewportHeight * tr.screenSsaoImage->height / (float)glConfig.vidHeight;
|
||||
|
||||
//FBO_BlitFromTexture(tr.screenSsaoImage, srcBox, NULL, srcFbo, dstBox, NULL, NULL, GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO);
|
||||
FBO_Blit(tr.screenSsaoFbo, srcBox, NULL, srcFbo, dstBox, NULL, NULL, GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue