Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 448b306a authored by RODRIGUEZ Simon's avatar RODRIGUEZ Simon :dragon:
Browse files

FloodFill: implement half res test.

parent 85a616c3
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@ void FloodFillRenderer::loadShaders() {
sibr::loadFile(shaderDstPath + "synthetic_fill.vert"),
sibr::loadFile(shaderDstPath + "synthetic_fill_flood.frag"));
_stepDist.init(_floodFill, "stepDist");
_halfRes.init(_floodFill, "halfRes");
_composite.init("Composite",
sibr::loadFile(shaderDstPath + "synthetic_fill.vert"),
sibr::loadFile(shaderDstPath + "synthetic_fill_composite.frag"));
......@@ -28,8 +29,8 @@ void FloodFillRenderer::loadShaders() {
void FloodFillRenderer::resize(uint w, uint h) {
_ping.reset(new RenderTargetID(w, h, 0, 2));
_pong.reset(new RenderTargetID(w, h, 0, 2));
_iterations = int(std::ceil(std::log2(std::max(w, h))));
_pong.reset(new RenderTargetID(_ping->w(), _ping->h(), 0, 2));
_iterations = int(std::ceil(std::log2(std::max(_ping->w(), _ping->h()))));
}
void FloodFillRenderer::process(const IRenderTarget & src, const IRenderTarget & ref, const IRenderTarget& refRefl, IRenderTarget & dst) {
......@@ -37,9 +38,12 @@ void FloodFillRenderer::process(const IRenderTarget & src, const IRenderTarget &
resize(src.w(), src.h());
}
glViewport(0,0, src.w(), src.h());
glViewport(0,0, _ping->w()/2, _ping->h()/2);
glDisable(GL_DEPTH_TEST);
_ping->clear();
_pong->clear();
// Transfert seeds from src to ping.
_ping->bind();
_extract.begin();
......@@ -56,7 +60,17 @@ void FloodFillRenderer::process(const IRenderTarget & src, const IRenderTarget &
_floodFill.begin();
// Perform JFA+1
for (int i = 0; i < _iterations+1; i++) {
_stepDist.set(int(std::pow(2, std::max(0, _iterations - i - 1))));
if(i >= _iterations) {
// Final flood at full resolution, from half of ping to full pong.
glViewport(0, 0, _pong->w(), _pong->h());
_stepDist.set(1);
_halfRes.set(false);
} else {
glViewport(0, 0, _ping->w() / 2, _ping->h() / 2);
_stepDist.set(int(std::pow(2, _iterations - i - 1)));
_halfRes.set(true);
}
_pong->bind();
glActiveTexture(GL_TEXTURE0);
......@@ -81,6 +95,7 @@ void FloodFillRenderer::process(const IRenderTarget & src, const IRenderTarget &
_floodFill.end();
dst.bind();
glViewport(0,0,dst.w(), dst.h());
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_ALWAYS);
_composite.begin();
......
......@@ -34,6 +34,7 @@ namespace sibr {
GLShader _extract;
GLShader _floodFill;
GLuniform<int> _stepDist;
GLuniform<bool> _halfRes;
GLShader _composite;
RenderTargetID::Ptr _ping;
......
......@@ -12,14 +12,22 @@ const int unknownCoord = 65500; ///< Arbitrary high number.
void main(void)
{
// Assume both src and the destination have the same pixel size/same viewport.
ivec2 coords = ivec2(gl_FragCoord.xy);
vec4 refPos = texelFetch(src0, coords, 0);
// Filter based on material.
if(refPos.a >= 1000000.0){
seedCoords = vec4(unknownCoord, unknownCoord, 0.0, 1000000.0);
return;
ivec2 coords = 2*ivec2(gl_FragCoord.xy);
// Default "not found" value.
seedCoords = vec4(unknownCoord, unknownCoord, 0.0, 1000000.0);
const ivec2 offsets[4] = ivec2[](ivec2(0,0), ivec2(1,0), ivec2(0,1), ivec2(1,1));
for(int i = 0; i < 4; ++i){
vec4 refPos = texelFetchOffset(src0, coords, 0, offsets[i]);
// Filter based on material.
if(refPos.a < 1000000.0){
float mat = round(texelFetchOffset(src1, coords, 0, offsets[i]).a*255.0);
seedCoords = vec4(coords + offsets[i], mat, 1000000.0);
seedInfos = refPos;
return;
}
}
float mat = round(texelFetch(src1, coords, 0).a*255.0);
seedCoords = vec4(coords, mat, 1000000.0);
seedInfos = refPos;
}
......@@ -8,6 +8,7 @@ layout(binding = 3) uniform sampler2D seedMap;
layout(binding = 4) uniform sampler2D seedMapInfos;
uniform int stepDist;
uniform bool halfRes;
layout(location = 0) out vec4 seedCoords;
layout(location = 1) out vec4 seedInfos;
......@@ -22,9 +23,11 @@ bool isOutside(ivec2 pos, ivec2 size){
void main(){
vec2 currentPixel = floor(gl_FragCoord.xy);
ivec2 baseCoords = ivec2(currentPixel);
ivec2 size = ivec2(textureSize(seedMap, 0));
ivec2 currentPixel = ivec2(floor(gl_FragCoord.xy));
ivec2 baseCoords = (halfRes ? 2 : 1)*currentPixel;
ivec2 neigCoords = currentPixel / (halfRes ? 1: 2);
ivec2 size = ivec2(textureSize(seedMap, 0).xy) / (halfRes ? 2 : 1);
vec4 dirAndMat = texelFetch(dirMat, baseCoords, 0);
vec4 surfPosAndConf = texelFetch(posConf, baseCoords, 0);
......@@ -40,8 +43,8 @@ void main(){
float refDist = distance(surfPos, refReflPos);
// Fetch the current seed for the pixel.
vec4 origSeed = texelFetch(seedMap, baseCoords, 0);
vec4 origInfos = texelFetch(seedMapInfos, baseCoords, 0);
vec4 origSeed = texelFetch(seedMap, neigCoords, 0);
vec4 origInfos = texelFetch(seedMapInfos, neigCoords, 0);
vec3 bestSeed = origSeed.xyz;
vec4 bestInfos = origInfos;
......@@ -59,7 +62,7 @@ void main(){
bool foundSame = false;
for(int i = 0; i < 8; ++i){
ivec2 coords = baseCoords + deltas[i];
ivec2 coords = neigCoords + deltas[i];
if(isOutside(coords, size)){
continue;
}
......@@ -81,7 +84,7 @@ void main(){
#else
float dist = length(seed.xy - currentPixel);
float dist = length(seed.xy/2 - currentPixel);
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment