Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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
4 registered members (degenerate_762, AbrahamR, AndrewAMD, ozgur), 667 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[Solved] I ask help to combine two shaders #435334
01/06/14 13:01
01/06/14 13:01
Joined: May 2008
Posts: 257
D
djfeeler Offline OP
Member
djfeeler  Offline OP
Member
D

Joined: May 2008
Posts: 257
Hello,

I wonder if anyone can help me to combine these two shaders.

first shader tiling

Code:
float4x4 matWorld;
float4x4 matWorldViewProj;
float4 vecSkill41;

texture entSkin1;

sampler TexSampler = sampler_state
{
	Texture = <entSkin1>;
	MipFilter = Linear;
	AddressU = Wrap;
	Addressv = Wrap;
};

struct out_tiling
{
	float4 Pos	: POSITION;
	float2 Tex0	: TEXCOORD0;
};

out_tiling vs_20
(
	in float4 inPos 	: POSITION,
	in float2 inTex0 	: TEXCOORD0
)
{
	out_tiling Out;
	
	Out.Pos = mul(inPos,matWorldViewProj);
	Out.Tex0 = inTex0;

	return Out;
}
	
float4 ps_20 ( out_tiling In ): COLOR
{
	float2 Coord;
	Coord.x = In.Tex0.x * vecSkill41.x;
	Coord.y = In.Tex0.y * vecSkill41.y;
	
	return tex2D ( TexSampler, Coord );
}

technique TexTile
{
	pass one
	{
		VertexShader = compile vs_2_0 vs_20();
		PixelShader = compile ps_2_0 ps_20();	
	}	
}




And this other shader with light

Code:
float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecSunDir;
float4 vecSunColor;
float4 vecSkill41;
texture entSkin1;

sampler ColorMapSampler = sampler_state
{ 
   Texture = <entSkin1>; 
}; 
    
void DiffuseVS( 
   in float4 InPos: POSITION, 
   in float3 InNormal: NORMAL, 
   in float2 InTex: TEXCOORD0, 
   out float4 OutPos: POSITION, 
   out float2 OutTex: TEXCOORD0, 
   out float3 OutNormal: TEXCOORD1)
   { 
 
   OutPos = mul(InPos, matWorldViewProj); 

   OutNormal = normalize(mul(InNormal, matWorld));

   OutTex = InTex*vecSkill41.x; 

} 
    
float4 DiffusePS( 
   in float2 InTex: TEXCOORD0, 
   in float3 InNormal: TEXCOORD1): COLOR 
{ 
 
   float4 Diffuse = saturate(dot(-vecSunDir, normalize(InNormal)));
   Diffuse *= vecSunColor; 
 
   float4 Color = tex2D(ColorMapSampler, InTex); 

   return (0.5+Diffuse)*Color; 
} 
 
technique DiffuseTechnique 
{ 
   pass P0 
   { 
      VertexShader = compile vs_2_0 DiffuseVS(); 
      PixelShader  = compile ps_2_0 DiffusePS(); 
   } 
}



I do this but I'm not sure if this is good.

Code:
float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecSunDir;
float4 vecSunColor;
float4 vecSkill41;
texture entSkin1;

sampler ColorMapSampler = sampler_state
{ 
   Texture = <entSkin1>;
   MipFilter = Linear;
	AddressU = Wrap;
	Addressv = Wrap; 
}; 
    
void DiffuseVS( 
   in float4 InPos: POSITION, 
   in float3 InNormal: NORMAL, 
   in float2 InTex: TEXCOORD0, 
   out float4 OutPos: POSITION, 
   out float2 OutTex: TEXCOORD0, 
   out float3 OutNormal: TEXCOORD1)
   { 
 
   OutPos = mul(InPos, matWorldViewProj); 

   OutNormal = normalize(mul(InNormal, matWorld));

   OutTex = InTex;

} 
    
float4 DiffusePS( 
   in float2 InTex: TEXCOORD0, 
   in float3 InNormal: TEXCOORD1): COLOR 
{ 
 	float2 Coord;
	Coord.x = InTex.x * vecSkill41.x;
	Coord.y = InTex.y * vecSkill41.y;
   
   float4 finalCoord = tex2D ( ColorMapSampler, Coord );
   
   float4 Diffuse = saturate(dot(-vecSunDir, normalize(InNormal)));
   Diffuse *= vecSunColor; 
 
   float4 Color = tex2D(ColorMapSampler, InTex); 

   return (0.5 + Diffuse) * Color * finalCoord;
} 
 
technique DiffuseTechnique 
{ 
   pass P0 
   { 
      VertexShader = compile vs_2_0 DiffuseVS(); 
      PixelShader  = compile ps_2_0 DiffusePS(); 
   } 
}



Thanks in advance.

djfeeler

Last edited by djfeeler; 01/13/14 07:19.
Re: I ask help to combine two shaders [Re: djfeeler] #435335
01/06/14 13:15
01/06/14 13:15
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Just take your "lighting" shader and replace
OutTex = InTex*vecSkill41.x;
with
OutTex = InTex*vecSkill41.xy;
That should exactly be what you are looking for, isn't it?


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: I ask help to combine two shaders [Re: Superku] #435336
01/06/14 13:33
01/06/14 13:33
Joined: May 2008
Posts: 257
D
djfeeler Offline OP
Member
djfeeler  Offline OP
Member
D

Joined: May 2008
Posts: 257
Yes that is exactly what I wanted. Thanks for your help.


Moderated by  Blink, Hummel, Superku 

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