Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, monk12, TipmyPip, Quad, aliswee), 1,029 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
blending 5 textures with this terrain-shader? #44874
04/26/05 07:59
04/26/05 07:59
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
Hi all you experts!

Can someone add a second pass (as it says in the todo) for blending two more textures? If someone does it, i'll jump 10 meters off ground...
I'm sorry not to be able to do it myself.
Thank you!
Code:
/////////////////////////////////////////
// Title: Terrain multitexture material
// Conitec / jcl 2004
/////////////////////////////////////////
// Blends 3 textures together, according to
// the red and green channel in the first skin.
// The blue channel can be used for a shadow map.

// Skin1 - Terrain RGB blend & shadow mask
// Skin2 - Base terrain texture
// Skin3 - Red channel masked tiled texture
// Skin4 - Green channel masked tiled texture
// Skin5 - Replacement base texture for non-shader hardware
// Skin6 - Replacement detail texture for non-shader hardware

// Skill41 - Skin2 scale, float(1..50)
// Skill42 - Skin3 scale, float(1..50)
// Skill43 - Skin4 scale, float(1..50)
// Skill44 - ambient, float(-1..1)

// Based on concepts by Thomas 'ventilator' Oppl
// and Eric 'Steempipe' Hendrickson-Lambert

// Requires A6.31, VS 1.1, PS 1.1

//todo: pass real sun color
//todo: blend 2 more textures on blue and alpha in a second pass


MATERIAL mtl_terrainmulti3
{
effect = "

//enable: Skin4 Masked on Green
//help: Skin 4 contains a texture masked by the Skin1 green channel.
#define GREENMASK

//enable: Shadow Map on Blue
//help: Terrain contains a shadow map on the Skin1 blue channel.
//help: With PS 1.1 (GeForce3), sun & dynamic lights are then disabled.
#define SHADOWMAP

//enable: PS 1.3
//help: Support pixelshader version 1.3 if available.
//help: This allows shadow map and lights on terrain at the same time.
#define PS13

//enable: DirectX Lighting
//help: Use the DirectX Lighting Formula for dynamic Lights.
//help: Otherwise use the Conitec Formula that produces smoother light.
//#define DXLIGHTING

float4x4 matWorld;
float4x4 matWorldInv;
float4x4 matWorldView;
float4x4 matWorldViewProj;

float4 vecSunDir;
float4 vecSunDiffuse = float4(200.f/255.f, 200.f/255.f, 200.f/255.f, 1.f);
float4 vecFog;
float4 vecLight;

Texture entSkin1; // Red/green for blending, blue for shadow
Texture entSkin2; // Basic tiled terrain texture
Texture entSkin3; // Red masked tiled texture
Texture entSkin4; // Green masked tiled texture

float4 vecSkill41;

float4 vecLightPos[8]; // preset this with light positions (xyz) and ranges (w)
float4 vecLightColor[8]; // preset this with light colors
float3 vecFalloff = float3(0.f, 0.f, 1.5f);


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

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

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

#ifdef GREENMASK
sampler sGreenTex = sampler_state
{
Texture = <entSkin4>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};
#endif

//////////////////////////////////////////////////////////////////////
// return the sun light on the surface
float4 DoSunLight(float3 N)
{
// modulate the sunlight by the surface angle
return vecSunDiffuse * dot(N,-vecSunDir);
}

// return the dynamic light on the surface
float4 DoPointLight(float3 P, float3 N, int i)
{
// calculate the light ray pointing from the light to the surface
float3 D = (float3)vecLightPos[i]-P;
// calculate the angle between surface and light ray
float NdotL = dot(N,normalize(D));
// modulate the light by the surface angle
float4 Color = vecLightColor[i] * NdotL;

// calculate the light attenuation factor, DX uses a really strange formula here
float fac = 0.f;
if (NdotL >= 0.f && vecLightPos[i].w > 0.f)
{
// get the distance factor
float LD = length(D)/vecLightPos[i].w;
#ifdef DXLIGHTING
if (LD < 1.3f)
fac = 1.f/(vecFalloff.x + vecFalloff.y*LD + vecFalloff.z*LD*LD);
#else // linear Lighting
if (LD < 1.f)
fac = 1.f - LD;
#endif
}
return Color * fac;
}


float DoFog(float4 Pos)
{
// convert the vector position to view space to get it's depth (.z)
float3 P = mul(Pos,matWorldView);
// apply the linear fog formula
return saturate((vecFog.y-P.z) * vecFog.z);
}

//////////////////////////////////////////////////////////////////////
struct TMULTI_VS_OUT // Output to the pixelshader fragment
{
float4 Pos : POSITION;
float4 Color: COLOR0;
float Fog: FOG;
float2 MaskCoord : TEXCOORD0;
float2 BaseCoord : TEXCOORD1;
float2 RedCoord : TEXCOORD2;
#ifdef GREENMASK
float2 GreenCoord : TEXCOORD3;
#endif
};


TMULTI_VS_OUT TMulti_VS(
float4 inPos : POSITION,
float3 inNormal : NORMAL,
float2 inTexCoord0 : TEXCOORD0)
{
TMULTI_VS_OUT Out;

// transform the vector position to screen coordinates
Out.Pos = mul(inPos,matWorldViewProj);

// rotate and normalize the normal
float3 N = normalize(mul(inNormal,matWorldInv));
//float3 N = normalize(inNormal);
float3 P = mul(inPos,matWorld);
// Add ambient and sun light
Out.Color = vecSkill41.w + DoSunLight(N);
// Add 6 dynamic lights (maximum for vs 1.1)
for (int i=0; i<6; i++)
Out.Color += DoPointLight(P,N,i);
// Add fog
Out.Fog = DoFog(inPos);

// scale the texture coordinates for the masked textures
Out.MaskCoord = inTexCoord0.xy;
Out.BaseCoord = inTexCoord0.xy * vecSkill41.x;
Out.RedCoord = inTexCoord0.xy * vecSkill41.y;
#ifdef GREENMASK
Out.GreenCoord = inTexCoord0.xy * vecSkill41.z;
#endif
return Out;
}

#ifdef PS13 // version 1.3 pixelshader
float4 TMulti_PS_13(TMULTI_VS_OUT In): COLOR
{
// retrieve the pixels for the textures and the masks
float4 MaskColor = tex2D(sMaskTex,In.MaskCoord);
float4 BaseColor = tex2D(sBaseTex,In.BaseCoord);
float4 RedColor = tex2D(sRedTex,In.RedCoord);

// blend the red and green textures over the base texture
#ifdef GREENMASK
float4 GreenColor = tex2D(sGreenTex,In.GreenCoord);
float4 BaseRed = lerp(BaseColor,RedColor,MaskColor.r);
float4 FinalColor = lerp(BaseRed,GreenColor,MaskColor.g);
#else
float4 FinalColor = lerp(BaseColor,RedColor,MaskColor.r);
#endif

// Add the vertex light and shadow map
#ifdef SHADOWMAP
// entry: Shadow Map Offset
// help: Offset light factor 0..1.0
FinalColor *= In.Color + MaskColor.b - 0.25f;
#else
FinalColor *= In.Color;
#endif
FinalColor.a = 1.0f; // prevent transparency
return FinalColor;
}
#endif

// version 1.1 pixelshader
float4 TMulti_PS_11(TMULTI_VS_OUT In): COLOR
{
// retrieve the pixels for the textures and the masks
float4 MaskColor = tex2D(sMaskTex,In.MaskCoord);
float4 BaseColor = tex2D(sBaseTex,In.BaseCoord);
float4 RedColor = tex2D(sRedTex,In.RedCoord);

// blend the red and green textures over the base texture
#ifdef GREENMASK
float4 GreenColor = tex2D(sGreenTex,In.GreenCoord);
float4 BaseRed = lerp(BaseColor,RedColor,MaskColor.r);
float4 FinalColor = lerp(BaseRed,GreenColor,MaskColor.g);
#else
float4 FinalColor = lerp(BaseColor,RedColor,MaskColor.r);
#endif

// Add the vertex light or shadow map, plus the entity ambient
#ifdef SHADOWMAP
FinalColor *= MaskColor.b + vecSkill41.w;
#else
FinalColor *= In.Color;
#endif
FinalColor.a = 1.0f; // prevent transparency
return FinalColor;
}


#ifdef PS13 // version 1.3 pixelshader
technique tmulti3_13
{
pass one
{
sampler[0] = (sMaskTex);
sampler[1] = (sBaseTex);
sampler[2] = (sRedTex);
#ifdef GREENMASK
sampler[3] = (sGreenTex);
#endif

VertexShader = compile vs_1_1 TMulti_VS();
PixelShader = compile ps_1_3 TMulti_PS_13();
}
}
#endif

// fallback for pixelshader 1.1
technique tmulti3_11
{
pass one
{
sampler[0] = (sMaskTex);
sampler[1] = (sBaseTex);
sampler[2] = (sRedTex);
#ifdef GREENMASK
sampler[3] = (sGreenTex);
#endif

VertexShader = compile vs_1_1 TMulti_VS();
PixelShader = compile ps_1_1 TMulti_PS_11();
}
}

// fallback if nothing works
technique fallback { pass one { } }

";
}

// C-Script stuff /////////////////////////////////////////////////////

define ScaleSkin2,SKILL2;
define ScaleSkin3,SKILL3;
define ScaleSkin4,SKILL4;

// uses: ScaleSkin2 ScaleSkin3 ScaleSkin4
action terrain_multi3
{
my.ambient = 40;
my.albedo = 10;
if (d3d_shaderversion < 1111) {
if (ent_skins(my) >= 5) {
my.skin = 5; } // use skin 5 for non-shader hardware
return; }

my.material = mtl_terrainmulti3;

if (my.ScaleSkin2) {
my.skill41 = my.ScaleSkin2; }
else {
//entry: Skin2 default scale
//help: Number of tiles in x/y direction for Skin 2 (Base Texture).
//help: Set this to 1 for an untiled texture.
my.skill41 = 120; }

if (my.ScaleSkin3) {
my.skill42 = my.ScaleSkin3; }
else {
// entry: Skin3 default scale
// help: Number of tiles in x/y direction for Skin 3 (red masked texture).
my.skill42 = 100; }//180

if (my.ScaleSkin4) {
my.skill43 = my.ScaleSkin4; }
else {
// entry: Skin4 default scale
// help: Number of tiles in x/y direction for Skin 4 (green masked texture).
my.skill43 = 80; }

my.skill41 = float(my.skill41);
my.skill42 = float(my.skill42);
my.skill43 = float(my.skill43);
my.skill44 = float(my.ambient/100);
}



Heeeeeeeeeeelp! [Re: Loopix] #44875
04/27/05 08:57
04/27/05 08:57
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
hmm...no help??? Ok...a deal: the one who can solve my problem (blending 5 textures) gets these trees free for use in commercial projects...(just e-mail me via my website).


Re: Heeeeeeeeeeelp! [Re: Loopix] #44876
04/27/05 18:34
04/27/05 18:34
Joined: Dec 2003
Posts: 1,097
Maryland, USA
Steempipe Offline
Serious User
Steempipe  Offline
Serious User

Joined: Dec 2003
Posts: 1,097
Maryland, USA
Hmmm... I like the trees. You'll be getting an email.

Re: Heeeeeeeeeeelp! [Re: Steempipe] #44877
04/27/05 20:33
04/27/05 20:33
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
I knew there are some great people in this forum...Thanks in advance, Steempipe!

Re: Heeeeeeeeeeelp! [Re: Loopix] #44878
04/27/05 21:52
04/27/05 21:52
Joined: Apr 2005
Posts: 134
MN, US
Jalen Offline
Member
Jalen  Offline
Member

Joined: Apr 2005
Posts: 134
MN, US
Me too please!!! I don't have any trees but...I know Loopix! lol


A6 Pro v. 6.60 www.BloodClans.com
Re: Heeeeeeeeeeelp! [Re: Jalen] #44879
04/28/05 10:52
04/28/05 10:52
Joined: Mar 2004
Posts: 217
UK (Peterborough)
KyiasShadow Offline
Member
KyiasShadow  Offline
Member

Joined: Mar 2004
Posts: 217
UK (Peterborough)
Sorry i havent done nothing with the shader yet. not been concentrating on creating my lvl's to much lately, but yeahlove the trees.


A6 Commercial V6.3 1024MB DDR RAM P4 2.8GHz 256MB GeForce FX 5600 160GB HDD
Re: Heeeeeeeeeeelp! [Re: KyiasShadow] #44880
04/28/05 11:58
04/28/05 11:58
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
Well...ther's an other unsolved problem of mine in the scripting forum:
clipping problem
You solve it..you get the trees too!!! (is this forum turning into a marketplace???)

Shader Guru...where are ya? [Re: Steempipe] #44881
05/01/05 21:50
05/01/05 21:50
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
What more can I offer you (the trees are still waiting)? Maybe some grass ...! hmm...I mean real grass models (not the grass you stuff in a steaming pipe...and get dizzy of it). Pleeeease help me with the multitexturing-shader (blending 4-5 textures).

Re: Shader Guru...where are ya? [Re: Loopix] #44882
05/01/05 22:30
05/01/05 22:30
Joined: Oct 2000
Posts: 1,543
Germany
A
Alexander Esslinger Offline
Senior Developer
Alexander Esslinger  Offline
Senior Developer
A

Joined: Oct 2000
Posts: 1,543
Germany
For what shader version do you need the shader? I may look into this tomorrow.

Re: Shader Guru...where are ya? [Re: Alexander Esslinger] #44883
05/01/05 22:40
05/01/05 22:40
Joined: Mar 2005
Posts: 969
ch
Loopix Offline OP
User
Loopix  Offline OP
User

Joined: Mar 2005
Posts: 969
ch
haaaa...someone knows that I (and my problem) still exist, thanks! I think for ver.1.1 would be great...but it could also be for ver 1.3...(ver.2... would work on my card too, but is not that social to share with others...)

Page 1 of 3 1 2 3

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