Seawall Battery


(Mark.C) #1

I have a few questions regarding Seawall Battery.


1- How was the water made, with the effect of a white surf ?

2- How do i add a fog to a certain part of my map, like in Seawall Battery, at the beach and in the water so you dont see the edge of the map ?


(The Wanderer) #2

the white surf effect is basically done with a shader that uses a sin function to periodically vary the rgb value of the water brush vertexes in order to create the effect of the foam appearing/dissapearing.
The foam distribution over the water(so that it only appears around rocks and the shore) is done with indexed blending just like you would do a terrain(with an alphamap and so on).
I’m not sure which shader they used for the fog(as there are a ton of fog shaders in their shader files). You can decompile the map(or maybe just open the bsp with a text editor) to take a look at the actual fog values they used in their woldspawn and maybe water brushes.

Having said that however, you don’t have to do the water that way anymore as there are far easier and better methods that can give you the same if not better results. I’m talking about alphaMod brushes of course.
Take a look at Saberpeak which uses a lot of the same water effects and also has the source files available(do a search here to find its homepage and get the source files). It also has the a nice blend so you don’t see the edge of the map and it’s done without fog


(Mark.C) #3

Thanks alot for that wonderer, lost me a bit with your first sentence though !


(DAbell) #4

This is a post about Seawall Battery fog might help you, or it might just confuse you even more. There was a lot of discussion about water shaders by the saberpeak author do a search for it and you might find it.

http://www.splashdamage.com/index.php?name=pnPHPbb2&file=viewtopic&t=2844&highlight=battery+fog


(The Wanderer) #5

Sorry…you’re right that is kinda confusing.
Let me dissect the a portion of the battery shader that does the foam…maybe this will give you a better idea of what’s going on.


textures/battery/ocean_1
{
	q3map_baseshader textures/battery/ocean_base
	cull none
	deformVertexes wave 1317 sin 0 2.5 0 0.15
 	deformVertexes wave 317 sin 0 1.5 0 0.30
	
	{
		map textures/liquids_sd/seawall_specular.tga
		blendFunc GL_ONE GL_ONE
		rgbGen vertex
		tcGen environment
		depthWrite
	}
	
	{ 
		map textures/liquids_sd/sea_bright_na.tga
		blendFunc blend
		rgbGen identity
		alphaGen const .8
		tcmod scroll 0.005 0.03

	}
	{
		map textures/liquids_sd/seawall_foam.tga
		blendFunc GL_SRC_ALPHA GL_ONE
		rgbGen wave sin 0.2 0.1 0 0.2
		alphaGen vertex
		tcMod turb 0 0.05 0 0.15
		tcmod scroll -0.01 0.08
	}
	{ 
		map textures/liquids_sd/seawall_foam.tga
		blendFunc GL_SRC_ALPHA GL_ONE
		rgbGen wave sin 0.15 0.1 0.1 0.15
		alphaGen vertex
		tcMod turb 0 0.05 0.5 0.15
		tcmod scroll 0.01 0.09
	}
	
}

This is the shader used for the water with the foam. The last 2 stages are responsible for the foam effect. I’ll dissect one of them since they’re pretty much the same. The reason why there’s 2 is because the water has 2 layers of foam to give a more natural effect.


map textures/liquids_sd/seawall_foam.tga

This is just the texture used for the foam.


blendFunc GL_SRC_ALPHA GL_ONE

This is the blending function used. It’s the most important part. The blending formula used in this case is the following.
[(Texture RGB Value) * (RGB Value generated by rgbGen command) * (GL_SRC_ALPHA) ] + [ (Frame buffer RGB data…basically previous stage) * (GL_ONE) ]

Let me explain what each one of those values is

  1. (Texture RGB Value) is well…the texture colors.

  2. (RGB Value generated by rgbGen command) are the values generated by the command

 rgbGen wave sin 0.2 0.1 0 0.2

This command is generating rgb data that oscillate according to a sin wave function. The various number parameters are the base, amplitude, phase and frequency of the sin wave used. Not really that important to understand exactly what this function is … for this example it’s helpful just to think of it as data that’s oscillating between 0 and 1(although this is not exactly the case).

  1. b[/b] is basically the texture alpha channel multiplied by the value generated by the
 alphaGen vertex

command. The texture doesn’t have an alpha channels so that value is 1. The alphaGen vertex command generates an alpha value based on the alpha value assigned to the vertices of the surface the shader is applied. (In case you didn’t know, Yes you can assign alpha and rgb values to vertexes of surfaces…that’s how terrain blending and alphaMod brushes work)
Anyway the value generated by the command is 1 because the alpha values of the surface vertices where this shader is applied is 1. So the whole value of GL_SRC_ALPHA is 1. In that respect you could just replace it with GL_ONE(which is basically a constant 1) for this shader only, but it’s best to leave it at GL_SRC_ALPHA for consistency with shaders that don’t generate a 1 vertex alpha such as the /ocean_0to1 shader.

  1. (Frame buffer RGB data…basically previous stage) is pretty self explanatory. It’s just the data that’s already in the frame buffer from previous stages, that’s going to be blended with the data generated by the current stage.

5 b[/b] is a constant 1.

In the end to total result of the blending is this.

[ (Constant texture RGB data) * (Periodically varying data from 0 to 1) *( 1 ) ] + [constant Data]

As you can see it’s very much dependent on the data from the rgbGen command. When this data is 0 the whole left part of the + sign is 0 which means that all you see is the data in the frame buffer…basically no foam.
When this data is 1 the what you see is pretty much the foam blended with the previous stages giving the full foam effect.

Well that’s pretty much it
The last tcMod commands just scroll the water around giving the impression it’s moving.

Hope this helps although I’m not sure if I made anything clearer. You should check the shader manual which has full explanations of all the commands and can be very useful.


(Mark.C) #6

Thanks for clearing that up Wanderer, i got my fog to work at least, but i still have no clue on how to do the water. Im going to take a look at the Saberpeak source now, if i can find it.!