Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, degenerate_762, ozgur), 1,311 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Print Thread
Rate Thread
Specular normalmapping with specular map #248554
01/27/09 17:03
01/27/09 17:03
Joined: Apr 2005
Posts: 4,506
Germany
F
fogman Offline OP
Expert
fogman  Offline OP
Expert
F

Joined: Apr 2005
Posts: 4,506
Germany
RedPhoenix has written an nice specular shader which fits
into the standard gs shader library.

Itīs a specular mapping shader, that uses the alpha channel
of the normalmap as specular map.
It should work with lightmapped level meshes, too.

Just paste the code into a fx file.
It uses the default.fx library.

Code:
#include <transform>
#include <fog>
#include <pos>
#include <normal>
#include <tangent>
#include <light>
#include <vecskill>
#include <bump_vs>

texture entSkin1;	// texture
texture entSkin2;	// normal map or lightmap
texture entSkin3;	// normal map on blocks

sampler sBaseTex = sampler_state { Texture = <entSkin1>; MipFilter = Linear;	};
sampler sSkin2 = sampler_state { Texture = <entSkin2>; MipFilter = Linear;	};
sampler sSkin3 = sampler_state { Texture = <entSkin3>; MipFilter = Linear;	};

//vecSkill41.x: float facAmbient = 0.2;
//vecSkill41.y: float facDiff = 0.5;
//vecSkill41.z: float facSpec = 0.8;
//vecSkill41.w: float shininess = 4;

bumpOut bump_VS_corrected(
   in float4 inPos: 	POSITION, 
   in float3 inNormal:	NORMAL,
   in float2 inTex1: 	TEXCOORD0,
   in float2 inTex2: 	TEXCOORD1,
   in float4 inTangent: TEXCOORD2)
{
	bumpOut Out;

	Out.Pos	= DoTransform(inPos);
	Out.Tex1 = inTex1;
	Out.Tex2 = inTex2;
	Out.Fog	= DoFog(inPos);

    float facAmbient = DoDefault(vecSkill41.x*0.01,0.5); 
    float3 P = DoPos(inPos);	
	Out.Ambient = facAmbient * vecLight;	

	CreateTangents(inNormal,inTangent);
	Out.WorldPos = DoTangent(normalize(vecViewPos-P));//DoPos(inPos);
	Out.Light1 = DoTangent(normalize(vecLightPos[0].xyz-P));
	Out.Light2 = DoTangent(normalize(vecLightPos[1].xyz-P));
	
	float facDiff = DoDefault(vecSkill41.y*0.05,2.5);
	Out.Diffuse1 = DoLightFactor(vecLightPos[0],P) * vecLightColor[0] * facDiff;
	Out.Diffuse2 = DoLightFactor(vecLightPos[1],P) * vecLightColor[1] * facDiff;
	
	return Out;		
}

float4 DoBlinn(bumpOut In,float4 Normal)
{
	float facSpec = vecSkill41.z;
	float shininess = vecSkill41.w;
			
	float3 viewDir = In.WorldPos;//DoTangent(normalize(vecViewPos-In.WorldPos));	
			
	float fLight = dot(normalize(In.Light1),Normal.rgb);
	float3 Halfway = normalize(In.Light1+viewDir);

	float4 Diffuse = In.Diffuse1 * (saturate(fLight) + pow(max(dot(Halfway,Normal.rgb),0),shininess) *facSpec * Normal.w);		

	fLight = dot(normalize(In.Light2),Normal.rgb);
	Halfway = normalize(In.Light2+viewDir);
	Diffuse += In.Diffuse2 * (saturate(fLight) + pow(max(dot(Halfway,Normal.rgb),0),shininess) * facSpec * Normal.w );		

	return Diffuse;
}

float4 blinnBump_PS(bumpOut In): COLOR
{
	float4 Base = tex2D(sBaseTex,In.Tex1);
	float4 Normalmap = tex2D(sSkin2,In.Tex1);
   Normalmap.rgb = Normalmap.rgb*2-1;

   float4 Diffuse = DoBlinn(In,Normalmap);	
	return Base * (Diffuse + In.Ambient);
}

float4 blinnBumpLM_PS(bumpOut In): COLOR
{
	float4 Base = tex2D(sBaseTex,In.Tex1);
	float4 Lightmap = tex2D(sSkin2,In.Tex2);
	float4 Normalmap = tex2D(sSkin3,In.Tex1);
   Normalmap.rgb = Normalmap.rgb*2-1;

   float4 Diffuse = DoBlinn(In,Normalmap);	
	return Base * (Diffuse + Lightmap);
}



technique blinn
{
	pass one
	{		
		VertexShader = compile vs_2_0 bump_VS_corrected();
		PixelShader = compile ps_2_0 blinnBump_PS();
	}
}

technique blinn_lm
{
	pass one
	{		
		VertexShader = compile vs_2_0 bump_VS_corrected();
		PixelShader = compile ps_2_0 blinnBumpLM_PS();
	}
}

technique fallback { pass one { } } 



no science involved
Re: Specular normalmapping with specular map [Re: fogman] #249385
02/02/09 09:29
02/02/09 09:29
Joined: Apr 2005
Posts: 4,506
Germany
F
fogman Offline OP
Expert
fogman  Offline OP
Expert
F

Joined: Apr 2005
Posts: 4,506
Germany
Here you can see it in action, applied to the knife on the right side:



RedPhoenix has done a good job.
Maybe someone can add it to the wiki. Iīve no time atm.


no science involved
Re: Specular normalmapping with specular map [Re: fogman] #294967
10/22/09 09:15
10/22/09 09:15
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline
Serious User
darkinferno  Offline
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
i pasted into an fx file an tried to start it in the shader viewer:

error in effect:
mtl_specBump(36): error X3018: invalid subscript 'Tex1'

> Out.Tex1 = inTex1;<

any ideas?

Re: Specular normalmapping with specular map [Re: darkinferno] #294982
10/22/09 11:44
10/22/09 11:44
Joined: Nov 2008
Posts: 946
T
the_clown Offline
User
the_clown  Offline
User
T

Joined: Nov 2008
Posts: 946
I'm not sure, but I think something with the A7 versions changed so the shader got outdated; He somewhen stated he had to overwork it for his project, and I think he forgot to post the updated version here.

Re: Specular normalmapping with specular map [Re: the_clown] #294990
10/22/09 12:23
10/22/09 12:23
Joined: May 2009
Posts: 1,816
at my pc (duh)
darkinferno Offline
Serious User
darkinferno  Offline
Serious User

Joined: May 2009
Posts: 1,816
at my pc (duh)
ohhh... makes sense, well, lets hope for an update


Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1