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
-
(Texture RGB Value) is well…the texture colors.
-
(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).
-
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.
-
(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.