Jump to content
  • Advertisement
Sign in to follow this  
KKTHXBYE

strange artifacts, when using fbo and enabling depth

This topic is 557 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hmm how to describe that issue hmm. lets start from what code is supposed to do:

-draw sky to fbo

-go to main buffer (glbindframebuffer 0)

-clear depth and color buffers

- draw fullscreen quad with above fbo texture (with depth test and depth writes disabled)

- draw water

- draw ships

- end

 

 

problem is when i call draw sky to fbo i get something like z fighting on some parts of the screen (actually few screen rectangles are covering parts that are drawn after fullscr quads - where they should be overwritten), ill post video of that but be aware of borken screen on my device :x

 

ill post code first then video coz it has to be converted from hd cam... unfortunatetly my graphics card broke and i am forced to work on standard vdm windows driver(no support for 3d)

so

void main()
{

    DrawSky(); //draw sky to fbo texture


glBindFramebuffer(GL_FRAMEBUFFER, 0);
//screen width and height are device screen
	glViewport(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);
	glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glClear(GL_DEPTH_BUFFER_BIT);

DrawFullScrQuad(sky_fbo.FBO_TEX); //draw sky texture to screen as fullscr quad


//everything below is not important anyway go to  DrawSky(); function that causes artifacts
gluPerspectiveA(ACTUAL_PROJECTION, 90.0f, float(SCREEN_WIDTH)/float(SCREEN_HEIGHT), 2.0f, 1000.0f);

ACTUAL_MODEL.LoadIdentity();
FPP_CAM->SetView();

glViewport(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);

ocean->sky_color = TimeToWaterColor(actual_time, 0.0);
ocean->sun_color = TimeToSunColor(actual_time,0.0);
ocean->Draw(FPP_CAM,0.1f,1000.0f, SCREEN_WIDTH,SCREEN_HEIGHT,90.0f,WH_ASPECT, sun_pos, sky_fbo.FBO_TEX);

}







if you want i can show more code but i think its useless for post purposes

now drawsky code which causes problems, note that i commented out all drawing routines to see if glenable gldepth mask cause problems and they do but its a bit retarded since when i bind particular fbo it shouldnt affect main buffer depth test etc.

[spoiler]

void DrawSky()
	{
		float sky_aspect = float(SCREEN_WIDTH) / float(SCREEN_HEIGHT);//float(sky_fbo.w) / float(sky_fbo.h);
		sky_fbo.bind();
		glViewport(0,0, 256, 256);
		glClearColor(1.0f, 0.0f, 0.0f, 1.0f);

		glClearDepthf(1.0f);
		glEnable(GL_DEPTH_TEST);
		glDepthFunc(GL_LEQUAL);
		glDepthMask(GL_TRUE);

	    glClear(GL_COLOR_BUFFER_BIT);
	    glClear(GL_DEPTH_BUFFER_BIT);

	    FPP_CAM->SetView();
		glActiveTexture(GL_TEXTURE0);

		  gluPerspectiveA(ACTUAL_PROJECTION, 90.0f, sky_aspect, 0.010f, 1000.0f * 1000.0f);

//		  SkyDome->Draw(FPP_CAM);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
		glDepthMask(GL_FALSE);
		glDisable(GL_DEPTH_TEST);
//		sunflare.Bind();
//		sun_flare.particles[0].pos = sun_pos;
//		sun_flare.Transform( (ACTUAL_MODEL * ACTUAL_VIEW) * ACTUAL_PROJECTION, FPP_CAM);
//		sun_flare.mycolor = TimeToSunColor(actual_time, 0.0);
//		sun_flare.Draw(PARTICLE_SHADER);

		glEnable(GL_DEPTH_TEST);
		glDepthMask(GL_TRUE);
		glDisable(GL_BLEND);
			gluPerspectiveA(ACTUAL_PROJECTION, 90.0f, sky_aspect, 1000.0f, 1000.0f * 1000.0f * 1000.0f);

//		    CloudDome->Draw(sun_pos, TimeToAmbientColor(actual_time, 0.0), TimeToSunColor(actual_time,0.0));

		    gluPerspectiveA(ACTUAL_PROJECTION, 90.0f, sky_aspect, 0.010f, 1000.0f * 1000.0f);
		glActiveTexture(GL_TEXTURE0);



		if (draw_volumetric_clouds) //set to false in setting aint drawing that
		{
			ALOG("DRAWING VOL CLOUDS");
			DrawVolumeClouds();
		}
		glDisable(GL_DEPTH_TEST);
		glDepthMask(GL_FALSE);
		sky_fbo.unbind();

	}

[/spoiler]

 

 

and helper functions that bind fbo and unbind

[spoiler]


	extern TLightVertex vfullscrq[4];
	extern unsigned int FULL_SCREEN_QUAD_BUFFER;
	extern TShaderObject * fullscrquad_shader;

inline void DrawFullScrQuad(unsigned int & tex)
{
	glDisable(GL_DEPTH_TEST);
	glDepthMask(GL_FALSE);
	fullscrquad_shader->Enable();
//	glEnable(GL_BLEND);
//	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glBindBuffer(GL_ARRAY_BUFFER, FULL_SCREEN_QUAD_BUFFER);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, tex);

	    fullscrquad_shader->Send1I(glGetUniformLocation(fullscrquad_shader->gProgram, "output_tex"), 0);

glVertexAttribPointer(fullscrquad_shader->vertex_pos, 3, GL_FLOAT, GL_FALSE, sizeof(TLightVertex), (void*)(offsetof(struct TLightVertex, v)));
glEnableVertexAttribArray(fullscrquad_shader->vertex_pos);

glDrawArrays(GL_TRIANGLE_FAN, 0 , 4);

glDisableVertexAttribArray(fullscrquad_shader->vertex_pos);

glBindBuffer(GL_ARRAY_BUFFER, 0);
//glDisable(GL_BLEND);
	fullscrquad_shader->Disable();
	glDepthMask(GL_TRUE);
	glEnable(GL_DEPTH_TEST);
}

inline void Deinit_glHelper()
{
	delete fullscrquad_shader;
}
inline void Init_glHelper()
{
	fullscrquad_shader = new TShaderObject();
	fullscrquad_shader->LoadShaderProgram(
			appdir+"shaders/fullscreen2d_vp.shader",
			appdir+"shaders/fullscreen2d_fp.shader");

	vfullscrq[0].v = t3dpoint<float>(-1.0,-1.0,0.0);
	vfullscrq[1].v = t3dpoint<float>(1.0,-1.0,0.0);
	vfullscrq[2].v = t3dpoint<float>(1.0,1.0,0.0);
	vfullscrq[3].v = t3dpoint<float>(-1.0,1.0,0.0);

	glGenBuffers(1, &FULL_SCREEN_QUAD_BUFFER);
	glBindBuffer(GL_ARRAY_BUFFER, FULL_SCREEN_QUAD_BUFFER);
	glBufferData(GL_ARRAY_BUFFER, sizeof(TLightVertex) * 4, vfullscrq, GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
}

struct TGLFBOObject
{
	unsigned int FBO_TEX;
//	unsigned int FBO_DEPTH;
	unsigned int FBO_ID;
	unsigned int RBO_ID;
	TShaderObject * shader;
	TGLFBOObject() { shader = 0; }
	~TGLFBOObject() { Deinitialize(); }
	bool initialized;

	void Deinitialize()
	{
if (!initialized) return;
if (shader != 0) delete shader;
//delete renderbuffer
//delete framebuffer
//delete textures
	}
	int w;
	int h;

	void bind()
	{
		glBindFramebuffer(GL_FRAMEBUFFER, FBO_ID);
	}

	void unbind()
	{
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	}

	void Initialize(int aw, int ah, AnsiString shaderpartname, AnsiString shaderdir)
	{
		if (shaderpartname != "")
		{
		shader = new TShaderObject();
		shader->LoadShaderProgram(
				appdir+"shaders/"+shaderdir+shaderpartname+"_vp.shader",
				appdir+"shaders/"+shaderdir+shaderpartname+"_fp.shader");

		}
ShowGLERROR();
ALOG("preinit skyfbo");
w = aw;
h = ah;
                        glGenTextures(1, &FBO_TEX);
			glBindTexture(GL_TEXTURE_2D, FBO_TEX);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);


//			glGenTextures(1, &FBO_DEPTH);
//			glBindTexture(GL_TEXTURE_2D, FBO_DEPTH);
//			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
//			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

			glGenFramebuffers(1, &FBO_ID);
			glGenRenderbuffers(1, &RBO_ID);
			glBindRenderbuffer(GL_RENDERBUFFER, RBO_ID);
			glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, w, h);
			glBindFramebuffer(GL_FRAMEBUFFER, FBO_ID);
			glBindTexture(GL_TEXTURE_2D, FBO_TEX);
			glFramebufferRenderbuffer(GL_FRAMEBUFFER,
			                          GL_DEPTH_ATTACHMENT,
			                          GL_RENDERBUFFER,
									  RBO_ID);
			glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, FBO_TEX, 0);
//			glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, FBO_DEPTH, 0);
			glBindFramebuffer(GL_FRAMEBUFFER, 0);
			ShowGLERROR();
			ALOG("skyfbo DONE");
			initialized = true;
	}
}; 

[/spoiler]

 

 

well actually o wont post video itr way too much work unless noone will be able to answer me and ask for it'

 

here are scrs

 

liek it should look (but i dont have earlier screens so its with disabled sky drawing and you see gray thing instead of sky)

device-2017-01-07-221657.png

 

 

and here is my actual crap

 

device-2017-01-08-162114.png

 

 

 

 

 

i just dont see what is going on

 

 

it should just render sky toi fbo

 

then in main buffer draw that sky to the screen without any depth writes and test enabled

 

then draw ocean and ships with depth tests and writes enabled but it get something like that (not that ocean and ships are drawn to main buffer not to fbos)

 

please help

Edited by WiredCat

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!