Change water color?

Jan 23, 2008 at 4:30 PM
How would I change the water color? Right now it has a purple tint to it and I can't seem to find where this color is coming from. I've tried changing all textures associated with it and the AmbientColor, SpecularColor, and DiffuseColor properties and can't seem to get this to change. Am I overlooking something?
Jan 23, 2008 at 4:50 PM
In 0.82b? LordIkon will be best able to answer this, though my guess would be its an artifact from the port from XNA 1.0 to 2.0. The water is predominantly reflection/refraction rendering, pulling the texture data from render targets. In XNA 2.0, render targets are automatically cleared to a purple color, so my guess would be that the render targets aren't being properly cleared before use, resulting in a purple background. When used as a reflection/refraction map, these render targets may be giving the purple tint.
Jan 23, 2008 at 7:57 PM
The fog component can associate with the water component. Whenever you're underwater the fog color is altered. This should be in either the fog or water components, and you will see a color value somewhere in there. I don't have code in front of me, and it has been a couple months, so I'm guessing. So far I'm talking about water-fog.

However, the actual water color itself was never implemented like it was meant to, so the color of the water is being set in the water shader file I believe. water.fx I think?
Jan 23, 2008 at 9:36 PM
Ahh ok, I found it. Thanks! Here is what I changed just in case anyone else is wondering:

private void DrawRefractionMap(GameTime gameTime, ref Matrix ViewMatrix, ref Matrix ProjectionMatrix, Light SceneLight, Camera CurrentCam) {
Device.SetRenderTarget(0, RefractionRenderTarg);

private void DrawReflectionMap(GameTime gameTime, ref Matrix ViewMatrix, ref Matrix ProjectionMatrix, Light SceneLight, Camera CurrentCam) {
Device.SetRenderTarget(0, ReflectionRenderTarg);

Thanks again guys for the timely response. Awesome work on the engine by the way!
Jan 23, 2008 at 10:14 PM
The fact that you specifically mentioned it was purple was what tipped me off. Alternately, you could create the render targets with the PlatformContents flag. That should go back to the old XNA behavior. Or just call Clear. Either way. :)
Jan 24, 2008 at 3:38 PM
I decided to try using the PlatformContents to test it out and it gave some weird results. Basically my scene is just a ship floating out in the middle of the ocean. It rendered the ship onto the water's reflection/refraction in a very strange way. Here is an image of the results:

Basically I decided to go back to clearing it and using the WaterColor property as the color it clears to. Would this be a bad use of the WaterColor property?

Device.Clear(new Color(this.WaterColor));
Jan 24, 2008 at 5:01 PM
Edited Jan 24, 2008 at 5:13 PM
Having a water color other than black can give a less realistic look where water meets terrain. If you're not concerned with that then I would say what you're doing is fine.

I'm curious how your reflection ended up like that. The reflection is based on a rendertarget, so that would mean your rendertarget ended up strange. You may want to output the rendertarget to a file to see what it looks like. I believe the engine has that ability, but it is commented out. It should be in the drawreflection() function.