Skip to content

Commit

Permalink
Merge pull request #133 from sintefmath/reduce_num_varyings
Browse files Browse the repository at this point in the history
reduce number of varyings used in autoproxy. Neccessary on some brows…

And OK with autoproxy enabled :)
  • Loading branch information
MrGaribaldi committed May 27, 2015
2 parents 5e32afd + 9bf0f5a commit 14202e0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
18 changes: 12 additions & 6 deletions js/gui/autoProxy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ uniform sampler2D rgbImage;
uniform sampler2D depthImg;
// 141129: textureSize(sampler, lod) is not available in GLSL ES 1.0 (WebGL) so we use DEPTH_WIDTH and DEPTH_HEIGHT added in ProxyRenderer.js.

varying highp vec2 texCoo;
varying highp float sampled_depth; // Splat-centered depth
varying highp vec2 depth_e; // For approximating the intra-splat depth, depth = sampled_depth + depth_e' * c

varying highp float frag_depth;
varying highp vec2 frag_depth_e;
varying highp vec4 texCoo_depth_e; // packed texCoo and depth_e for approximating the intra-splat depth, depth = sampled_depth + depth_e' * c
varying highp vec4 frag_depth_e_F_sampled_depth_F_frag_depth; // Fused: frag_depth_e, sampled_depth, frag_depth

varying highp mat2 intraSplatTexCooTransform;
varying highp mat2 intraSplatTexCooTransform2;
Expand Down Expand Up @@ -50,6 +46,16 @@ const highp float mostRecentProxyModelOffset = 0.001;

void main(void)
{
// unpack varyings fused into single registers

highp vec2 texCoo = texCoo_depth_e.xy;
highp vec2 depth_e = texCoo_depth_e.zw; // For approximating the intra-splat depth, depth = sampled_depth + depth_e' * c

highp vec2 frag_depth_e = frag_depth_e_F_sampled_depth_F_frag_depth.xy;
highp float sampled_depth = frag_depth_e_F_sampled_depth_F_frag_depth.z;
highp float frag_depth = frag_depth_e_F_sampled_depth_F_frag_depth.w;


// The "most recent" is -1, the others have indices 0, 1, ...
// if (splatSetIndex!=-1) discard;

Expand Down
32 changes: 19 additions & 13 deletions js/gui/autoProxy.vs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

attribute vec2 aVertexPosition;

varying highp vec2 texCoo; // Implicitly taken to be *output*?!
varying highp float sampled_depth; // Actually sampled depth from the texture. Should also not be needed in the FS, probably.
varying highp vec2 depth_e; // For approximating the intra-splat depth, depth = sampled_depth + depth_e' * c
varying highp vec4 texCoo_depth_e; // packed texCoo and depth_e for approximating the intra-splat depth, depth = sampled_depth + depth_e' * c

varying highp vec4 frag_depth_e_F_sampled_depth_F_frag_depth; // Fused: frag_depth_e, sampled_depth, frag_depth
// vec2 frag_depth_e:
// float sampled_depth: Actually sampled depth from the texture. Should also not be needed in the FS, probably.
// float frag_depth: Fragment depth for the vertex, i.e., the center of the splat

varying highp float frag_depth; // Fragment depth for the vertex, i.e., the center of the splat
varying highp vec2 frag_depth_e;

varying highp mat2 intraSplatTexCooTransform;
varying highp mat2 intraSplatTexCooTransform2;
Expand Down Expand Up @@ -70,23 +71,28 @@ mat2 invrs(mat2 tmp)

void main(void)
{
highp float sampled_depth; // Actually sampled depth from the texture. Should also not be needed in the FS, probably.
highp float frag_depth; // Fragment depth for the vertex, i.e., the center of the splat


#ifdef DEBUG
splat_j = floor( (0.5*aVertexPosition.x+1.0)*splats_x ); // For debugging
splat_i = floor( (0.5*aVertexPosition.y+1.0)*splats_y );
debugCol = vec4(0.0, 0.0, 0.0, 0.0); // Using alpha=1 to signify "yes, escape with this fragment color" in the FS.
#endif
#ifdef VS_DISCARD_DEBUG
// Setting these now, so that we can safely exit early from the VS.
depth_e = vec2(0.0);
texCoo_depth_e.zw = vec2(0.0);
frag_depth = 0.5;
frag_depth_e = vec2(0.0);
frag_depth_e_F_sampled_depth_F_frag_depth.xy = vec2(0.0);
frag_depth_e_F_sampled_depth_F_frag_depth.w = frag_depth;
intraSplatTexCooTransform2 = mat2(1.0, 0.0, 0.0, 1.0);
intraSplatTexCooTransform = intraSplatTexCooTransform2;
#endif

vec2 st = 0.5*(aVertexPosition.xy+1.0); // From [-1, 1] to [0, 1]
st.y = 1.0-st.y;
texCoo = st;
texCoo_depth_e.xy = st;

// With a 1024^2 canvas and 512^2 splats, there are no artifacts to be seen from using 16 bits for the depth.
// (But 8 is clearly too coarse.)
Expand All @@ -99,7 +105,6 @@ void main(void)
st = st + vec2(0.5/splats_x, -0.5/splats_y);
#endif
sampled_depth = texture2D(depthImg, st).r + (texture2D(depthImg, st).g + texture2D(depthImg, st).b/255.0) / 255.0;

if ( sampled_depth > 0.999 ) {
// The depth should be 1 for fragments not rendered. Discarding the whole splat.
gl_Position = vec4(0.0, 0.0, -1000.0, 0.0);
Expand All @@ -117,6 +122,7 @@ void main(void)
sampled_depth = clamp(sampled_depth - mostRecentProxyModelOffset, 0.0, 1.0);
}
#endif
frag_depth_e_F_sampled_depth_F_frag_depth.z = sampled_depth;

// We may think of the depth texture as a grid of screen space points together with depths, which we will subsample
// in order to get a sparser set of 'splats'. First, we obtain ndc coordinates.
Expand All @@ -128,6 +134,7 @@ void main(void)
float z_ndc = pos.z/pos.w;
//depth = 0.5*( gl_DepthRange.diff*z_ndc + gl_DepthRange.near + gl_DepthRange.far ); // z_window
frag_depth = 0.5*( gl_DepthRange.diff*z_ndc + gl_DepthRange.near + gl_DepthRange.far ); // z_window
frag_depth_e_F_sampled_depth_F_frag_depth.w = frag_depth;
// This is not the depth of the point on the original geometry, but the new depth for the splat transformed into
// place. (This value is equal to gl_FragCoord.z in the fragment shader. Note that this is constant over the
// primitive, unless we modify it in the fragment shader. Doing this requires the GL_EXT_frag_depth extension
Expand Down Expand Up @@ -227,7 +234,7 @@ void main(void)
frag_depth_dx = 0.5*( gl_DepthRange.diff*frag_depth_dx + gl_DepthRange.near + gl_DepthRange.far );
float frag_depth_dy = pos_dy.z/pos_dy.w;
frag_depth_dy = 0.5*( gl_DepthRange.diff*frag_depth_dy + gl_DepthRange.near + gl_DepthRange.far );
frag_depth_e = (1.0/delta)*vec2(frag_depth_dx-frag_depth, frag_depth_dy-frag_depth);
frag_depth_e_F_sampled_depth_F_frag_depth.xy = (1.0/delta)*vec2(frag_depth_dx-frag_depth, frag_depth_dy-frag_depth);

// Difference of screen coordinates, in pixels:
vec2 scr_dx = float(vp_width )/(2.0*delta) * ( pos_dx.xy/pos_dx.w - pos.xy/pos.w ); // @@@ vp-size or DEPTH-size?!
Expand All @@ -236,7 +243,7 @@ void main(void)
vec2 st_e1 = vec2( 1.0/splats_x, 0.0 );
vec2 st_e2 = vec2( 0.0, -1.0/splats_y );

depth_e = (1.0/delta)*vec2(depth_dx-sampled_depth, depth_dy-sampled_depth);
texCoo_depth_e.zw = (1.0/delta)*vec2(depth_dx-sampled_depth, depth_dy-sampled_depth);

// This will discard all splats not facing forward
#ifdef CULL_BACK_SIDES
Expand Down Expand Up @@ -386,8 +393,7 @@ void main(void)
gl_Position = vec4(0.0, 0.0, -1000.0, 0.0); // This amounts to a "discard" operation on the primitive
#endif
#endif
return;
}
#endif

// frag_depth_e_F_sampled_depth_F_frag_depth.w=frag_depth; //not neccessary, frag_depth has not changed since previous assignment
}

0 comments on commit 14202e0

Please sign in to comment.