I pushed the changes as Mike suggested. Mike: Is there a chance that some implementations of GLSL might, in fact, provide mul()? I'm no expert at that sort of thing, but I never encountered any errors with the use of mul() while doing my own testing.
Is this correct?
- Code: Select all
<technique name="Techniques/TerrainBlend8EditTriplanar.xml" />
<texture unit="1" name="Textures/TerrainBlend4/Grass0126_2_S.jpg"/>
<texture unit="2" name="Textures/TerrainBlend4/Desert2.jpg" />
<texture unit="3" name="Textures/TerrainBlend4/Cliff2.jpg" />
<texture unit="4" name="Textures/TerrainBlend4/Cliff3.jpg" />
<parameter name="MatSpecColor" value="0 0 0 1" />
<parameter name="DetailTiling" value="1024 1024" />
<parameter name="BumpStrength" value="128" />
<parameter name="PackTexFactors" value="0.25 0.5 512 9" />
GLSL compilation errors aside, that isn't the correct usage of the shader. Perhaps a bit more explanation of it is in order.
The shader (either 8Detail or 8DetailTriplanar) only uses 3, 4 or 5 texture units. The number used depends on whether or not BUMPMAP and USEMASKTEXTURE are specified as options.
Slot 0: Weight map for terrain types 0,1,2 and 3
Slot 1: Weight map for terrain types 4,5,6 and 7
Slot 2: Terrain texture atlas (more on its format/layout in a bit)
Slot 3: Normal map of terrain texture atlas
Slot 4: Mask texture (provided to allow for visualization of the editing mask in the terrain editor).
The weight maps are straightforward: a value of 0 for a given component corresponding to a terrain type means that terrain type provides no contribution, a value of 1 means it provides full contribution. All weights are balanced in the shader so they add up to 1.
The terrain texture atlas is constructed as an atlas of 8 terrain types. Each type provides the diffuse color in RGB and the height of the texture in A. The height channel is used to alter the blending weight as described earlier in the thread, achieving the effect of terrain such as raised stones more realistically combining with terrain such as dirt, so that dirt tends to fill in the cracks around the stones rather than just simply fading from one to the other. The terrain texture provided with the editor can be found in Bin/TerrainEditorData/Textures/diff.png with the normal map at normal.png. It is laid out in a 4x2 pattern of textures (4 across, 2 down), and each texture is 512 pixels in size. This is important. The PackTexFactors passed to the shader as a float4/vec4 describes this layout, and must be edited if the layout is changed. The first float, 0.25, describes the width of a single terrain texture in comparison to the entire texture. ie, 0.25 (1/4, given that the texture is 4 terrain types wide). The second float, 0.5, describes the height of a single terrain texture in relation to the height of the whole texture. In this case, 0.5 given that the texture is 2 terrain types high. The third float is the size, in pixels, of a single terrain type texture. The final float is the exponential size, of the top level terrain texture dimensions. ie, 9 in this case, given that 2^9=512. This exponent is used in the calculation of the mip-map level in a custom fashion described earlier in the thread.
The mask texture specifies a texture that is mapped across the entire terrain. The red channel is currently the only mask channel used, though I might provide for the ability to use up to 4 mask layers in a layer iteration of the editor. The mask value is used to mix between the final diffuse texture color and a reddish mask color, to give a visual indicator of where your mask is applied. The mask texture only really makes sense in the context of the editor, and in a real game usage should probably be omitted.
The BumpStrength shader uniform is a bit of legacy cruft that is no longer used, and can safely be omitted.