Sponsored Adverts

Author Topic: Specularmap and bumpmap on transparent surfaces  (Read 6476 times)

0 Members and 1 Guest are viewing this topic.

Offline pazur

  • Jr. Member
  • *
  • Posts: 69
Specularmap and bumpmap on transparent surfaces
« on: August 03, 2010, 11:09:06 AM »
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


Offline kat

  • Administrator
  • Hero Member
  • *
  • Posts: 2187
Re: Specularmap and bumpmap on transparent surfaces
« Reply #1 on: August 03, 2010, 04:00:18 PM »
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.

Offline pazur

  • Jr. Member
  • *
  • Posts: 69
Re: Specularmap and bumpmap on transparent surfaces
« Reply #2 on: August 03, 2010, 09:35:22 PM »
Maybe I can copy what is in the water material that makes it possible. Will play around and let you know.

Offline kat

  • Administrator
  • Hero Member
  • *
  • Posts: 2187
Re: Specularmap and bumpmap on transparent surfaces
« Reply #3 on: August 03, 2010, 10:39:38 PM »
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.

Offline pazur

  • Jr. Member
  • *
  • Posts: 69
Re: Specularmap and bumpmap on transparent surfaces
« Reply #4 on: August 04, 2010, 06:10:27 AM »
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: [Select]
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;
%> }
}

Any idea where I can find a documentation on this?

Offline kat

  • Administrator
  • Hero Member
  • *
  • Posts: 2187
Re: Specularmap and bumpmap on transparent surfaces
« Reply #5 on: August 04, 2010, 03:13:11 PM »
http://wiki.splashdamage.com/index.php?title=Render_program_documentation

There is no documentation, looks like that page hasn't been written yet. And that's why you need to looks for similar shaders like I said above because different visual effects are treated in different ways. Glas and transparent surfaces don't normally have normal or specular maps; specular is done via env_maps. D3/Q4 et-al used alpha test for shaders that did have normals but that only allowed certain types of masks and transparencies.

You still haven't said what it is you're trying to do here so I can only repeat what I've already said. However, if you want to look into ARB and fragment programing I'd go and have a look at modwiki as I think the chaps over there looked into to this.

Offline pazur

  • Jr. Member
  • *
  • Posts: 69
Re: Specularmap and bumpmap on transparent surfaces
« Reply #6 on: August 05, 2010, 02:54:47 AM »
jRAD from SD replied to my thread over in their forum. The renderprogam language is this here: http://en.wikipedia.org/wiki/ARB_%28GPU_assembly_language%29 ... and to be frankly it looks a bit too complicated for me as it's a kind of Assembler :o

What I tried to do on the texture is taking my window texture and adding some transparency to it so you can see things behind it. My plan was to have the bumpmap for the wood of the frame and the same specularity as on the non-transparent windows.



Notice that the transparent window on the bottom has "map" instead of "diffusemap" and the color of the wooden frame is brighter. It's based on the original glass shader that came with ETQW (textures/glass/dirty_window) that is also using only "map".

... and yea modwiki.net is awesome!

Tags:
 

Sponsored Adverts
RSS Content is copyright © KatsBits™ 2017 unless otherwise stated. All Rights Reserved.
No part of this web site may be reproduced (except for personal use, or otherwise stated) without prior written permission from KatsBits.com. For more infomation on copyright click here.
Web design cpdtAdvertisePrivacy PolicyDMCA (about DMCA) Home Store Workshops Blog Jobs Support About Katsbits Contact Site Search KatsBits Help Site Map RSS feed Forum YouTube FaceBook LinkedIn Twitter IMVU