Game Editing > Textures & 2D content

Specularmap and bumpmap on transparent surfaces

(1/2) > >>

pazur:
Any idea how I can solve this problem with a ETQW (id Tech 4) transparent material?

http://www.splashdamage.com/forums/showthread.php?t=21686

Basically I want to add a specularmap and bumpmap to a transparent material but when I do that it becomes non-transparent. Do I maybe need to add an alpha channel to the specularmap and bumpmap and "blend" it too?

paz

kat:
Best thing for this one would be to see if you can find something similar to what you're trying to set up in the default assets, the reason being that water probably uses a different process to say glass with cracks in it.

pazur:
Maybe I can copy what is in the water material that makes it possible. Will play around and let you know.

kat:
Are you trying to make a 'water' type shader? If you are then yes, copy that and play around with the parameters. Else no, you need to find a material similar to what you want - water isn't just a material/shader it's a volume type which means shaders are written specifically for that task, it's why, if you were doing 'glass' and not 'water', you need to find the correct type of shader.

pazur:
I found out it's the renderprogram that can make the specularmap and bumpmap go on transparent surfaces. It's now the second time I stumble over these ARB OpenGL programs but I can't find any proper documentation on it. The link on the SD Wiki doesn't work: http://wiki.splashdamage.com/index.php/Materials#Shaders_in_Materials

That's the code from the water material that I looked at:


--- Code: ---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;
%> }
}

--- End code ---

Any idea where I can find a documentation on this?

Navigation

[0] Message Index

[#] Next page

Go to full version