I found out that the “magic” of having specularmaps and bumpmaps on the water material is done via the renderprogram:
"program water/shoreline_froth sets the renderprogram to be used, and requires the following parameters:
* diffuseMap should point to a 32-bit TGA diffuse map with an alpha channel denoting the transparency of the surface.
* bumpMap should point to a 24-bit TGA normal-map matching up to the diffuse map.
* map should point to a 24-bit TGA reflection map, where darker colours will lead to more cubemap reflection."
It actually works with my texture but looks a bit strange because the reflectionmap (usually specularmap) needs to be inverted.
I think it’s now the second time I stumble over these OpenGL ARB renderprograms and still I can’t find any proper documentation about it. The link on the SD Editing Wiki doesn’t work: http://wiki.splashdamage.com/index.php/Materials#Shaders_in_Materials
Here is the program from the water material… a bit complicated.
Any idea where I can find some documentation on that?
I also wonder if the renderprogram has an influence on the fps and rendering performance if it’s used multiple times.
renderProgram water/shoreline_froth {
program vertex arb { <%
OPTION ARB_position_invariant;
TEMP R0, R1, R2, bitangent;
XPD bitangent, $normalAttrib, $tangentAttrib;
MUL bitangent, bitangent, $tangentAttrib.w;
# bumpmap texture coords
DP4 result.texcoord[0].x, $texCoordAttrib, $diffuseMatrix_s;
DP4 result.texcoord[0].y, $texCoordAttrib, $diffuseMatrix_t;
# vector to eye
SUB R1, $positionAttrib, $viewOrigin;
DP3 result.texcoord[3].x, R1, $transposedModelMatrix_x;
DP3 result.texcoord[3].y, R1, $transposedModelMatrix_y;
DP3 result.texcoord[3].z, R1, $transposedModelMatrix_z;
# tangent->world matrix
DP3 result.texcoord[4].x, $tangentAttrib, $transposedModelMatrix_x;
DP3 result.texcoord[4].y, bitangent, $transposedModelMatrix_x;
DP3 result.texcoord[4].z, $normalAttrib, $transposedModelMatrix_x;
DP3 result.texcoord[5].x, $tangentAttrib, $transposedModelMatrix_y;
DP3 result.texcoord[5].y, bitangent, $transposedModelMatrix_y;
DP3 result.texcoord[5].z, $normalAttrib, $transposedModelMatrix_y;
DP3 result.texcoord[6].x, $tangentAttrib, $transposedModelMatrix_z;
DP3 result.texcoord[6].y, bitangent, $transposedModelMatrix_z;
DP3 result.texcoord[6].z, $normalAttrib, $transposedModelMatrix_z;
MAD R0, $colorAttrib, $colorModulate, $colorAdd;
MUL result.color, $diffuseColor, R0;
%> }
program fragment arb { <%
OPTION ARB_precision_hint_fastest;
TEMP R0, R1, R2, R3, R4, eye, mix, spec;
# get diffuse
TEX R1, fragment.texcoord[0], $diffuseMap, 2D;
# get normal from normal map
TEX R0, fragment.texcoord[0], $bumpMap, 2D;
$if !r_dxnNormalMaps
MOV R0.x, R0.a;
$endif
MAD R2, R0, 2, -1;
$if r_normalizeNormalMaps
TEMP NR1;
MOV R2.z, 0;
DP3 NR1.x, R2,R2;
ADD NR1.x, 1, -NR1.x;
RSQ NR1.x, NR1.x;
RCP R2.z, NR1.x;
$endif
# put in world space
DP3 R0.x, R2, fragment.texcoord[4];
DP3 R0.y, R2, fragment.texcoord[5];
DP3 R0.z, R2, fragment.texcoord[6];
# normalize to eye
DP3 eye.w, fragment.texcoord[3], fragment.texcoord[3];
RSQ eye.w, eye.w;
MUL eye, fragment.texcoord[3], eye.w;
# calc reflection vector: i - 2 * dot(i, n) * n
DP3 R2, eye, R0;
MUL R2, R2, 2;
MAD R4, -R0, R2.x, eye;
# specular
DP3_SAT R0, R4, $sunDirection;
TEX spec, R0, $map, 2D;
MUL spec, spec, $sunColor;
MUL spec, spec, $water_glare;
MUL spec, spec, fragment.color.r;
MOV spec.a, 0;
ADD result.color, spec, R1;
MUL result.color.a, R1, fragment.color.a;
#MOV result.color, fragment.color.a;
#MAD result.color, R4, 0.5, 0.5;
%> }
}
renderProgram water/shoreline_wetshine {
program vertex arb { <%
OPTION ARB_position_invariant;
TEMP R0, R1, R2, bitangent;
XPD bitangent, $normalAttrib, $tangentAttrib;
MUL bitangent, bitangent, $tangentAttrib.w;
# bumpmap texture coords
DP4 result.texcoord[0].x, $texCoordAttrib, $diffuseMatrix_s;
DP4 result.texcoord[0].y, $texCoordAttrib, $diffuseMatrix_t;
# sand texture coords
DP4 result.texcoord[1].x, $texCoordAttrib, $bumpMatrix_s;
DP4 result.texcoord[1].y, $texCoordAttrib, $bumpMatrix_t;
# vector to eye
SUB R1, $positionAttrib, $viewOrigin;
DP3 result.texcoord[3].x, R1, $transposedModelMatrix_x;
DP3 result.texcoord[3].y, R1, $transposedModelMatrix_y;
DP3 result.texcoord[3].z, R1, $transposedModelMatrix_z;
# tangent->world matrix
DP3 result.texcoord[4].x, $tangentAttrib, $transposedModelMatrix_x;
DP3 result.texcoord[4].y, bitangent, $transposedModelMatrix_x;
DP3 result.texcoord[4].z, $normalAttrib, $transposedModelMatrix_x;
DP3 result.texcoord[5].x, $tangentAttrib, $transposedModelMatrix_y;
DP3 result.texcoord[5].y, bitangent, $transposedModelMatrix_y;
DP3 result.texcoord[5].z, $normalAttrib, $transposedModelMatrix_y;
DP3 result.texcoord[6].x, $tangentAttrib, $transposedModelMatrix_z;
DP3 result.texcoord[6].y, bitangent, $transposedModelMatrix_z;
DP3 result.texcoord[6].z, $normalAttrib, $transposedModelMatrix_z;
MAD R0, $colorAttrib, $colorModulate, $colorAdd;
MUL result.color, $diffuseColor, R0;
%> }
program fragment arb { <%
OPTION ARB_precision_hint_fastest;
TEMP R0, R1, R2, R3, R4, eye, mix, spec;
# get diffuse-mask
TEX R1, fragment.texcoord[0], $diffuseMap, 2D;
# get normal from normal map
TEX R0, fragment.texcoord[1], $bumpMap, 2D;
$if !r_dxnNormalMaps
MOV R0.x, R0.a;
$endif
MAD R2, R0, 2, -1;
$if r_normalizeNormalMaps
TEMP NR1;
MOV R2.z, 0;
DP3 NR1.x, R2,R2;
ADD NR1.x, 1, -NR1.x;
RSQ NR1.x, NR1.x;
RCP R2.z, NR1.x;
$endif
# put in world space
DP3 R0.x, R2, fragment.texcoord[4];
DP3 R0.y, R2, fragment.texcoord[5];
DP3 R0.z, R2, fragment.texcoord[6];
# normalize to eye
DP3 eye.w, fragment.texcoord[3], fragment.texcoord[3];
RSQ eye.w, eye.w;
MUL eye, fragment.texcoord[3], eye.w;
# calc reflection vector: i - 2 * dot(i, n) * n
DP3 R2, eye, R0;
MUL R2, R2, 2;
MAD R4, -R0, R2.x, eye;
# specular
DP3_SAT R0, R4, $sunDirection;
TEX spec, R0, $map, 2D;
MUL spec, spec, $sunColor;
MUL spec, spec, $water_glare;
MUL spec, spec, R1.x;
MUL result.color, spec, fragment.color.r;
%> }
}