3D Game Programming All in One (Course Technology PTR Game Development Series)
Water blocks are special objects that we can insert into our game world via a mission file. Here is a water block:
new WaterBlock(Water) { position = "-1024 -1024 0"; rotation = "1 0 0 0"; scale = "2048 2048 125"; UseDepthMask = "1"; surfaceTexture = "./water"; liquidType = "OceanWater"; density = "1"; viscosity = "15"; waveMagnitude = "1"; surfaceOpacity = "0.75"; envMapIntensity = "0.7"; TessSurface = "50"; TessShore = "60"; SurfaceParallax = "0.5"; FlowAngle = "0"; FlowRate = "0"; DistortGridScale = "0.1"; DistortMag = "0.05"; DistortTime = "0.5"; ShoreDepth = "20"; DepthGradient = "1"; MinAlpha = "0.03"; MaxAlpha = "1"; removeWetEdges = "0"; specularColor = "1.000000 1.000000 1.000000 1.000000"; specularPower = "6"; params0 = "0.32 -0.67 0.066 0.5"; extent = "100 100 10"; textureSize = "32 32"; params2 = "0.39 0.39 0.2 0.133"; envMapOverTexture = "./day_0007"; params3 = "1.21 -0.61 0.13 -0.33"; params1 = "0.63 -2.41 0.33 0.21"; seedPoints = "0 0 1 0 1 1 0 1"; floodFill = "1"; };
Water blocks repeat in the same way that terrain blocks repeat, and because water blocks are flat, the only positioning information of real interest is the height. Table 18.2 describes the significant properties (and there are many!).
Property | Description |
---|---|
surfaceTexture | Specifies the texture generally used for the surface. |
ShoreTexture | Specifies the texture used in shallow areas. |
envMapOverTexture | Defines the environment map texture used when looking over the fluid surface. |
envMapUnderTexture | Defines the environment map texture used when looking under the fluid surface. |
surfaceOpacity | Specifies the maximum opacity of the surface (0.0 -> 1.0). |
envMapIntensity | Specifies the intensity of the applied environment map (0.0 -> 1.0). Setting the intensity to 0 results in the environment map pass being skipped, which increases performance slightly. |
UseDepthMask | Toggles the depth map feature on and off. |
ShoreDepth | Specifies the depth at which the shore texture will start being applied. Larger values result in larger shore texture areas. |
DepthGradient | Specifies the gradient that the shore textures will interpolate between MinAlpha and MaxAlpha. The value of 1 equates to linear interpolation, whereas values 0 -> 1 equate to fast fade-out/slow fade-in and the values 1 -> inf equate to slow fade-out/fast fade-in (from deep to shallow). |
MinAlpha/MaxAlpha | Specifies the alpha levels used from shore to deep fluid. The MinAlpha can be used to prevent totally transparent areas. You will always be able to see underneath the fluid surface, so use the fog volumes from the Sky object to restrict visibility underwater. |
TessSurface/TessShore | Specifies the number of times the textures are repeated over the water block surface for surface/shore textures. |
SurfaceParallax | Renders the surface as two layers. When the surface is distorting or flowing, then this controls the ratio of one surface with respect to the other. If you set this to 0.5, then one surface will move at half the speed of the other. |
FlowAngle/FlowRate | Specifies the way the fluid flows. The FlowRate controls how fast the fluid flows, and the FlowAngle is a polar angle controlling its direction. Using a FlowRate of 0 completely stops the fluid from flowing. |
DistortGridScale/DistortMag/DistortTime | Controls the distortion effect of the fluid surface. This allows you to create many different surfaces. To control the speed, use DistortTime. Use DistortMag to control the overall magnitude of the distortion. DistortGridScale normally does not need adjusting but can be used to adjust a setting for a small water block that may not look correct on a large one. |
Water block textures, as described in various places in Table 18.2, can be created in exactly the same way as cloud textures. In fact, you can even get away with using cloud textures in a pinch!
Take a look at Figure 18.17 to see a water block in action.
Категории