Specularmap and bumpmap on transparent surfaces


(pazur) #1

Hi,

I’m trying to add specularity and bump-mapping on a transparent texture but as soon as I add it the texture stops to be transparent. Below the specular and bump map are commented out. What am I doing wrong?

I found an example of it here http://wiki.splashdamage.com/index.php/Water_Surfaces#Scrolling_Water_Materials but it doesn’t work for me at all.


material textures/paz/pkinwindow_nocurtain_trans
{
	nonsolid
	noSelfShadow
	noshadows
	twosided
	translucent
	surfaceType "glass"
	forceoverlays
	sort decal

	{
		blend blend
		map textures/paz/pkinwindow_nocurtain_trans.tga
		
		//bumpmap			picmip -1 textures/paz/pkinwindow_nm.tga
		//specularmap		picmip -2 textures/paz/pkinwindow_sp1.tga
	}
}

paz


(Violator) #2

I found the same problem and couldn’t find any solution (was trying to make frosted glass windows) - I think its beyond the engine :frowning:


(SebaSOFT) #3

Actually there are some frosted glass in the stock materials, both translucent and opaque. In consite we have a glass material with some neat specular map. Is in every subway exit (not the tunnel), go check it out!


(Violator) #4

That glass texture doesn’t have a specular or bumpmap -

material textures/glass/dirty_window
{
	noSelfShadow
	noshadows
	twosided
	translucent
	surfaceType "glass"
	forceoverlays
	sort decal

	{
		maskcolor
		map		makealpha(textures/glass/dirty_window_mask1.tga)
	}

	{
		blend		gl_dst_alpha, gl_one
		maskalpha
		program sfx/cubemap
		red		Parm0
		green   Parm1
		blue	Parm2
	}

	{
     	blend	filter
		map		textures/glass/dirty_window2.tga
	}
}

From what I found blend doesn’t work with specular or bumpmaps :frowning: I think the subway looks like its got specular highlights due to the cubemap. However if I add a specular map to the last blend, the shader completely dissapears when rendered :frowning:


(pazur) #5

Very interesting. I still wonder why it works for the water in the example material on the Wiki:


material textures/water/scrolling_water_01 {
	qer_editorimage textures/water/water_01_local
	sort refraction
	translucent
	forceAtmosphere
	nonsolid
	twoSided
	{
		blend blend
		program water/shoreline_froth
		diffuseMap textures/water/water_01_d.tga
		bumpMap textures/water/water_01_local.tga	
		map textures/water/water_01_s.tga	
		
		translate 0, time * (-0.5)
		
		vertexColor
	}
}

Will play around (probably not leading anywhere but worth a try) and let you know if find something out.


(pazur) #6

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


(Violator) #7

Good find pazur :slight_smile: Yeah they’re a bit of a mystery to me as well - it actually looks like assembly language and its a while since I did any of that and that was on a 6502 in the old 8-bit days :slight_smile:


(jRAD) #8

The ARB shaders are this: http://en.wikipedia.org/wiki/ARB_(GPU_assembly_language)
We didn’t switch to using higher-level shading languages until later in the project, so there are still some assembly-based programs around.


(Violator) #9

Great that works pazur :slight_smile: Here’s my shader -

material textures/viotex/shinyglass
{
	noSelfShadow
	noshadows
	twosided
	translucent
	surfaceType "glass"
	forceAtmosphere
	sort decal

	{
     		blend	blend
		program water/simple_cube
		diffusemap  textures/viotex/brick1.tga
                bumpMap     textures/viotex/brick1_n.tga
		map clamp highquality textures/penta/specular.tga
	}
}

(pazur) #10

Uff… So it’s assembly :o I don’t think I will really get into it but I found a renderprogram that fits my needs. It’s program sfx/windowglass.