Correct way to do transparent water?

Started by
5 comments, last by zedzeek 19 years, 6 months ago
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...
Advertisement
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)
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...
This is one of those screenshots are helpful situations.
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?
http://www.8ung.at/basiror/theironcross.html
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
yes supply a screenshot of the problem, my guess is youre not disabling depthwrites when u draw the water surface

This topic is closed to new replies.

Advertisement