Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (VoroneTZ, dr_panther, TedMar, vicknick), 833 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
HLSL - PS.1.1 Terrain Shader #35640
11/03/04 06:46
11/03/04 06:46
Joined: Dec 2003
Posts: 1,097
Maryland, USA
Steempipe Offline OP
Serious User
Steempipe  Offline OP
Serious User

Joined: Dec 2003
Posts: 1,097
Maryland, USA
Alright... Sometimes it is just nice to put something here when the forum quiets down

You might ask, why go thru the trouble of converting an already good ps.1.1 terrain shader... maybe just to see if I could (thats how we learn):) But, probably more so because it will be easier to incorporate great things to it without having to deal with the cryptic ASM code.
Easier to take it from ps.1.1 to ps.1.4 and beyond.

Your immediate mission: Add lighting and fog... J/K. But it could give some good shader excercises.
-Somewhere in here is a thread "HLSL Envmapping" where you can grab fog code and see how I crammed it in there.
-lighting is a piece of cake, too.

The code is copied/pasted from my FX file. If you're not sure on how to load the FX file, then look around in the Tutorials Forum for a Tut that I put there.... Or look in the manual.
If you cannot figure out how to get the blendmaps in the A and the B channels and do not have PSP or PS... look in the Tutorial Forum for a Terrain Masking Tutorial I made and it will have info on using free "Imagemagick" to do that.


/***************************************************************

MultiTex.fx

A simple example of using HLSL to multitexture.

-Requires pixelshader.1.1 and DX9.00c
-Lighting and Fog is not worked in.

This should give a "jumping off" point for someone
who wants to convert it to ps.1.4 and ps.2.0, to
allow more textures in the pass. As well as to
explore some things like lighting.

By: Eric Hendrickson-Lambert (AKA Steempipe)

11/2/04: Implemented.

If used, credit is nice... these things take time.

****************************************************************/

float4x4 matWorldViewProj;



//Texture entSkin1 -- Mine has a big skin, not needed here.
Texture entSkin2; // Grass Texture in RGB
Texture entSkin3; // Sand Texture in RGB
Texture entSkin4; // Rock Texture in RGB
Texture mtlSkin1; // Blendmaps in B and in A


sampler s_GrassTex = sampler_state
{
Texture = <entSkin2>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};

sampler s_SandTex = sampler_state
{
Texture = <entSkin3>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};

sampler s_RockTex = sampler_state
{
Texture = <entSkin4>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};


sampler s_BlendTex = sampler_state
{
Texture = <mtlSkin1>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};


struct MULTITEX_VS_OUT // Output to the pixelshader fragment
{
float4 Pos : POSITION;
float2 GrassTex : TEXCOORD0;
float2 SandTex : TEXCOORD1;
float2 RockTex : TEXCOORD2;
float2 BlendTex : TEXCOORD3;
};



MULTITEX_VS_OUT Multi_VS(float4 inPos : POSITION,
float3 inNormal : NORMAL,
float2 inTex1 : TEXCOORD0,
float2 inTex2 : TEXCOORD1,
float2 inTex3 : TEXCOORD2,
float2 inTex4 : TEXCOORD3)
{
MULTITEX_VS_OUT Out;

//////////////////////////////////////////////////////////////////////
// Just the bare minimum needed...
// Take the vertex position of an object and transpose it
// to screen space.

Out.Pos = mul(inPos, matWorldViewProj);

Out.GrassTex = inTex2.xy * 15; // UV Scale -- Could be vecSkill41
Out.SandTex = inTex2.xy * 15; // UV Scale -- Could be vecSkill41
Out.RockTex = inTex2.xy * 15; // UV Scale -- Could be vecSkill41
Out.BlendTex = inTex1.xy;

return Out;
}


float4 Multi_PS(MULTITEX_VS_OUT IN): COLOR
{

//////////////////////////////////////////////////////////////////////
// Lerp the RockTex and GrassTex
// using the blendmap in the A channel of BlendTex

float4 Tex1_Color1 = tex2D(s_RockTex, IN.RockTex);
float4 Tex1_Color2 = tex2D(s_GrassTex, IN.GrassTex);
float4 Tex1_Color3 = tex2D(s_BlendTex, IN.BlendTex).a;
float4 Tex1_BlendOp = lerp(Tex1_Color1, Tex1_Color2, Tex1_Color3);

//////////////////////////////////////////////////////////////////////
// Lerp the SandTex with result from Rock/GrassTex
// using the blendmap in the B channel of BlendTex

float4 Tex2_Color1 = tex2D(s_SandTex, IN.SandTex);
float4 Tex2_Color2 = tex2D(s_BlendTex, IN.BlendTex).b;

//////////////////////////////////////////////////////////////////////
// Assemble the final blend

float4 Final_Output = lerp(Tex1_BlendOp, Tex2_Color1, Tex2_Color2);

//////////////////////////////////////////////////////////////////////
// Could add a detailmap... could live in the A channel of someone.

//float4 Detailmap = tex2D(s_RockTex, IN.RockTex);
//float4 Final_Output_Detailmap = Tex2_BlendOp + Detailmap - 0.5;

//////////////////////////////////////////////////////////////////////
// Send to the framebuffer

return Final_Output; // return Final_Output_Detailmap
// if using that portion on the
// effect.
}



technique multitex_fx
{
pass One
{
sampler[0] = (s_GrassTex);
sampler[1] = (s_SandTex);
sampler[2] = (s_RockTex);
sampler[3] = (s_BlendTex);

VertexShader = compile vs_1_1 Multi_VS();
PixelShader = compile ps_1_1 Multi_PS();
}
}


////////////// End of FX

Re: HLSL - PS.1.1 Terrain Shader [Re: Steempipe] #35641
11/03/04 09:35
11/03/04 09:35
Joined: Aug 2003
Posts: 169
Tennessee, US
Ahriman Offline
Member
Ahriman  Offline
Member

Joined: Aug 2003
Posts: 169
Tennessee, US
Just started getting used asm coding, now I have to learn HLSL . Thank you very much Eric I appreciate it. This should atleast point me in the right direction for all of this.

Re: HLSL - PS.1.1 Terrain Shader [Re: Ahriman] #35642
11/03/04 10:19
11/03/04 10:19
Joined: Dec 2003
Posts: 1,097
Maryland, USA
Steempipe Offline OP
Serious User
Steempipe  Offline OP
Serious User

Joined: Dec 2003
Posts: 1,097
Maryland, USA
Your welcome. I look forward to seeing screenshots of effects that you program in the future. ASM, HLSL..... fun stuff.

Thanks,
Eric

Re: HLSL - PS.1.1 Terrain Shader [Re: Steempipe] #35643
11/03/04 11:25
11/03/04 11:25
Joined: Aug 2001
Posts: 2,320
Alberta, Canada
William Offline
Expert
William  Offline
Expert

Joined: Aug 2001
Posts: 2,320
Alberta, Canada
This is great! Thanks Steempipe.


Check out Silas. www.kartsilas.com

Hear my band Finding Fire - www.myspace.com/findingfire

Daily dev updates - http://kartsilas.blogspot.com/
Re: HLSL - PS.1.1 Terrain Shader [Re: Steempipe] #35644
11/05/04 20:34
11/05/04 20:34
Joined: Aug 2003
Posts: 169
Tennessee, US
Ahriman Offline
Member
Ahriman  Offline
Member

Joined: Aug 2003
Posts: 169
Tennessee, US
Quick question for you Eric, I am sure this is possible but I want to make sure. Would it be possible instead of using an Alpha for the texture placement, using vertex height? So that you could then use PS.1.1 and use the 4 textures on the terrain.

Re: HLSL - PS.1.1 Terrain Shader [Re: Ahriman] #35645
11/06/04 07:14
11/06/04 07:14
Joined: Dec 2003
Posts: 1,097
Maryland, USA
Steempipe Offline OP
Serious User
Steempipe  Offline OP
Serious User

Joined: Dec 2003
Posts: 1,097
Maryland, USA
Interesting idea and we should explore that. Also, I am kicking around another thought... kind of forming it little by little. Thanks for the suggestion.

William: No problem, man.

Eric


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