Sign in to follow this  

Correct way to do transparent water?

This topic is 4856 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

I have this code to try and do transparent water and getting the wrong effect? I am using a .tga water texture with alpha but not sure if water texture I am using is correctly setup for this...
glActiveTextureARB(GL_TEXTURE0_ARB);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, textureObject[WATER]);

	glEnable(GL_BLEND);
	glEnable(GL_ALPHA_TEST);
	glBlendFunc(GL_ONE, GL_ONE);
	/*
	glActiveTextureARB(GL_TEXTURE1_ARB);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, textureObject[WATER_DETAIL]);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
	glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);
*/
	glBegin(GL_QUADS);
	glMultiTexCoord2f(GL_TEXTURE0_ARB, 0.0f, 0.0f);
	/*glMultiTexCoord2f(GL_TEXTURE1_ARB, 0.0f, 0.0f);*/ glVertex3f(-size, waterHeight, -size);
	glMultiTexCoord2f(GL_TEXTURE0_ARB, 0.0f, 1.0f);
	/*glMultiTexCoord2f(GL_TEXTURE1_ARB, 0.0f, 1.0f);*/ glVertex3f(-size, waterHeight, (MAP_Z * SCALE_FACTOR) + size);
	glMultiTexCoord2f(GL_TEXTURE0_ARB, 1.0f, 1.0f);
	/*glMultiTexCoord2f(GL_TEXTURE1_ARB, 1.0f, 1.0f);*/ glVertex3f(size + (MAP_X * SCALE_FACTOR), waterHeight, (MAP_Z * SCALE_FACTOR) + size);
	glMultiTexCoord2f(GL_TEXTURE0_ARB, 1.0f, 0.0f);
	/*glMultiTexCoord2f(GL_TEXTURE1_ARB, 1.0f, 0.0f);*/ glVertex3f(size + (MAP_X * SCALE_FACTOR), waterHeight, -size);
	glEnd();
	
	glDisable(GL_TEXTURE_2D);
	glActiveTextureARB(GL_TEXTURE0_ARB);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_ALPHA);
	glDisable(GL_BLEND);


Maybe I am not even close to being right? Thanks for the help...

Share this post


Link to post
Share on other sites
why are you enabling the alpha test?
also, your blend equation is wrong, you want one of the ones which mentions alpha (cant remember off the top of my head and dont have code handy to look)

Share this post


Link to post
Share on other sites

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);



This is what I am using now. And still looks wrong. If the water is over my terrain its somewhat transparent but the water over nothing is black. The texture is of water, and I see none of that on my terrain...

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
*** Source Snippet Removed ***

This is what I am using now. And still looks wrong. If the water is over my terrain its somewhat transparent but the water over nothing is black. The texture is of water, and I see none of that on my terrain...


as far as i know you only render transparent water if you have terrain underneath it otherwise disable alpha blending

and yes it is wrong maybe use another clearcolor

do you use a skybox or skydome?

Share this post


Link to post
Share on other sites
Quote:
Original post by Basiror
Quote:
Original post by MARS_999
*** Source Snippet Removed ***

This is what I am using now. And still looks wrong. If the water is over my terrain its somewhat transparent but the water over nothing is black. The texture is of water, and I see none of that on my terrain...


as far as i know you only render transparent water if you have terrain underneath it otherwise disable alpha blending

and yes it is wrong maybe use another clearcolor

do you use a skybox or skydome?


Hey Basiror, long time no see, anyway, I am using a skyplane. I am debating just using a vertex program and a fragment program to do the water with and use a bumpmap.... I would be interested in seeing any new screenshots of you terrain engine... since last time. I can send you mine if you would like...

Thanks

Share this post


Link to post
Share on other sites
yes supply a screenshot of the problem, my guess is youre not disabling depthwrites when u draw the water surface

Share this post


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